From: Anthony Talarico Date: Wed, 19 Sep 2018 20:03:44 +0000 (-0400) Subject: adding base code for the text field search autocomplete for the widgets X-Git-Url: http://cvs2.gaslightmedia.com/gitweb/?a=commitdiff_plain;h=3bee4651bdbffaabb6eb239572f7c56524e4ddcc;p=WP-Plugins%2Fglm-member-db.git adding base code for the text field search autocomplete for the widgets --- diff --git a/glm-grid b/glm-grid index efb374ff..c5770e1f 160000 --- a/glm-grid +++ b/glm-grid @@ -1 +1 @@ -Subproject commit efb374ff00ef46a991d94f3bdeb0ff69213275c6 +Subproject commit c5770e1f6248cf83be2845bb2b8420226451257e diff --git a/models/admin/ajax/glmTextSearch.php b/models/admin/ajax/glmTextSearch.php index 155b9f18..48f18c0d 100644 --- a/models/admin/ajax/glmTextSearch.php +++ b/models/admin/ajax/glmTextSearch.php @@ -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); diff --git a/views/admin/newDashboard/components/widgetSearch.html b/views/admin/newDashboard/components/widgetSearch.html index a25c84d4..d2d5949f 100644 --- a/views/admin/newDashboard/components/widgetSearch.html +++ b/views/admin/newDashboard/components/widgetSearch.html @@ -10,22 +10,29 @@ 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. + }); + } + }); + }) }); \ No newline at end of file