adding shortcode builder functionality
authorAnthony Talarico <talarico@gaslightmedia.com>
Thu, 16 Jun 2016 17:11:35 +0000 (13:11 -0400)
committerAnthony Talarico <talarico@gaslightmedia.com>
Thu, 16 Jun 2016 17:11:35 +0000 (13:11 -0400)
classes/glmPluginSupport.php
js/shortcodeBuilder.js
models/admin/member/index.php

index 461a67d..5a1ee35 100644 (file)
@@ -347,7 +347,7 @@ return; // Off for now ** Need to make this switchable in management
 
     public function get_post_id_by_slug($postName)
     {
-        $value = $this->wpdb->get_var("SELECT ID FROM ".$this->wpdb->posts." WHERE post_name = '".$postName."'");
+        $value = $this->wpdb->get_var("SELECT ID FROM ". $this->wpdb->posts." WHERE post_name = '" . $postName."'");
         return $value;
     }
     
@@ -407,9 +407,9 @@ return; // Off for now ** Need to make this switchable in management
     public function shortcode_builder_markup_template($shortCodes, $list) {
         //dropdown for shortcode names
         $this->increase_shortcode_count();
-        echo '<div id="categoryContainer" class="'.$this->get_shortcode_count().'" style="overflow: auto">';
+        echo '<div id="shortcode_container" class="'.$this->get_shortcode_count().'" style="overflow: auto">';
         echo '<div id="shortcodeBuilder">';
-        echo '<select id="shortcodeDropdown">
+        echo '<select id="shortcodeDropdown" class="shortcodeDropdown">
         <option value=""> Select Shortcode </option>';
         foreach($shortCodes as $code){
             if (false !== strpos($code, 'members-list') || false !== strpos($code, 'packaging-list')){
@@ -438,16 +438,6 @@ return; // Off for now ** Need to make this switchable in management
             }
         }
         echo '</select>';
-        
-        echo '<div id="categoryBox" title="Member Categories ">';
-        foreach($list as $key=>$value){
-             if( ! empty($value['parent']['name'])){
-                echo '<label class="checkList" for="'.$value['name'].'"><input class="categoryLists" type="checkbox" name="listBox" value='. $key . '>' . '&nbsp&nbsp&nbsp'. $value['name'] .'</label>';
-            } else {
-                echo '<label class="checkList" for="'.$value['name'].'"><input class="categoryLists" type="checkbox" name="listBox" value='. $key . '>' . '&nbsp'. $value['name'] .'</label>';
-            }
-        }
-        echo '</div>';
 
         // dropdown for blank start
         echo '<select id="blank-start-scDropdown">';
@@ -463,27 +453,6 @@ return; // Off for now ** Need to make this switchable in management
         echo '<option value="grid"> Grid View </option>';
         echo '</select>';
 
-        // show list options 'scb' = shortcode builder acronym
-//        echo '<div id="showList" title="List Options">';
-//        echo '<label><input class="showLists" type="checkbox" name="listBox" value="all">All</label>';
-//        echo '<label><input class="showLists" type="checkbox" name="listBox" value="none">None</label>';
-//        foreach($listAttr as $key=>$value){
-//            if($value != ''){
-//                echo '<label class="checkList"><input class="showLists" type="checkbox" name="listBox" value='. $key . '>' . $key .'</label>';
-//            }
-//        }
-//        echo '</div>';
-
-        // show detail options
-//        echo '<div id="showDetail" title="Detail Options">';
-//        echo '<label><input class="showDetails" type="checkbox" name="detailBox" value="all">All</label>';
-//        echo '<label><input class="showDetails" type="checkbox" name="detailBox" value="none">None</label>';
-//        foreach($detailAttr as $key=>$value){
-//            if($value != ''){
-//                echo '<label class="checkDetails"><input class="showDetails" type="checkbox" name="detailBox" value='. $key . '>' . $key .'</label>';
-//            }
-//        }
-
        // packaging addOn mark up
         if(file_exists(GLM_MEMBERS_PACKAGING_PLUGIN_PATH . "/setup/shortcodeBuilder.php")){
             include GLM_MEMBERS_PACKAGING_PLUGIN_PATH . "/setup/shortcodeBuilder.php";
@@ -539,13 +508,24 @@ return; // Off for now ** Need to make this switchable in management
         
         // This function when called will auto-increment the shortcode ID
         $this->shortcode_builder_markup_template($shortCodes, $list);
-        
+        ?>
+        <script type="text/javascript">
+            jQuery(document).ready( function () {
+                jQuery("#additionalShortcode").click( function () {
+
+                });
+            });
+        </script>
+
+
+        <?php
         // It should be able to be called several times (once every time the 
         // additionalShortcode button is clicked), but there are still some 
         // issues with that. Nice-print conflict..
-        $this->shortcode_builder_markup_template($shortCodes, $list);
+//        $this->shortcode_builder_markup_template($shortCodes, $list);
         
         // This button will add another shortcode editor
+
         echo '<button id="additionalShortcode" class="button" type="button"> Configure Additional Shortcode </button>';
     }
 }
