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
|
|
|
|
* ---------------------------------------------------------------------------- */
|
|
|
|
|
2016-04-26 22:33:30 +03:00
|
|
|
(function() {
|
|
|
|
|
|
|
|
'use strict';
|
|
|
|
|
2013-09-24 19:05:40 +03:00
|
|
|
/**
|
2016-04-26 22:33:30 +03:00
|
|
|
* Secretaries Helper
|
2015-10-09 00:12:59 +03:00
|
|
|
*
|
2016-04-26 22:33:30 +03:00
|
|
|
* This class contains the Secretaries helper class declaration, along with the "Secretaries"
|
2016-10-10 19:29:48 +03:00
|
|
|
* tab event handlers. By dividing the backend/users tab functionality into separate files
|
2016-04-26 22:33:30 +03:00
|
|
|
* it is easier to maintain the code.
|
|
|
|
*
|
|
|
|
* @class SecretariesHelper
|
2013-09-24 19:05:40 +03:00
|
|
|
*/
|
2016-04-26 22:33:30 +03:00
|
|
|
var SecretariesHelper = function() {
|
|
|
|
this.filterResults = {}; // Store the results for later use.
|
|
|
|
};
|
2013-09-24 19:05:40 +03:00
|
|
|
|
2013-09-25 18:43:17 +03:00
|
|
|
/**
|
2016-04-26 22:33:30 +03:00
|
|
|
* Bind the event handlers for the backend/users "Secretaries" tab.
|
2013-09-25 18:43:17 +03:00
|
|
|
*/
|
2016-04-26 22:33:30 +03:00
|
|
|
SecretariesHelper.prototype.bindEventHandlers = function() {
|
|
|
|
/**
|
|
|
|
* Event: Filter Secretaries Form "Submit"
|
|
|
|
*
|
|
|
|
* Filter the secretary records with the given key string.
|
|
|
|
*/
|
2016-05-14 13:44:28 +03:00
|
|
|
$('#secretaries').on('submit', '#filter-secretaries form', function() {
|
2016-04-26 22:33:30 +03:00
|
|
|
var key = $('#filter-secretaries .key').val();
|
2016-07-15 22:15:27 +03:00
|
|
|
$('#filter-secretaries .selected').removeClass('selected');
|
2016-04-26 22:33:30 +03:00
|
|
|
this.resetForm();
|
|
|
|
this.filter(key);
|
|
|
|
return false;
|
|
|
|
}.bind(this));
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Event: Clear Filter Results Button "Click"
|
|
|
|
*/
|
|
|
|
$('#secretaries').on('click', '#filter-secretaries .clear', function() {
|
|
|
|
this.filter('');
|
|
|
|
$('#filter-secretaries .key').val('');
|
|
|
|
this.resetForm();
|
|
|
|
}.bind(this));
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Event: Filter Secretary Row "Click"
|
|
|
|
*
|
|
|
|
* Display the selected secretary data to the user.
|
|
|
|
*/
|
2016-06-29 21:38:34 +03:00
|
|
|
$('#secretaries').on('click', '.secretary-row', function(e) {
|
2016-04-26 22:33:30 +03:00
|
|
|
if ($('#filter-secretaries .filter').prop('disabled')) {
|
|
|
|
$('#filter-secretaries .results').css('color', '#AAA');
|
|
|
|
return; // exit because we are currently on edit mode
|
|
|
|
}
|
2013-09-25 18:43:17 +03:00
|
|
|
|
2016-07-15 21:52:21 +03:00
|
|
|
var secretaryId = $(e.currentTarget).attr('data-id');
|
|
|
|
var secretary = {};
|
2016-05-14 13:44:28 +03:00
|
|
|
|
2016-04-26 22:33:30 +03:00
|
|
|
$.each(this.filterResults, function(index, item) {
|
|
|
|
if (item.id === secretaryId) {
|
|
|
|
secretary = item;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
this.display(secretary);
|
2016-05-14 13:44:28 +03:00
|
|
|
|
2016-07-15 22:15:27 +03:00
|
|
|
$('#filter-secretaries .selected').removeClass('selected');
|
|
|
|
$(e.currentTarget).addClass('selected');
|
2016-04-26 22:33:30 +03:00
|
|
|
$('#edit-secretary, #delete-secretary').prop('disabled', false);
|
|
|
|
}.bind(this));
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Event: Add New Secretary Button "Click"
|
|
|
|
*/
|
|
|
|
$('#secretaries').on('click', '#add-secretary', function() {
|
|
|
|
this.resetForm();
|
|
|
|
$('#filter-secretaries button').prop('disabled', true);
|
2013-09-25 18:43:17 +03:00
|
|
|
$('#filter-secretaries .results').css('color', '#AAA');
|
2013-09-24 19:05:40 +03:00
|
|
|
|
2016-04-26 22:33:30 +03:00
|
|
|
$('#secretaries .add-edit-delete-group').hide();
|
|
|
|
$('#secretaries .save-cancel-group').show();
|
2016-07-15 22:15:27 +03:00
|
|
|
$('#secretaries .record-details').find('input, textarea').prop('readonly', false);
|
2016-07-19 00:46:15 +03:00
|
|
|
$('#secretaries .record-details').find('select').prop('disabled', false);
|
2016-04-26 22:33:30 +03:00
|
|
|
$('#secretary-password, #secretary-password-confirm').addClass('required');
|
|
|
|
$('#secretary-notifications').prop('disabled', false);
|
|
|
|
$('#secretary-providers input[type="checkbox"]').prop('disabled', false);
|
|
|
|
}.bind(this));
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Event: Edit Secretary Button "Click"
|
|
|
|
*/
|
|
|
|
$('#secretaries').on('click', '#edit-secretary', function() {
|
|
|
|
$('#filter-secretaries button').prop('disabled', true);
|
|
|
|
$('#filter-secretaries .results').css('color', '#AAA');
|
|
|
|
$('#secretaries .add-edit-delete-group').hide();
|
|
|
|
$('#secretaries .save-cancel-group').show();
|
2016-07-15 22:15:27 +03:00
|
|
|
$('#secretaries .record-details').find('input, textarea').prop('readonly', false);
|
2016-07-19 00:46:15 +03:00
|
|
|
$('#secretaries .record-details').find('select').prop('disabled', false);
|
2016-04-26 22:33:30 +03:00
|
|
|
$('#secretary-password, #secretary-password-confirm').removeClass('required');
|
|
|
|
$('#secretary-notifications').prop('disabled', false);
|
|
|
|
$('#secretary-providers input[type="checkbox"]').prop('disabled', false);
|
2013-09-24 19:05:40 +03:00
|
|
|
});
|
2015-10-09 00:12:59 +03:00
|
|
|
|
2016-04-26 22:33:30 +03:00
|
|
|
/**
|
|
|
|
* Event: Delete Secretary Button "Click"
|
|
|
|
*/
|
|
|
|
$('#secretaries').on('click', '#delete-secretary', function() {
|
2016-07-15 21:52:21 +03:00
|
|
|
var secretaryId = $('#secretary-id').val();
|
|
|
|
var messageBtns = {};
|
2016-04-26 22:33:30 +03:00
|
|
|
|
|
|
|
messageBtns[EALang['delete']] = function() {
|
|
|
|
this.delete(secretaryId);
|
|
|
|
$('#message_box').dialog('close');
|
|
|
|
}.bind(this);
|
2016-05-14 13:44:28 +03:00
|
|
|
|
2016-04-26 22:33:30 +03:00
|
|
|
messageBtns[EALang['cancel']] = function() {
|
|
|
|
$('#message_box').dialog('close');
|
|
|
|
};
|
|
|
|
|
|
|
|
GeneralFunctions.displayMessageBox(EALang['delete_secretary'],
|
|
|
|
EALang['delete_record_prompt'], messageBtns);
|
2016-11-29 22:02:11 +03:00
|
|
|
}.bind(this));
|
2013-09-24 19:05:40 +03:00
|
|
|
|
2016-04-26 22:33:30 +03:00
|
|
|
/**
|
|
|
|
* Event: Save Secretary Button "Click"
|
|
|
|
*/
|
|
|
|
$('#secretaries').on('click', '#save-secretary', 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: {
|
|
|
|
username: $('#secretary-username').val(),
|
2016-07-19 00:46:15 +03:00
|
|
|
notifications: $('#secretary-notifications').hasClass('active'),
|
|
|
|
calendar_view: $('#secretary-calendar-view').val()
|
2016-04-26 22:33:30 +03:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
// 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();
|
|
|
|
}
|
|
|
|
|
2016-05-14 13:44:28 +03:00
|
|
|
// Include ID if changed.
|
2016-04-26 22:33:30 +03:00
|
|
|
if ($('#secretary-id').val() !== '') {
|
|
|
|
secretary.id = $('#secretary-id').val();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!this.validate(secretary)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.save(secretary);
|
|
|
|
}.bind(this));
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Event: Cancel Secretary Button "Click"
|
|
|
|
*
|
|
|
|
* Cancel add or edit of an secretary record.
|
|
|
|
*/
|
2016-11-20 19:56:35 +03:00
|
|
|
$('#secretaries').on('click', '#cancel-secretary', function() {
|
2016-04-26 22:33:30 +03:00
|
|
|
var id = $('#secretary-id').val();
|
|
|
|
this.resetForm();
|
|
|
|
if (id != '') {
|
|
|
|
this.select(id, true);
|
|
|
|
}
|
|
|
|
}.bind(this));
|
|
|
|
};
|
2013-09-24 19:05:40 +03:00
|
|
|
|
|
|
|
/**
|
2016-04-26 22:33:30 +03:00
|
|
|
* Save secretary record to database.
|
|
|
|
*
|
2016-05-14 13:44:28 +03:00
|
|
|
* @param {Object} secretary Contains the admin record data. If an 'id' value is provided
|
2016-04-26 22:33:30 +03:00
|
|
|
* then the update operation is going to be executed.
|
2013-09-24 19:05:40 +03:00
|
|
|
*/
|
2016-04-26 22:33:30 +03:00
|
|
|
SecretariesHelper.prototype.save = function(secretary) {
|
2016-07-15 21:52:21 +03:00
|
|
|
var postUrl = GlobalVariables.baseUrl + '/index.php/backend_api/ajax_save_secretary';
|
|
|
|
var postData = {
|
|
|
|
csrfToken: GlobalVariables.csrfToken,
|
|
|
|
secretary: JSON.stringify(secretary)
|
|
|
|
};
|
2016-04-26 22:33:30 +03:00
|
|
|
|
|
|
|
$.post(postUrl, postData, function(response) {
|
|
|
|
if (!GeneralFunctions.handleAjaxExceptions(response)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
Backend.displayNotification(EALang['secretary_saved']);
|
|
|
|
this.resetForm();
|
|
|
|
$('#filter-secretaries .key').val('');
|
|
|
|
this.filter('', response.id, true);
|
|
|
|
}.bind(this), 'json').fail(GeneralFunctions.ajaxFailureHandler);
|
|
|
|
};
|
2013-09-24 19:05:40 +03:00
|
|
|
|
|
|
|
/**
|
2016-04-26 22:33:30 +03:00
|
|
|
* Delete a secretary record from database.
|
|
|
|
*
|
2016-05-14 13:44:28 +03:00
|
|
|
* @param {Number} id Record id to be deleted.
|
2013-09-24 19:05:40 +03:00
|
|
|
*/
|
2016-04-26 22:33:30 +03:00
|
|
|
SecretariesHelper.prototype.delete = function(id) {
|
2016-07-15 21:52:21 +03:00
|
|
|
var postUrl = GlobalVariables.baseUrl + '/index.php/backend_api/ajax_delete_secretary';
|
|
|
|
var postData = {
|
|
|
|
csrfToken: GlobalVariables.csrfToken,
|
|
|
|
secretary_id: id
|
|
|
|
};
|
2016-04-26 22:33:30 +03:00
|
|
|
|
|
|
|
$.post(postUrl, postData, function(response) {
|
|
|
|
if (!GeneralFunctions.handleAjaxExceptions(response)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
Backend.displayNotification(EALang['secretary_deleted']);
|
|
|
|
this.resetForm();
|
|
|
|
this.filter($('#filter-secretaries .key').val());
|
|
|
|
}.bind(this), 'json').fail(GeneralFunctions.ajaxFailureHandler);
|
|
|
|
};
|
2013-09-24 19:05:40 +03:00
|
|
|
|
|
|
|
/**
|
2016-04-26 22:33:30 +03:00
|
|
|
* Validates a secretary record.
|
|
|
|
*
|
2016-05-14 13:44:28 +03:00
|
|
|
* @param {Object} secretary Contains the admin data to be validated.
|
|
|
|
*
|
|
|
|
* @return {Boolean} Returns the validation result.
|
2013-09-24 19:05:40 +03:00
|
|
|
*/
|
2016-04-26 22:33:30 +03:00
|
|
|
SecretariesHelper.prototype.validate = function(secretary) {
|
|
|
|
$('#secretaries .required').css('border', '');
|
|
|
|
$('#secretary-password, #secretary-password-confirm').css('border', '');
|
|
|
|
|
|
|
|
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.';
|
2013-09-24 19:05:40 +03:00
|
|
|
}
|
|
|
|
|
2016-04-26 22:33:30 +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!';
|
2013-09-24 19:05:40 +03:00
|
|
|
}
|
|
|
|
|
2016-04-26 22:33:30 +03:00
|
|
|
if ($('#secretary-password').val().length < BackendUsers.MIN_PASSWORD_LENGTH
|
|
|
|
&& $('#secretary-password').val() != '') {
|
|
|
|
$('#secretary-password, #secretary-password-confirm').css('border', '2px solid red');
|
|
|
|
throw 'Password must be at least ' + BackendUsers.MIN_PASSWORD_LENGTH
|
|
|
|
+ ' characters long.';
|
|
|
|
}
|
2013-09-24 19:05:40 +03:00
|
|
|
|
2016-04-26 22:33:30 +03:00
|
|
|
// Validate user email.
|
|
|
|
if (!GeneralFunctions.validateEmail($('#secretary-email').val())) {
|
|
|
|
$('#secretary-email').css('border', '2px solid red');
|
|
|
|
throw 'Invalid email address!';
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check if username exists
|
|
|
|
if ($('#secretary-username').attr('already-exists') == 'true') {
|
|
|
|
$('#secretary-username').css('border', '2px solid red');
|
|
|
|
throw 'Username already exists.';
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
} catch(exc) {
|
|
|
|
$('#secretaries .form-message').text(exc);
|
|
|
|
$('#secretaries .form-message').show();
|
|
|
|
return false;
|
2013-09-24 19:05:40 +03:00
|
|
|
}
|
2016-04-26 22:33:30 +03:00
|
|
|
};
|
2013-09-24 19:05:40 +03:00
|
|
|
|
2016-04-26 22:33:30 +03:00
|
|
|
/**
|
|
|
|
* Resets the admin tab form back to its initial state.
|
|
|
|
*/
|
|
|
|
SecretariesHelper.prototype.resetForm = function() {
|
2016-07-15 22:15:27 +03:00
|
|
|
$('#secretaries .record-details').find('input, textarea').val('');
|
2016-04-26 22:33:30 +03:00
|
|
|
$('#secretaries .add-edit-delete-group').show();
|
|
|
|
$('#secretaries .save-cancel-group').hide();
|
|
|
|
$('#edit-secretary, #delete-secretary').prop('disabled', true);
|
2016-07-15 22:15:27 +03:00
|
|
|
$('#secretaries .record-details').find('input, textarea').prop('readonly', true);
|
2016-07-19 00:46:15 +03:00
|
|
|
$('#secretaries .record-details').find('select').prop('disabled', true);
|
2016-04-26 22:33:30 +03:00
|
|
|
$('#secretaries .form-message').hide();
|
|
|
|
$('#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', '');
|
2013-09-24 19:05:40 +03:00
|
|
|
|
2016-07-15 22:15:27 +03:00
|
|
|
$('#filter-secretaries .selected').removeClass('selected');
|
2016-04-26 22:33:30 +03:00
|
|
|
$('#filter-secretaries button').prop('disabled', false);
|
|
|
|
$('#filter-secretaries .results').css('color', '');
|
|
|
|
};
|
2013-09-24 19:05:40 +03:00
|
|
|
|
|
|
|
/**
|
2016-04-26 22:33:30 +03:00
|
|
|
* Display a secretary record into the admin form.
|
2015-10-09 00:12:59 +03:00
|
|
|
*
|
2016-05-14 13:44:28 +03:00
|
|
|
* @param {Object} secretary Contains the secretary record data.
|
2013-09-24 19:05:40 +03:00
|
|
|
*/
|
2016-04-26 22:33:30 +03:00
|
|
|
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);
|
|
|
|
|
|
|
|
$('#secretary-username').val(secretary.settings.username);
|
2016-07-19 00:46:15 +03:00
|
|
|
$('#secretary-calendar-view').val(secretary.settings.calendar_view);
|
2016-04-26 22:33:30 +03:00
|
|
|
if (secretary.settings.notifications == true) {
|
|
|
|
$('#secretary-notifications').addClass('active');
|
|
|
|
} else {
|
|
|
|
$('#secretary-notifications').removeClass('active');
|
2013-09-25 18:43:17 +03:00
|
|
|
}
|
2013-09-24 19:05:40 +03:00
|
|
|
|
2016-04-26 22:33:30 +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);
|
|
|
|
}
|
|
|
|
});
|
2013-09-24 19:05:40 +03:00
|
|
|
});
|
2016-04-26 22:33:30 +03:00
|
|
|
};
|
2015-10-09 00:12:59 +03:00
|
|
|
|
2016-04-26 22:33:30 +03:00
|
|
|
/**
|
|
|
|
* Filters secretary records depending a string key.
|
|
|
|
*
|
2016-05-14 13:44:28 +03:00
|
|
|
* @param {String} key This is used to filter the secretary records of the database.
|
|
|
|
* @param {Numeric} selectId Optional, if provided the given ID will be selected in the filter results
|
|
|
|
* (only selected, not displayed).
|
|
|
|
* @param {Bool} display Optional (false).
|
2016-04-26 22:33:30 +03:00
|
|
|
*/
|
|
|
|
SecretariesHelper.prototype.filter = function(key, selectId, display) {
|
|
|
|
display = display || false;
|
|
|
|
|
2016-07-15 21:52:21 +03:00
|
|
|
var postUrl = GlobalVariables.baseUrl + '/index.php/backend_api/ajax_filter_secretaries';
|
|
|
|
var postData = {
|
|
|
|
csrfToken: GlobalVariables.csrfToken,
|
|
|
|
key: key
|
|
|
|
};
|
2016-04-26 22:33:30 +03:00
|
|
|
|
|
|
|
$.post(postUrl, postData, function(response) {
|
|
|
|
if (!GeneralFunctions.handleAjaxExceptions(response)) {
|
|
|
|
return;
|
|
|
|
}
|
2015-10-09 00:12:59 +03:00
|
|
|
|
2016-04-26 22:33:30 +03:00
|
|
|
this.filterResults = response;
|
2015-10-09 00:12:59 +03:00
|
|
|
|
2016-04-26 22:33:30 +03:00
|
|
|
$('#filter-secretaries .results').data('jsp').destroy();
|
|
|
|
$('#filter-secretaries .results').html('');
|
|
|
|
$.each(response, function(index, secretary) {
|
|
|
|
var html = this.getFilterHtml(secretary);
|
|
|
|
$('#filter-secretaries .results').append(html);
|
|
|
|
}.bind(this));
|
|
|
|
$('#filter-secretaries .results').jScrollPane({ mouseWheelSpeed: 70 });
|
2015-10-09 00:12:59 +03:00
|
|
|
|
2016-04-26 22:33:30 +03:00
|
|
|
if (response.length == 0) {
|
|
|
|
$('#filter-secretaries .results').html('<em>' + EALang['no_records_found'] + '</em>')
|
2013-09-24 19:05:40 +03:00
|
|
|
}
|
|
|
|
|
2016-04-26 22:33:30 +03:00
|
|
|
if (selectId != undefined) {
|
|
|
|
this.select(selectId, display);
|
|
|
|
}
|
|
|
|
}.bind(this), 'json').fail(GeneralFunctions.ajaxFailureHandler);
|
2015-05-28 00:42:40 +03:00
|
|
|
};
|
2015-10-09 00:12:59 +03:00
|
|
|
|
2016-04-26 22:33:30 +03:00
|
|
|
/**
|
|
|
|
* Get an secretary row html code that is going to be displayed on the filter results list.
|
|
|
|
*
|
2016-05-14 13:44:28 +03:00
|
|
|
* @param {Object} secretary Contains the secretary record data.
|
|
|
|
*
|
|
|
|
* @return {String} The html code that represents the record on the filter results list.
|
2016-04-26 22:33:30 +03:00
|
|
|
*/
|
|
|
|
SecretariesHelper.prototype.getFilterHtml = function(secretary) {
|
2016-07-15 21:52:21 +03:00
|
|
|
var name = secretary.first_name + ' ' + secretary.last_name;
|
|
|
|
var info = secretary.email;
|
2015-10-09 00:12:59 +03:00
|
|
|
|
2016-04-26 22:33:30 +03:00
|
|
|
info = (secretary.mobile_number != '' && secretary.mobile_number != null)
|
|
|
|
? info + ', ' + secretary.mobile_number : info;
|
2015-10-09 00:12:59 +03:00
|
|
|
|
2016-04-26 22:33:30 +03:00
|
|
|
info = (secretary.phone_number != '' && secretary.phone_number != null)
|
|
|
|
? info + ', ' + secretary.phone_number : info;
|
2015-10-09 00:12:59 +03:00
|
|
|
|
2016-04-26 22:33:30 +03:00
|
|
|
var html =
|
2016-07-15 22:15:27 +03:00
|
|
|
'<div class="secretary-row entry" data-id="' + secretary.id + '">' +
|
2016-04-26 22:33:30 +03:00
|
|
|
'<strong>' + name + '</strong><br>' +
|
|
|
|
info + '<br>' +
|
|
|
|
'</div><hr>';
|
2015-10-09 00:12:59 +03:00
|
|
|
|
2016-04-26 22:33:30 +03:00
|
|
|
return html;
|
|
|
|
};
|
2013-09-24 19:05:40 +03:00
|
|
|
|
2016-04-26 22:33:30 +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.
|
|
|
|
*
|
2016-05-14 13:44:28 +03:00
|
|
|
* @param {Number} id The record id to be selected from the filter results.
|
|
|
|
* @param {Boolean} display Optional (false), if true the method will display the record in the form.
|
2016-04-26 22:33:30 +03:00
|
|
|
*/
|
|
|
|
SecretariesHelper.prototype.select = function(id, display) {
|
|
|
|
display = display || false;
|
|
|
|
|
2016-07-15 22:15:27 +03:00
|
|
|
$('#filter-secretaries .selected').removeClass('selected');
|
2015-10-09 00:12:59 +03:00
|
|
|
|
2016-04-26 22:33:30 +03:00
|
|
|
$('#filter-secretaries .secretary-row').each(function() {
|
|
|
|
if ($(this).attr('data-id') == id) {
|
2016-07-15 22:15:27 +03:00
|
|
|
$(this).addClass('selected');
|
2013-09-25 18:43:17 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
});
|
2016-04-26 22:33:30 +03:00
|
|
|
|
|
|
|
if (display) {
|
|
|
|
$.each(this.filterResults, function(index, admin) {
|
|
|
|
if (admin.id == id) {
|
|
|
|
this.display(admin);
|
|
|
|
$('#edit-secretary, #delete-secretary').prop('disabled', false);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}.bind(this));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
window.SecretariesHelper = SecretariesHelper;
|
|
|
|
|
|
|
|
})();
|