2015-07-20 22:41:24 +03:00
|
|
|
/* ----------------------------------------------------------------------------
|
|
|
|
* Easy!Appointments - Open Source Web Scheduler
|
|
|
|
*
|
|
|
|
* @package EasyAppointments
|
|
|
|
* @author A.Tselegidis <alextselegidis@gmail.com>
|
|
|
|
* @copyright Copyright (c) 2013 - 2015, Alex Tselegidis
|
|
|
|
* @license http://opensource.org/licenses/GPL-3.0 - GPLv3
|
|
|
|
* @link http://easyappointments.org
|
|
|
|
* @since v1.0.0
|
|
|
|
* ---------------------------------------------------------------------------- */
|
|
|
|
|
2013-07-05 11:39:52 +03:00
|
|
|
/**
|
|
|
|
* Backend Customers javasript namespace. Contains the main functionality
|
|
|
|
* of the backend customers page. If you need to use this namespace in a
|
|
|
|
* different page, do not bind the default event handlers during initialization.
|
|
|
|
*
|
2013-09-13 16:21:03 +03:00
|
|
|
* @namespace BackendCustomers
|
2013-07-05 11:39:52 +03:00
|
|
|
*/
|
|
|
|
var BackendCustomers = {
|
2013-09-25 18:43:17 +03:00
|
|
|
/**
|
|
|
|
* The page helper contains methods that implement each record type functionality
|
|
|
|
* (for now there is only the CustomersHelper).
|
|
|
|
*
|
|
|
|
* @type {object{
|
|
|
|
*/
|
|
|
|
helper: {},
|
|
|
|
|
2013-07-05 11:39:52 +03:00
|
|
|
/**
|
|
|
|
* This method initializes the backend customers page. If you use this namespace
|
|
|
|
* in a different page do not use this method.
|
|
|
|
*
|
2013-09-25 18:43:17 +03:00
|
|
|
* @param {bool} defaultEventHandlers (OPTIONAL = false) Whether to bind the default
|
|
|
|
* event handlers or not.
|
2013-07-05 11:39:52 +03:00
|
|
|
*/
|
2013-09-25 18:43:17 +03:00
|
|
|
initialize: function(defaultEventHandlers) {
|
|
|
|
if (defaultEventHandlers == undefined) defaultEventHandlers = false;
|
|
|
|
|
|
|
|
BackendCustomers.helper = new CustomersHelper();
|
|
|
|
BackendCustomers.helper.resetForm();
|
|
|
|
BackendCustomers.helper.filter('');
|
2013-07-15 17:27:19 +03:00
|
|
|
|
2013-10-10 19:50:33 +03:00
|
|
|
$('#filter-customers .results').jScrollPane();
|
|
|
|
$('#customer-appointments').jScrollPane();
|
|
|
|
|
2013-09-25 18:43:17 +03:00
|
|
|
if (defaultEventHandlers) {
|
2013-07-05 11:39:52 +03:00
|
|
|
BackendCustomers.bindEventHandlers();
|
|
|
|
}
|
|
|
|
},
|
2013-07-06 03:00:04 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Default event handlers declaration for backend customers page.
|
|
|
|
*/
|
2013-07-05 11:39:52 +03:00
|
|
|
bindEventHandlers: function() {
|
2013-09-25 18:43:17 +03:00
|
|
|
CustomersHelper.prototype.bindEventHandlers();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This class contains the methods that are used in the backend customers page.
|
|
|
|
*
|
|
|
|
* @class CustomersHelper
|
|
|
|
*/
|
|
|
|
var CustomersHelper = function() {
|
|
|
|
this.filterResults = {};
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Binds the default event handlers of the backend customers page.
|
|
|
|
*/
|
|
|
|
CustomersHelper.prototype.bindEventHandlers = function() {
|
|
|
|
/**
|
|
|
|
* Event: Filter Customers Form "Submit"
|
|
|
|
*/
|
2014-01-04 00:26:10 +02:00
|
|
|
$('#filter-customers form').submit(function(event) {
|
2013-09-25 18:43:17 +03:00
|
|
|
var key = $('#filter-customers .key').val();
|
|
|
|
$('#filter-customers .selected-row').removeClass('selected-row');
|
|
|
|
BackendCustomers.helper.resetForm();
|
|
|
|
BackendCustomers.helper.filter(key);
|
2014-01-04 00:26:10 +02:00
|
|
|
return false;
|
2013-09-25 18:43:17 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Event: Filter Customers Clear Button "Click"
|
|
|
|
*/
|
|
|
|
$('#filter-customers .clear').click(function() {
|
|
|
|
$('#filter-customers .key').val('');
|
|
|
|
BackendCustomers.helper.filter('');
|
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Event: Customer Row "Click"
|
|
|
|
*
|
|
|
|
* Display the customer data of the selected row.
|
|
|
|
*/
|
|
|
|
$(document).on('click', '.customer-row', function() {
|
|
|
|
if ($('#filter-customers .filter').prop('disabled')) {
|
|
|
|
return; // Do nothing when user edits a customer record.
|
|
|
|
}
|
2013-07-15 17:27:19 +03:00
|
|
|
|
2013-09-25 18:43:17 +03:00
|
|
|
var customerId = $(this).attr('data-id');
|
|
|
|
var customer = {};
|
|
|
|
$.each(BackendCustomers.helper.filterResults, function(index, item) {
|
|
|
|
if (item.id == customerId) {
|
|
|
|
customer = item;
|
|
|
|
return false;
|
|
|
|
}
|
2013-07-15 17:27:19 +03:00
|
|
|
});
|
|
|
|
|
2013-09-25 18:43:17 +03:00
|
|
|
BackendCustomers.helper.display(customer);
|
|
|
|
$('#filter-customers .selected-row').removeClass('selected-row');
|
|
|
|
$(this).addClass('selected-row');
|
|
|
|
$('#edit-customer, #delete-customer').prop('disabled', false);
|
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Event: Appointment Row "Click"
|
|
|
|
*
|
|
|
|
* Display appointment data of the selected row.
|
|
|
|
*/
|
|
|
|
$(document).on('click', '.appointment-row', function() {
|
|
|
|
$('#customer-appointments .selected-row').removeClass('selected-row');
|
|
|
|
$(this).addClass('selected-row');
|
|
|
|
|
|
|
|
var customerId = $('#filter-customers .selected-row').attr('data-id');
|
|
|
|
var appointmentId = $(this).attr('data-id');
|
|
|
|
var appointment = {};
|
|
|
|
|
|
|
|
$.each(BackendCustomers.helper.filterResults, function(index, c) {
|
|
|
|
if (c.id === customerId) {
|
|
|
|
$.each(c.appointments, function(index, a) {
|
|
|
|
if (a.id == appointmentId) {
|
|
|
|
appointment = a;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
return false;
|
2013-07-15 17:27:19 +03:00
|
|
|
}
|
|
|
|
});
|
2013-09-25 18:43:17 +03:00
|
|
|
|
|
|
|
BackendCustomers.helper.displayAppointment(appointment);
|
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Event: Add Customer Button "Click"
|
|
|
|
*/
|
|
|
|
$('#add-customer').click(function() {
|
|
|
|
BackendCustomers.helper.resetForm();
|
|
|
|
$('#add-edit-delete-group').hide();
|
|
|
|
$('#save-cancel-group').show();
|
2013-10-17 18:31:43 +03:00
|
|
|
$('.details').find('input, textarea').prop('readonly', false);
|
2013-09-25 18:43:17 +03:00
|
|
|
|
|
|
|
$('#filter-customers button').prop('disabled', true);
|
|
|
|
$('#filter-customers .results').css('color', '#AAA');
|
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Event: Edit Customer Button "Click"
|
|
|
|
*/
|
|
|
|
$('#edit-customer').click(function() {
|
2013-10-17 18:31:43 +03:00
|
|
|
$('.details').find('input, textarea').prop('readonly', false);
|
2013-09-25 18:43:17 +03:00
|
|
|
$('#add-edit-delete-group').hide();
|
|
|
|
$('#save-cancel-group').show();
|
|
|
|
|
|
|
|
$('#filter-customers button').prop('disabled', true);
|
|
|
|
$('#filter-customers .results').css('color', '#AAA');
|
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Event: Cancel Customer Add/Edit Operation Button "Click"
|
|
|
|
*/
|
|
|
|
$('#cancel-customer').click(function() {
|
|
|
|
var id = $('#customer-id').val();
|
|
|
|
BackendCustomers.helper.resetForm();
|
|
|
|
if (id != '') {
|
|
|
|
BackendCustomers.helper.select(id, true);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Event: Save Add/Edit Customer Operation "Click"
|
|
|
|
*/
|
|
|
|
$('#save-customer').click(function() {
|
|
|
|
var customer = {
|
|
|
|
'first_name': $('#first-name').val(),
|
|
|
|
'last_name': $('#last-name').val(),
|
|
|
|
'email': $('#email').val(),
|
|
|
|
'phone_number': $('#phone-number').val(),
|
|
|
|
'address': $('#address').val(),
|
|
|
|
'city': $('#city').val(),
|
|
|
|
'zip_code': $('#zip-code').val(),
|
|
|
|
'notes': $('#notes').val()
|
|
|
|
};
|
|
|
|
|
|
|
|
if ($('#customer-id').val() != '') {
|
|
|
|
customer.id = $('#customer-id').val();
|
|
|
|
}
|
2013-07-15 17:27:19 +03:00
|
|
|
|
2013-09-25 18:43:17 +03:00
|
|
|
if (!BackendCustomers.helper.validate(customer)) return;
|
2013-07-15 17:27:19 +03:00
|
|
|
|
2013-09-25 18:43:17 +03:00
|
|
|
BackendCustomers.helper.save(customer);
|
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Event: Delete Customer Button "Click"
|
|
|
|
*/
|
|
|
|
$('#delete-customer').click(function() {
|
|
|
|
var customerId = $('#customer-id').val();
|
2013-07-15 17:27:19 +03:00
|
|
|
|
2013-12-19 18:28:19 +02:00
|
|
|
var messageBtns = {};
|
2013-12-20 19:44:44 +02:00
|
|
|
messageBtns[EALang['delete']] = function() {
|
2013-12-19 18:28:19 +02:00
|
|
|
BackendCustomers.helper.delete(customerId);
|
|
|
|
$('#message_box').dialog('close');
|
|
|
|
};
|
2013-12-20 19:44:44 +02:00
|
|
|
messageBtns[EALang['cancel']] = function() {
|
2013-12-19 18:28:19 +02:00
|
|
|
$('#message_box').dialog('close');
|
2013-09-25 18:43:17 +03:00
|
|
|
};
|
|
|
|
|
2013-12-20 19:44:44 +02:00
|
|
|
GeneralFunctions.displayMessageBox(EALang['delete_customer'],
|
|
|
|
EALang['delete_record_prompt'], messageBtns);
|
2013-09-25 18:43:17 +03:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Save a customer record to the database (via ajax post).
|
|
|
|
*
|
|
|
|
* @param {object} customer Contains the customer data.
|
|
|
|
*/
|
|
|
|
CustomersHelper.prototype.save = function(customer) {
|
2015-05-28 01:01:50 +03:00
|
|
|
var postUrl = GlobalVariables.baseUrl + '/index.php/backend_api/ajax_save_customer';
|
2015-05-28 00:42:40 +03:00
|
|
|
var postData = {
|
|
|
|
'csrfToken': GlobalVariables.csrfToken,
|
|
|
|
'customer': JSON.stringify(customer)
|
|
|
|
};
|
2013-09-25 18:43:17 +03:00
|
|
|
|
|
|
|
$.post(postUrl, postData, function(response) {
|
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
console.log('Save Customer Response:', response);
|
|
|
|
///////////////////////////////////////////////////////////
|
2013-07-15 17:27:19 +03:00
|
|
|
|
2013-09-25 18:43:17 +03:00
|
|
|
if (!GeneralFunctions.handleAjaxExceptions(response)) return;
|
2013-07-15 17:27:19 +03:00
|
|
|
|
2013-12-20 19:44:44 +02:00
|
|
|
Backend.displayNotification(EALang['customer_saved']);
|
2013-09-25 18:43:17 +03:00
|
|
|
BackendCustomers.helper.resetForm();
|
|
|
|
$('#filter-customers .key').val('');
|
|
|
|
BackendCustomers.helper.filter('', response.id, true);
|
|
|
|
}, 'json');
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Delete a customer record from database.
|
|
|
|
*
|
|
|
|
* @param {numeric} id Record id to be deleted.
|
|
|
|
*/
|
|
|
|
CustomersHelper.prototype.delete = function(id) {
|
2015-05-20 23:26:11 +03:00
|
|
|
var postUrl = GlobalVariables.baseUrl + '/index.php/backend_api/ajax_delete_customer';
|
2015-05-28 00:42:40 +03:00
|
|
|
var postData = {
|
|
|
|
'csrfToken': GlobalVariables.csrfToken,
|
|
|
|
'customer_id': id
|
|
|
|
};
|
2013-09-25 18:43:17 +03:00
|
|
|
|
|
|
|
$.post(postUrl, postData, function(response) {
|
|
|
|
////////////////////////////////////////////////////
|
|
|
|
//console.log('Delete customer response:', response);
|
|
|
|
////////////////////////////////////////////////////
|
2013-07-15 17:27:19 +03:00
|
|
|
|
2013-09-25 18:43:17 +03:00
|
|
|
if (!GeneralFunctions.handleAjaxExceptions(response)) return;
|
2013-07-15 17:27:19 +03:00
|
|
|
|
2013-12-20 19:44:44 +02:00
|
|
|
Backend.displayNotification(EALang['customer_deleted']);
|
2013-09-25 18:43:17 +03:00
|
|
|
BackendCustomers.helper.resetForm();
|
|
|
|
BackendCustomers.helper.filter($('#filter-customers .key').val());
|
|
|
|
}, 'json');
|
|
|
|
};
|
2013-07-15 17:27:19 +03:00
|
|
|
|
2013-09-25 18:43:17 +03:00
|
|
|
/**
|
|
|
|
* Validate customer data before save (insert or update).
|
|
|
|
*
|
|
|
|
* @param {object} customer Contains the customer data.
|
|
|
|
*/
|
|
|
|
CustomersHelper.prototype.validate = function(customer) {
|
|
|
|
$('#form-message').hide();
|
|
|
|
$('.required').css('border', '');
|
|
|
|
|
|
|
|
try {
|
|
|
|
// Validate required fields.
|
|
|
|
var missingRequired = false;
|
|
|
|
$('.required').each(function() {
|
|
|
|
if ($(this).val() == '') {
|
|
|
|
$(this).css('border', '2px solid red');
|
|
|
|
missingRequired = true;
|
2013-07-15 17:27:19 +03:00
|
|
|
}
|
2013-09-25 18:43:17 +03:00
|
|
|
});
|
|
|
|
if (missingRequired) {
|
2013-12-20 19:44:44 +02:00
|
|
|
throw EALang['fields_are_required'];
|
2013-09-25 18:43:17 +03:00
|
|
|
}
|
2013-07-15 17:27:19 +03:00
|
|
|
|
2013-09-25 18:43:17 +03:00
|
|
|
// Validate email address.
|
|
|
|
if (!GeneralFunctions.validateEmail($('#email').val())) {
|
|
|
|
$('#email').css('border', '2px solid red');
|
2013-12-20 19:44:44 +02:00
|
|
|
throw EALang['invalid_email'];
|
2013-07-15 17:27:19 +03:00
|
|
|
}
|
|
|
|
|
2013-09-25 18:43:17 +03:00
|
|
|
return true;
|
|
|
|
|
|
|
|
} catch(exc) {
|
|
|
|
$('#form-message').text(exc).show();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Bring the customer form back to its initial state.
|
|
|
|
*/
|
|
|
|
CustomersHelper.prototype.resetForm = function() {
|
2013-10-17 18:31:43 +03:00
|
|
|
$('.details').find('input, textarea').val('');
|
|
|
|
$('.details').find('input, textarea').prop('readonly', true);
|
2013-09-26 19:06:57 +03:00
|
|
|
|
2013-09-25 18:43:17 +03:00
|
|
|
$('#customer-appointments').html('');
|
|
|
|
$('#appointment-details').html('');
|
|
|
|
$('#edit-customer, #delete-customer').prop('disabled', true);
|
|
|
|
$('#add-edit-delete-group').show();
|
|
|
|
$('#save-cancel-group').hide();
|
|
|
|
|
2013-10-17 18:31:43 +03:00
|
|
|
$('.details .required').css('border', '');
|
|
|
|
$('.details #form-message').hide();
|
2013-09-26 19:06:57 +03:00
|
|
|
|
2013-09-25 18:43:17 +03:00
|
|
|
$('#filter-customers button').prop('disabled', false);
|
|
|
|
$('#filter-customers .selected-row').removeClass('selected-row');
|
|
|
|
$('#filter-customers .results').css('color', '');
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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);
|
|
|
|
|
2013-10-10 19:50:33 +03:00
|
|
|
$('#customer-appointments').data('jsp').destroy();
|
2013-09-25 18:43:17 +03:00
|
|
|
$('#customer-appointments').empty();
|
|
|
|
$.each(customer.appointments, function(index, appointment) {
|
2013-07-15 17:27:19 +03:00
|
|
|
var start = Date.parse(appointment.start_datetime).toString('dd/MM/yyyy HH:mm');
|
|
|
|
var end = Date.parse(appointment.end_datetime).toString('dd/MM/yyyy HH:mm');
|
|
|
|
var html =
|
2013-09-25 18:43:17 +03:00
|
|
|
'<div class="appointment-row" data-id="' + appointment.id + '">' +
|
2013-07-15 17:27:19 +03:00
|
|
|
start + ' - ' + end + '<br>' +
|
2013-09-25 18:43:17 +03:00
|
|
|
appointment.service.name + ', ' +
|
|
|
|
appointment.provider.first_name + ' ' + appointment.provider.last_name +
|
|
|
|
'</div>';
|
|
|
|
$('#customer-appointments').append(html);
|
|
|
|
});
|
2013-10-11 18:58:46 +03:00
|
|
|
$('#customer-appointments').jScrollPane({ mouseWheelSpeed: 70 });
|
2013-10-18 17:56:12 +03:00
|
|
|
|
|
|
|
$('#appointment-details').empty();
|
2013-09-25 18:43:17 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Filter customer records.
|
|
|
|
*
|
|
|
|
* @param {string} key This key string is used to filter the customer records.
|
|
|
|
* @param {numeric} selectId (OPTIONAL = undefined) If set then after the filter
|
|
|
|
* operation the record with the given id will be selected (but not displayed).
|
|
|
|
* @param {bool} display (OPTIONAL = false) If true then the selected record will
|
|
|
|
* be displayed on the form.
|
|
|
|
*/
|
|
|
|
CustomersHelper.prototype.filter = function(key, selectId, display) {
|
|
|
|
if (display == undefined) display = false;
|
|
|
|
|
2015-05-20 23:26:11 +03:00
|
|
|
var postUrl = GlobalVariables.baseUrl + '/index.php/backend_api/ajax_filter_customers';
|
2015-05-28 00:42:40 +03:00
|
|
|
var postData = {
|
|
|
|
'csrfToken': GlobalVariables.csrfToken,
|
|
|
|
'key': key
|
|
|
|
};
|
2013-09-25 18:43:17 +03:00
|
|
|
|
|
|
|
$.post(postUrl, postData, function(response) {
|
|
|
|
///////////////////////////////////////////////////////
|
|
|
|
console.log('Filter Customers Response:', response);
|
|
|
|
///////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
if (!GeneralFunctions.handleAjaxExceptions(response)) return;
|
|
|
|
|
|
|
|
BackendCustomers.helper.filterResults = response;
|
|
|
|
|
2013-10-10 19:50:33 +03:00
|
|
|
$('#filter-customers .results').data('jsp').destroy();
|
2013-09-25 18:43:17 +03:00
|
|
|
$('#filter-customers .results').html('');
|
|
|
|
$.each(response, function(index, customer) {
|
|
|
|
var html = BackendCustomers.helper.getFilterHtml(customer);
|
|
|
|
$('#filter-customers .results').append(html);
|
|
|
|
});
|
2013-10-11 18:58:46 +03:00
|
|
|
$('#filter-customers .results').jScrollPane({ mouseWheelSpeed: 70 });
|
2013-10-10 19:50:33 +03:00
|
|
|
|
2013-09-25 18:43:17 +03:00
|
|
|
if (response.length == 0) {
|
2013-12-20 19:44:44 +02:00
|
|
|
$('#filter-customers .results').html('<em>' + EALang['no_records_found'] + '</em>');
|
2013-09-25 18:43:17 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (selectId != undefined) {
|
|
|
|
BackendCustomers.helper.select(selectId, display);
|
|
|
|
}
|
|
|
|
|
|
|
|
}, 'json');
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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) {
|
2013-10-27 19:41:37 +02:00
|
|
|
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;
|
|
|
|
|
2013-09-25 18:43:17 +03:00
|
|
|
var html =
|
|
|
|
'<div class="customer-row" data-id="' + customer.id + '">' +
|
|
|
|
'<strong>' +
|
2013-10-27 19:41:37 +02:00
|
|
|
name +
|
2013-09-25 18:43:17 +03:00
|
|
|
'</strong><br>' +
|
2013-10-27 19:41:37 +02:00
|
|
|
info +
|
2013-09-25 18:43:17 +03:00
|
|
|
'</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 {numeric} id The record id to be selected from the filter results.
|
|
|
|
* @param {bool} display (OPTIONAL = false) If true then the method will display the record
|
|
|
|
* on the form.
|
|
|
|
*/
|
|
|
|
CustomersHelper.prototype.select = function(id, display) {
|
|
|
|
if (display == undefined) display = false;
|
|
|
|
|
|
|
|
$('#filter-customers .selected-row').removeClass('selected-row');
|
|
|
|
|
|
|
|
$('#filter-customers .customer-row').each(function() {
|
|
|
|
if ($(this).attr('data-id') == id) {
|
|
|
|
$(this).addClass('selected-row');
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
if (display) {
|
|
|
|
$.each(BackendCustomers.helper.filterResults, function(index, customer) {
|
|
|
|
if (customer.id == id) {
|
|
|
|
BackendCustomers.helper.display(customer);
|
|
|
|
$('#edit-customer, #delete-customer').prop('disabled', false);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
});
|
2013-07-15 17:27:19 +03:00
|
|
|
}
|
2013-09-25 18:43:17 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Display appointment details on customers backend page.
|
|
|
|
*
|
|
|
|
* @param {object} appointment Appointment data
|
|
|
|
*/
|
|
|
|
CustomersHelper.prototype.displayAppointment = function(appointment) {
|
|
|
|
var start = Date.parse(appointment.start_datetime).toString('dd/MM/yyyy HH:mm');
|
|
|
|
var end = Date.parse(appointment.end_datetime).toString('dd/MM/yyyy HH:mm');
|
|
|
|
|
|
|
|
var html =
|
|
|
|
'<div>' +
|
|
|
|
'<strong>' + appointment.service.name + '</strong><br>' +
|
|
|
|
appointment.provider.first_name + ' ' + appointment.provider.last_name + '<br>' +
|
|
|
|
start + ' - ' + end + '<br>' +
|
|
|
|
'</div>';
|
|
|
|
|
|
|
|
$('#appointment-details').html(html);
|
2013-07-05 11:39:52 +03:00
|
|
|
};
|