Add member search field.
authorSteve Sutton <steve@gaslightmedia.com>
Fri, 6 Sep 2019 14:16:47 +0000 (10:16 -0400)
committerSteve Sutton <steve@gaslightmedia.com>
Fri, 6 Sep 2019 14:16:47 +0000 (10:16 -0400)
Adds members attribute to the shortcode.

css/admin.css
js/shortcodeBuilder.js
models/admin/ajax/memberNameJson.php [new file with mode: 0644]
setup/validActions.php
views/admin/pages/shortcode.html

index ae7aa9f..27d0c68 100755 (executable)
@@ -489,7 +489,7 @@ td.glm-nowrap {
 }
 #reset-shortcode{
     background: #DE5D60;
-    
+
 }
 .shortcode-button:hover{
     cursor: pointer;
@@ -512,7 +512,7 @@ td.glm-nowrap {
 .shortcode-confirmation.confirmed{
     top: -50px;
     z-index: 1;
-    
+
 }
 .delete-shortcode-tile{
     margin-left: 10px;
@@ -812,10 +812,10 @@ td.glm-nowrap {
     width:50%;*/
     display: block;
 }
-#categoryTitle > span, #groupsTitle > span, #regionsTitle > span {
+#categoryTitle > span, #memberTitle > span, #groupsTitle > span, #regionsTitle > span {
     font-weight: bold;
 }
-#categoryTitle, #shortcodesTitle, #groupsTitle, #regionsTitle {
+#categoryTitle, #memberTitle, #shortcodesTitle, #groupsTitle, #regionsTitle {
     font-weight: bold;
     font-size: 16px;
     /* border-bottom: 2px #ddd solid; */
index 85cd4aa..1f6b289 100644 (file)
@@ -42,6 +42,7 @@ jQuery(function ($) {
         $(".shortcode-tile-container").empty();
         shortcodeAttributes = {
             categories  : {list:[], isList: true},
+            members     : {list:[], isList: true},
             regions     : {list:[], isList: true},
             groups      : {list:[], isList: true},
             views       : {list:[], isList: false},
@@ -79,10 +80,43 @@ jQuery(function ($) {
         generateShortCodeAttribute(shortcodeData);
     }
     setupAttributes();
+    var cache = {};
+    var memberNames = [
+        { label: 'Steve', value: 1 },
+        { label: 'George', value: 2 },
+        { label: 'Dave', value: 3 },
+        { label: 'Banner', value: 4 }
+    ];
+    $('#shortcode-members').autocomplete({
+        minLength: 2,
+        source: function( request, response ){
+            var term = request.term;
+            if ( term in cache ) {
+                response( cache[ term ] );
+                return;
+            }
+
+            $.getJSON( memberNameJsonUrl, request, function( data, status, xhr ){
+                cache[ term ] = data;
+                response( data );
+            } );
+        },
+        select: function( event, ui ){
+            var id     = $(this).val();
+            var type   = 'members';
+            let record = {id: ui.item.value, name: ui.item.label, type: 'members'};
+            $('#shortcode-members').val('');
+            shortcodeAttributes['members'].list.push(record);
+            updateShortcode({list: shortcodeAttributes[type].list, type: type, isList: shortcodeAttributes[type].isList});
+        },
+        close: function( event, ui ) {
+            $('#shortcode-members').val('');
+        }
+    });
     $(document).on("change", ".shortcode-selection",function(){
         var id              = $(this).val();
         var name            = $(this).find("option:selected").text();
-        var type            = $(this).find("option:selected").data("type");            
+        var type            = $(this).find("option:selected").data("type");
         let record          = {id: id, name: name, type: type};
         if(shortcodeAttributes[type].list.length == 0 || !checkDuplicates(record, shortcodeAttributes[type].list) && shortcodeAttributes[type].isList ){
             shortcodeAttributes[type].list.push(record);
@@ -154,4 +188,4 @@ jQuery(function ($) {
         tile.remove();
         updateShortcode({list: shortcodeAttributes[type].list, type: type});
     });
-});
\ No newline at end of file
+});
diff --git a/models/admin/ajax/memberNameJson.php b/models/admin/ajax/memberNameJson.php
new file mode 100644 (file)
index 0000000..5948582
--- /dev/null
@@ -0,0 +1,92 @@
+<?php
+
+/**
+ * Gaslight Media Members Database
+ * Members List JSON Export by AJAX
+ *
+ * PHP version 5.5
+ *
+ * @category glmWordPressPlugin
+ * @package  glmMembersDatabase
+ * @author   Chuck Scott <cscott@gaslightmedia.com>
+ * @license  http://www.gaslightmedia.com Gaslightmedia
+ * @version  0.1
+ */
+
+
+/**
+ *
+ * This class exports the currently selected members list
+ * to a printable HTML file, to a CSV file, or otherwise.
+ */
+class GlmMembersAdmin_ajax_memberNameJson
+{
+
+    /**
+     * WordPress Database Object
+     *
+     * @var $wpdb
+     * @access public
+     */
+    public $wpdb;
+    /**
+     * Plugin Configuration Data
+     *
+     * @var $config
+     * @access public
+     */
+    public $config;
+
+    /**
+     * Constructor
+     *
+     * This constructor sets up this model. At this time that only includes
+     * storing away the WordPress data object.
+     *
+     * @return object Class object
+     *
+     */
+    public function __construct ( $wpdb, $config )
+    {
+
+        // Save WordPress Database object
+        $this->wpdb = $wpdb;
+
+        // Save plugin configuration object
+        $this->config = $config;
+
+    }
+
+    public function modelAction( $actionData = false ) {
+
+        // Create json export of active members.
+        $members = array();
+
+        $whereParts = array( 'true' );
+
+        $whereParts[] = " (
+            SELECT access
+             FROM ".GLM_MEMBERS_PLUGIN_DB_PREFIX."members
+            WHERE id = T.member
+        ) IN (
+             " . $this->config['access_numb']['NoAccess'] . ",
+             " . $this->config['access_numb']['Moderated'] . ",
+             " . $this->config['access_numb']['Full'] . "
+             )
+        AND T.status = " . $this->config['status_numb']['Active'];
+
+        $where = implode( ' AND ', $whereParts );
+
+        $members = $this->wpdb->get_results(
+            "SELECT T.member as value,T.member_name as name,T.member_name as label
+              FROM " . GLM_MEMBERS_PLUGIN_DB_PREFIX . "member_info T
+             WHERE true
+               AND $where",
+            ARRAY_A
+        );
+
+        header( 'Content-Type: application/json' );
+        echo json_encode( $members );
+    }
+
+}
index 53467ce..95a966c 100644 (file)
@@ -52,6 +52,7 @@ $glmMembersValidActions = array(
             'membersListJson'     => 'glm-member-db',
             'verifyLatLon'        => 'glm-member-db',
             'memberCountCheck'    => 'glm-member-db',
+            'memberNameJson'      => 'glm-member-db',
         ),
         'dashboard' => array(
             'index'   => 'glm-member-db',
index f602845..248f5a1 100644 (file)
@@ -1,3 +1,6 @@
+<script>
+    var memberNameJsonUrl = '{$ajaxUrl}?action=glm_members_admin_ajax&glm_action=memberNameJson';
+</script>
 <div id="shortcode_container" class="{$shortcode_count}" style="overflow: auto">
     <input id="shortcode-copy" type="text" style="display: none;">
     <div id="shortcode-preview"></div>
                 <option data-type="regions" value="{$region.id}">&nbsp{$region.name}</option>
             {/foreach}
         </select>
-        <div id="reset-shortcode" class="right shortcode-button" type="button"> 
+        <input type="text" id="shortcode-members" class="shortcode-input" placeholder="Search Members" data-type="members" />
+        <div id="reset-shortcode" class="right shortcode-button" type="button">
                 Reset Shortcode
                 <div id="shortcode-reset-confirmation" class="shortcode-confirmation">Shortcode Reset</div>
         </div>
-        <div id="copy-to-clipboard" class="right shortcode-button" type="button"> 
-            Copy To Clipboard 
+        <div id="copy-to-clipboard" class="right shortcode-button" type="button">
+            Copy To Clipboard
             <div id="shortcode-copy-confirmation" class="shortcode-confirmation">Shortcode Copied</div>
         </div>
-        
+
 
     </div>
     <div id="activeCategories" class="glm-dynSelect-box scCategories" style="height: auto; overflow: auto;">
         <div id="categoryTitle" class="shortcode-tile-title">Categories</div>
         <div id="categories-container" class="shortcode-tile-container"></div>
     </div>
+    <div id="activeMembers" class="glm-dynSelect-box scMembers" style="height: auto; overflow: auto;">
+        <div id="memberTitle" class="shortcode-tile-title">Members</div>
+        <div id="members-container" class="shortcode-tile-container"></div>
+    </div>
     <div id="activeGroups" class="glm-group-dynSelect-box scGroups" style="height: auto; overflow: auto;">
         <div id="groupsTitle" class="shortcode-tile-title">Amenity Groups</div>
             <div id="groups-container" class="shortcode-tile-container"></div>
@@ -76,4 +84,4 @@
     .glma-category-child::before{
         content: "-";
     }
-</style>
\ No newline at end of file
+</style>