From 844977bde1e9e86ec31541d0eb53633b284c97f6 Mon Sep 17 00:00:00 2001 From: patrick Date: Thu, 4 Jul 2019 00:43:20 +1000 Subject: [PATCH] search staff or clients using input box works --- js/bts_timesheet.js | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/js/bts_timesheet.js b/js/bts_timesheet.js index 4f951f6..ca0c578 100644 --- a/js/bts_timesheet.js +++ b/js/bts_timesheet.js @@ -148,11 +148,34 @@ } function init_user_search(){ - $('div.b_search input').keyup(debounce(function(){ - console.log('key pressed'); + $('div.b_search input').keyup(debounce(function(e){ + filter_user(e.target); }, 500)); } + function filter_user(input){ + var value = $(input).attr('value'); + var selector = get_selector_for_filter_people(input); + $.each( $(selector).find('div.peopleitem'), function(index, e){ + var html = $(e).find('div[name="title"] a').html(); + if (-1 != html.indexOf(value)){//we find it; + $(e).show(); + }else{ + $(e).hide(); + } + }); + } + + function get_selector_for_filter_people(input){ + var selector=''; + var role = $(input).attr('placeholder'); + if (role == 'staff') //we filter staff + selector = 'div.stafflist'; + else if (role = 'client') + selector = 'div.clientlist'; + return selector; + } + function init_ts(){ list_staff(); list_clients();