Setup search form
authorSteve Sutton <steve@gaslightmedia.com>
Wed, 1 Mar 2017 17:01:59 +0000 (12:01 -0500)
committerSteve Sutton <steve@gaslightmedia.com>
Wed, 1 Mar 2017 17:01:59 +0000 (12:01 -0500)
Setting up the name search for account list page.

classes/data/dataAccount.php
models/admin/registrations/accounts.php
views/admin/registrations/account.html

index 444d156..d5923f5 100644 (file)
@@ -584,4 +584,27 @@ class GlmDataRegistrationsAccount extends GlmDataAbstract
         return $r;
     }
 
+    /**
+     * Get ID/Name list
+     *
+     * @param string $where
+     *
+     * @return array ID/Name pairs
+     */
+    public function getIdName( $where = 'true' )
+    {
+        $savedFields = $this->fields;
+
+        $this->fields = array(
+            'id'    => $savedFields['id'],
+            'lname' => $savedFields['lname'],
+            'fname' => $savedFields['fname'],
+        );
+
+        $r = $this->getList( $where );
+
+        $this->fields = $savedFields;
+        return $r;
+
+    }
 }
index f216f3f..7f26738 100644 (file)
@@ -107,6 +107,7 @@ class GlmMembersAdmin_registrations_accounts extends GlmDataRegistrationsAccount
         $accountUpdateError = false;
         $accountAdded       = false;
         $accountAddError    = false;
+        $namesList          = false;
 
         // Get any provided option
         if (isset($_REQUEST['option'])) {
@@ -174,9 +175,19 @@ class GlmMembersAdmin_registrations_accounts extends GlmDataRegistrationsAccount
             $view   = 'account';
 
         default:
+            $where       = 'true';
             $accounts    = $this->getList();
             $hasAccounts = ( $accounts !== false && count( $accounts > 0 ) ) ? true: false;
             $view        = 'account';
+
+            // Check if we have a Text Search string
+            if (isset($_REQUEST['textSearch']) && trim($_REQUEST['textSearch']) != '') {
+                $textSearch = trim($_REQUEST['textSearch']);
+                $where .= " AND ( lname LIKE '%$textSearch%' OR fname LIKE '%$textSearch%' OR CONCAT_WS( ' ', fname, lname) LIKE '%$textSearch%' )";
+            }
+
+            // Get full list of names matching this where clause for search box
+            $namesList = $this->getIdName($where);
             break;
         }
 
@@ -201,6 +212,7 @@ class GlmMembersAdmin_registrations_accounts extends GlmDataRegistrationsAccount
             'option'             => $option,
             'accountAdded'       => $accountAdded,
             'accountAddError'    => $accountAddError,
+            'namesList'          => $namesList,
         );
              // Return status, any suggested view, and any data to controller
         return array(
index fdc0d77..7d51f9b 100644 (file)
@@ -12,7 +12,7 @@
         <div class="">
             <p>
                 <span class="glm-nowrap">
-                    <b>Text Search: </b><input  id="glmEventsSearch" name="textSearch" type="text" id="autoTest">
+                    <b>Name Search: </b><input  id="glmEventsSearch" name="textSearch" type="text" id="autoTest">
                     <input type="submit" value="Submit">
                 </span>
             <p>
 
     </form>
 
+    <script>
+        jQuery(document).ready(function($){
+            /*
+             * Do autocomplete search for member
+             * label: What will be searched
+             * value: What will be displayed when selected
+             * id: Member id added so we can go to the member while showing what was selected
+             * Also note that autocomplete does not properly render HTML codes, so we
+             * "unescape" them for HTML in Smarty.
+             */
+
+             var availableTags = [
+                {foreach $namesList as $e}
+                    { label: "{$e.fname|replace:'"':"'"} {$e.lname|replace:'"':"'"}", value: "{$e.fname|replace:'"':"'"} {$e.lname|replace:'"':"'"}", id: '{$e.id}' },
+                {/foreach}
+             ];
+
+             $( "#glmEventsSearch" ).autocomplete({
+                 source: availableTags,
+                 html: true,
+                 position: { my : "right top", at: "right bottom" },
+                 select: function( event, ui ) {
+                     var accountID = ui.item.id;
+                     window.location.replace("{$adminUrl}?page=glm-members-admin-menu-registrations-accounts&glm_action=accounts&option=edit&account=" + accountID );
+                 },
+                 response: function(event, ui) {
+                     if (!ui.content.length) {
+                         var noResult = { value:"",label:"No results found" };
+                         ui.content.push(noResult);
+                     }
+                 }
+             });
+        });
+    </script>
+
 {include file='admin/footer.html'}