Appointment modal in backend now search clients using the ajax filter.

This allow using the most recent clients without refreshing the main page.
This commit is contained in:
h3ct0r 2016-03-10 15:45:17 -03:00
parent 1c4ab83d32
commit 2eb63a21d1

View file

@ -842,6 +842,8 @@ var BackendCalendar = {
// Display modal form.
$dialog.find('.modal-header h3').text(EALang['new_appointment_title']);
$dialog.modal('show');
});
/**
@ -926,17 +928,90 @@ var BackendCalendar = {
$('#filter-existing-customers').keyup(function() {
var key = $(this).val().toLowerCase();
var $list = $('#existing-customers-list');
$list.empty();
$.each(GlobalVariables.customers, function(index, c) {
if (c.first_name.toLowerCase().indexOf(key) != -1
|| c.last_name.toLowerCase().indexOf(key) != -1
|| c.email.toLowerCase().indexOf(key) != -1
|| c.phone_number.toLowerCase().indexOf(key) != -1
|| c.address.toLowerCase().indexOf(key) != -1
|| c.city.toLowerCase().indexOf(key) != -1
|| c.zip_code.toLowerCase().indexOf(key) != -1) {
$list.append('<div data-id="' + c.id + '">'
+ c.first_name + ' ' + c.last_name + '</div>');
var postUrl = GlobalVariables.baseUrl + '/index.php/backend_api/ajax_filter_customers';
var postData = {
'csrfToken': GlobalVariables.csrfToken,
'key': key
};
// $.post(postUrl, postData, function(response) {
// ///////////////////////////////////////////////////////
// console.log('Filter Customers Response:', response);
// ///////////////////////////////////////////////////////
// if (!GeneralFunctions.handleAjaxExceptions(response)) return;
// BackendCustomers.helper.filterResults = response;
// $('#filter-customers .results').data('jsp').destroy();
// $('#filter-customers .results').html('');
// $.each(response, function(index, customer) {
// var html = BackendCustomers.helper.getFilterHtml(customer);
// $('#filter-customers .results').append(html);
// });
// $('#filter-customers .results').jScrollPane({ mouseWheelSpeed: 70 });
// if (response.length == 0) {
// $('#filter-customers .results').html('<em>' + EALang['no_records_found'] + '</em>');
// }
// if (selectId != undefined) {
// BackendCustomers.helper.select(selectId, display);
// }
// }, 'json').fail(GeneralFunctions.ajaxFailureHandler);
// Try to get the updated customer list
$.ajax({
'type': 'POST',
'url': postUrl,
'data': postData,
'dataType': 'json',
'timeout': 1000,
'global': false,
'success': function(response) {
/////////////////////////////////////////////////////////////
console.log('Filter Customers Appointment Response:', response);
/////////////////////////////////////////////////////////////
$list.empty();
$.each(response, function(index, c) {
$list.append('<div data-id="' + c.id + '">'
+ c.first_name + ' ' + c.last_name + '</div>');
// Verify if this customer is on the old customer list
var result = $.grep(GlobalVariables.customers,
function(e){ return e.id == c.id; });
// Add it to the customer list
if(result.length == 0){
GlobalVariables.customers.push(c);
}
});
},
'error': function(jqXHR, textStatus, errorThrown) {
//////////////////////////////////////////////////////////////////
console.log('Filter Customers Appointment Error:', jqXHR, textStatus,
errorThrown);
//////////////////////////////////////////////////////////////////
// If there is any error on the request, search by the local
// client database
$list.empty();
$.each(GlobalVariables.customers, function(index, c) {
if (c.first_name.toLowerCase().indexOf(key) != -1
|| c.last_name.toLowerCase().indexOf(key) != -1
|| c.email.toLowerCase().indexOf(key) != -1
|| c.phone_number.toLowerCase().indexOf(key) != -1
|| c.address.toLowerCase().indexOf(key) != -1
|| c.city.toLowerCase().indexOf(key) != -1
|| c.zip_code.toLowerCase().indexOf(key) != -1
|| c.notes.toLowerCase().indexOf(key) != -1) {
$list.append('<div data-id="' + c.id + '">'
+ c.first_name + ' ' + c.last_name + '</div>');
}
});
}
});
});