index 7bd02ee..219d388 100644 (file)
@@ -6,9 +6,10 @@
 jQuery(document).ready(function ($) {
     
     'use strict';
-
+    
     var shortcodeDropdown, shortcodeCategory, blankStart, listBox, detailBox, target, boxTarget, shortcodeString,
     editor_shortcodes, category_id, shortcodeValues = {};
+    
     $("#showDetail").hide();
     $("#categoryBox").hide();
     $("#showCategory").hide();
@@ -18,23 +19,33 @@ jQuery(document).ready(function ($) {
     $(".scCategories").hide();
     
     // reset checkboxes after page load
-    function uncheckAll() {
-      var w = document.getElementsByTagName('input');
-      for (var i = 0; i < w.length; i++){ 
-        if(w[i].type === 'checkbox'){ 
-          w[i].checked = false; 
-        }
-      }
-    }
-    
-    
+//    function uncheckAll() {
+//      var w = document.getElementsByTagName('input');
+//      for (var i = 0; i < w.length; i++){ 
+//        if(w[i].type === 'checkbox'){ 
+//          w[i].checked = false; 
+//        }
+//      }
+//    }
+    var shortcode = $("#shortcode_container").not('.glm-dynSelect-item'), clone, id_count;
+    id_count = 0;
+//    $("#additionalShortcode").on( "click", function () {
+//            id_count++;
+//            clone = shortcode.clone(true);
+//            clone.find("#shortcodeDropdown").attr("id", "shortcodeDropdown" + "_" + id_count);
+//            clone.find(".glm-dynSelect-item").remove();
+//            clone.find("#generate").attr("id", "generate" + "_" + id_count);
+//            clone.insertAfter("#shortcode_container:last");
+//         
+//    });
+
     
     
     /////////////////////////////////////////////////////////////////////////////////////////
     // CHANGE MAIN SHORTCODE 
     /////////////////////////////////////////////////////////////////////////////////////////
    // fire core events and reset settings when switching between shortcodes
-    $("#shortcodeDropdown").on("change", function () {
+    $("[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)
@@ -42,7 +53,7 @@ jQuery(document).ready(function ($) {
         if($('#id-scDropdown').length)
             document.getElementById('id-scDropdown').options[0].selected = 'selected';
         
-        uncheckAll();
+//        uncheckAll();
         
         // delete the object properties to reset the object
         shortcodeString = "";
@@ -51,7 +62,7 @@ jQuery(document).ready(function ($) {
         }
         
         // get the shortcode option name and hide / show necessary elements
-        shortcodeDropdown = $("#shortcodeDropdown option:selected").val();
+        shortcodeDropdown = $(".shortcodeDropdown option:selected").val();
         
         if(shortcodeDropdown === "glm-members-list"){
             $("#showCategory").show();
@@ -129,14 +140,23 @@ jQuery(document).ready(function ($) {
     }
 
     editor_shortcodes = get_tinymce_content();
+    
     if(editor_shortcodes){
         var number_of_categories = (editor_shortcodes.match(/category="(.*?)"/g) || []).length;
     }
     console.debug(number_of_categories);
+    console.debug(editor_shortcodes);
     if(editor_shortcodes){
         if(editor_shortcodes.match(/category="(.*?)"/) !== null){
             category_id = editor_shortcodes.match(/category="(.*?)"/)[1];
+//            console.debug(category_id);
+//            var cat_id_array = [];
+//            $.each(category_id, function (key, value) {
+//                  cat_id_array.push(value.match(/"(.*?)"/)[1]); 
+//            });
+
             category_id = category_id.split(',');
+
         } else if (editor_shortcodes.match(/category=""/) !== null){
             category_id = editor_shortcodes.match(/category="(.*?)"/)[1];       
         }
@@ -273,7 +293,7 @@ jQuery(document).ready(function ($) {
     // INSERT SHORTCODE FUNCTION 
     /////////////////////////////////////////////////////////////////////////////////////////////////
     // generate the shortcode into a string and insert into the content upon clicking
-    $("#generate").on("click", function () {
+    $("[id$=generate]").on("click", function () {
         count = 0;
         if(number_of_categories){
             count = number_of_categories;
@@ -318,7 +338,7 @@ jQuery(document).ready(function ($) {
                 }
             }
             // start the shortcode string that will be added to the tinymce editor
-            shortcodeString = '<div class="previewCodes" id="' + shortcodeDropdown + '_'+ count + '"> [' + shortcodeDropdown;
+            shortcodeString = '<div class="previewCodes" id="' + count + '"> [' + shortcodeDropdown;
             
             // populate the shortcode object
             for (var key in shortcodeValues) {
@@ -368,7 +388,7 @@ jQuery(document).ready(function ($) {
 
        editor_shortcodes = get_tinymce_content();
 
-       if(editor_shortcodes.match(/category="(.*?)"/) !== null){
+       if(editor_shortcodes && editor_shortcodes.match(/category="(.*?)"/) !== null){
             category_id = editor_shortcodes.match(/category="(.*?)"/)[1];
             category_id = category_id.split(',');
             ids = category_id.join(',');
@@ -434,6 +454,6 @@ jQuery(document).ready(function ($) {
     if(view){
         window.onload = document.getElementById('view-scDropdown').options[0].selected = 'selected';
     }
-    window.onload = uncheckAll();
+//    window.onload = uncheckAll();
 }); 
 
index 70486a8..d5eed2c 100644 (file)
@@ -98,7 +98,7 @@ class GlmMembersAdmin_member_index extends GlmDataMembers
      */
     public function modelAction ($actionData = false)
     {
-
+         echo current_user_can('edit_pages');
         $success = true;
         $haveMember = false;
         $addingMember = false;