From: Anthony Talarico Date: Tue, 10 May 2016 14:37:38 +0000 (-0400) Subject: fixed bug in js code by adding alternate target variable for checkboxes for their... X-Git-Tag: v2.0.0^2~21^2~7 X-Git-Url: http://cvs2.gaslightmedia.com/gitweb/?a=commitdiff_plain;h=bed6e2e150e15e790e0965d78569742ac4e69d7c;p=WP-Plugins%2Fglm-member-db.git fixed bug in js code by adding alternate target variable for checkboxes for their values array --- diff --git a/controllers/admin.php b/controllers/admin.php index 90bea237..60178325 100644 --- a/controllers/admin.php +++ b/controllers/admin.php @@ -707,7 +707,7 @@ class glmMembersAdmin extends GlmPluginSupport // //dropdown for categories echo ''; - echo ' - - '; + echo ' + + '; echo ''; // show list options 'scb' = shortcode builder acronym echo '
'; - echo ''; - echo ''; + echo ''; + echo ''; foreach($listAttr as $key=>$value){ if($value != ''){ echo ''; @@ -733,8 +733,8 @@ class glmMembersAdmin extends GlmPluginSupport // show detail options echo '
'; - echo ''; - echo ''; + echo ''; + echo ''; foreach($detailAttr as $key=>$value){ if($value != ''){ echo ''; diff --git a/js/shortcodeBuilder.js b/js/shortcodeBuilder.js index 7f61837e..e0d4f7fb 100644 --- a/js/shortcodeBuilder.js +++ b/js/shortcodeBuilder.js @@ -5,7 +5,7 @@ */ jQuery(document).ready(function ($) { - var shortcodeDropdown, shortcodeCategory, blankStart, listBox, detailBox, target, shortcodeString; + var shortcodeDropdown, shortcodeCategory, blankStart, listBox, detailBox, target, boxTarget, shortcodeString; var shortcodeValues = {}; $("#showDetail").hide(); $("#showList").hide(); @@ -19,7 +19,8 @@ jQuery(document).ready(function ($) { // reset the dropdowns and checkbox if when switching shortcodes document.getElementById('category-scDropdown').options[0].selected = 'selected'; document.getElementById('blank-start-scDropdown').options[0].selected = 'selected'; - document.getElementById('id-scDropdown').options[0].selected = 'selected'; + if(document.getElementById('id-scDropdown').length > 0) + document.getElementById('id-scDropdown').options[0].selected = 'selected'; UncheckAll(); // delete the object properties to reset the object @@ -101,7 +102,6 @@ jQuery(document).ready(function ($) { var targetVal = $("#" + target + "-scDropdown option:selected").val(); shortcodeValues[target] = targetVal; }); - // use jquery dialog to separate the checkbox lists $("#listBtn").on("click", function () { $("#showList").dialog(); @@ -109,7 +109,7 @@ jQuery(document).ready(function ($) { $("#detailBtn").on("click", function () { $("#showDetail").dialog(); }); - + // generate the shortcode into a string and insert into the content upon clicking $("#generate").on("click", function () { // enforce the selection of a shortcode @@ -117,22 +117,25 @@ jQuery(document).ready(function ($) { // set up properties for shortcode lists if(shortcodeDropdown === "glm-members-list"){ var listValues = $('input[name="listBox"]:checkbox:checked').map(function() { - target = $(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 + ","; }); + if(listValues !== ""){ listString = listString.replace(/,\s*$/, ""); - shortcodeValues[target] = listString; + console.log(target + "string:" + listString); + shortcodeValues[boxTarget] = listString; } + // set up properties for detail shortcode } else if( shortcodeDropdown === "glm-member-detail"){ var detailValues = $('input[name="detailBox"]:checkbox:checked').map(function() { - target = $(this).attr("class").slice(0, -7); + boxTarget = $(this).attr("class").slice(0, -7); return this.value; }).get(); @@ -142,10 +145,9 @@ jQuery(document).ready(function ($) { }); if(detailValues !== ""){ detailString = detailString.replace(/,\s*$/, ""); - shortcodeValues[target] = detailString; + shortcodeValues[boxTarget] = detailString; } } - // start the shortcode string that will be added to the tinymce editor shortcodeString = "[" + shortcodeDropdown; @@ -175,8 +177,8 @@ jQuery(document).ready(function ($) { } return false; } - } insert_tag(shortcodeString); + } } else { alert("Please Select a Shortcode"); } @@ -187,6 +189,7 @@ jQuery(document).ready(function ($) { var catscd = document.getElementById('category-scDropdown'); var blank = document.getElementById('blank-start-scDropdown'); var list = document.getElementById('type-scList'); + var members = document.getElementById('member-scDropdown'); if(scd){ window.onload = document.getElementById('shortcodeDropdown').options[0].selected = 'selected'; @@ -200,6 +203,9 @@ jQuery(document).ready(function ($) { if(list){ window.onload = document.getElementById('type-scList').options[0].selected = 'selected'; } + if(members){ + window.onload = document.getElementById('member-scDropdown').options[0].selected = 'selected'; + } window.onload = UncheckAll(); function UncheckAll(){