From 66bfefe015127dc13d57f375ee44e82f20c4052b Mon Sep 17 00:00:00 2001 From: Laury GvR Date: Thu, 3 Jan 2019 15:53:16 -0500 Subject: [PATCH] Add textSearch to manageDashboard to get autocomplete-based member info opening to work (it is not) --- .../components/textSearch.html | 13 +- views/admin/manageDashboard/index.html | 118 ++++++++++++++++-- 2 files changed, 123 insertions(+), 8 deletions(-) diff --git a/views/admin/manageDashboard/components/textSearch.html b/views/admin/manageDashboard/components/textSearch.html index 25c95057..7c8cb47c 100644 --- a/views/admin/manageDashboard/components/textSearch.html +++ b/views/admin/manageDashboard/components/textSearch.html @@ -4,4 +4,15 @@ - \ No newline at end of file + + \ No newline at end of file diff --git a/views/admin/manageDashboard/index.html b/views/admin/manageDashboard/index.html index ee26d203..882e21cd 100644 --- a/views/admin/manageDashboard/index.html +++ b/views/admin/manageDashboard/index.html @@ -127,18 +127,28 @@ }); }, renderItem: function (item, search){ + search = search.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&'); var re = new RegExp("(" + search.split(' ').join('|') + ")", "gi"); - return '
'+item.replace(re, "$1")+'
'; + return '
'+item.replace(re, "$1")+'
'; }, - onSelect: function(e, term, item){ - let search = $(item).text(); + // onSelect: function(e, term, item){ + // console.log(item); + // let search = $(item).text(); - if(search !== "No Results Found"){ - window.location.replace(textSearchData.resultUrl+searchResults[search].entityID); - } - }, + // if(search !== "No Results Found"){ + // window.location.replace("TEST"); + // } + // }, + onSelect: function(e, term, item){ + alert('Item "'+item.data('langname')+' ('+item.data('lang')+')" selected by '+(e.type == 'keydown' ? 'pressing enter' : 'mouse click')+'.'); + } + // select: function( event, ui ) { + // console.log("ui:" + ui) + // var memberID = ui.item.id; + // window.location.replace("#=" + memberID ); + // }, }); }); } @@ -217,6 +227,7 @@ }); $(document).on("click",".member-record-name", function(){ + console.log("HERE"); // fails $(".edit-screen").html(''); editData.option = "manage"; editData.memberID = $(this).parent().data('id'); @@ -257,6 +268,99 @@ ); }); }); + /* + * Text Search Autocomplete + */ + function textSearch(textSearchData){ + // Text Search Component + jQuery(function($){ + let searchResults = {}; + let imageUrl = `{$glmPluginMediaUrl}/images` + let listData = { + action : 'glm_members_admin_ajax', + glm_action : 'glmTextSearch', + table : textSearchData.table, + fields : textSearchData.fields, + where : textSearchData.where + } + console.log(listData); + $('input#'+textSearchData.slug+'-text').autoComplete({ + minChars: 1, + source: function( request, response ) { + listData.query = request; + $.ajax({ + dataType: "json", + type : 'POST', + url: '{$ajaxUrl}', + data: listData, + success: function(data) { + if(data.searchData){ + let searchDropdown = []; + for(let i = 0;i < data.searchData.length;i++){ + let searchTitle = Object.keys(data.searchData[i])[0]; + let image = (data.searchData[i][searchTitle].image) ? data.searchData[i][searchTitle].image : null; + let memberID = data.searchData[i][searchTitle].memberID; + let entityID = data.searchData[i][searchTitle].entityID; + searchDropdown.push(searchTitle); + {literal} searchResults[searchTitle] = {image: image, memberID: memberID, entityID: entityID}; {/literal} + } + {literal} response(searchDropdown); {/literal} + }else{ + response(['No Results Found']) + } + } + }); + }, + renderItem: function (item, search){ + + search = search.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&'); + var re = new RegExp("(" + search.split(' ').join('|') + ")", "gi"); + let entityID = 0; + //console.log(search); + //console.log(re); + if(search !== "No Results Found"){ + entityID = searchResults[item].entityID; + } + console.log('
'+item.replace(re, "$1")+'
'); + return '
'+item.replace(re, "$1")+'
'; + + }, + }); + }); + } + + /* + * Date Search Widget + * IF WE WANT DATE SEARCH FOR MEMBERS + */ + // function dateSearch(dateSearchData){ + // jQuery(function($){ + + // var date = new Date(); + // var toDate = '', fromDate = (dateSearchData.defaultFromDate) ? '&' + dateSearchData.fromDate + '=' + dateSearchData.defaultFromDate : ''; + // $('.fromDate').datepicker({ + // format : 'mm/dd/yyyy', + // setDefaultDate : true, + // defaultDate : date, + // autoClose : true, + // onClose : function(){ + // fromDate = '&' + dateSearchData.fromDate + '=' + $(this)[0].el.value; + // } + // }); + // $('.toDate').datepicker({ + // format : 'mm/dd/yyyy', + // autoClose : true, + // onClose: function(){ + // toDate = '&' + dateSearchData.toDate + '=' + $(this)[0].el.value; + // } + // }); + + // $('#' + dateSearchData.searchBtn).on("click", function(){ + // window.location = dateSearchData.resultUrl + fromDate + toDate; + // }) + // }); + // } + {include file='admin/footer.html'} \ No newline at end of file -- 2.17.1