adding base code for the text field search autocomplete for the widgets
authorAnthony Talarico <talarico@gaslightmedia.com>
Wed, 19 Sep 2018 20:03:44 +0000 (16:03 -0400)
committerAnthony Talarico <talarico@gaslightmedia.com>
Wed, 19 Sep 2018 20:03:44 +0000 (16:03 -0400)
glm-grid
models/admin/ajax/glmTextSearch.php
views/admin/newDashboard/components/widgetSearch.html

index efb374f..c5770e1 160000 (submodule)
--- a/glm-grid
+++ b/glm-grid
@@ -1 +1 @@
-Subproject commit efb374ff00ef46a991d94f3bdeb0ff69213275c6
+Subproject commit c5770e1f6248cf83be2845bb2b8420226451257e
index 155b9f1..48f18c0 100644 (file)
@@ -72,12 +72,25 @@ class GlmMembersAdmin_ajax_glmTextSearch
      */
     public function modelAction ($actionData = false)
     {
-        if( isset( $_REQUST['table'] ) ){
-            
+        global $wpdb;
+
+        if( isset( $_REQUEST['table'] ) ){
+            $fields     = $_REQUEST['fields'];
+            $table      = filter_var($_REQUEST['table'], FILTER_SANITIZE_STRING);
+            $sql        = "SELECT $fields image FROM $table where title like '%pack%'";
+            $packages   = $wpdb->get_results($sql); 
+            foreach($packages as $package){
+                $searchData[] = [
+                    $package->title => $package->image 
+                ];
+            }
+        }else{
+            $table = null;
         }
-        $data = "test";
+   
         $return = array(
-            'data'          => $data  ,    // Where our events list will go
+            'data'          => $fields,
+            'searchData'    => $searchData        // Where our events list will go
         );
 
         header('Content-type:application/json;charset=utf-8', true);
index a25c84d..d2d5949 100644 (file)
         let data = {
             action      : 'glm_members_admin_ajax',
             glm_action  : 'glmTextSearch',
-            table       : '{$widgetField.table}'
+            table       : '{$widgetField.table}',
+            fields      : '{", "|implode:$widgetField.fields}'
         }
-        $.ajax({
-            type: 'POST',
-            url: '{$ajaxUrl}',
-            data: data,
-            success: function(response) {
-                console.log(response)
-                $('input.earch-autocomplete').autocomplete({
-                    data: {
-                    "Apple": null,
-                    "Microsoft": null,
-                    "Google": 'https://placehold.it/250x250'
-                    }, // The max amount of results that can be shown at once. Default: Infinity.
-                });
-            }
-        });
+        $(function() {
+            $.ajax({
+                type: 'POST',
+                url: '{$ajaxUrl}',
+                data: data,
+                success: function(response) {
+                    let searchDropdown = {};
+                    
+                    for(let i = 0;i < response.searchData.length;i++){
+                        let searchTitle = Object.keys(response.searchData[i]);
+                        let image       = (response.searchData[i][searchTitle]) ? response.searchData[i][searchTitle] : null;
+                        searchDropdown[searchTitle] = null;
+                    }
+                    console.log(searchDropdown)
+                    $('input.search-autocomplete').autocomplete({
+                        minLength: 3,
+                        data: searchDropdown // The max amount of results that can be shown at once. Default: Infinity.
+                    });
+                }
+            });
+        })
     });
 </script>
\ No newline at end of file