2015-07-20 22:41:24 +03:00
|
|
|
/* ----------------------------------------------------------------------------
|
|
|
|
* Easy!Appointments - Open Source Web Scheduler
|
2015-10-09 00:12:59 +03:00
|
|
|
*
|
2015-07-20 22:41:24 +03:00
|
|
|
* @package EasyAppointments
|
|
|
|
* @author A.Tselegidis <alextselegidis@gmail.com>
|
2016-01-02 15:47:04 +02:00
|
|
|
* @copyright Copyright (c) 2013 - 2016, Alex Tselegidis
|
2015-10-09 00:12:59 +03:00
|
|
|
* @license http://opensource.org/licenses/GPL-3.0 - GPLv3
|
2015-07-20 22:41:24 +03:00
|
|
|
* @link http://easyappointments.org
|
|
|
|
* @since v1.0.0
|
|
|
|
* ---------------------------------------------------------------------------- */
|
|
|
|
|
2013-09-24 19:05:40 +03:00
|
|
|
/**
|
2015-10-09 00:12:59 +03:00
|
|
|
* This class contains the Secretaries helper class declaration, along with the "Secretaries"
|
2013-09-24 19:05:40 +03:00
|
|
|
* tab event handlers. By deviding the backend/users tab functionality into separate files
|
|
|
|
* it is easier to maintain the code.
|
2015-10-09 00:12:59 +03:00
|
|
|
*
|
2013-09-24 19:05:40 +03:00
|
|
|
* @class SecretariesHelper
|
|
|
|
*/
|
|
|
|
var SecretariesHelper = function() {
|
|
|
|
this.filterResults = {}; // Store the results for later use.
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Bind the event handlers for the backend/users "Secretaries" tab.
|
|
|
|
*/
|
|
|
|
SecretariesHelper.prototype.bindEventHandlers = function() {
|
|
|
|
/**
|
2013-09-25 18:43:17 +03:00
|
|
|
* Event: Filter Secretaries Form "Submit"
|
2015-10-09 00:12:59 +03:00
|
|
|
*
|
2013-09-24 19:05:40 +03:00
|
|
|
* Filter the secretary records with the given key string.
|
|
|
|
*/
|
2014-01-04 00:26:10 +02:00
|
|
|
$('#filter-secretaries form').submit(function(event) {
|
2013-09-25 18:43:17 +03:00
|
|
|
var key = $('#filter-secretaries .key').val();
|
|
|
|
$('#filter-secretaries .selected-row').removeClass('selected-row');
|
2013-09-24 19:05:40 +03:00
|
|
|
BackendUsers.helper.resetForm();
|
|
|
|
BackendUsers.helper.filter(key);
|
2014-01-04 00:26:10 +02:00
|
|
|
return false;
|
2013-09-24 19:05:40 +03:00
|
|
|
});
|
|
|
|
|
2013-09-25 18:43:17 +03:00
|
|
|
/**
|
|
|
|
* Event: Clear Filter Results Button "Click"
|
|
|
|
*/
|
|
|
|
$('#filter-secretaries .clear').click(function() {
|
|
|
|
BackendUsers.helper.filter('');
|
|
|
|
$('#filter-secretaries .key').val('');
|
2015-11-28 13:21:12 +02:00
|
|
|
BackendUsers.helper.resetForm();
|
2013-09-25 18:43:17 +03:00
|
|
|
});
|
|
|
|
|
2013-09-24 19:05:40 +03:00
|
|
|
/**
|
|
|
|
* Event: Filter Secretary Row "Click"
|
2015-10-09 00:12:59 +03:00
|
|
|
*
|
2013-09-24 19:05:40 +03:00
|
|
|
* Display the selected secretary data to the user.
|
|
|
|
*/
|
|
|
|
$(document).on('click', '.secretary-row', function() {
|
2013-09-25 18:43:17 +03:00
|
|
|
if ($('#filter-secretaries .filter').prop('disabled')) {
|
|
|
|
$('#filter-secretaries .results').css('color', '#AAA');
|
2013-09-24 19:05:40 +03:00
|
|
|
return; // exit because we are currently on edit mode
|
|
|
|
}
|
|
|
|
|
2015-10-09 00:12:59 +03:00
|
|
|
var secretaryId = $(this).attr('data-id');
|
2013-09-25 18:43:17 +03:00
|
|
|
var secretary = {};
|
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 === secretaryId) {
|
2013-09-24 19:05:40 +03:00
|
|
|
secretary = item;
|
2013-09-25 18:43:17 +03:00
|
|
|
return false;
|
2013-09-24 19:05:40 +03:00
|
|
|
}
|
|
|
|
});
|
2015-10-09 00:12:59 +03:00
|
|
|
|
2013-09-24 19:05:40 +03:00
|
|
|
BackendUsers.helper.display(secretary);
|
2013-09-25 18:43:17 +03:00
|
|
|
$('#filter-secretaries .selected-row').removeClass('selected-row');
|
2013-09-24 19:05:40 +03:00
|
|
|
$(this).addClass('selected-row');
|
|
|
|
$('#edit-secretary, #delete-secretary').prop('disabled', false);
|
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Event: Add New Secretary Button "Click"
|
|
|
|
*/
|
|
|
|
$('#add-secretary').click(function() {
|
|
|
|
BackendUsers.helper.resetForm();
|
2013-09-25 18:43:17 +03:00
|
|
|
$('#filter-secretaries button').prop('disabled', true);
|
|
|
|
$('#filter-secretaries .results').css('color', '#AAA');
|
2015-10-09 00:12:59 +03:00
|
|
|
|
2013-09-24 19:05:40 +03:00
|
|
|
$('#secretaries .add-edit-delete-group').hide();
|
|
|
|
$('#secretaries .save-cancel-group').show();
|
|
|
|
$('#secretaries .details').find('input, textarea').prop('readonly', false);
|
|
|
|
$('#secretary-password, #secretary-password-confirm').addClass('required');
|
|
|
|
$('#secretary-notifications').prop('disabled', false);
|
|
|
|
$('#secretary-providers input[type="checkbox"]').prop('disabled', false);
|
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Event: Edit Secretary Button "Click"
|
|
|
|
*/
|
|
|
|
$('#edit-secretary').click(function() {
|
2013-09-25 18:43:17 +03:00
|
|
|
$('#filter-secretaries button').prop('disabled', true);
|
|
|
|
$('#filter-secretaries .results').css('color', '#AAA');
|
2015-10-09 00:12:59 +03:00
|
|
|
|
2013-09-24 19:05:40 +03:00
|
|
|
$('#secretaries .add-edit-delete-group').hide();
|
|
|
|
$('#secretaries .save-cancel-group').show();
|
|
|
|
$('#secretaries .details').find('input, textarea').prop('readonly', false);
|
|
|
|
$('#secretary-password, #secretary-password-confirm').removeClass('required');
|
|
|
|
$('#secretary-notifications').prop('disabled', false);
|
|
|
|
$('#secretary-providers input[type="checkbox"]').prop('disabled', false);
|
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Event: Delete Secretary Button "Click"
|
|
|
|
*/
|
|
|
|
$('#delete-secretary').click(function() {
|
2013-09-25 18:43:17 +03:00
|
|
|
var secretaryId = $('#secretary-id').val();
|
2013-09-24 19:05:40 +03:00
|
|
|
|
2014-01-04 19:25:21 +02:00
|
|
|
var messageBtns = {};
|
|
|
|
messageBtns[EALang['delete']] = function() {
|
|
|
|
BackendUsers.helper.delete(secretaryId);
|
|
|
|
$('#message_box').dialog('close');
|
|
|
|
};
|
|
|
|
messageBtns[EALang['cancel']] = function() {
|
|
|
|
$('#message_box').dialog('close');
|
2013-09-24 19:05:40 +03:00
|
|
|
};
|
|
|
|
|
2015-10-09 00:12:59 +03:00
|
|
|
GeneralFunctions.displayMessageBox(EALang['delete_secretary'],
|
2014-01-04 19:25:21 +02:00
|
|
|
EALang['delete_record_prompt'], messageBtns);
|
2013-09-24 19:05:40 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Event: Save Secretary Button "Click"
|
|
|
|
*/
|
|
|
|
$('#save-secretary').click(function() {
|
|
|
|
var secretary = {
|
|
|
|
'first_name': $('#secretary-first-name').val(),
|
|
|
|
'last_name': $('#secretary-last-name').val(),
|
|
|
|
'email': $('#secretary-email').val(),
|
|
|
|
'mobile_number': $('#secretary-mobile-number').val(),
|
|
|
|
'phone_number': $('#secretary-phone-number').val(),
|
|
|
|
'address': $('#secretary-address').val(),
|
|
|
|
'city': $('#secretary-city').val(),
|
|
|
|
'state': $('#secretary-state').val(),
|
|
|
|
'zip_code': $('#secretary-zip-code').val(),
|
|
|
|
'notes': $('#secretary-notes').val(),
|
|
|
|
'settings': {
|
2015-10-09 00:12:59 +03:00
|
|
|
'username': $('#secretary-username').val(),
|
2013-09-24 19:05:40 +03:00
|
|
|
'notifications': $('#secretary-notifications').hasClass('active')
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
// Include secretary services.
|
|
|
|
secretary.providers = [];
|
|
|
|
$('#secretary-providers input[type="checkbox"]').each(function() {
|
|
|
|
if ($(this).prop('checked')) {
|
|
|
|
secretary.providers.push($(this).attr('data-id'));
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
// Include password if changed.
|
|
|
|
if ($('#secretary-password').val() !== '') {
|
|
|
|
secretary.settings.password = $('#secretary-password').val();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Include id if changed.
|
|
|
|
if ($('#secretary-id').val() !== '') {
|
|
|
|
secretary.id = $('#secretary-id').val();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!BackendUsers.helper.validate(secretary)) return;
|
|
|
|
|
|
|
|
BackendUsers.helper.save(secretary);
|
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Event: Cancel Secretary Button "Click"
|
2015-10-09 00:12:59 +03:00
|
|
|
*
|
2013-09-24 19:05:40 +03:00
|
|
|
* Cancel add or edit of an secretary record.
|
|
|
|
*/
|
|
|
|
$('#cancel-secretary').click(function() {
|
2013-09-25 18:43:17 +03:00
|
|
|
var id = $('#secretary-id').val();
|
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
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Save secretary record to database.
|
2015-10-09 00:12:59 +03:00
|
|
|
*
|
2013-09-24 19:05:40 +03:00
|
|
|
* @param {object} secretary Contains the admin record data. If an 'id' value is provided
|
|
|
|
* then the update operation is going to be executed.
|
|
|
|
*/
|
|
|
|
SecretariesHelper.prototype.save = function(secretary) {
|
2016-04-02 13:02:17 +03:00
|
|
|
var postUrl = GlobalVariables.baseUrl + '/index.php/backend_api/ajax_save_secretary',
|
|
|
|
postData = {
|
|
|
|
'csrfToken': GlobalVariables.csrfToken,
|
|
|
|
'secretary': JSON.stringify(secretary)
|
|
|
|
};
|
2015-10-09 00:12:59 +03:00
|
|
|
|
2013-09-24 19:05:40 +03:00
|
|
|
$.post(postUrl, postData, function(response) {
|
|
|
|
if (!GeneralFunctions.handleAjaxExceptions(response)) return;
|
2014-01-04 19:25:21 +02:00
|
|
|
Backend.displayNotification(EALang['secretary_saved']);
|
2013-09-24 19:05:40 +03:00
|
|
|
BackendUsers.helper.resetForm();
|
2013-09-25 18:43:17 +03:00
|
|
|
$('#filter-secretaries .key').val('');
|
|
|
|
BackendUsers.helper.filter('', response.id, true);
|
2015-10-09 00:12:59 +03:00
|
|
|
}, 'json').fail(GeneralFunctions.ajaxFailureHandler);
|
2013-09-24 19:05:40 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Delete a secretary record from database.
|
2015-10-09 00:12:59 +03:00
|
|
|
*
|
|
|
|
* @param {int} id Record id to be deleted.
|
2013-09-24 19:05:40 +03:00
|
|
|
*/
|
|
|
|
SecretariesHelper.prototype.delete = function(id) {
|
2016-04-02 13:02:17 +03:00
|
|
|
var postUrl = GlobalVariables.baseUrl + '/index.php/backend_api/ajax_delete_secretary',
|
|
|
|
postData = {
|
|
|
|
'csrfToken': GlobalVariables.csrfToken,
|
|
|
|
'secretary_id': id
|
|
|
|
};
|
2015-10-09 00:12:59 +03:00
|
|
|
|
2013-09-24 19:05:40 +03:00
|
|
|
$.post(postUrl, postData, function(response) {
|
|
|
|
if (!GeneralFunctions.handleAjaxExceptions(response)) return;
|
2014-01-04 19:25:21 +02:00
|
|
|
Backend.displayNotification(EALang['secretary_deleted']);
|
2013-09-24 19:05:40 +03:00
|
|
|
BackendUsers.helper.resetForm();
|
2013-09-25 18:43:17 +03:00
|
|
|
BackendUsers.helper.filter($('#filter-secretaries .key').val());
|
2015-10-09 00:12:59 +03:00
|
|
|
}, 'json').fail(GeneralFunctions.ajaxFailureHandler);
|
2013-09-24 19:05:40 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Validates a secretary record.
|
2015-10-09 00:12:59 +03:00
|
|
|
*
|
2013-09-24 19:05:40 +03:00
|
|
|
* @param {object} secretary Contains the admin data to be validated.
|
|
|
|
* @returns {bool} Returns the validation result.
|
|
|
|
*/
|
|
|
|
SecretariesHelper.prototype.validate = function(secretary) {
|
|
|
|
$('#secretaries .required').css('border', '');
|
|
|
|
$('#secretary-password, #secretary-password-confirm').css('border', '');
|
2015-10-09 00:12:59 +03:00
|
|
|
|
2013-09-24 19:05:40 +03:00
|
|
|
try {
|
|
|
|
// Validate required fields.
|
|
|
|
var missingRequired = false;
|
|
|
|
$('#secretaries .required').each(function() {
|
|
|
|
if ($(this).val() == '' || $(this).val() == undefined) {
|
|
|
|
$(this).css('border', '2px solid red');
|
|
|
|
missingRequired = true;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
if (missingRequired) {
|
|
|
|
throw 'Fields with * are required.';
|
|
|
|
}
|
2015-10-09 00:12:59 +03:00
|
|
|
|
2013-09-24 19:05:40 +03:00
|
|
|
// Validate passwords.
|
|
|
|
if ($('#secretary-password').val() != $('#secretary-password-confirm').val()) {
|
|
|
|
$('#secretary-password, #secretary-password-confirm').css('border', '2px solid red');
|
|
|
|
throw 'Passwords mismatch!';
|
|
|
|
}
|
2015-10-09 00:12:59 +03:00
|
|
|
|
2013-09-24 19:05:40 +03:00
|
|
|
if ($('#secretary-password').val().length < BackendUsers.MIN_PASSWORD_LENGTH
|
|
|
|
&& $('#secretary-password').val() != '') {
|
|
|
|
$('#secretary-password, #secretary-password-confirm').css('border', '2px solid red');
|
2015-10-09 00:12:59 +03:00
|
|
|
throw 'Password must be at least ' + BackendUsers.MIN_PASSWORD_LENGTH
|
2013-09-24 19:05:40 +03:00
|
|
|
+ ' characters long.';
|
|
|
|
}
|
2015-10-09 00:12:59 +03:00
|
|
|
|
2013-09-24 19:05:40 +03:00
|
|
|
// Validate user email.
|
|
|
|
if (!GeneralFunctions.validateEmail($('#secretary-email').val())) {
|
|
|
|
$('#secretary-email').css('border', '2px solid red');
|
|
|
|
throw 'Invalid email address!';
|
|
|
|
}
|
2015-10-09 00:12:59 +03:00
|
|
|
|
2013-11-23 21:10:31 +02:00
|
|
|
// Check if username exists
|
|
|
|
if ($('#secretary-username').attr('already-exists') == 'true') {
|
|
|
|
$('#secretary-username').css('border', '2px solid red');
|
|
|
|
throw 'Username already exists.';
|
2015-10-09 00:12:59 +03:00
|
|
|
}
|
|
|
|
|
2013-09-24 19:05:40 +03:00
|
|
|
return true;
|
|
|
|
} catch(exc) {
|
|
|
|
$('#secretaries .form-message').text(exc);
|
|
|
|
$('#secretaries .form-message').show();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2015-10-09 00:12:59 +03:00
|
|
|
* Resets the admin tab form back to its initial state.
|
2013-09-24 19:05:40 +03:00
|
|
|
*/
|
|
|
|
SecretariesHelper.prototype.resetForm = function() {
|
|
|
|
$('#secretaries .details').find('input, textarea').val('');
|
|
|
|
$('#secretaries .add-edit-delete-group').show();
|
|
|
|
$('#secretaries .save-cancel-group').hide();
|
|
|
|
$('#edit-secretary, #delete-secretary').prop('disabled', true);
|
|
|
|
$('#secretaries .details').find('input, textarea').prop('readonly', true);
|
2015-10-09 00:12:59 +03:00
|
|
|
$('#secretaries .form-message').hide();
|
2013-09-24 19:05:40 +03:00
|
|
|
$('#secretary-notifications').removeClass('active');
|
|
|
|
$('#secretary-notifications').prop('disabled', true);
|
|
|
|
$('#secretary-providers input[type="checkbox"]').prop('checked', false);
|
|
|
|
$('#secretary-providers input[type="checkbox"]').prop('disabled', true);
|
|
|
|
$('#secretaries .required').css('border', '');
|
|
|
|
$('#secretary-password, #secretary-password-confirm').css('border', '');
|
2015-10-09 00:12:59 +03:00
|
|
|
|
2013-09-25 18:43:17 +03:00
|
|
|
$('#filter-secretaries .selected-row').removeClass('selected-row');
|
|
|
|
$('#filter-secretaries button').prop('disabled', false);
|
|
|
|
$('#filter-secretaries .results').css('color', '');
|
2013-09-24 19:05:40 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Display a secretary record into the admin form.
|
2015-10-09 00:12:59 +03:00
|
|
|
*
|
2013-09-24 19:05:40 +03:00
|
|
|
* @param {object} secretary Contains the secretary record data.
|
|
|
|
*/
|
|
|
|
SecretariesHelper.prototype.display = function(secretary) {
|
|
|
|
$('#secretary-id').val(secretary.id);
|
|
|
|
$('#secretary-first-name').val(secretary.first_name);
|
|
|
|
$('#secretary-last-name').val(secretary.last_name);
|
|
|
|
$('#secretary-email').val(secretary.email);
|
|
|
|
$('#secretary-mobile-number').val(secretary.mobile_number);
|
|
|
|
$('#secretary-phone-number').val(secretary.phone_number);
|
|
|
|
$('#secretary-address').val(secretary.address);
|
|
|
|
$('#secretary-city').val(secretary.city);
|
|
|
|
$('#secretary-state').val(secretary.state);
|
|
|
|
$('#secretary-zip-code').val(secretary.zip_code);
|
|
|
|
$('#secretary-notes').val(secretary.notes);
|
2015-10-09 00:12:59 +03:00
|
|
|
|
2013-09-24 19:05:40 +03:00
|
|
|
$('#secretary-username').val(secretary.settings.username);
|
|
|
|
if (secretary.settings.notifications == true) {
|
|
|
|
$('#secretary-notifications').addClass('active');
|
|
|
|
} else {
|
|
|
|
$('#secretary-notifications').removeClass('active');
|
|
|
|
}
|
2015-10-09 00:12:59 +03:00
|
|
|
|
2013-09-24 19:05:40 +03:00
|
|
|
$('#secretary-providers input[type="checkbox"]').prop('checked', false);
|
|
|
|
$.each(secretary.providers, function(index, providerId) {
|
|
|
|
$('#secretary-providers input[type="checkbox"]').each(function() {
|
|
|
|
if ($(this).attr('data-id') == providerId) {
|
|
|
|
$(this).prop('checked', true);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Filters secretary records depending a string key.
|
2015-10-09 00:12:59 +03:00
|
|
|
*
|
2013-09-24 19:05:40 +03:00
|
|
|
* @param {string} key This is used to filter the secretary records of the database.
|
2015-10-09 00:12:59 +03:00
|
|
|
* @param {numeric} selectId (OPTIONAL = undefined) If provided then the given id will be
|
2013-09-24 19:05:40 +03:00
|
|
|
* selected in the filter results (only selected, not displayed).
|
2013-09-25 18:43:17 +03:00
|
|
|
* @param {bool} display (OPTIONAL = false)
|
2013-09-24 19:05:40 +03:00
|
|
|
*/
|
2013-09-25 18:43:17 +03:00
|
|
|
SecretariesHelper.prototype.filter = function(key, selectId, display) {
|
|
|
|
if (display == undefined) display = false;
|
2015-10-09 00:12:59 +03:00
|
|
|
|
2015-05-20 23:26:11 +03:00
|
|
|
var postUrl = GlobalVariables.baseUrl + '/index.php/backend_api/ajax_filter_secretaries';
|
2015-10-09 00:12:59 +03:00
|
|
|
var postData = {
|
2015-05-28 00:42:40 +03:00
|
|
|
'csrfToken': GlobalVariables.csrfToken,
|
2015-10-09 00:12:59 +03:00
|
|
|
'key': key
|
2015-05-28 00:42:40 +03:00
|
|
|
};
|
2015-10-09 00:12:59 +03:00
|
|
|
|
2013-09-24 19:05:40 +03:00
|
|
|
$.post(postUrl, postData, function(response) {
|
|
|
|
if (!GeneralFunctions.handleAjaxExceptions(response)) return;
|
2015-10-09 00:12:59 +03:00
|
|
|
|
2013-09-24 19:05:40 +03:00
|
|
|
BackendUsers.helper.filterResults = response;
|
2015-10-09 00:12:59 +03:00
|
|
|
|
2013-10-10 19:50:33 +03:00
|
|
|
$('#filter-secretaries .results').data('jsp').destroy();
|
2013-09-25 18:43:17 +03:00
|
|
|
$('#filter-secretaries .results').html('');
|
2013-09-24 19:05:40 +03:00
|
|
|
$.each(response, function(index, secretary) {
|
|
|
|
var html = SecretariesHelper.prototype.getFilterHtml(secretary);
|
2013-09-25 18:43:17 +03:00
|
|
|
$('#filter-secretaries .results').append(html);
|
2013-09-24 19:05:40 +03:00
|
|
|
});
|
2013-10-11 18:58:46 +03:00
|
|
|
$('#filter-secretaries .results').jScrollPane({ mouseWheelSpeed: 70 });
|
2015-10-09 00:12:59 +03:00
|
|
|
|
2013-09-25 18:43:17 +03:00
|
|
|
if (response.length == 0) {
|
2014-01-11 02:07:25 +02:00
|
|
|
$('#filter-secretaries .results').html('<em>' + EALang['no_records_found'] + '</em>')
|
2013-09-25 18:43:17 +03:00
|
|
|
}
|
2015-10-09 00:12:59 +03:00
|
|
|
|
2013-09-25 18:43:17 +03:00
|
|
|
if (selectId != undefined) {
|
|
|
|
BackendUsers.helper.select(selectId, display);
|
2013-09-24 19:05:40 +03:00
|
|
|
}
|
2015-10-09 00:12:59 +03:00
|
|
|
}, 'json').fail(GeneralFunctions.ajaxFailureHandler);
|
2013-09-24 19:05:40 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get an secretary row html code that is going to be displayed on the filter results list.
|
2015-10-09 00:12:59 +03:00
|
|
|
*
|
2013-09-24 19:05:40 +03:00
|
|
|
* @param {object} secretary Contains the secretary record data.
|
|
|
|
* @returns {string} The html code that represents the record on the filter results list.
|
|
|
|
*/
|
|
|
|
SecretariesHelper.prototype.getFilterHtml = function(secretary) {
|
2013-10-27 14:53:51 +02:00
|
|
|
var name = secretary.first_name + ' ' + secretary.last_name;
|
|
|
|
var info = secretary.email;
|
|
|
|
info = (secretary.mobile_number != '' && secretary.mobile_number != null)
|
|
|
|
? info + ', ' + secretary.mobile_number : info;
|
|
|
|
info = (secretary.phone_number != '' && secretary.phone_number != null)
|
2015-10-09 00:12:59 +03:00
|
|
|
? info + ', ' + secretary.phone_number : info;
|
|
|
|
|
2013-09-24 19:05:40 +03:00
|
|
|
var html =
|
2015-10-09 00:12:59 +03:00
|
|
|
'<div class="secretary-row" data-id="' + secretary.id + '">' +
|
2013-10-27 14:53:51 +02:00
|
|
|
'<strong>' + name + '</strong><br>' +
|
2015-10-09 00:12:59 +03:00
|
|
|
info + '<br>' +
|
2013-10-10 19:50:33 +03:00
|
|
|
'</div><hr>';
|
2013-09-24 19:05:40 +03:00
|
|
|
|
|
|
|
return html;
|
2013-09-25 18:43:17 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2015-10-09 00:12:59 +03:00
|
|
|
* Select a specific record from the current filter results. If the secretary id does not exist
|
|
|
|
* in the list then no record will be selected.
|
|
|
|
*
|
2013-09-25 18:43:17 +03:00
|
|
|
* @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.
|
|
|
|
*/
|
|
|
|
SecretariesHelper.prototype.select = function(id, display) {
|
|
|
|
if (display == undefined) display = false;
|
2015-10-09 00:12:59 +03:00
|
|
|
|
2013-09-25 18:43:17 +03:00
|
|
|
$('#filter-secretaries .selected-row').removeClass('selected-row');
|
2015-10-09 00:12:59 +03:00
|
|
|
|
2013-09-25 18:43:17 +03:00
|
|
|
$('#filter-secretaries .secretary-row').each(function() {
|
|
|
|
if ($(this).attr('data-id') == id) {
|
|
|
|
$(this).addClass('selected-row');
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
});
|
2015-10-09 00:12:59 +03:00
|
|
|
|
|
|
|
if (display) {
|
2013-09-25 18:43:17 +03:00
|
|
|
$.each(BackendUsers.helper.filterResults, function(index, admin) {
|
|
|
|
if (admin.id == id) {
|
|
|
|
BackendUsers.helper.display(admin);
|
|
|
|
$('#edit-secretary, #delete-secretary').prop('disabled', false);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2015-10-09 00:12:59 +03:00
|
|
|
};
|