From aefe30060d69271d4c2068de85f900f26d8e6436 Mon Sep 17 00:00:00 2001 From: Steve Sutton Date: Tue, 5 Jul 2016 08:10:34 -0400 Subject: [PATCH] Work on shortcode deletion Also working on Packages part --- css/admin.css | 4 +- js/shortcodeBuilder.js | 155 +++++++++++++++++++++++++++-------------- 2 files changed, 106 insertions(+), 53 deletions(-) diff --git a/css/admin.css b/css/admin.css index 91bcab4f..78f986ea 100644 --- a/css/admin.css +++ b/css/admin.css @@ -213,7 +213,7 @@ td.glm-nowrap { padding: .2em; margin: .4em; } -.glm-dynSelect-delete, .glm-group-dynSelect { +.glm-dynSelect-delete, .glm-group-dynSelect-delete { font-weight: bold; font-size: 1.1em; color: #bbb; @@ -221,7 +221,7 @@ td.glm-nowrap { padding-left: .5em; margin-left: .5em; } -.glm-dynSelect-delete:hover, .glm-group-dynSelect-delete { +.glm-dynSelect-delete:hover, .glm-group-dynSelect-delete:hover { font-size: 1.1em; color: #000; cursor: pointer; diff --git a/js/shortcodeBuilder.js b/js/shortcodeBuilder.js index c13b2317..9c14ae8e 100644 --- a/js/shortcodeBuilder.js +++ b/js/shortcodeBuilder.js @@ -20,7 +20,9 @@ jQuery(document).ready(function ($) { $("#detailBtn").hide(); $("[id$=-scDropdown]").hide(); $("#packageListAttr").hide(); - //$(".scCategories").hide(); + $('#activeCategories').hide(); + $('#activeGroups').hide(); + $('#glmRemoveShortCode').hide(); ///////////////////////////////////////////////////////////////////////////////////////// @@ -60,6 +62,8 @@ jQuery(document).ready(function ($) { $("#category-scDropdown").show(); $(".scCategories").show(); $("#amenitygroup-scDropdown").show(); + $('#activeCategories').show(); + $('#activeGroups').show(); } if(shortcodeDropdown === "glm-members-packaging-list"){ @@ -71,7 +75,10 @@ jQuery(document).ready(function ($) { $("#packageListAttr").children().show(); $("[id^='packageList']").show(); $("#view-scDropdown").hide(); - $(".scCategories").hide(); + $(".scCategories").hide(); + $("#amenitygroup-scDropdown").hide(); + $('#activeCategories').hide(); + $('#activeGroups').hide(); } }); @@ -85,7 +92,11 @@ jQuery(document).ready(function ($) { $("[id$=-scDropdown]").on("change", function () { target = $(this).attr("id").slice(0, -11); var targetVal = $("#" + target + "-scDropdown option:selected").val(); - shortcodeValues[target] = targetVal; + if ( target === 'amenitygroup' ) { + shortcodeValues['amenity-groups'] = targetVal; + } else { + shortcodeValues[target] = targetVal; + } }); // use jquery dialog to separate the checkbox lists $("#showCategory").on("click", function () { @@ -130,7 +141,11 @@ jQuery(document).ready(function ($) { if(editor_shortcodes){ // get the number of instances of shortcodes with the category option var number_of_categories = (editor_shortcodes.match(/glm-members-list category="(.*?)"/g) || []).length; - //$('#shortcodeBuilder').hide(); + $('#glmRemoveShortCode').show(); + $('#generate').hide(); + } else { + $('#glmRemoveShortCode').hide(); + $('#generate').show(); } if ( editor_shortcodes ) { @@ -156,7 +171,9 @@ jQuery(document).ready(function ($) { } else if (editor_shortcodes.match(/glm-members-list category=""/) !== null){ category_id = editor_shortcodes.match(/glm-members-list category="(.*?)"/)[1]; } - $('#shortcodeDropdown').val( 'glm-members-list' ); + if ( number_of_categories ) { + $('#shortcodeDropdown').val( 'glm-members-list' ); + } } // find the category names from the category select @@ -186,7 +203,6 @@ jQuery(document).ready(function ($) { 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) { @@ -371,21 +387,16 @@ jQuery(document).ready(function ($) { } } 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); @@ -401,16 +412,21 @@ jQuery(document).ready(function ($) { $('#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() ); + 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); + } + } else { editor_content = tinyMCE.get('content').getContent({format: 'raw'}); - editor_content = editor_content.replace( 'blank-start="' + blankStart +'"', 'blank-start="' + $(this).val() + '"' ); + var shortcodeReg = /(\[glm-members-list .*)(\])/; + var groupMatch = editor_content.match( shortcodeReg ); + editor_content = editor_content.replace( shortcodeReg, '$1 blank-start="' + $(this).val() + '"$2' ); tinyMCE.activeEditor.setContent(editor_content); } } @@ -421,16 +437,21 @@ jQuery(document).ready(function ($) { $('#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( 'view="' + memberView +'"', 'view="' + $(this).val() + '"' ); - } else if ( tinyMCE.activeEditor !== null ) { - console.log( 'Found #2', $(this).val() ); + 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); + } + } else { editor_content = tinyMCE.get('content').getContent({format: 'raw'}); - editor_content = editor_content.replace( 'view="' + memberView +'"', 'view="' + $(this).val() + '"' ); + var shortcodeReg = /(\[glm-members-list .*)(\])/; + var groupMatch = editor_content.match( shortcodeReg ); + editor_content = editor_content.replace( shortcodeReg, '$1 view="' + $(this).val() + '"$2' ); tinyMCE.activeEditor.setContent(editor_content); } } @@ -461,11 +482,10 @@ jQuery(document).ready(function ($) { // 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); + boxTarget = $(this).attr("class").slice(0, -5); return this.value; }).get(); - var listString = ""; listValues.forEach( function( value ) { listString += value + ","; @@ -479,9 +499,9 @@ jQuery(document).ready(function ($) { // 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(); + boxTarget = $(this).attr("class").slice(0, -7); + return this.value; + }).get(); var detailString = ''; detailValues.forEach( function( value ) { @@ -529,15 +549,48 @@ jQuery(document).ready(function ($) { } else { alert("Please Select a Shortcode"); } + $('#glmRemoveShortCode').show(); + $('#generate').hide(); }); - + /** + * Deletes the 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); + 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 .*?])/; + editor_content = editor_content.replace( shortcodeReg, '' ); + tinyMCE.activeEditor.setContent(editor_content); + $('.glm-dynSelect-item').remove(); + $('.glm-group-dynSelect-item').remove(); + $("#showDetail").hide(); + $("#categoryBox").hide(); + $("#showCategory").hide(); + $("#detailBtn").hide(); + $("[id$=-scDropdown]").hide(); + $("#packageListAttr").hide(); + $('#shortcodeDropdown').val('glm-members-list'); + window.onload = document.getElementById('shortcodeDropdown').options[0].selected = 'selected'; + $('#shortcodeDropdown').change(); + $('#shortcodeDropdown').show(); + $('#activeCategories').hide(); + $('#activeGroups').hide(); + } 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 .*?])/; + editor_content = editor_content.replace( shortcodeReg, '' ); + tinyMCE.activeEditor.setContent(editor_content); + $("[id$=-scDropdown]").hide(); + } + $('#glmRemoveShortCode').hide(); + $('#generate').show(); }); @@ -594,7 +647,6 @@ jQuery(document).ready(function ($) { 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(','); } @@ -618,9 +670,6 @@ jQuery(document).ready(function ($) { 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); @@ -640,32 +689,36 @@ jQuery(document).ready(function ($) { var groups = document.getElementById('amenitygroup-scDropdown'); if ( editor_shortcodes ) { - $('#shortcodeDropdown').val('glm-members-list'); - $('#shortcodeDropdown').change(); + if ( number_of_categories ) { + $('#shortcodeDropdown').val('glm-members-list'); + $('#shortcodeDropdown').change(); + } else { + $('#shortcodeDropdown').val('glm-members-packaging-list'); + $('#shortcodeDropdown').change(); + } $('#shortcodeDropdown').hide(); $('#generate').hide(); } - if( scd && !editor_shortcodes ){ + if ( scd && !editor_shortcodes ) { window.onload = document.getElementById('shortcodeDropdown').options[0].selected = 'selected'; } - if( catscd ){ + if ( catscd ) { window.onload = document.getElementById('category-scDropdown').options[0].selected = 'selected'; } - if( blank ){ + if ( blank ) { if ( blankStart ) { $('#blank-start-scDropdown').val( blankStart ); - console.log( blankStart ); } else { window.onload = document.getElementById('blank-start-scDropdown').options[0].selected = 'selected'; } } - if( list ){ + if ( list ) { window.onload = document.getElementById('type-scList').options[0].selected = 'selected'; } - if( members ){ + if ( members ) { window.onload = document.getElementById('member-scDropdown').options[0].selected = 'selected'; } - if( view ){ + if ( view ) { if ( memberView ) { $('#view-scDropdown').val( memberView ); } else { -- 2.17.1