From: Steve Sutton Date: Wed, 29 Jun 2016 19:31:08 +0000 (-0400) Subject: Adding amenity-groups into shortcode editing X-Git-Tag: v2.1.16^2~5^2~2 X-Git-Url: http://cvs2.gaslightmedia.com/gitweb/?a=commitdiff_plain;h=133dea52d38d4247c1ff9ec879558869b5120cc5;p=WP-Plugins%2Fglm-member-db.git Adding amenity-groups into shortcode editing Just for the editing of a current shortcode. It will add the amenity-groups. --- diff --git a/classes/glmPluginSupport.php b/classes/glmPluginSupport.php index 0eb771ca..543d225f 100644 --- a/classes/glmPluginSupport.php +++ b/classes/glmPluginSupport.php @@ -350,11 +350,11 @@ return; // Off for now ** Need to make this switchable in management $value = $this->wpdb->get_var("SELECT ID FROM ". $this->wpdb->posts." WHERE post_name = '" . $postName."'"); return $value; } - + public function nicePrint($array){ echo '
', print_r($array), '
'; } - + /** * * Shortcode Builder Functions @@ -368,11 +368,11 @@ return; // Off for now ** Need to make this switchable in management $this->shortcodeCounter += 1; } public function glmMembersShortcode(){ - + // load shortcodeBuilder.js when the shortcode function has been fired if it hasn't been enqueued yet if( ! wp_script_is( 'jquery-ui-dialog', 'enqueued' ) ){ wp_enqueue_style('jquery-style', 'http://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/themes/smoothness/jquery-ui.css'); - wp_enqueue_script('jquery-ui-dialog', false, array('jquery'), false, true); + wp_enqueue_script('jquery-ui-dialog', false, array('jquery'), false, true); } function custom_js_css() { @@ -430,8 +430,8 @@ return; // Off for now ** Need to make this switchable in management //dropdown for categories echo ''; // dropdown for Amenity Groups - /* - echo ''; echo ''; + foreach ( $amenGroups as $group ) { + echo ''; + } echo ''; - */ // packaging addOn mark up if(file_exists(GLM_MEMBERS_PACKAGING_PLUGIN_PATH . "/setup/shortcodeBuilder.php")){ @@ -466,7 +472,7 @@ return; // Off for now ** Need to make this switchable in management } // list and detail buttons to open dialog for member db 'show' attr options - + // echo ''; echo ''; @@ -476,6 +482,8 @@ return; // Off for now ** Need to make this switchable in management echo '
Categories
'; + echo '
Amenity Groups
'; + // echo '
Shortcodes
'; echo ''; } @@ -483,7 +491,7 @@ return; // Off for now ** Need to make this switchable in management public function shortcode_builder_markup(){ require_once(GLM_MEMBERS_PLUGIN_CLASS_PATH.'/data/dataCategories.php'); - + $listAttr = $this->config['addOns']['glm-member-db']['shortcodes']['glm-members-list']['attributes']; $detailAttr = $this->config['addOns']['glm-member-db']['shortcodes']['glm-member-detail']['attributes']; $glmcat = new GlmDataCategories($this->wpdb, $this->config); @@ -501,7 +509,7 @@ return; // Off for now ** Need to make this switchable in management foreach($addOnSlugs as $addOn){ if ($this->config['addOns'][$addOn]['shortcodes']) { $shortCodeList[] = $this->config['addOns'][$addOn]['shortcodes']; - + } } @@ -528,11 +536,11 @@ return; // Off for now ** Need to make this switchable in management shortcode_builder_markup_template($shortCodes, $list); - + // This button will add another shortcode editor //echo ''; @@ -569,22 +577,22 @@ function glmMembersAdminNotices($windowed = true)
'.date('m/d/Y G:i:s A').'
'.GLM_MEMBERS_PLUGIN_NAME.' - Debug Data
- '; + '; // Display alerts - $alerts = get_option('glmMembersAdminNoticeAlerts'); - if(is_array($alerts)) { - $output .= '

Alerts

'; - foreach($alerts as $a) { - $output .= $a.'
'; - } - } else { - $output .= '

Alerts

'; - } + $alerts = get_option('glmMembersAdminNoticeAlerts'); + if(is_array($alerts)) { + $output .= '

Alerts

'; + foreach($alerts as $a) { + $output .= $a.'
'; + } + } else { + $output .= '

Alerts

'; + } $output .= '

'; delete_option('glmMembersAdminNoticeAlerts'); - // Display process messages + // Display process messages $process = get_option('glmMembersAdminNoticeProcess'); $output .= '

Processing

'; if(is_array($process)) { @@ -595,7 +603,7 @@ function glmMembersAdminNotices($windowed = true) $output .= '

'; delete_option('glmMembersAdminNoticeProcess'); - // Display data blocks table of contents then the data blocks + // Display data blocks table of contents then the data blocks $dataBlocks = get_option('glmMembersAdminNoticeDataBlocks'); $output .= '

Data Blocks

    '; $n = 0; diff --git a/css/admin.css b/css/admin.css index bc527c1e..91bcab4f 100644 --- a/css/admin.css +++ b/css/admin.css @@ -23,13 +23,13 @@ color: blue; } .glm-right { - float: right; + float: right; } .glm-left { - float: left; + float: left; } .glm-indent { - margin-left: 2em; + margin-left: 2em; } .glm-center { text-align: center; @@ -45,18 +45,18 @@ white-space: nowrap; } .glm-hidden { - display: none !important; + display: none !important; } .glm-button { margin-left: 4px !important; - margin-right: 4px !important; + margin-right: 4px !important; } .glm-button-small { font-size: 0.9em !important; padding: .0em .3em 0em .3em !important; margin-right: 2px !important; line-height: 1.8em !important; - height: 1.8em !important; + height: 1.8em !important; } /* Admin Area - General */ @@ -65,7 +65,7 @@ border: 1px #ccc solid; padding: 1em; background-color: #fff; -} +} .glm-item-container { border: 1px #ccc solid; padding: .4em; @@ -81,7 +81,7 @@ /* Admin Forms */ .glm-bad-input-area { - background: #FFaBa9 !important; + background: #FFaBa9 !important; } .glm-form-bad-input { background: #FFaBa9; @@ -127,7 +127,7 @@ white-space: nowrap; padding-right: 1em; padding-bottom: .4em; - width: 1%; /* used to keep header fields on a line with td's to be as narrow as they can be without breaking the text */ + width: 1%; /* used to keep header fields on a line with td's to be as narrow as they can be without breaking the text */ } .glm-admin-table td { text-align: left; @@ -194,7 +194,10 @@ td.glm-nowrap { } /* Dynamic Select Active Values Box */ -.glm-dynSelect-box, #shortcode_preview_box { +.glm-dynSelect-box, .glm-group-dynSelect-box { + width: 90%; +} +.glm-dynSelect-box, #shortcode_preview_box, .glm-group-dynSelect-box { border: 2px #ddd solid; min-height: 2.5em; min-width: 100px; @@ -202,7 +205,7 @@ td.glm-nowrap { background: #fff; margin: .2em; } -.glm-dynSelect-item { +.glm-dynSelect-item, .glm-group-dynSelect-item { border: 2px #ddd solid; border-radius: 5px; background: #eee; @@ -210,7 +213,7 @@ td.glm-nowrap { padding: .2em; margin: .4em; } -.glm-dynSelect-delete { +.glm-dynSelect-delete, .glm-group-dynSelect { font-weight: bold; font-size: 1.1em; color: #bbb; @@ -218,22 +221,22 @@ td.glm-nowrap { padding-left: .5em; margin-left: .5em; } -.glm-dynSelect-delete:hover { +.glm-dynSelect-delete:hover, .glm-group-dynSelect-delete { font-size: 1.1em; color: #000; cursor: pointer; } /* Map Edit */ -.glm-map-edit { - width:90%; +.glm-map-edit { + width:90%; min-width: 400px; - height:400px; + height:400px; border: 2px black solid; } .glm-map-edit-small { - width: 450px; - height: 300px; + width: 450px; + height: 300px; border: 2px black solid; } @@ -319,8 +322,8 @@ td.glm-nowrap { resize: none; } .glm-ol-selected -{ - font-weight: bold; +{ + font-weight: bold; color: green; } .glm-calendar { @@ -343,16 +346,16 @@ input[type=submit], input[type=file] { float:left; width:50%; */ } -#showDetail > label, #categoryBox > label{ +#showDetail > label, #categoryBox > label{ /* margin:0; float:left; width:50%;*/ display: block; } -#categoryTitle > span{ +#categoryTitle > span, #groupsTitle > span { font-weight: bold; } -#categoryTitle, #shortcodesTitle{ +#categoryTitle, #shortcodesTitle, #groupsTitle { font-weight: bold; font-size: 16px; border-bottom: 2px #ddd solid; diff --git a/js/shortcodeBuilder.js b/js/shortcodeBuilder.js index 071c1c66..c13b2317 100644 --- a/js/shortcodeBuilder.js +++ b/js/shortcodeBuilder.js @@ -1,18 +1,17 @@ -/* - * - * Other needed Admin JS code - * Block level comments used temporarily to make finding sections of the code easier - * alot of duplicate code and unecessary variables I need to clean up, need to change case from camel case to snake case - * need to create a function for setting the edtior content because it is duplicated a few times +/** + * Other needed Admin JS code + * Block level comments used temporarily to make finding sections of the code easier + * a lot of duplicate code and unnecessary variables I need to clean up, need to change case from camel case to snake case + * need to create a function for setting the editor content because it is duplicated a few times */ jQuery(document).ready(function ($) { - + 'use strict'; - + var shortcodeDropdown, shortcodeCategory, blankStart, memberView, amenityGroups, listBox, detailBox, target, boxTarget, shortcodeString, - editor_shortcodes, category_id, shortcodeValues = {}, editor_content, debug = false; - + editor_shortcodes, category_id, groups_id, shortcodeValues = {}, editor_content, debug = false; + debug = true; $("#showDetail").hide(); @@ -23,32 +22,32 @@ jQuery(document).ready(function ($) { $("#packageListAttr").hide(); //$(".scCategories").hide(); - + ///////////////////////////////////////////////////////////////////////////////////////// - // CHANGE MAIN SHORTCODE + // CHANGE MAIN SHORTCODE ///////////////////////////////////////////////////////////////////////////////////////// // fire events and reset settings when switching between shortcodes $("[id$=shortcodeDropdown]").on("change", function () { - + // reset the dropdowns and checkbox if when switching shortcodes document.getElementById('category-scDropdown').options[0].selected = 'selected'; if($('#blank-start-scDropdown').length) document.getElementById('blank-start-scDropdown').options[0].selected = 'selected'; if($('#id-scDropdown').length) document.getElementById('id-scDropdown').options[0].selected = 'selected'; - + // uncheckAll(); - + // delete the object properties to reset the object shortcodeString = ""; - + for (var prop in shortcodeValues){ delete shortcodeValues[prop]; } - + // get the shortcode option name and hide / show necessary elements shortcodeDropdown = $(".shortcodeDropdown option:selected").val(); - + // many of these are not necessary as much of the shortcode has been stripped if(shortcodeDropdown === "glm-members-list"){ $("#showCategory").show(); @@ -58,10 +57,11 @@ jQuery(document).ready(function ($) { $("#view-scDropdown").show(); $("#map-opened-scDropdown").show(); $("[id^='packageList']").hide(); - $("#category-scDropdown").show(); + $("#category-scDropdown").show(); $(".scCategories").show(); + $("#amenitygroup-scDropdown").show(); } - + if(shortcodeDropdown === "glm-members-packaging-list"){ $("#blank-start-scDropdown").hide(); $("#showCategory").hide(); @@ -72,14 +72,13 @@ jQuery(document).ready(function ($) { $("[id^='packageList']").show(); $("#view-scDropdown").hide(); $(".scCategories").hide(); - } + } }); - - + //////////////////////////////////////////////////////////////////// - // PAGE LOAD FUNCTIONS + // PAGE LOAD FUNCTIONS ///////////////////////////////////////////////////////////////////// // shortcode attribute name from dropdowns containing '-scDropdown' in their ID // Then append the values to the shortcode object @@ -95,14 +94,14 @@ jQuery(document).ready(function ($) { $("#detailBtn").on("click", function () { $("#showDetail").dialog().dialog("option", "width", 422); }); - + // get shortcodes between square brackets var regExp = /\[([^)]+)\]/; // function used to get everything out of the visual and text editors function get_tinymce_content(){ if (jQuery("#wp-content-wrap").hasClass("tmce-active")){ - + tinyMCE.triggerSave(); if(regExp.exec($('#content').val())){ @@ -113,11 +112,11 @@ jQuery(document).ready(function ($) { } } else { - + // get the shortcode from the editor with [ ] as the delimiters 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]; @@ -134,89 +133,105 @@ jQuery(document).ready(function ($) { //$('#shortcodeBuilder').hide(); } - if(editor_shortcodes){ + if ( editor_shortcodes ) { if ( editor_shortcodes.match( /glm-members-list .* amenity-groups="(.*?)"/ ) !== null ) { - if ( debug ) { - console.info('DEBUG INFO: editor_shortcodes.match amenity-groups ', editor_shortcodes.match(/glm-members-list .* amenity-groups="(.*?)"/)[1] ); - } + 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]; } if ( editor_shortcodes.match( /glm-members-list .* blank-start="(.*?)"/ ) !== null ) { blankStart = editor_shortcodes.match(/glm-members-list .* blank-start="(.*?)"/)[1]; - if ( debug ) { - console.info('DEBUG INFO: editor_shortcodes.match blank-start ', blankStart ); - } } if ( editor_shortcodes.match( /glm-members-list .* view="(.*?)"/ ) !== null ) { memberView = editor_shortcodes.match(/glm-members-list .* view="(.*?)"/)[1]; - if ( debug ) { - console.info('DEBUG INFO: editor_shortcodes.match view ', memberView ); - } } if(editor_shortcodes.match(/glm-members-list category="(.*?)"/) !== null){ - + // return the category option from the shortcode category_id = editor_shortcodes.match(/glm-members-list category="(.*?)"/)[1]; - + // pull the ID numbers from the returned category string category_id = category_id.split(','); } else if (editor_shortcodes.match(/glm-members-list category=""/) !== null){ - category_id = editor_shortcodes.match(/glm-members-list category="(.*?)"/)[1]; + category_id = editor_shortcodes.match(/glm-members-list category="(.*?)"/)[1]; } - $('#shortcodeDropdown').val('glm-members-list'); + $('#shortcodeDropdown').val( 'glm-members-list' ); } + // find the category names from the category select var category_names_ids = new Array(); - var categoryNames = $("#category-scDropdown>option").map(function() { + var categoryNames = $("#category-scDropdown>option").map(function() { var index = $.inArray($(this).val(), category_id); if(index !== -1 && index !== ""){ category_names_ids.push([$(this).text(), $(this).val()]); - return $(this).text(); + return $(this).text(); } }).get(); + // add the category names to #activeCategories $.each( category_names_ids, function (index, obj) { $('#activeCategories').append('
    ' + + '" class="glm-dynSelect-item glm-members-categories">' + obj[0] + " (ID: " + obj[1] + ')' + 'X' + '
    '); }); + // find the group names from the group select + var group_names_ids = new Array(); + var groupNames = $("#amenitygroup-scDropdown>option").map(function() { + var index = $.inArray($(this).val(), groups_id); + if(index !== -1 && index !== ""){ + group_names_ids.push([$(this).text(), $(this).val()]); + return $(this).text(); + } + }).get(); + console.log( 'group_names_id', group_names_ids ); + + // add the group names to #activeGroups + $.each( group_names_ids, function (index, obj) { + $('#activeGroups').append('
    ' + + obj[0] + " (ID: " + obj[1] + ')' + 'X' + + '
    '); + }); + ///////////////////////////////////////////////////////////////////////////////////////////// /* * 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; - + $('#category-scDropdown').change( function() { editor_shortcodes = get_tinymce_content(); 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(','); - + ids = category_id.join(','); empty_space = false; } else { ids = 'category=""'; - + // this determines if the category option is blank "" to determine if the jquery replace method works properly empty_space = true; } } } - + // Get the ID, name, and parent of the category - var catValue = $('#category-scDropdown').val(); + var catValue = $('#category-scDropdown').val(); var catName = $('#category-scDropdown').find(':selected').text(); var catParent = $('#category-scDropdown').find(':selected').attr('data-parent'); // Check if the category has already been added - var found = false; + var found = false; $(".glm-members-catgegory").each( function() { var id = $(this).attr('data-id'); if (id === catValue) { @@ -228,28 +243,28 @@ jQuery(document).ready(function ($) { // If not found, Add the category if (!found) { $('#activeCategories').append('
    ' + + '" class="glm-dynSelect-item glm-members-catgegory">' + catName.trim() + ' (ID: ' + catValue + ')' + 'X' + '
    '); } - + // reset the id string after each set of iterations id_string = ''; - + $.each($(".glm-dynSelect-item"), function () { if($.inArray($(this).data("id"), new_ids) === -1){ new_ids.push($(this).data("id")); } - }); - - // if more than one category id in the array, join together with ',' otherwise set the id string to a single value + }); + + // if more than one category id in the array, join together with ',' otherwise set the id string to a single value if ( new_ids.length > 1 ){ id_string = new_ids.join(','); } else if ( new_ids.length === 1 ) { id_string = new_ids[0]; } - - + + // replace the current content in either the visual or text editor and replace it with a filtered version of the categories if ( $("#content").css("display") !== "none" ) { editor_content = content.val(); @@ -276,13 +291,147 @@ jQuery(document).ready(function ($) { $('#category-scDropdown').val('Select Category'); }); + var group_ids, group_id_string, group_new_ids = new Array(), group_empty_space, group_missing; + + // Amenity Groups + // This fires when the groups select is changed + $('#amenitygroup-scDropdown').change(function(){ + editor_shortcodes = get_tinymce_content(); + if ( editor_shortcodes ) { + if ( editor_shortcodes.match( /amenity-groups="(.*?)"/ ) !== null ){ + group_missing = false; + groups_id = editor_shortcodes.match( /amenity-groups="(.*?)"/ )[1]; + + if ( groups_id !== "" ) { + groups_id = groups_id.split(','); + + group_ids = groups_id.join(','); + group_empty_space = false; + } else { + + group_ids = 'amenity-groups=""'; + + // this determines if the groups option is blank "" to determine if the jquery replace method works properly + group_empty_space = true; + } + } else { + group_missing = true; + group_empty_space = false; + } + } + + // Get the ID, name + var groupValue = $('#amenitygroup-scDropdown').val(); + var groupName = $('#amenitygroup-scDropdown').find(':selected').text(); + + // Check if the group has already been added + var found = false; + $(".glm-members-groups").each( function() { + var id = $(this).attr('data-id'); + if (id === groupValue) { + found = true; + } + }); + + // If not found, Add the group + if (!found) { + $('#activeGroups').append('
    ' + + groupName.trim() + ' (ID: ' + groupValue + ')' + 'X' + + '
    '); + } + + // reset the id string after each set of iterations + group_id_string = ''; + + $.each($(".glm-group-dynSelect-item"), function () { + if($.inArray($(this).data("id"), group_new_ids) === -1){ + group_new_ids.push($(this).data("id")); + } + }); + + // if more than one category id in the array, join together with ',' otherwise set the id string to a single value + if ( group_new_ids.length > 1 ){ + group_id_string = group_new_ids.join(','); + } else if ( group_new_ids.length === 1 ) { + group_id_string = group_new_ids[0]; + } + + // replace the current content in either the visual or text editor and replace it with a filtered version of the groups + if ( $("#content").css("display") !== "none" ) { + editor_content = content.val(); + if ( group_empty_space ) { + editor_content = editor_content.replace( group_ids, 'amenity-groups="' + group_id_string + '"' ); + content.val( editor_content ); + } else if ( group_missing ) { + content.val( editor_content ); + } else { + editor_content = editor_content.replace( 'amenity-groups="' + group_ids, 'amenity-groups="' + group_id_string ); + content.val( editor_content ); + } + } else if ( tinyMCE.activeEditor !== null ) { + if ( group_empty_space ) { + console.log( 'group empty space found 2' ); + console.log( 'group_ids', group_ids ); + editor_content = tinyMCE.get('content').getContent({format: 'raw'}); + editor_content = editor_content.replace(group_ids, 'amenity-groups="' + group_id_string + '"' ); + tinyMCE.activeEditor.setContent(editor_content); + } else if ( group_missing ) { + console.log( 'group missing found 2' ); + 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 amenity-groups="' + group_id_string + '"$2' ); + tinyMCE.activeEditor.setContent(editor_content); + } else { + console.log( 'group normal found 2' ); + console.log( 'tinyMCE replace amenity-group', group_ids, group_id_string ); + editor_content = tinyMCE.get('content').getContent({format: 'raw'}); + editor_content = editor_content.replace('amenity-groups="' + group_ids, 'amenity-groups="' + group_id_string); + tinyMCE.activeEditor.setContent(editor_content); + } + } + + // Reset picklist + $('#amenitygroup-scDropdown').val('Select Groups'); + }); + + // Blank Start change event + // These fire when the blank-start select is changed $('#blank-start-scDropdown').change(function(){ editor_shortcodes = get_tinymce_content(); editor_content = content.val(); + if ( editor_shortcodes.match( /glm-members-list .* blank-start="(.*?)"/ ) !== null ) { + blankStart = editor_shortcodes.match(/glm-members-list .* blank-start="(.*?)"/)[1]; + } + if ( editor_shortcodes ) { + if ( $("#content").css("display") !== "none" ) { + editor_content = editor_content.replace( 'blank-start="' + blankStart +'"', 'blank-start="' + $(this).val() + '"' ); + } else if ( tinyMCE.activeEditor !== null ) { + console.log( 'Found #2', $(this).val() ); + 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); + } + } + }); + + // View dropdown + // These events fire when the View select is changed + $('#view-scDropdown').change(function(){ + editor_shortcodes = get_tinymce_content(); + editor_content = content.val(); + if ( editor_shortcodes.match( /glm-members-list .* view="(.*?)"/ ) !== null ) { + memberView = editor_shortcodes.match(/glm-members-list .* view="(.*?)"/)[1]; + } if ( editor_shortcodes ) { if ( $("#content").css("display") !== "none" ) { - editor_content = editor_content.replace( ids, 'blank-start="' + $(this).val() + '"' ); + editor_content = editor_content.replace( 'view="' + memberView +'"', 'view="' + $(this).val() + '"' ); } else if ( tinyMCE.activeEditor !== null ) { + console.log( 'Found #2', $(this).val() ); + editor_content = tinyMCE.get('content').getContent({format: 'raw'}); + editor_content = editor_content.replace( 'view="' + memberView +'"', 'view="' + $(this).val() + '"' ); + tinyMCE.activeEditor.setContent(editor_content); } } }); @@ -294,59 +443,59 @@ 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 $("[id$=generate]").on("click", function () { count = 0; - if(number_of_categories){ + if ( number_of_categories ) { count = number_of_categories; count++; } else { count++; } // enforce the selection of a shortcode - if(shortcodeDropdown){ + if ( shortcodeDropdown ) { // set up properties for shortcode lists - if(shortcodeDropdown === "glm-members-list"){ - var listValues = $('input[name="listBox"]:checkbox:checked').map(function() { + 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){ + listValues.forEach( function( value ) { listString += value + ","; }); - if(listValues !== ""){ - listString = listString.replace(/,\s*$/, ""); + 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() { + 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){ + detailValues.forEach( function( value ) { detailString += value + ","; }); - if(detailValues !== ""){ - detailString = detailString.replace(/,\s*$/, ""); + if ( detailValues !== "" ) { + detailString = detailString.replace( /,\s*$/, "" ); shortcodeValues[boxTarget] = detailString; } } - + // start the shortcode string that will be added to the tinymce editor shortcodeString = '
    [' + shortcodeDropdown; - + // populate the shortcode object with all of the shortcode attributes and their values for (var key in shortcodeValues) { if (shortcodeValues.hasOwnProperty(key)) { @@ -355,10 +504,10 @@ 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 ) { + category_id = shortcodeString.match( /glm-members-list category="(.*?)"/ )[1]; category_id = category_id.split(','); ids = category_id.join(','); shortcodeString = shortcodeString.replace(ids, id_string); @@ -366,28 +515,37 @@ jQuery(document).ready(function ($) { shortcodeString += ']
    '; // insert shortcode at current cursor position - if($("#content").css("display") !== "none"){ - var cursorPos = $('#content').prop('selectionStart'); + if ( $("#content").css("display") !== "none" ) { + var cursorPos = $('#content').prop( 'selectionStart' ); var v = $('#content').val(); var textBefore = v.substring(0, cursorPos ); var textAfter = v.substring( cursorPos, v.length ); $('#content').val( textBefore + shortcodeString + textAfter ); - - } else if($("#content").css("display") === "none") { - - insert_tag(shortcodeString); + + } else if( $("#content").css("display") === "none" ) { + + insert_tag( shortcodeString ); } - } else { + } else { alert("Please Select a Shortcode"); } }); + $('#glmRemoveShortCode').on('click', function(){ + // find the short code and remove it! + editor_content = tinyMCE.get('content').getContent({format: 'raw'}); + var shortcodeReg = /(\[glm-members-list .*?])/; + editor_content = editor_content.replace( shortcodeReg, '' ); + tinyMCE.activeEditor.setContent(editor_content); + }); + + ////////////////////////////////////////////////////////////////////////////////////// // 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(); @@ -399,10 +557,10 @@ jQuery(document).ready(function ($) { } $(this).parent().remove(); - + // reset the array after each set of iterations new_ids.length = 0; - + $.each($(".glm-dynSelect-item"), function () { if($.inArray($(this).data("id"), new_ids) === -1){ new_ids.push($(this).data("id")); @@ -411,24 +569,64 @@ jQuery(document).ready(function ($) { // create a string of id's from the array id_string = new_ids.join(','); - + // get and replace current editor content if($("#content").css("display") !== "none"){ - + editor_content = content.val(); editor_content = editor_content.replace('category="' + ids, 'category="' + id_string ); content.val(editor_content); - + } else if(tinyMCE.activeEditor !== null){ - + editor_content = tinyMCE.get('content').getContent({format: 'raw'}); editor_content = editor_content.replace('category="' + ids, 'category="' + id_string); tinyMCE.activeEditor.setContent(editor_content); - + + } + + }); + + // group delete + $('.groupDelete').live('click', function(){ + editor_shortcodes = get_tinymce_content(); + + 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(','); + console.log( 'found - ', groups_id ); + group_ids = groups_id.join(','); + } + + $(this).parent().remove(); + + // reset the array after each set of iterations + group_new_ids.length = 0; + + $.each($(".glm-group-dynSelect-item"), function () { + if($.inArray($(this).data("id"), group_new_ids) === -1){ + group_new_ids.push($(this).data("id")); + } + }); + + // create a string of id's from the array + group_id_string = group_new_ids.join(','); + + // get and replace current editor content + if($("#content").css("display") !== "none"){ + editor_content = content.val(); + editor_content = editor_content.replace('amenity-groups="' + group_ids, 'amenity-groups="' + group_id_string ); + content.val(editor_content); + } else if(tinyMCE.activeEditor !== null){ + console.log( 'amenity-groups replacement reached' ); + console.log( 'group_id_string', group_id_string ); + console.log( 'group_ids', group_ids ); + editor_content = tinyMCE.get('content').getContent({format: 'raw'}); + editor_content = editor_content.replace('amenity-groups="' + group_ids, 'amenity-groups="' + group_id_string); + tinyMCE.activeEditor.setContent(editor_content); } }); - ///////////////////////////////////////////////////////////////////////////////////////////////// // MAINENANCE these were necessary to reset the dropdowns but most of them are no longer needed @@ -439,13 +637,15 @@ jQuery(document).ready(function ($) { var list = document.getElementById('type-scList'); var members = document.getElementById('member-scDropdown'); var view = document.getElementById('view-scDropdown'); + var groups = document.getElementById('amenitygroup-scDropdown'); if ( editor_shortcodes ) { $('#shortcodeDropdown').val('glm-members-list'); $('#shortcodeDropdown').change(); + $('#shortcodeDropdown').hide(); $('#generate').hide(); } - if( scd ){ + if( scd && !editor_shortcodes ){ window.onload = document.getElementById('shortcodeDropdown').options[0].selected = 'selected'; } if( catscd ){ @@ -472,5 +672,7 @@ jQuery(document).ready(function ($) { window.onload = document.getElementById('view-scDropdown').options[0].selected = 'selected'; } } -}); - + if ( groups ) { + window.onload = document.getElementById('amenitygroup-scDropdown').options[0].selected = 'selected'; + } +});