From ab8c40673845e8d10addf145e815327c4f009375 Mon Sep 17 00:00:00 2001 From: Anthony Talarico Date: Thu, 6 Oct 2016 14:28:21 -0400 Subject: [PATCH] added regions to the shortcode builder, fixed issues between visual and text mode operations. --- css/admin.css | 14 +- js/shortcodeBuilder.js | 576 +++++++++++++++++++++---------- models/admin/pages/shortcode.php | 8 + views/admin/pages/shortcode.html | 11 +- 4 files changed, 423 insertions(+), 186 deletions(-) diff --git a/css/admin.css b/css/admin.css index 42bd5030..c74e49dc 100644 --- a/css/admin.css +++ b/css/admin.css @@ -207,10 +207,10 @@ td.glm-nowrap { } /* Dynamic Select Active Values Box */ -.glm-dynSelect-box, .glm-group-dynSelect-box { +.glm-dynSelect-box, .glm-group-dynSelect-box, .glm-regions-dynSelect-box { width: 90%; } -.glm-dynSelect-box, #shortcode_preview_box, .glm-group-dynSelect-box { +.glm-dynSelect-box, #shortcode_preview_box, .glm-group-dynSelect-box, .glm-regions-dynSelect-box { border: 2px #ddd solid; min-height: 2.5em; min-width: 100px; @@ -218,7 +218,7 @@ td.glm-nowrap { background: #fff; margin: .2em; } -.glm-dynSelect-item, .glm-group-dynSelect-item { +.glm-dynSelect-item, .glm-group-dynSelect-item, .glm-regions-dynSelect-item { border: 2px #ddd solid; border-radius: 5px; background: #eee; @@ -226,7 +226,7 @@ td.glm-nowrap { padding: .2em; margin: .4em; } -.glm-dynSelect-delete, .glm-group-dynSelect-delete { +.glm-dynSelect-delete, .glm-group-dynSelect-delete, .glm-regions-dynSelect-delete { font-weight: bold; font-size: 1.1em; color: #bbb; @@ -234,7 +234,7 @@ td.glm-nowrap { padding-left: .5em; margin-left: .5em; } -.glm-dynSelect-delete:hover, .glm-group-dynSelect-delete:hover { +.glm-dynSelect-delete:hover, .glm-group-dynSelect-delete:hover, .glm-region-dynSelect-delete:hover { font-size: 1.1em; color: #000; cursor: pointer; @@ -365,10 +365,10 @@ input[type=submit], input[type=file] { width:50%;*/ display: block; } -#categoryTitle > span, #groupsTitle > span { +#categoryTitle > span, #groupsTitle > span, #regionsTitle > span { font-weight: bold; } -#categoryTitle, #shortcodesTitle, #groupsTitle { +#categoryTitle, #shortcodesTitle, #groupsTitle, #regionsTitle { font-weight: bold; font-size: 16px; border-bottom: 2px #ddd solid; diff --git a/js/shortcodeBuilder.js b/js/shortcodeBuilder.js index 772bd685..e3c2ce84 100644 --- a/js/shortcodeBuilder.js +++ b/js/shortcodeBuilder.js @@ -11,8 +11,8 @@ jQuery(document).ready(function ($) { var shortcodeDropdown, shortcodeCategory, blankStart, memberView, amenityGroups, listBox, detailBox, target, boxTarget, shortcodeString, editor_shortcodes, category_id, groups_id, shortcodeValues = {}, editor_content, debug = false; - debug = true; + $("#showDetail").hide(); $("#categoryBox").hide(); @@ -22,12 +22,12 @@ jQuery(document).ready(function ($) { $("#packageListAttr").hide(); $('#activeCategories').hide(); $('#activeGroups').hide(); + $('#activeRegions').hide(); $('#glmRemoveShortCode').hide(); - - ///////////////////////////////////////////////////////////////////////////////////////// - // CHANGE MAIN SHORTCODE - ///////////////////////////////////////////////////////////////////////////////////////// +/* + * Change Main Shortcode + */ // fire events and reset settings when switching between shortcodes $("[id$=shortcodeDropdown]").on("change", function () { @@ -38,8 +38,6 @@ jQuery(document).ready(function ($) { if($('#id-scDropdown').length) document.getElementById('id-scDropdown').options[0].selected = 'selected'; -// uncheckAll(); - // delete the object properties to reset the object shortcodeString = ""; @@ -62,10 +60,11 @@ jQuery(document).ready(function ($) { $("#category-scDropdown").show(); $(".scCategories").show(); $("#amenitygroup-scDropdown").show(); + $("#region-search-scDropdown").show(); $('#activeCategories').show(); $('#activeGroups').show(); + $('#activeRegions').show(); } - if(shortcodeDropdown === "glm-members-packaging-list"){ $("#blank-start-scDropdown").hide(); $("#showCategory").hide(); @@ -80,13 +79,8 @@ jQuery(document).ready(function ($) { $('#activeCategories').hide(); $('#activeGroups').hide(); } - }); - - //////////////////////////////////////////////////////////////////// - // PAGE LOAD FUNCTIONS - ///////////////////////////////////////////////////////////////////// // shortcode attribute name from dropdowns containing '-scDropdown' in their ID // Then append the values to the shortcode object $("[id$=-scDropdown]").on("change", function () { @@ -98,14 +92,6 @@ jQuery(document).ready(function ($) { shortcodeValues[target] = targetVal; } }); - // use jquery dialog to separate the checkbox lists - $("#showCategory").on("click", function () { - $("#categoryBox").dialog().dialog("option", "width", 450 ); - }); - $("#detailBtn").on("click", function () { - $("#showDetail").dialog().dialog("option", "width", 422); - }); - // get shortcodes between square brackets var regExp = /\[([^)]+)\]/; @@ -121,14 +107,9 @@ jQuery(document).ready(function ($) { } else { return; } - } else { - - // get the shortcode from the editor with [ ] as the delimiters - + // get the shortcode from the editor with [ ] as the delimiter editor_content = regExp.exec($("#content").val()); - - // getting an array as the value from the previous reExp, will need to investigate if(regExp.exec($("#content").val())){ return editor_content[0]; } @@ -154,8 +135,8 @@ jQuery(document).ready(function ($) { if ( editor_shortcodes.match( /glm-members-list .* amenity-groups="(.*?)"/ ) !== null ) { amenityGroups = editor_shortcodes.match( /glm-members-list .* amenity-groups="(.*?)"/ )[1]; groups_id = amenityGroups.split(','); - } else if ( editor_shortcodes.match( /glm-members-list .* amenity-groups=""/ ) !== null ) { - groups_id = editor_shortcodes.match( /glm-members-list .* amenity-groups=""/ )[1]; + } else if ( editor_shortcodes.match( /glm-members-list amenity-groups=""/ ) !== null ) { + groups_id = editor_shortcodes.match( /glm-members-list amenity-groups=""/ )[1]; } if ( editor_shortcodes.match( /glm-members-list .* blank-start="(.*?)"/ ) !== null ) { blankStart = editor_shortcodes.match(/glm-members-list .* blank-start="(.*?)"/)[1]; @@ -219,27 +200,31 @@ jQuery(document).ready(function ($) { * Category Selection these functions fire whenever the 'select category' dropdown is changed */ ////////////////////////////////////////////////////////////////////////////////////////////// - var content = $("#content"), editor_category_index, ids, id_string, new_ids = new Array(), empty_space, count; + var content = $("#content"), editor_category_index, ids, id_string, new_ids = new Array(), empty_space, category_missing; $('#category-scDropdown').change( function() { editor_shortcodes = get_tinymce_content(); + + if ( editor_shortcodes ) { + if ( editor_shortcodes.match( /glm-members-list category="(.*?)"/ ) !== null || editor_shortcodes.match( /glm-members-list .* category="(.*?)"/ ) ){ + category_missing = false; + ids = editor_shortcodes.match( /category="(.*?)"/ )[1]; - if ( editor_shortcodes ) { - if ( editor_shortcodes.match( /category="(.*?)"/ ) !== null ){ - category_id = editor_shortcodes.match( /glm-members-list category="(.*?)"/ )[1]; - - if ( category_id !== "" ) { - category_id = category_id.split(','); + if ( ids !== "" ) { + ids = ids.split(','); - ids = category_id.join(','); - empty_space = false; + ids = ids.join(','); + empty_space = false; } else { ids = 'category=""'; - // this determines if the category option is blank "" to determine if the jquery replace method works properly + // this determines if the groups option is blank "" to determine if the jquery replace method works properly empty_space = true; } + } else { + category_missing = true; + empty_space = false; } } @@ -257,7 +242,6 @@ jQuery(document).ready(function ($) { } }); - // If not found, Add the category if (!found) { $('#activeCategories').append('
' + + regionsName.trim() + ' (ID: ' + regionsValue + ')' + 'X' + + '
'); + } + + // reset the id string after each set of iterations + regions_id_string = ''; + + $.each($(".glm-regions-dynSelect-item"), function () { + if($.inArray($(this).data("id"), regions_new_ids) === -1){ + regions_new_ids.push($(this).data("id")); + } + }); + + // if more than one region id in the array, join together with ',' otherwise set the id string to a single value + if ( regions_new_ids.length > 1 ){ + regions_id_string = regions_new_ids.join(','); + } else if ( regions_new_ids.length === 1 ) { + regions_id_string = regions_new_ids[0]; + } + + // replace the current content in either the visual or text editor and replace it with a filtered version of the regions + if ( $("#content").css("display") !== "none" ) { + editor_content = content.val(); + if ( regions_empty_space ) { + editor_content = editor_content.replace( regions_id, 'region-search="' + regions_id_string + '"' ); + content.val( editor_content ); + } else if ( regions_missing ) { + var shortcodeReg = /(\[glm-members-list [^\]]*)(\])/; + editor_content = editor_content.replace( shortcodeReg, '$1 region-search="' + regions_id_string + '"$2' ); + content.val( editor_content ); + } else { + editor_content = editor_content.replace( 'region-search="' + regions_id, 'region-search="' + regions_id_string ); + content.val( editor_content ); + } + } else if ( tinyMCE.activeEditor !== null ) { + if ( regions_empty_space ) { + editor_content = tinyMCE.get('content').getContent({format: 'raw'}); + editor_content = editor_content.replace(regions_id, 'region-search="' + regions_id_string + '"' ); + tinyMCE.activeEditor.setContent(editor_content); + } else if ( regions_missing ) { + editor_content = tinyMCE.get('content').getContent({format: 'raw'}); + var shortcodeReg = /(\[glm-members-list [^\]]*)(\])/; + var regionsMatch = editor_content.match( shortcodeReg ); + editor_content = editor_content.replace( shortcodeReg, '$1 region-search="' + regions_id_string + '"$2' ); + tinyMCE.activeEditor.setContent(editor_content); + } else { + editor_content = tinyMCE.get('content').getContent({format: 'raw'}); + editor_content = editor_content.replace('region-search="' + regions_id, 'region-search="' + regions_id_string); + tinyMCE.activeEditor.setContent(editor_content); + } + } + + // Reset picklist + $('#regions-scDropdown').val('Select Regions'); + }); // Blank Start change event // These fire when the blank-start select is changed + var blank_start_id, blank_start_missing, blank_start_empty_space; $('#blank-start-scDropdown').change(function(){ - editor_shortcodes = get_tinymce_content(); - editor_content = content.val(); - if ( editor_shortcodes ) { - if ( editor_shortcodes.match( /glm-members-list .* blank-start="(.*?)"/ ) !== null ) { - blankStart = editor_shortcodes.match(/glm-members-list .* blank-start="(.*?)"/)[1]; - if ( $("#content").css("display") !== "none" ) { - editor_content = editor_content.replace( 'blank-start="' + blankStart +'"', 'blank-start="' + $(this).val() + '"' ); - } else if ( tinyMCE.activeEditor !== null ) { - editor_content = tinyMCE.get('content').getContent({format: 'raw'}); - editor_content = editor_content.replace( 'blank-start="' + blankStart +'"', 'blank-start="' + $(this).val() + '"' ); - tinyMCE.activeEditor.setContent(editor_content); + editor_shortcodes = get_tinymce_content(); + if ( editor_shortcodes ) { + if ( editor_shortcodes.match( /glm-members-list blank-start="(.*?)"/ ) !== null || editor_shortcodes.match( /glm-members-list .* blank-start="(.*?)"/ ) !== null ){ + blank_start_missing = false; + blank_start_id = editor_shortcodes.match( /blank-start="(.*?)"/ )[1]; + + if ( blank_start_id !== "" ) { + blank_start_id = blank_start_id.split(','); + + blank_start_id = blank_start_id.join(','); + blank_start_empty_space = false; + } else { + + blank_start_id = 'blank-start=""'; + + // this determines if the groups option is blank "" to determine if the jquery replace method works properly + blank_start_empty_space = true; } } else { + blank_start_missing = true; + blank_start_empty_space = false; + } + } + if ( $("#content").css("display") !== "none" ) { + editor_content = content.val(); + if ( blank_start_empty_space ) { + console.log("empty space"); + editor_content = editor_content.replace( blank_start_id, 'blank-start="' + $(this).val() + '"' ); + content.val( editor_content ); + } else if ( blank_start_missing ) { + console.log("blank start"); + var shortcodeReg = /(\[glm-members-list [^\]]*)(\])/; + var blankMatch = editor_content.match( shortcodeReg ); + console.log(editor_content); + editor_content = editor_content.replace( shortcodeReg, '$1 blank-start="' + $(this).val() + '"$2' ); + content.val( editor_content ); + console.log(blankMatch); + } else { + console.log("none"); + editor_content = editor_content.replace( 'blank-start="' + blank_start_id, 'blank-start="' + $(this).val() ); + content.val( editor_content ); + } + } else if ( tinyMCE.activeEditor !== null ) { + if ( blank_start_empty_space ) { + console.log("empty"); editor_content = tinyMCE.get('content').getContent({format: 'raw'}); - var shortcodeReg = /(\[glm-members-list .*)(\])/; - var groupMatch = editor_content.match( shortcodeReg ); - editor_content = editor_content.replace( shortcodeReg, '$1 blank-start="' + $(this).val() + '"$2' ); + editor_content = editor_content.replace(blank_start_id, 'blank-start="' + $(this).val() + '"' ); + tinyMCE.activeEditor.setContent(editor_content); + } else if ( blank_start_missing ) { + editor_content = tinyMCE.get('content').getContent({format: 'raw'}); + var shortcodeReg = /(\[glm-members-list [^\]]*)(\])/; + console.log(editor_content); + var blankMatch = editor_content.match( shortcodeReg ); + editor_content = editor_content.replace( shortcodeReg, '$1 blank-start="' + $(this).val() + '"$2' ); + tinyMCE.activeEditor.setContent(editor_content); + console.log(blankMatch); + } else { + console.log("none"); + editor_content = tinyMCE.get('content').getContent({format: 'raw'}); + editor_content = editor_content.replace('blank-start="' + blank_start_id, 'blank-start="' + $(this).val() ); tinyMCE.activeEditor.setContent(editor_content); } } @@ -436,30 +573,64 @@ jQuery(document).ready(function ($) { // View dropdown // These events fire when the View select is changed + var view_id, view_missing, view_empty_space; $('#view-scDropdown').change(function(){ editor_shortcodes = get_tinymce_content(); - editor_content = content.val(); - if ( editor_shortcodes ) { - if ( editor_shortcodes.match( /glm-members-list .* view="(.*?)"/ ) !== null ) { - memberView = editor_shortcodes.match(/glm-members-list .* view="(.*?)"/)[1]; - if ( $("#content").css("display") !== "none" ) { - editor_content = editor_content.replace( 'view="' + memberView +'"', 'view="' + $(this).val() + '"' ); - } else if ( tinyMCE.activeEditor !== null ) { - editor_content = tinyMCE.get('content').getContent({format: 'raw'}); - editor_content = editor_content.replace( 'view="' + memberView +'"', 'view="' + $(this).val() + '"' ); - tinyMCE.activeEditor.setContent(editor_content); + if ( editor_shortcodes ) { + if ( editor_shortcodes.match( /glm-members-list view="(.*?)"/ ) !== null || editor_shortcodes.match( /glm-members-list .* view="(.*?)"/ ) !== null ){ + view_missing = false; + view_id = editor_shortcodes.match( /view="(.*?)"/ )[1]; + + if ( view_id !== "" ) { + view_id = view_id.split(','); + + view_id = view_id.join(','); + view_empty_space = false; + } else { + + view_id = 'view=""'; + + // this determines if the groups option is blank "" to determine if the jquery replace method works properly + view_empty_space = true; } } else { + view_missing = true; + view_empty_space = false; + } + } + if ( $("#content").css("display") !== "none" ) { + editor_content = content.val(); + if ( view_empty_space ) { + editor_content = editor_content.replace( view_id, 'view="' + $(this).val() + '"' ); + content.val( editor_content ); + } else if ( view_missing ) { + var shortcodeReg = /(\[glm-members-list [^\]]*)(\])/; + editor_content = editor_content.replace( shortcodeReg, '$1 view="' + $(this).val() + '"$2' ); + content.val( editor_content ); + } else { + editor_content = editor_content.replace( 'view="' + view_id, 'view="' + $(this).val() ); + content.val( editor_content ); + } + } else if ( tinyMCE.activeEditor !== null ) { + if ( view_empty_space ) { editor_content = tinyMCE.get('content').getContent({format: 'raw'}); - var shortcodeReg = /(\[glm-members-list .*)(\])/; - var groupMatch = editor_content.match( shortcodeReg ); - editor_content = editor_content.replace( shortcodeReg, '$1 view="' + $(this).val() + '"$2' ); + editor_content = editor_content.replace(view_id, 'view="' + $(this).val() + '"' ); + tinyMCE.activeEditor.setContent(editor_content); + } else if ( view_missing ) { + editor_content = tinyMCE.get('content').getContent({format: 'raw'}); + var shortcodeReg = /(\[glm-members-list [^\]]*)(\])/; + var viewMatch = editor_content.match( shortcodeReg ); + console.log(viewMatch); + editor_content = editor_content.replace( shortcodeReg, '$1 view="' + $(this).val() + '"$2' ); + tinyMCE.activeEditor.setContent( editor_content ); + } else { + editor_content = tinyMCE.get('content').getContent({format: 'raw'}); + editor_content = editor_content.replace('view="' + view_id, 'view="' + $(this).val() ); tinyMCE.activeEditor.setContent(editor_content); } } }); - function insert_tag( text ) { if ( tinyMCE && tinyMCE.activeEditor ) { tinyMCE.activeEditor.selection.setContent(text); @@ -467,56 +638,14 @@ jQuery(document).ready(function ($) { return false; } - ///////////////////////////////////////////////////////////////////////////////////////////////// - // INSERT SHORTCODE FUNCTION these fire when the 'insert shortcode' button is clicked - ///////////////////////////////////////////////////////////////////////////////////////////////// // generate the shortcode into a string and insert into the content upon clicking + var replace_me, replace_with; $("[id$=generate]").on("click", function () { - count = 0; - if ( number_of_categories ) { - count = number_of_categories; - count++; - } else { - count++; - } // enforce the selection of a shortcode if ( shortcodeDropdown ) { // set up properties for shortcode lists - if ( shortcodeDropdown === "glm-members-list" ) { - var listValues = $('input[name="listBox"]:checkbox:checked').map( function() { - boxTarget = $(this).attr("class").slice(0, -5); - return this.value; - }).get(); - - var listString = ""; - listValues.forEach( function( value ) { - listString += value + ","; - }); - - if ( listValues !== "" ) { - listString = listString.replace( /,\s*$/, "" ); - shortcodeValues[boxTarget] = listString; - } - - // set up properties for detail shortcode - } else if( shortcodeDropdown === "glm-member-detail"){ - var detailValues = $('input[name="detailBox"]:checkbox:checked').map( function() { - boxTarget = $(this).attr("class").slice(0, -7); - return this.value; - }).get(); - - var detailString = ''; - detailValues.forEach( function( value ) { - detailString += value + ","; - }); - if ( detailValues !== "" ) { - detailString = detailString.replace( /,\s*$/, "" ); - shortcodeValues[boxTarget] = detailString; - } - } - // start the shortcode string that will be added to the tinymce editor - shortcodeString = '
[' + shortcodeDropdown; + shortcodeString = '[' + shortcodeDropdown; // populate the shortcode object with all of the shortcode attributes and their values for (var key in shortcodeValues) { @@ -526,18 +655,49 @@ jQuery(document).ready(function ($) { } } } - + // add the list of category ids instead of the single value originally inserted - if ( shortcodeString.match( /glm-members-list category="(.*?)"/ ) !== null ) { - category_id = shortcodeString.match( /glm-members-list category="(.*?)"/ )[1]; + if ( shortcodeString.match( /glm-members-list category="(.*?)"/ ) !== null || shortcodeString.match( /glm-members-list .* category="(.*?)"/ ) ) { + if(shortcodeString.match( /glm-members-list category="(.*?)"/ ) !== null ){ + category_id = shortcodeString.match( /glm-members-list category="(.*?)"/ )[1]; + } else if( shortcodeString.match( /glm-members-list .* category="(.*?)"/ ) !== null ){ + category_id = shortcodeString.match( /glm-members-list .* category="(.*?)"/ )[1]; + } category_id = category_id.split(','); ids = category_id.join(','); - shortcodeString = shortcodeString.replace(ids, id_string); + replace_me = 'category="'+ids+'"'; + replace_with = 'category="'+id_string+'"'; + shortcodeString = shortcodeString.replace(replace_me, replace_with); + } + if( shortcodeString.match( /glm-members-list amenity-groups="(.*?)"/ ) !== null || shortcodeString.match( /glm-members-list .* amenity-groups="(.*?)"/ ) ){ + if( shortcodeString.match( /glm-members-list amenity-groups="(.*?)"/ ) !== null ){ + group_ids = shortcodeString.match( /glm-members-list amenity-groups="(.*?)"/ )[1]; + } else if( shortcodeString.match( /glm-members-list .* amenity-groups="(.*?)"/ ) !== null){ + group_ids = shortcodeString.match( /glm-members-list .* amenity-groups="(.*?)"/ )[1]; + } + group_ids = group_ids.split(','); + group_ids = group_ids.join(','); + replace_me = 'amenity-groups="'+group_ids+'"'; + replace_with = 'amenity-groups="'+group_id_string+'"'; + shortcodeString = shortcodeString.replace(replace_me, replace_with); + } + if( shortcodeString.match( /glm-members-list region-search="(.*?)"/ ) !== null || shortcodeString.match( /glm-members-list .* region-search="(.*?)"/ ) !== null ){ + if( shortcodeString.match( /glm-members-list region-search="(.*?)"/ ) !== null ){ + regions_id = shortcodeString.match( /glm-members-list region-search="(.*?)"/ )[1]; + }else if( shortcodeString.match( /glm-members-list .* region-search="(.*?)"/ ) !== null ){ + regions_id = shortcodeString.match( /glm-members-list .* region-search="(.*?)"/ )[1]; + } + regions_id = regions_id.split(','); + regions_id = regions_id.join(','); + replace_me = 'region-search="'+regions_id+'"'; + replace_with = 'region-search="'+regions_id_string+'"'; + shortcodeString = shortcodeString.replace(replace_me, replace_with); } - shortcodeString += ']
'; + + shortcodeString += ']'; // insert shortcode at current cursor position - if ( $("#content").css("display") !== "none" ) { + if ( $("#content").css("display") !== "none" ) { var cursorPos = $('#content').prop( 'selectionStart' ); var v = $('#content').val(); var textBefore = v.substring(0, cursorPos ); @@ -559,17 +719,29 @@ jQuery(document).ready(function ($) { * Deletes the shortcode. */ $('#glmRemoveShortCode').on('click', function(){ + + editor_shortcodes = get_tinymce_content(); + var member_list_shortcodes = (editor_shortcodes.match(/glm-members-list/g) || []).length; var member_package_shortcodes = (editor_shortcodes.match(/glm-members-packaging-list/g) || []).length; if ( member_list_shortcodes ) { - console.log( 'removing member list shortcode' ); // find the short code and remove it! - editor_content = tinyMCE.get('content').getContent({format: 'raw'}); + var shortcodeReg = /(\[glm-members-list .*?])/; + if ( $("#content").css("display") !== "none" ) { + editor_content = content.val(); + editor_content = editor_content.replace( shortcodeReg, '' ); + content.val( editor_content ); + } else if ( tinyMCE.activeEditor !== null ) { + editor_content = tinyMCE.get('content').getContent({format: 'raw'}); + editor_content = editor_content.replace( shortcodeReg, '' ); + tinyMCE.activeEditor.setContent(editor_content); + } + var shortcodeReg = /(\[glm-members-list .*?])/; - editor_content = editor_content.replace( shortcodeReg, '' ); - tinyMCE.activeEditor.setContent(editor_content); + $('.glm-dynSelect-item').remove(); $('.glm-group-dynSelect-item').remove(); + $('.glm-regions-dynSelect-item').remove(); $("#showDetail").hide(); $("#categoryBox").hide(); $("#showCategory").hide(); @@ -578,12 +750,17 @@ jQuery(document).ready(function ($) { $("#packageListAttr").hide(); $('#shortcodeDropdown').val('glm-members-list'); window.onload = document.getElementById('shortcodeDropdown').options[0].selected = 'selected'; + reset_options(); $('#shortcodeDropdown').change(); $('#shortcodeDropdown').show(); $('#activeCategories').hide(); $('#activeGroups').hide(); + $('#activeRegions').hide(); + ids, groups_id, regions_id, id_string, group_id_string, regions_id_string = ''; + group_new_ids.length = 0; + new_ids.length = 0; + regions_new_ids.length = 0; } else if ( member_package_shortcodes ) { - console.log( 'removing member package list shortcode' ); // find the short code and remove it! editor_content = tinyMCE.get('content').getContent({format: 'raw'}); var shortcodeReg = /(\[glm-members-packaging-list .*?])/; @@ -595,21 +772,20 @@ jQuery(document).ready(function ($) { $('#generate').show(); }); - - ////////////////////////////////////////////////////////////////////////////////////// - // DELETE CATEGORY these fire when a category box's X is clicked to delete a category - ///////////////////////////////////////////////////////////////////////////////////// // Action to de-select a category and dynamically adjust the shortcode categories in the editor - $('.catDelete').live('click', function() { - editor_shortcodes = get_tinymce_content(); - if(editor_shortcodes && editor_shortcodes.match(/glm-members-list category="(.*?)"/) !== null){ - category_id = editor_shortcodes.match(/glm-members-list category="(.*?)"/)[1]; + if( (editor_shortcodes && editor_shortcodes.match(/glm-members-list category="(.*?)"/) !== null) || ( editor_shortcodes && editor_shortcodes.match(/glm-members-list .* category="(.*?)"/) !== null)){ + if( editor_shortcodes.match(/glm-members-list category="(.*?)"/) ){ + category_id = editor_shortcodes.match(/glm-members-list category="(.*?)"/)[1]; + } else { + category_id = editor_shortcodes.match(/glm-members-list .* category="(.*?)"/)[1]; + } + category_id = category_id.split(','); ids = category_id.join(','); - } + } $(this).parent().remove(); @@ -637,9 +813,48 @@ jQuery(document).ready(function ($) { editor_content = tinyMCE.get('content').getContent({format: 'raw'}); editor_content = editor_content.replace('category="' + ids, 'category="' + id_string); tinyMCE.activeEditor.setContent(editor_content); - } + }); + + $('.regionDelete').live('click', function() { + editor_shortcodes = get_tinymce_content(); + if( (editor_shortcodes && editor_shortcodes.match(/glm-members-list region-search="(.*?)"/) !== null) || (editor_shortcodes && editor_shortcodes.match(/glm-members-list .* region-search="(.*?)"/) !== null) ){ + if(editor_shortcodes.match(/glm-members-list region-search="(.*?)"/) ){ + regions_id = editor_shortcodes.match(/glm-members-list region-search="(.*?)"/)[1]; + } else { + regions_id = editor_shortcodes.match(/glm-members-list .* region-search="(.*?)"/)[1]; + } + regions_id = regions_id.split(','); + regions_id = regions_id.join(','); + } + + $(this).parent().remove(); + + // reset the array after each set of iterations + regions_new_ids.length = 0; + + $.each($(".glm-regions-dynSelect-item"), function () { + if($.inArray($(this).data("id"), regions_new_ids) === -1){ + regions_new_ids.push($(this).data("id")); + } + }); + + // create a string of id's from the array + regions_id_string = regions_new_ids.join(','); + + // get and replace current editor content + if($("#content").css("display") !== "none"){ + + editor_content = content.val(); + editor_content = editor_content.replace('region-search="' + regions_id, 'region-search="' + regions_id_string ); + content.val(editor_content); + } else if(tinyMCE.activeEditor !== null){ + + editor_content = tinyMCE.get('content').getContent({format: 'raw'}); + editor_content = editor_content.replace('region-search="' + regions_id, 'region-search="' + regions_id_string); + tinyMCE.activeEditor.setContent(editor_content); + } }); // group delete @@ -650,6 +865,10 @@ jQuery(document).ready(function ($) { groups_id = editor_shortcodes.match(/glm-members-list .* amenity-groups="(.*?)"/)[1]; groups_id = groups_id.split(','); group_ids = groups_id.join(','); + } else if(editor_shortcodes && editor_shortcodes.match(/glm-members-list amenity-groups="(.*?)"/) !== null){ + groups_id = editor_shortcodes.match(/glm-members-list amenity-groups="(.*?)"/)[1]; + groups_id = groups_id.split(','); + group_ids = groups_id.join(','); } $(this).parent().remove(); @@ -679,8 +898,6 @@ jQuery(document).ready(function ($) { }); - ///////////////////////////////////////////////////////////////////////////////////////////////// - // MAINENANCE these were necessary to reset the dropdowns but most of them are no longer needed // reset dropdowns and checkboxes to default values on page reload var scd = document.getElementById('shortcodeDropdown'); var catscd = document.getElementById('category-scDropdown'); @@ -689,6 +906,7 @@ jQuery(document).ready(function ($) { var members = document.getElementById('member-scDropdown'); var view = document.getElementById('view-scDropdown'); var groups = document.getElementById('amenitygroup-scDropdown'); + var regions = document.getElementById('region-search-scDropdown'); if ( editor_shortcodes && number_of_categories) { if ( number_of_categories ) { @@ -705,33 +923,39 @@ jQuery(document).ready(function ($) { $('#shortcodeDropdown').change(); $('#shortcodeDropdown').hide(); } - if ( scd && !editor_shortcodes && !number_of_categories) { - window.onload = document.getElementById('shortcodeDropdown').options[0].selected = 'selected'; - } - if ( catscd ) { - window.onload = document.getElementById('category-scDropdown').options[0].selected = 'selected'; - } - if ( blank ) { - if ( blankStart ) { - $('#blank-start-scDropdown').val( blankStart ); - } else { - window.onload = document.getElementById('blank-start-scDropdown').options[0].selected = 'selected'; + function reset_options(){ + if ( scd && !editor_shortcodes && !number_of_categories) { + window.onload = document.getElementById('shortcodeDropdown').options[0].selected = 'selected'; } - } - if ( list ) { - window.onload = document.getElementById('type-scList').options[0].selected = 'selected'; - } - if ( members ) { - window.onload = document.getElementById('member-scDropdown').options[0].selected = 'selected'; - } - if ( view ) { - if ( memberView ) { - $('#view-scDropdown').val( memberView ); - } else { - window.onload = document.getElementById('view-scDropdown').options[0].selected = 'selected'; + if ( catscd ) { + window.onload = document.getElementById('category-scDropdown').options[0].selected = 'selected'; + } + if ( blank ) { + if ( blankStart ) { + $('#blank-start-scDropdown').val( blankStart ); + } else { + window.onload = document.getElementById('blank-start-scDropdown').options[0].selected = 'selected'; + } + } + if ( list ) { + window.onload = document.getElementById('type-scList').options[0].selected = 'selected'; + } + if ( members ) { + window.onload = document.getElementById('member-scDropdown').options[0].selected = 'selected'; + } + if ( view ) { + if ( memberView ) { + $('#view-scDropdown').val( memberView ); + } else { + window.onload = document.getElementById('view-scDropdown').options[0].selected = 'selected'; + } + } + if ( groups ) { + window.onload = document.getElementById('amenitygroup-scDropdown').options[0].selected = 'selected'; + } + if ( regions ) { + window.onload = document.getElementById('region-search-scDropdown').options[0].selected = 'selected'; } } - if ( groups ) { - window.onload = document.getElementById('amenitygroup-scDropdown').options[0].selected = 'selected'; - } + reset_options(); }); diff --git a/models/admin/pages/shortcode.php b/models/admin/pages/shortcode.php index 8bf2adcb..3b79e127 100644 --- a/models/admin/pages/shortcode.php +++ b/models/admin/pages/shortcode.php @@ -187,12 +187,20 @@ class GlmMembersAdmin_pages_shortcode FROM " . GLM_MEMBERS_PLUGIN_DB_PREFIX . "amenity_groups ORDER BY name"; $amenGroups = $this->wpdb->get_results( $amenGroupSql, ARRAY_A ); + + // regions. + $regionSql = " + SELECT id,name + FROM " . GLM_MEMBERS_PLUGIN_DB_PREFIX . "regions + ORDER BY name"; + $regions = $this->wpdb->get_results( $regionSql, ARRAY_A ); // Compile template data $templateData = array( 'categories' => $categories, 'amenGroups' => $amenGroups, 'shortCodes' => $shortCodes, + 'regions' => $regions ); // Return status, suggested view, and data to controller diff --git a/views/admin/pages/shortcode.html b/views/admin/pages/shortcode.html index 91931cfb..530b0e71 100644 --- a/views/admin/pages/shortcode.html +++ b/views/admin/pages/shortcode.html @@ -2,9 +2,7 @@
+
Categories
Amenity Groups
+
Regions
-- 2.17.1