mirror of
https://github.com/alextselegidis/easyappointments.git
synced 2024-11-09 17:42:21 +03:00
Debounce keyup events when searching for existing customers
This commit is contained in:
parent
b794cb6e74
commit
53a6a8c3a8
1 changed files with 55 additions and 41 deletions
|
@ -223,11 +223,19 @@ window.BackendCalendarAppointmentsModal = window.BackendCalendarAppointmentsModa
|
|||
$('#select-customer').trigger('click'); // Hide the list.
|
||||
});
|
||||
|
||||
var filterExistingCustomersTimeout = null;
|
||||
|
||||
/**
|
||||
* Event: Filter Existing Customers "Change"
|
||||
*/
|
||||
$('#filter-existing-customers').on('keyup', function () {
|
||||
if (filterExistingCustomersTimeout) {
|
||||
clearTimeout(filterExistingCustomersTimeout);
|
||||
}
|
||||
|
||||
var key = $(this).val().toLowerCase();
|
||||
|
||||
filterExistingCustomersTimeout = setTimeout(function() {
|
||||
var $list = $('#existing-customers-list');
|
||||
|
||||
var url = GlobalVariables.baseUrl + '/index.php/backend_api/ajax_filter_customers';
|
||||
|
@ -237,6 +245,8 @@ window.BackendCalendarAppointmentsModal = window.BackendCalendarAppointmentsModa
|
|||
key: key
|
||||
};
|
||||
|
||||
$('#loading').css('visibility', 'hidden');
|
||||
|
||||
// Try to get the updated customer list.
|
||||
$.post(url, data)
|
||||
.done(function (response) {
|
||||
|
@ -280,7 +290,11 @@ window.BackendCalendarAppointmentsModal = window.BackendCalendarAppointmentsModa
|
|||
.appendTo($list);
|
||||
}
|
||||
});
|
||||
})
|
||||
.always(function() {
|
||||
$('#loading').css('visibility', '');
|
||||
});
|
||||
}, 1000);
|
||||
});
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in a new issue