/** * CustomersHelper Class * * This class contains the methods that are used in the backend customers page. * * @class CustomersHelper */ function CustomersHelper() { this.filterResults = {}; }
/** * Binds the default event handlers of the backend customers page. */ CustomersHelper.prototype.bindEventHandlers = function () { var instance = this;
/** * Event: Filter Entry "Click" * * Display the customer data of the selected row. */ $(document).on('click', '.entry', function () { if ($('#filter-customers .filter').prop('disabled')) { return; // Do nothing when user edits a customer record. }
var customerId = $(this).attr('data-id'); var customer = {}; $.each(instance.filterResults, function (index, item) { if (item.id == customerId) { customer = item; return false; } });
/** * Save a customer record to the database (via ajax post). * * @param {Object} customer Contains the customer data. */ CustomersHelper.prototype.save = function (customer) { var postUrl = GlobalVariables.baseUrl + '/index.php/backend_api/ajax_save_customer'; var postData = { csrfToken: GlobalVariables.csrfToken, customer: JSON.stringify(customer) };
$.post(postUrl, postData, function (response) { if (!GeneralFunctions.handleAjaxExceptions(response)) { return; }
/** * Delete a customer record from database. * * @param {Number} id Record id to be deleted. */ CustomersHelper.prototype.delete = function (id) { var postUrl = GlobalVariables.baseUrl + '/index.php/backend_api/ajax_delete_customer'; var postData = { csrfToken: GlobalVariables.csrfToken, customer_id: id };
$.post(postUrl, postData, function (response) { if (!GeneralFunctions.handleAjaxExceptions(response)) { return; }
/** * Validate customer data before save (insert or update). */ CustomersHelper.prototype.validate = function () { $('#form-message') .removeClass('alert-danger') .hide(); $('.has-error').removeClass('has-error');
try { // Validate required fields. var missingRequired = false;
/** * Bring the customer form back to its initial state. */ CustomersHelper.prototype.resetForm = function () { $('.record-details').find('input, textarea').val(''); $('.record-details').find('input, textarea').prop('readonly', true);
/** * Display a customer record into the form. * * @param {Object} customer Contains the customer record data. */ CustomersHelper.prototype.display = function (customer) { $('#customer-id').val(customer.id); $('#first-name').val(customer.first_name); $('#last-name').val(customer.last_name); $('#email').val(customer.email); $('#phone-number').val(customer.phone_number); $('#address').val(customer.address); $('#city').val(customer.city); $('#zip-code').val(customer.zip_code); $('#notes').val(customer.notes);
$('#customer-appointments').empty(); $.each(customer.appointments, function (index, appointment) { if (GlobalVariables.user.role_slug === Backend.DB_SLUG_PROVIDER && parseInt(appointment.id_users_provider) !== GlobalVariables.user.id) { return true; // continue }
var start = GeneralFunctions.formatDate(Date.parse(appointment.start_datetime), GlobalVariables.dateFormat, true); var end = GeneralFunctions.formatDate(Date.parse(appointment.end_datetime), GlobalVariables.dateFormat, true);
var html = '<tr><td data-id="' + appointment.id + '"> ' +appointment.provider.first_name+' </td><td > ' +appointment.provider.first_name+' </td></tr>';
$('#customer-appointments').append(html); });
$('#appointment-details').empty(); };
/** * Filter customer records. * * @param {String} key This key string is used to filter the customer records. * @param {Number} selectId Optional, if set then after the filter operation the record with the given * ID will be selected (but not displayed). * @param {Boolean} display Optional (false), if true then the selected record will be displayed on the form. */ CustomersHelper.prototype.filter = function (key, selectId, display) { display = display || false;
var postUrl = GlobalVariables.baseUrl + '/index.php/backend_api/ajax_filter_customers'; var postData = { csrfToken: GlobalVariables.csrfToken, key: key };
$.post(postUrl, postData, function (response) { if (!GeneralFunctions.handleAjaxExceptions(response)) { return; }
this.filterResults = response;
$('#filter-customers .results').html(''); $.each(response, function (index, customer) { var html = this.getFilterHtml(customer); $('#filter-customers .results').append(html); }.bind(this)); if (response.length == 0) { $('#filter-customers .results').html('<em>' + EALang.no_records_found + '</em>'); }
if (selectId != undefined) { this.select(selectId, display); }
/** * Get the filter results row HTML code. * * @param {Object} customer Contains the customer data. * * @return {String} Returns the record HTML code. */ CustomersHelper.prototype.getFilterHtml = function (customer) { var name = customer.first_name + ' ' + customer.last_name; var info = customer.email; info = (customer.phone_number != '' && customer.phone_number != null) ? info + ', ' + customer.phone_number : info;
var html = '<div class="entry" data-id="' + customer.id + '">' + '<strong>' + name + '</strong><br>' + info + '</div><hr>';
return html; };
/** * Select a specific record from the current filter results. * * If the customer id does not exist in the list then no record will be selected. * * @param {Number} id The record id to be selected from the filter results. * @param {Boolean} display Optional (false), if true then the method will display the record * on the form. */ CustomersHelper.prototype.select = function (id, display) { display = display || false;
DH forumlarında vakit geçirmekten keyif alıyor gibisin ancak giriş yapmadığını görüyoruz.
Üye Ol Şimdi DeğilÜye olduğunda özel mesaj gönderebilir, beğendiğin konuları favorilerine ekleyip takibe alabilir ve daha önce gezdiğin konulara hızlıca erişebilirsin.