Przeglądaj źródła

debounce works for staff input

master
patrick 6 lat temu
rodzic
commit
a8fee31a8c
2 zmienionych plików z 83 dodań i 7 usunięć
  1. +69
    -3
      js/bts_timesheet.js
  2. +14
    -4
      ts.php

+ 69
- 3
js/bts_timesheet.js Wyświetl plik

(function ($) { (function ($) {
$(function () { $(function () {
// http://davidwalsh.name/javascript-debounce-function
function debounce(func, wait, immediate) {
var timeout;
return function () {
var context = this, args = arguments;
var later = function () {
timeout = null;
if (!immediate)
func.apply(context, args);
};
var callNow = immediate && !timeout;
clearTimeout(timeout);
timeout = setTimeout(later, wait);
if (callNow)
func.apply(context, args);
};
};
/*____________________________________________________________________________________*/ /*____________________________________________________________________________________*/
class People{ class People{
constructor(selector, data){ constructor(selector, data){
} }
} }
function list_staff() { function list_staff() {
$('div.stafflist div.peopleitem').remove();
$.post(bts().ajax_url, { // POST request $.post(bts().ajax_url, { // POST request
_ajax_nonce: bts().nonce, // nonce _ajax_nonce: bts().nonce, // nonce
action: "list_staff", // action action: "list_staff", // action
}, function(response, status, xhr){ }, function(response, status, xhr){
if (response.status =='success'){ if (response.status =='success'){
response.staff.forEach(function(staff){
var html = bts_people_html(staff);
response.users.forEach(function(u){
var html = bts_people_html(u);
jQuery('div.stafflist').append(html); jQuery('div.stafflist').append(html);
new People("#p" + staff.login, staff);
new People("#p" + u.login, u);
}); });
}else{ }else{
alert('error getting staff list'); alert('error getting staff list');
} }
}); });
} }
function list_clients() {
$('div.clientlist div.peopleitem').remove(); //clear it
$.post(bts().ajax_url, { // POST request
_ajax_nonce: bts().nonce, // nonce
action: "list_client", // action
}, function(response, status, xhr){
if (response.status =='success'){
response.users.forEach(function(u){
var html = bts_people_html(u);
jQuery('div.clientlist').append(html);
new People("#p" + u.login, u);
});
}else{
alert('error getting Client list');
}
});
}
function xero(t){
if (t)
$('div.xero i').show();
else
$('div.xero i').hide();
}
function wifi(t){
if (t)
$('div.wifi i').show();
else
$('div.wifi i').hide();
}
function init_user_search(){
$('div.b_search input').keyup(debounce(function(){
console.log('key pressed');
}, 500));
}
function init_ts(){ function init_ts(){
list_staff(); list_staff();
list_clients();
xero(false);
wifi(false);
init_user_search();
} }


init_ts(); init_ts();
/*________________________________________________________________________*/ /*________________________________________________________________________*/
}); });

+ 14
- 4
ts.php Wyświetl plik

add_shortcode( 'bts_people_item', array($this, 'bts_people_item')); add_shortcode( 'bts_people_item', array($this, 'bts_people_item'));
add_action('wp_ajax_list_staff', array($this,'list_staff' )); add_action('wp_ajax_list_staff', array($this,'list_staff' ));
add_action('wp_ajax_list_client', array($this,'list_client' ));
} }
function list_staff(){ function list_staff(){
check_ajax_referer('acaresydney');
return $this->list_people_by_role('staff');
}
function list_client(){
check_ajax_referer('acaresydney');
return $this->list_people_by_role('client');
}
function list_people_by_role($role){
check_ajax_referer('acaresydney'); check_ajax_referer('acaresydney');
// Handle the ajax request // Handle the ajax request
$response = array( $response = array(
'status' =>'error', 'status' =>'error',
'staff' => [],
'users' => [],
); );
//search all users that are staff //search all users that are staff
$staffq = new \WP_User_Query(array('role'=>'staff'));
$staffq = new \WP_User_Query(array('role'=>$role));
$staff = $staffq->get_results(); $staff = $staffq->get_results();
if (! empty($staff)){ if (! empty($staff)){
$response['status'] = 'success'; $response['status'] = 'success';
foreach( $staff as $s){ foreach( $staff as $s){
$response['staff'][] = array(
$response['users'][] = array(
'login' => $s->user_login, 'login' => $s->user_login,
'firstname'=> $s->first_name, 'firstname'=> $s->first_name,
'lastname'=> $s->last_name, 'lastname'=> $s->last_name,
'hour' => 0 , 'hour' => 0 ,
'OT' => 0 , 'OT' => 0 ,
'petrol'=> 0 , 'petrol'=> 0 ,
'rating'=> 0,
'rating'=> 0,
'unconfirmedjob'=> 0, 'unconfirmedjob'=> 0,
); );
} }

Ładowanie…
Anuluj
Zapisz