2013-09-24 19:05:40 +03:00
|
|
|
/**
|
|
|
|
* This class contains the Providers helper class declaration, along with the "Providers" tab
|
|
|
|
* event handlers. By deviding the backend/users tab functionality into separate files
|
|
|
|
* it is easier to maintain the code.
|
|
|
|
*
|
|
|
|
* @class ProvidersHelper
|
|
|
|
*/
|
|
|
|
var ProvidersHelper = function() {
|
|
|
|
this.filterResults = {}; // Store the results for later use.
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Bind the event handlers for the backend/users "Providers" tab.
|
|
|
|
*/
|
|
|
|
ProvidersHelper.prototype.bindEventHandlers = function() {
|
|
|
|
/**
|
2013-09-25 18:43:17 +03:00
|
|
|
* Event: Filter Providers Form "Submit"
|
2013-09-24 19:05:40 +03:00
|
|
|
*
|
|
|
|
* Filter the provider records with the given key string.
|
|
|
|
*/
|
2013-09-25 18:43:17 +03:00
|
|
|
$('#filter-providers form').submit(function() {
|
|
|
|
event.preventDefault();
|
|
|
|
var key = $('#filter-providers .key').val();
|
2013-09-24 19:05:40 +03:00
|
|
|
$('.selected-row').removeClass('selected-row');
|
|
|
|
BackendUsers.helper.resetForm();
|
|
|
|
BackendUsers.helper.filter(key);
|
|
|
|
});
|
|
|
|
|
2013-09-25 18:43:17 +03:00
|
|
|
/**
|
|
|
|
* Event: Clear Filter Button "Click"
|
|
|
|
*/
|
|
|
|
$('#filter-providers .clear').click(function() {
|
|
|
|
BackendUsers.helper.filter('');
|
|
|
|
$('#filter-providers .key').val('');
|
|
|
|
});
|
|
|
|
|
2013-09-24 19:05:40 +03:00
|
|
|
/**
|
|
|
|
* Event: Filter Provider Row "Click"
|
|
|
|
*
|
|
|
|
* Display the selected provider data to the user.
|
|
|
|
*/
|
|
|
|
$(document).on('click', '.provider-row', function() {
|
2013-09-25 18:43:17 +03:00
|
|
|
if ($('#filter-providers .filter').prop('disabled')) {
|
|
|
|
$('#filter-providers .results').css('color', '#AAA');
|
|
|
|
return; // Exit because we are currently on edit mode.
|
2013-09-24 19:05:40 +03:00
|
|
|
}
|
2013-09-25 18:43:17 +03:00
|
|
|
|
|
|
|
var providerId = $(this).attr('data-id');
|
|
|
|
var provider = {};
|
2013-09-24 19:05:40 +03:00
|
|
|
$.each(BackendUsers.helper.filterResults, function(index, item) {
|
2013-09-25 18:43:17 +03:00
|
|
|
if (item.id === providerId) {
|
2013-09-24 19:05:40 +03:00
|
|
|
provider = item;
|
2013-09-25 18:43:17 +03:00
|
|
|
return false;
|
2013-09-24 19:05:40 +03:00
|
|
|
}
|
|
|
|
});
|
2013-09-25 18:43:17 +03:00
|
|
|
|
2013-09-24 19:05:40 +03:00
|
|
|
BackendUsers.helper.display(provider);
|
2013-09-25 18:43:17 +03:00
|
|
|
$('#filter-providers .selected-row').removeClass('selected-row');
|
2013-09-24 19:05:40 +03:00
|
|
|
$(this).addClass('selected-row');
|
|
|
|
$('#edit-provider, #delete-provider').prop('disabled', false);
|
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Event: Add New Provider Button "Click"
|
|
|
|
*/
|
|
|
|
$('#add-provider').click(function() {
|
|
|
|
BackendUsers.helper.resetForm();
|
2013-09-25 18:43:17 +03:00
|
|
|
$('#filter-providers button').prop('disabled', true);
|
|
|
|
$('#filter-providers .results').css('color', '#AAA');
|
2013-09-24 19:05:40 +03:00
|
|
|
$('#providers .add-edit-delete-group').hide();
|
|
|
|
$('#providers .save-cancel-group').show();
|
|
|
|
$('#providers .details').find('input, textarea').prop('readonly', false);
|
|
|
|
$('#provider-password, #provider-password-confirm').addClass('required');
|
|
|
|
$('#provider-notifications').prop('disabled', false);
|
2013-10-18 17:56:12 +03:00
|
|
|
$('#providers').find('.add-break, .edit-break, .delete-break, #reset-working-plan').prop('disabled', false);
|
2013-09-24 19:05:40 +03:00
|
|
|
$('#provider-services input[type="checkbox"]').prop('disabled', false);
|
|
|
|
$('#providers input[type="checkbox"]').prop('disabled', false);
|
|
|
|
|
|
|
|
// Apply default working plan
|
2013-09-25 18:43:17 +03:00
|
|
|
BackendUsers.wp.setup(GlobalVariables.workingPlan);
|
|
|
|
BackendUsers.wp.timepickers(false);
|
2013-09-24 19:05:40 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Event: Edit Provider Button "Click"
|
|
|
|
*/
|
|
|
|
$('#edit-provider').click(function() {
|
|
|
|
$('#providers .add-edit-delete-group').hide();
|
|
|
|
$('#providers .save-cancel-group').show();
|
2013-09-25 18:43:17 +03:00
|
|
|
$('#filter-providers button').prop('disabled', true);
|
|
|
|
$('#filter-providers .results').css('color', '#AAA');
|
2013-09-24 19:05:40 +03:00
|
|
|
$('#providers .details').find('input, textarea').prop('readonly', false);
|
|
|
|
$('#provider-password, #provider-password-confirm').removeClass('required');
|
|
|
|
$('#provider-notifications').prop('disabled', false);
|
|
|
|
$('#provider-services input[type="checkbox"]').prop('disabled', false);
|
2013-10-17 18:31:43 +03:00
|
|
|
$('#providers').find('.add-break, .edit-break, .delete-break, #reset-working-plan').prop('disabled', false);
|
2013-09-24 19:05:40 +03:00
|
|
|
$('#providers input[type="checkbox"]').prop('disabled', false);
|
2013-09-25 18:43:17 +03:00
|
|
|
BackendUsers.wp.timepickers(false);
|
2013-09-24 19:05:40 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Event: Delete Provider Button "Click"
|
|
|
|
*/
|
|
|
|
$('#delete-provider').click(function() {
|
|
|
|
var providerId = $('#provider-id').val();
|
|
|
|
|
2013-12-19 18:28:19 +02:00
|
|
|
var messageBtns = {};
|
|
|
|
messageBtns[EALang['be_delete']] = function() {
|
|
|
|
BackendUsers.helper.delete(providerId);
|
|
|
|
$('#message_box').dialog('close');
|
|
|
|
};
|
|
|
|
messageBtns[EALang['be_cancel']] = function() {
|
|
|
|
$('#message_box').dialog('close');
|
2013-09-24 19:05:40 +03:00
|
|
|
};
|
|
|
|
|
2013-12-19 18:28:19 +02:00
|
|
|
GeneralFunctions.displayMessageBox(EALang['be_delete_provider'],
|
|
|
|
EALang['be_delete_record_prompt'], messageBtns);
|
2013-09-24 19:05:40 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Event: Save Provider Button "Click"
|
|
|
|
*/
|
|
|
|
$('#save-provider').click(function() {
|
|
|
|
var provider = {
|
|
|
|
'first_name': $('#provider-first-name').val(),
|
|
|
|
'last_name': $('#provider-last-name').val(),
|
|
|
|
'email': $('#provider-email').val(),
|
|
|
|
'mobile_number': $('#provider-mobile-number').val(),
|
|
|
|
'phone_number': $('#provider-phone-number').val(),
|
|
|
|
'address': $('#provider-address').val(),
|
|
|
|
'city': $('#provider-city').val(),
|
|
|
|
'state': $('#provider-state').val(),
|
|
|
|
'zip_code': $('#provider-zip-code').val(),
|
|
|
|
'notes': $('#provider-notes').val(),
|
|
|
|
'settings': {
|
|
|
|
'username': $('#provider-username').val(),
|
2013-09-25 18:43:17 +03:00
|
|
|
'working_plan': JSON.stringify(BackendUsers.wp.get()),
|
2013-09-24 19:05:40 +03:00
|
|
|
'notifications': $('#provider-notifications').hasClass('active')
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
// Include provider services.
|
|
|
|
provider.services = [];
|
|
|
|
$('#provider-services input[type="checkbox"]').each(function() {
|
|
|
|
if ($(this).prop('checked')) {
|
|
|
|
provider.services.push($(this).attr('data-id'));
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
// Include password if changed.
|
|
|
|
if ($('#provider-password').val() !== '') {
|
|
|
|
provider.settings.password = $('#provider-password').val();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Include id if changed.
|
|
|
|
if ($('#provider-id').val() !== '') {
|
|
|
|
provider.id = $('#provider-id').val();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!BackendUsers.helper.validate(provider)) return;
|
|
|
|
|
|
|
|
BackendUsers.helper.save(provider);
|
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Event: Cancel Provider Button "Click"
|
|
|
|
*
|
|
|
|
* Cancel add or edit of an provider record.
|
|
|
|
*/
|
|
|
|
$('#cancel-provider').click(function() {
|
2013-09-25 18:43:17 +03:00
|
|
|
var id = $('#filter-providers .selected-row').attr('data-id');
|
2013-09-24 19:05:40 +03:00
|
|
|
BackendUsers.helper.resetForm();
|
2013-09-25 18:43:17 +03:00
|
|
|
if (id != '') {
|
|
|
|
BackendUsers.helper.select(id, true);
|
|
|
|
}
|
2013-09-24 19:05:40 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Event: Display Provider Details "Click"
|
|
|
|
*/
|
|
|
|
$('#providers .display-details').click(function() {
|
|
|
|
$('#providers .switch-view .current').removeClass('current');
|
|
|
|
$(this).addClass('current');
|
|
|
|
$('.working-plan-view').hide('fade', function() {
|
|
|
|
$('.details-view').show('fade');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Event: Display Provider Working Plan "Click"
|
|
|
|
*/
|
|
|
|
$('#providers .display-working-plan').click(function() {
|
|
|
|
$('#providers .switch-view .current').removeClass('current');
|
|
|
|
$(this).addClass('current');
|
|
|
|
$('.details-view').hide('fade', function() {
|
|
|
|
$('.working-plan-view').show('fade');
|
|
|
|
});
|
|
|
|
});
|
2013-10-17 18:31:43 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Event: Reset Working Plan Button "Click".
|
|
|
|
*/
|
|
|
|
$('#reset-working-plan').click(function() {
|
|
|
|
$('.breaks').empty();
|
2013-11-21 23:58:51 +02:00
|
|
|
$('.work-start, .work-end').val('');
|
2013-10-17 18:31:43 +03:00
|
|
|
BackendUsers.wp.setup(GlobalVariables.workingPlan);
|
|
|
|
BackendUsers.wp.timepickers(false);
|
|
|
|
});
|
2013-09-24 19:05:40 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Save provider record to database.
|
|
|
|
*
|
|
|
|
* @param {object} provider Contains the admin record data. If an 'id' value is provided
|
|
|
|
* then the update operation is going to be executed.
|
|
|
|
*/
|
|
|
|
ProvidersHelper.prototype.save = function(provider) {
|
|
|
|
//////////////////////////////////////////////////
|
|
|
|
//console.log('Provider data to save:', provider);
|
|
|
|
//////////////////////////////////////////////////
|
|
|
|
|
|
|
|
var postUrl = GlobalVariables.baseUrl + 'backend_api/ajax_save_provider';
|
|
|
|
var postData = { 'provider': JSON.stringify(provider) };
|
|
|
|
|
|
|
|
$.post(postUrl, postData, function(response) {
|
|
|
|
///////////////////////////////////////////////////
|
|
|
|
//console.log('Save Provider Response:', response);
|
|
|
|
///////////////////////////////////////////////////
|
|
|
|
if (!GeneralFunctions.handleAjaxExceptions(response)) return;
|
2013-12-19 18:28:19 +02:00
|
|
|
Backend.displayNotification(EALang['be_provider_saved']);
|
2013-09-25 18:43:17 +03:00
|
|
|
BackendUsers.helper.resetForm();
|
|
|
|
$('#filter-providers .key').val('');
|
|
|
|
BackendUsers.helper.filter('', response.id, true);
|
2013-09-24 19:05:40 +03:00
|
|
|
}, 'json');
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Delete a provider record from database.
|
|
|
|
*
|
2013-09-25 18:43:17 +03:00
|
|
|
* @param {numeric} id Record id to be deleted.
|
2013-09-24 19:05:40 +03:00
|
|
|
*/
|
|
|
|
ProvidersHelper.prototype.delete = function(id) {
|
|
|
|
var postUrl = GlobalVariables.baseUrl + 'backend_api/ajax_delete_provider';
|
|
|
|
var postData = { 'provider_id': id };
|
|
|
|
|
|
|
|
$.post(postUrl, postData, function(response) {
|
|
|
|
/////////////////////////////////////////////////////
|
|
|
|
//console.log('Delete provider response:', response);
|
|
|
|
/////////////////////////////////////////////////////
|
|
|
|
if (!GeneralFunctions.handleAjaxExceptions(response)) return;
|
2013-12-19 18:28:19 +02:00
|
|
|
Backend.displayNotification(EALang['be_provider_deleted']);
|
2013-09-24 19:05:40 +03:00
|
|
|
BackendUsers.helper.resetForm();
|
2013-09-25 18:43:17 +03:00
|
|
|
BackendUsers.helper.filter($('#filter-providers .key').val());
|
2013-09-26 19:06:57 +03:00
|
|
|
}, 'json');
|
2013-09-24 19:05:40 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Validates a provider record.
|
|
|
|
*
|
|
|
|
* @param {object} provider Contains the admin data to be validated.
|
|
|
|
* @returns {bool} Returns the validation result.
|
|
|
|
*/
|
|
|
|
ProvidersHelper.prototype.validate = function(provider) {
|
|
|
|
$('#providers .required').css('border', '');
|
|
|
|
$('#provider-password, #provider-password-confirm').css('border', '');
|
|
|
|
|
|
|
|
try {
|
|
|
|
// Validate required fields.
|
|
|
|
var missingRequired = false;
|
|
|
|
$('#providers .required').each(function() {
|
|
|
|
if ($(this).val() == '' || $(this).val() == undefined) {
|
|
|
|
$(this).css('border', '2px solid red');
|
|
|
|
missingRequired = true;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
if (missingRequired) {
|
2013-12-19 18:28:19 +02:00
|
|
|
throw EALang['fe_fields_are_required'];
|
2013-09-24 19:05:40 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// Validate passwords.
|
|
|
|
if ($('#provider-password').val() != $('#provider-password-confirm').val()) {
|
|
|
|
$('#provider-password, #provider-password-confirm').css('border', '2px solid red');
|
2013-12-19 18:28:19 +02:00
|
|
|
throw EALang['be_passwords_mismatch'];
|
2013-09-24 19:05:40 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if ($('#provider-password').val().length < BackendUsers.MIN_PASSWORD_LENGTH
|
|
|
|
&& $('#provider-password').val() != '') {
|
|
|
|
$('#provider-password, #provider-password-confirm').css('border', '2px solid red');
|
2013-12-19 18:28:19 +02:00
|
|
|
throw EALang['be_password_length_notice'].replace('$number', BackendUsers.MIN_PASSWORD_LENGTH);
|
2013-09-24 19:05:40 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// Validate user email.
|
|
|
|
if (!GeneralFunctions.validateEmail($('#provider-email').val())) {
|
|
|
|
$('#provider-email').css('border', '2px solid red');
|
2013-12-19 18:28:19 +02:00
|
|
|
throw EALang['be_invalid_email'];
|
2013-09-24 19:05:40 +03:00
|
|
|
}
|
|
|
|
|
2013-11-23 21:10:31 +02:00
|
|
|
// Check if username exists
|
|
|
|
if ($('#provider-username').attr('already-exists') == 'true') {
|
|
|
|
$('#provider-username').css('border', '2px solid red');
|
2013-12-19 18:28:19 +02:00
|
|
|
throw EALang['be_username_already_exists'];
|
2013-11-23 21:10:31 +02:00
|
|
|
}
|
|
|
|
|
2013-09-24 19:05:40 +03:00
|
|
|
return true;
|
|
|
|
} catch(exc) {
|
|
|
|
$('#providers .form-message').text(exc);
|
|
|
|
$('#providers .form-message').show();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Resets the admin tab form back to its initial state.
|
|
|
|
*/
|
2013-09-25 18:43:17 +03:00
|
|
|
ProvidersHelper.prototype.resetForm = function() {
|
|
|
|
$('#filter-providers .selected-row').removeClass('selected-row');
|
|
|
|
$('#filter-providers button').prop('disabled', false);
|
|
|
|
$('#filter-providers .results').css('color', '');
|
2013-09-24 19:05:40 +03:00
|
|
|
|
|
|
|
$('#providers .add-edit-delete-group').show();
|
|
|
|
$('#providers .save-cancel-group').hide();
|
|
|
|
$('#providers .details').find('input, textarea').prop('readonly', true);
|
|
|
|
$('#providers .form-message').hide();
|
|
|
|
$('#provider-notifications').removeClass('active');
|
|
|
|
$('#provider-notifications').prop('disabled', true);
|
|
|
|
$('#provider-services input[type="checkbox"]').prop('disabled', true);
|
|
|
|
$('#providers .required').css('border', '');
|
|
|
|
$('#provider-password, #provider-password-confirm').css('border', '');
|
2013-10-17 18:31:43 +03:00
|
|
|
$('#providers .add-break, #reset-working-plan').prop('disabled', true);
|
2013-09-25 18:43:17 +03:00
|
|
|
BackendUsers.wp.timepickers(true);
|
2013-09-24 19:05:40 +03:00
|
|
|
$('#providers .working-plan input[type="text"]').timepicker('destroy');
|
2013-10-17 18:31:43 +03:00
|
|
|
$('#providers .working-plan input[type="checkbox"]').prop('disabled', true);
|
2013-09-25 18:43:17 +03:00
|
|
|
$('.breaks').find('.edit-break, .delete-break').prop('disabled', true);
|
|
|
|
|
|
|
|
$('#edit-provider, #delete-provider').prop('disabled', true);
|
|
|
|
$('#providers .details').find('input, textarea').val('');
|
|
|
|
$('#providers input[type="checkbox"]').prop('checked', false);
|
|
|
|
$('#provider-services input[type="checkbox"]').prop('checked', false);
|
|
|
|
$('#providers .breaks tbody').empty();
|
|
|
|
|
2013-09-24 19:05:40 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Display a provider record into the admin form.
|
|
|
|
*
|
|
|
|
* @param {object} provider Contains the provider record data.
|
|
|
|
*/
|
|
|
|
ProvidersHelper.prototype.display = function(provider) {
|
|
|
|
$('#provider-id').val(provider.id);
|
|
|
|
$('#provider-first-name').val(provider.first_name);
|
|
|
|
$('#provider-last-name').val(provider.last_name);
|
|
|
|
$('#provider-email').val(provider.email);
|
|
|
|
$('#provider-mobile-number').val(provider.mobile_number);
|
|
|
|
$('#provider-phone-number').val(provider.phone_number);
|
|
|
|
$('#provider-address').val(provider.address);
|
|
|
|
$('#provider-city').val(provider.city);
|
|
|
|
$('#provider-state').val(provider.state);
|
|
|
|
$('#provider-zip-code').val(provider.zip_code);
|
|
|
|
$('#provider-notes').val(provider.notes);
|
|
|
|
|
|
|
|
$('#provider-username').val(provider.settings.username);
|
|
|
|
if (provider.settings.notifications == true) {
|
|
|
|
$('#provider-notifications').addClass('active');
|
|
|
|
} else {
|
|
|
|
$('#provider-notifications').removeClass('active');
|
|
|
|
}
|
|
|
|
|
|
|
|
$('#provider-services input[type="checkbox"]').prop('checked', false);
|
|
|
|
$.each(provider.services, function(index, serviceId) {
|
|
|
|
$('#provider-services input[type="checkbox"]').each(function() {
|
|
|
|
if ($(this).attr('data-id') == serviceId) {
|
|
|
|
$(this).prop('checked', true);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
// Display working plan
|
2013-09-25 18:43:17 +03:00
|
|
|
$('#providers .breaks tbody').empty();
|
2013-09-24 19:05:40 +03:00
|
|
|
var workingPlan = $.parseJSON(provider.settings.working_plan);
|
2013-09-25 18:43:17 +03:00
|
|
|
BackendUsers.wp.setup(workingPlan);
|
|
|
|
$('.breaks').find('.edit-break, .delete-break').prop('disabled', true);
|
2013-09-24 19:05:40 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Filters provider records depending a string key.
|
|
|
|
*
|
|
|
|
* @param {string} key This is used to filter the provider records of the database.
|
2013-09-25 18:43:17 +03:00
|
|
|
* @param {numeric} selectId (OPTIONAL = undefined) If set, when the function is complete
|
2013-09-24 19:05:40 +03:00
|
|
|
* a result row can be set as selected.
|
2013-09-25 18:43:17 +03:00
|
|
|
* @param {bool} display (OPTIONAL = false) If true then the selected record will be also
|
|
|
|
* displayed.
|
2013-09-24 19:05:40 +03:00
|
|
|
*/
|
2013-09-25 18:43:17 +03:00
|
|
|
ProvidersHelper.prototype.filter = function(key, selectId, display) {
|
|
|
|
if (display == undefined) display = false;
|
|
|
|
|
2013-09-24 19:05:40 +03:00
|
|
|
var postUrl = GlobalVariables.baseUrl + 'backend_api/ajax_filter_providers';
|
|
|
|
var postData = { 'key': key };
|
|
|
|
|
|
|
|
$.post(postUrl, postData, function(response) {
|
|
|
|
//////////////////////////////////////////////////////
|
|
|
|
//console.log('Filter providers response:', response);
|
|
|
|
//////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
if (!GeneralFunctions.handleAjaxExceptions(response)) return;
|
|
|
|
|
|
|
|
BackendUsers.helper.filterResults = response;
|
|
|
|
|
2013-10-10 19:50:33 +03:00
|
|
|
|
|
|
|
$('#filter-providers .results').data('jsp').destroy;
|
2013-09-25 18:43:17 +03:00
|
|
|
$('#filter-providers .results').html('');
|
2013-09-24 19:05:40 +03:00
|
|
|
$.each(response, function(index, provider) {
|
|
|
|
var html = ProvidersHelper.prototype.getFilterHtml(provider);
|
2013-09-25 18:43:17 +03:00
|
|
|
$('#filter-providers .results').append(html);
|
2013-09-24 19:05:40 +03:00
|
|
|
});
|
2013-10-11 18:58:46 +03:00
|
|
|
$('#filter-providers .results').jScrollPane({ mouseWheelSpeed: 70 });
|
2013-09-24 19:05:40 +03:00
|
|
|
|
2013-09-25 18:43:17 +03:00
|
|
|
if (response.length == 0) {
|
2013-12-19 18:28:19 +02:00
|
|
|
$('#filter-providers .results').html('<em>' + EALang['be_no_records_found'] + '</em>')
|
2013-09-25 18:43:17 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (selectId != undefined) {
|
|
|
|
BackendUsers.helper.select(selectId, display);
|
2013-09-24 19:05:40 +03:00
|
|
|
}
|
|
|
|
}, 'json');
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get an provider row html code that is going to be displayed on the filter results list.
|
|
|
|
*
|
|
|
|
* @param {object} provider Contains the provider record data.
|
|
|
|
* @returns {string} The html code that represents the record on the filter results list.
|
|
|
|
*/
|
|
|
|
ProvidersHelper.prototype.getFilterHtml = function(provider) {
|
2013-10-27 14:53:51 +02:00
|
|
|
var name = provider.first_name + ' ' + provider.last_name;
|
|
|
|
var info = provider.email;
|
|
|
|
info = (provider.mobile_number != '' && provider.mobile_number != null)
|
|
|
|
? info + ', ' + provider.mobile_number : info;
|
|
|
|
info = (provider.phone_number != '' && provider.phone_number != null)
|
|
|
|
? info + ', ' + provider.phone_number : info;
|
|
|
|
|
2013-09-24 19:05:40 +03:00
|
|
|
var html =
|
|
|
|
'<div class="provider-row" data-id="' + provider.id + '">' +
|
2013-10-27 14:53:51 +02:00
|
|
|
'<strong>' + name + '</strong><br>' +
|
|
|
|
info + '<br>' +
|
2013-10-10 19:50:33 +03:00
|
|
|
'</div><hr>';
|
2013-09-24 19:05:40 +03:00
|
|
|
|
|
|
|
return html;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Initialize the editable functionality to the break day table cells.
|
|
|
|
*
|
|
|
|
* @param {object} $selector The cells to be initialized.
|
|
|
|
*/
|
|
|
|
ProvidersHelper.prototype.editableBreakDay = function($selector) {
|
2013-12-19 18:28:19 +02:00
|
|
|
var weekDays = {};
|
|
|
|
weekDays[EALang['be_monday']] = 'Monday';
|
|
|
|
weekDays[EALang['be_tuesday']] = 'Tuesday';
|
|
|
|
weekDays[EALang['be_wednesday']] = 'Wednesday';
|
|
|
|
weekDays[EALang['be_thursday']] = 'Thursday';
|
|
|
|
weekDays[EALang['be_friday']] = 'Friday';
|
|
|
|
weekDays[EALang['be_saturday']] = 'Saturday';
|
|
|
|
weekDays[EALang['be_sunday']] = 'Sunday';
|
|
|
|
|
|
|
|
|
2013-09-24 19:05:40 +03:00
|
|
|
$selector.editable(function(value, settings) {
|
|
|
|
return value;
|
|
|
|
}, {
|
|
|
|
'type': 'select',
|
2013-12-19 18:28:19 +02:00
|
|
|
// 'data': '{ "Monday": "Monday", "Tuesday": "Tuesday", "Wednesday": "Wednesday", '
|
|
|
|
// + '"Thursday": "Thursday", "Friday": "Friday", "Saturday": "Saturday", '
|
|
|
|
// + '"Sunday": "Sunday", "selected": "Monday"}',
|
|
|
|
'data': weekDays,
|
2013-09-24 19:05:40 +03:00
|
|
|
'event': 'edit',
|
|
|
|
'height': '30px',
|
|
|
|
'submit': '<button type="button" class="hidden submit-editable">Submit</button>',
|
|
|
|
'cancel': '<button type="button" class="hidden cancel-editable">Cancel</button>',
|
|
|
|
'onblur': 'ignore',
|
|
|
|
'onreset': function(settings, td) {
|
|
|
|
if (!BackendUsers.enableCancel) return false; // disable ESC button
|
|
|
|
},
|
|
|
|
'onsubmit': function(settings, td) {
|
|
|
|
if (!BackendUsers.enableSubmit) return false; // disable Enter button
|
|
|
|
}
|
|
|
|
});
|
2013-09-25 18:43:17 +03:00
|
|
|
};
|
2013-09-24 19:05:40 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Initialize the editable functionality to the break time table cells.
|
|
|
|
*
|
|
|
|
* @param {object} $selector The cells to be initialized.
|
|
|
|
*/
|
|
|
|
ProvidersHelper.prototype.editableBreakTime = function($selector) {
|
|
|
|
$selector.editable(function(value, settings) {
|
|
|
|
// Do not return the value because the user needs to press the "Save" button.
|
|
|
|
return value;
|
|
|
|
}, {
|
|
|
|
'event': 'edit',
|
|
|
|
'height': '25px',
|
|
|
|
'submit': '<button type="button" class="hidden submit-editable">Submit</button>',
|
|
|
|
'cancel': '<button type="button" class="hidden cancel-editable">Cancel</button>',
|
|
|
|
'onblur': 'ignore',
|
|
|
|
'onreset': function(settings, td) {
|
|
|
|
if (!BackendUsers.enableCancel) return false; // disable ESC button
|
|
|
|
},
|
|
|
|
'onsubmit': function(settings, td) {
|
|
|
|
if (!BackendUsers.enableSubmit) return false; // disable Enter button
|
|
|
|
}
|
|
|
|
});
|
2013-09-25 18:43:17 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Select and display a providers filter result on the form.
|
|
|
|
*
|
|
|
|
* @param {numeric} id Record id to be selected.
|
|
|
|
* @param {bool} display (OPTIONAL = false) If true the record will be displayed on the form.
|
|
|
|
*/
|
|
|
|
ProvidersHelper.prototype.select = function(id, display) {
|
|
|
|
if (display == undefined) display = false;
|
|
|
|
|
|
|
|
// Select record in filter results.
|
|
|
|
$('#filter-providers .provider-row').each(function() {
|
|
|
|
if ($(this).attr('data-id') == id) {
|
|
|
|
$(this).addClass('selected-row');
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
// Display record in form (if display = true).
|
|
|
|
if (display) {
|
|
|
|
$.each(BackendUsers.helper.filterResults, function(index, provider) {
|
|
|
|
if (provider.id == id) {
|
|
|
|
BackendUsers.helper.display(provider);
|
|
|
|
$('#edit-provider, #delete-provider').prop('disabled', false);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|