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>
|
2021-12-18 19:43:45 +03:00
|
|
|
* @copyright Copyright (c) Alex Tselegidis
|
|
|
|
* @license https://opensource.org/licenses/GPL-3.0 - GPLv3
|
|
|
|
* @link https://easyappointments.org
|
2015-07-20 22:41:24 +03:00
|
|
|
* @since v1.0.0
|
|
|
|
* ---------------------------------------------------------------------------- */
|
|
|
|
|
2018-01-23 12:08:37 +03:00
|
|
|
(function () {
|
2016-04-26 22:33:30 +03:00
|
|
|
'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
|
|
|
*/
|
2018-01-23 12:08:37 +03:00
|
|
|
var SecretariesHelper = function () {
|
2016-04-26 22:33:30 +03:00
|
|
|
this.filterResults = {}; // Store the results for later use.
|
2020-04-06 21:34:32 +03:00
|
|
|
this.filterLimit = 20;
|
2016-04-26 22:33:30 +03:00
|
|
|
};
|
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
|
|
|
*/
|
2018-01-23 12:08:37 +03:00
|
|
|
SecretariesHelper.prototype.bindEventHandlers = function () {
|
2016-04-26 22:33:30 +03:00
|
|
|
/**
|
|
|
|
* Event: Filter Secretaries Form "Submit"
|
|
|
|
*
|
|
|
|
* Filter the secretary records with the given key string.
|
2020-12-08 14:23:37 +03:00
|
|
|
*
|
|
|
|
* @param {jQuery.Event} event
|
2016-04-26 22:33:30 +03:00
|
|
|
*/
|
2021-11-06 19:38:37 +03:00
|
|
|
$('#secretaries').on(
|
|
|
|
'submit',
|
|
|
|
'#filter-secretaries form',
|
|
|
|
function (event) {
|
|
|
|
event.preventDefault();
|
|
|
|
var key = $('#filter-secretaries .key').val();
|
|
|
|
$('#filter-secretaries .selected').removeClass('selected');
|
|
|
|
this.resetForm();
|
|
|
|
this.filter(key);
|
|
|
|
}.bind(this)
|
|
|
|
);
|
2016-04-26 22:33:30 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Event: Clear Filter Results Button "Click"
|
|
|
|
*/
|
2021-11-06 19:38:37 +03:00
|
|
|
$('#secretaries').on(
|
|
|
|
'click',
|
|
|
|
'#filter-secretaries .clear',
|
|
|
|
function () {
|
|
|
|
this.filter('');
|
|
|
|
$('#filter-secretaries .key').val('');
|
|
|
|
this.resetForm();
|
|
|
|
}.bind(this)
|
|
|
|
);
|
2016-04-26 22:33:30 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Event: Filter Secretary Row "Click"
|
|
|
|
*
|
|
|
|
* Display the selected secretary data to the user.
|
|
|
|
*/
|
2021-11-06 19:38:37 +03:00
|
|
|
$('#secretaries').on(
|
|
|
|
'click',
|
|
|
|
'.secretary-row',
|
|
|
|
function (event) {
|
|
|
|
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
|
|
|
|
2021-11-06 19:38:37 +03:00
|
|
|
var secretaryId = $(event.currentTarget).attr('data-id');
|
2016-05-14 13:44:28 +03:00
|
|
|
|
2021-11-06 19:38:37 +03:00
|
|
|
var secretary = this.filterResults.find(function (filterResult) {
|
|
|
|
return Number(filterResult.id) === Number(secretaryId);
|
|
|
|
});
|
2016-04-26 22:33:30 +03:00
|
|
|
|
2021-11-06 19:38:37 +03:00
|
|
|
this.display(secretary);
|
2016-05-14 13:44:28 +03:00
|
|
|
|
2021-11-06 19:38:37 +03:00
|
|
|
$('#filter-secretaries .selected').removeClass('selected');
|
|
|
|
$(event.currentTarget).addClass('selected');
|
|
|
|
$('#edit-secretary, #delete-secretary').prop('disabled', false);
|
|
|
|
}.bind(this)
|
|
|
|
);
|
2016-04-26 22:33:30 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Event: Add New Secretary Button "Click"
|
|
|
|
*/
|
2021-11-06 19:38:37 +03:00
|
|
|
$('#secretaries').on(
|
|
|
|
'click',
|
|
|
|
'#add-secretary',
|
|
|
|
function () {
|
|
|
|
this.resetForm();
|
|
|
|
$('#filter-secretaries button').prop('disabled', true);
|
|
|
|
$('#filter-secretaries .results').css('color', '#AAA');
|
2013-09-24 19:05:40 +03:00
|
|
|
|
2021-11-06 19:38:37 +03:00
|
|
|
$('#secretaries .add-edit-delete-group').hide();
|
|
|
|
$('#secretaries .save-cancel-group').show();
|
|
|
|
$('#secretaries .record-details').find('input, textarea').prop('disabled', false);
|
|
|
|
$('#secretaries .record-details').find('select').prop('disabled', false);
|
|
|
|
$('#secretary-password, #secretary-password-confirm').addClass('required');
|
|
|
|
$('#secretary-providers input:checkbox').prop('disabled', false);
|
|
|
|
}.bind(this)
|
|
|
|
);
|
2016-04-26 22:33:30 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Event: Edit Secretary Button "Click"
|
|
|
|
*/
|
2018-01-23 12:08:37 +03:00
|
|
|
$('#secretaries').on('click', '#edit-secretary', function () {
|
2016-04-26 22:33:30 +03:00
|
|
|
$('#filter-secretaries button').prop('disabled', true);
|
|
|
|
$('#filter-secretaries .results').css('color', '#AAA');
|
|
|
|
$('#secretaries .add-edit-delete-group').hide();
|
|
|
|
$('#secretaries .save-cancel-group').show();
|
2020-05-05 20:35:33 +03:00
|
|
|
$('#secretaries .record-details').find('input, textarea').prop('disabled', 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');
|
2017-09-23 04:42:14 +03:00
|
|
|
$('#secretary-providers input: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"
|
|
|
|
*/
|
2021-11-06 19:38:37 +03:00
|
|
|
$('#secretaries').on(
|
|
|
|
'click',
|
|
|
|
'#delete-secretary',
|
|
|
|
function () {
|
|
|
|
var secretaryId = $('#secretary-id').val();
|
|
|
|
var buttons = [
|
|
|
|
{
|
2021-12-13 09:52:09 +03:00
|
|
|
text: App.Lang.cancel,
|
2021-11-06 19:38:37 +03:00
|
|
|
click: function () {
|
|
|
|
$('#message-box').dialog('close');
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
2021-12-13 09:52:09 +03:00
|
|
|
text: App.Lang.delete,
|
2021-11-06 19:38:37 +03:00
|
|
|
click: function () {
|
|
|
|
this.delete(secretaryId);
|
|
|
|
$('#message-box').dialog('close');
|
|
|
|
}.bind(this)
|
2020-09-07 11:15:01 +03:00
|
|
|
}
|
2021-11-06 19:38:37 +03:00
|
|
|
];
|
2016-04-26 22:33:30 +03:00
|
|
|
|
2021-12-13 09:52:09 +03:00
|
|
|
GeneralFunctions.displayMessageBox(App.Lang.delete_secretary, App.Lang.delete_record_prompt, buttons);
|
2021-11-06 19:38:37 +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"
|
|
|
|
*/
|
2021-11-06 19:38:37 +03:00
|
|
|
$('#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(),
|
|
|
|
timezone: $('#secretary-timezone').val(),
|
|
|
|
settings: {
|
|
|
|
username: $('#secretary-username').val(),
|
|
|
|
notifications: $('#secretary-notifications').prop('checked'),
|
|
|
|
calendar_view: $('#secretary-calendar-view').val()
|
|
|
|
}
|
|
|
|
};
|
2016-04-26 22:33:30 +03:00
|
|
|
|
2021-11-06 19:38:37 +03:00
|
|
|
// Include secretary services.
|
|
|
|
secretary.providers = [];
|
|
|
|
$('#secretary-providers input:checkbox').each(function (index, checkbox) {
|
|
|
|
if ($(checkbox).prop('checked')) {
|
|
|
|
secretary.providers.push($(checkbox).attr('data-id'));
|
|
|
|
}
|
|
|
|
});
|
2016-04-26 22:33:30 +03:00
|
|
|
|
2021-11-06 19:38:37 +03:00
|
|
|
// Include password if changed.
|
|
|
|
if ($('#secretary-password').val() !== '') {
|
|
|
|
secretary.settings.password = $('#secretary-password').val();
|
|
|
|
}
|
2016-04-26 22:33:30 +03:00
|
|
|
|
2021-11-06 19:38:37 +03:00
|
|
|
// Include ID if changed.
|
|
|
|
if ($('#secretary-id').val() !== '') {
|
|
|
|
secretary.id = $('#secretary-id').val();
|
|
|
|
}
|
2016-04-26 22:33:30 +03:00
|
|
|
|
2021-11-06 19:38:37 +03:00
|
|
|
if (!this.validate()) {
|
|
|
|
return;
|
|
|
|
}
|
2016-04-26 22:33:30 +03:00
|
|
|
|
2021-11-06 19:38:37 +03:00
|
|
|
this.save(secretary);
|
|
|
|
}.bind(this)
|
|
|
|
);
|
2016-04-26 22:33:30 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Event: Cancel Secretary Button "Click"
|
|
|
|
*
|
|
|
|
* Cancel add or edit of an secretary record.
|
|
|
|
*/
|
2021-11-06 19:38:37 +03:00
|
|
|
$('#secretaries').on(
|
|
|
|
'click',
|
|
|
|
'#cancel-secretary',
|
|
|
|
function () {
|
|
|
|
var id = $('#secretary-id').val();
|
|
|
|
this.resetForm();
|
|
|
|
if (id) {
|
|
|
|
this.select(id, true);
|
|
|
|
}
|
|
|
|
}.bind(this)
|
|
|
|
);
|
2016-04-26 22:33:30 +03:00
|
|
|
};
|
2013-09-24 19:05:40 +03:00
|
|
|
|
2020-12-08 14:23:37 +03:00
|
|
|
/**
|
|
|
|
* Remove the previously registered event handlers.
|
|
|
|
*/
|
2020-12-09 15:17:45 +03:00
|
|
|
SecretariesHelper.prototype.unbindEventHandlers = function () {
|
2020-12-08 14:23:37 +03:00
|
|
|
$('#secretaries')
|
|
|
|
.off('submit', '#filter-secretaries form')
|
|
|
|
.off('click', '#filter-secretaries .clear')
|
|
|
|
.off('click', '.secretary-row')
|
|
|
|
.off('click', '#add-secretary')
|
|
|
|
.off('click', '#edit-secretary')
|
|
|
|
.off('click', '#delete-secretary')
|
|
|
|
.off('click', '#save-secretary')
|
|
|
|
.off('click', '#cancel-secretary');
|
|
|
|
};
|
|
|
|
|
2013-09-24 19:05:40 +03:00
|
|
|
/**
|
2016-04-26 22:33:30 +03:00
|
|
|
* Save secretary record to database.
|
|
|
|
*
|
2020-05-07 19:47:14 +03:00
|
|
|
* @param {Object} secretary Contains the secretary 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
|
|
|
*/
|
2018-01-23 12:08:37 +03:00
|
|
|
SecretariesHelper.prototype.save = function (secretary) {
|
2020-04-27 21:14:20 +03:00
|
|
|
var url = GlobalVariables.baseUrl + '/index.php/backend_api/ajax_save_secretary';
|
2020-05-06 20:15:11 +03:00
|
|
|
|
2020-04-27 21:14:20 +03:00
|
|
|
var data = {
|
2021-12-14 09:29:51 +03:00
|
|
|
csrf_token: GlobalVariables.csrfToken,
|
2016-07-15 21:52:21 +03:00
|
|
|
secretary: JSON.stringify(secretary)
|
|
|
|
};
|
2016-04-26 22:33:30 +03:00
|
|
|
|
2021-11-06 19:38:37 +03:00
|
|
|
$.post(url, data).done(
|
|
|
|
function (response) {
|
2021-12-13 09:52:09 +03:00
|
|
|
Backend.displayNotification(App.Lang.secretary_saved);
|
2020-04-27 21:14:20 +03:00
|
|
|
this.resetForm();
|
|
|
|
$('#filter-secretaries .key').val('');
|
|
|
|
this.filter('', response.id, true);
|
2021-11-06 19:38:37 +03:00
|
|
|
}.bind(this)
|
|
|
|
);
|
2016-04-26 22:33:30 +03:00
|
|
|
};
|
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
|
|
|
*/
|
2018-01-23 12:08:37 +03:00
|
|
|
SecretariesHelper.prototype.delete = function (id) {
|
2020-04-27 21:14:20 +03:00
|
|
|
var url = GlobalVariables.baseUrl + '/index.php/backend_api/ajax_delete_secretary';
|
2020-05-06 20:15:11 +03:00
|
|
|
|
2020-04-27 21:14:20 +03:00
|
|
|
var data = {
|
2021-12-14 09:29:51 +03:00
|
|
|
csrf_token: GlobalVariables.csrfToken,
|
2016-07-15 21:52:21 +03:00
|
|
|
secretary_id: id
|
|
|
|
};
|
2016-04-26 22:33:30 +03:00
|
|
|
|
2021-11-06 19:38:37 +03:00
|
|
|
$.post(url, data).done(
|
|
|
|
function () {
|
2021-12-13 09:52:09 +03:00
|
|
|
Backend.displayNotification(App.Lang.secretary_deleted);
|
2020-04-27 21:14:20 +03:00
|
|
|
this.resetForm();
|
|
|
|
this.filter($('#filter-secretaries .key').val());
|
2021-11-06 19:38:37 +03:00
|
|
|
}.bind(this)
|
|
|
|
);
|
2016-04-26 22:33:30 +03:00
|
|
|
};
|
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
|
|
|
* @return {Boolean} Returns the validation result.
|
2013-09-24 19:05:40 +03:00
|
|
|
*/
|
2018-01-23 12:08:37 +03:00
|
|
|
SecretariesHelper.prototype.validate = function () {
|
2021-11-23 12:10:09 +03:00
|
|
|
$('#secretaries .is-invalid').removeClass('is-invalid');
|
2017-11-14 15:52:59 +03:00
|
|
|
$('#secretaries .form-message').removeClass('alert-danger');
|
2016-04-26 22:33:30 +03:00
|
|
|
|
|
|
|
try {
|
|
|
|
// Validate required fields.
|
|
|
|
var missingRequired = false;
|
2020-05-12 21:52:32 +03:00
|
|
|
$('#secretaries .required').each(function (index, requiredField) {
|
|
|
|
if (!$(requiredField).val()) {
|
2021-11-23 12:10:09 +03:00
|
|
|
$(requiredField).addClass('is-invalid');
|
2016-04-26 22:33:30 +03:00
|
|
|
missingRequired = true;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
if (missingRequired) {
|
2020-05-06 20:15:11 +03:00
|
|
|
throw new Error('Fields with * are required.');
|
2013-09-24 19:05:40 +03:00
|
|
|
}
|
|
|
|
|
2016-04-26 22:33:30 +03:00
|
|
|
// Validate passwords.
|
2020-05-06 20:15:11 +03:00
|
|
|
if ($('#secretary-password').val() !== $('#secretary-password-confirm').val()) {
|
2021-11-23 12:10:09 +03:00
|
|
|
$('#secretary-password, #secretary-password-confirm').addClass('is-invalid');
|
2020-05-06 20:15:11 +03:00
|
|
|
throw new Error('Passwords mismatch!');
|
2013-09-24 19:05:40 +03:00
|
|
|
}
|
|
|
|
|
2021-11-06 19:38:37 +03:00
|
|
|
if (
|
|
|
|
$('#secretary-password').val().length < BackendUsers.MIN_PASSWORD_LENGTH &&
|
|
|
|
$('#secretary-password').val() !== ''
|
|
|
|
) {
|
2021-11-23 12:10:09 +03:00
|
|
|
$('#secretary-password, #secretary-password-confirm').addClass('is-invalid');
|
2021-11-06 19:38:37 +03:00
|
|
|
throw new Error('Password must be at least ' + BackendUsers.MIN_PASSWORD_LENGTH + ' characters long.');
|
2016-04-26 22:33:30 +03:00
|
|
|
}
|
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())) {
|
2021-11-23 12:10:09 +03:00
|
|
|
$('#secretary-email').addClass('is-invalid');
|
2020-05-06 20:15:11 +03:00
|
|
|
throw new Error('Invalid email address!');
|
2016-04-26 22:33:30 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// Check if username exists
|
2020-05-06 20:15:11 +03:00
|
|
|
if ($('#secretary-username').attr('already-exists') === 'true') {
|
2021-11-23 12:10:09 +03:00
|
|
|
$('#secretary-username').addClass('is-invalid');
|
2020-05-06 20:15:11 +03:00
|
|
|
throw new Error('Username already exists.');
|
2016-04-26 22:33:30 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
2020-05-06 20:15:11 +03:00
|
|
|
} catch (error) {
|
2021-11-06 19:38:37 +03:00
|
|
|
$('#secretaries .form-message').addClass('alert-danger').text(error.message).show();
|
2016-04-26 22:33:30 +03:00
|
|
|
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
|
|
|
/**
|
2020-05-07 19:47:14 +03:00
|
|
|
* Resets the secretary tab form back to its initial state.
|
2016-04-26 22:33:30 +03:00
|
|
|
*/
|
2018-01-23 12:08:37 +03:00
|
|
|
SecretariesHelper.prototype.resetForm = function () {
|
2020-09-08 09:57:07 +03:00
|
|
|
$('#filter-secretaries .selected').removeClass('selected');
|
|
|
|
$('#filter-secretaries button').prop('disabled', false);
|
|
|
|
$('#filter-secretaries .results').css('color', '');
|
|
|
|
|
2021-11-06 19:38:37 +03:00
|
|
|
$('#secretaries .record-details').find('input, select, textarea').val('').prop('disabled', true);
|
2020-12-14 10:53:16 +03:00
|
|
|
$('#secretaries .record-details #secretary-calendar-view').val('default');
|
|
|
|
$('#secretaries .record-details #secretary-timezone').val('UTC');
|
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);
|
|
|
|
$('#secretaries .form-message').hide();
|
2017-09-23 04:42:14 +03:00
|
|
|
$('#secretary-providers input:checkbox').prop('checked', false);
|
2021-11-23 12:10:09 +03:00
|
|
|
$('#secretaries .is-invalid').removeClass('is-invalid');
|
2016-04-26 22:33:30 +03:00
|
|
|
};
|
2013-09-24 19:05:40 +03:00
|
|
|
|
|
|
|
/**
|
2020-05-07 19:47:14 +03:00
|
|
|
* Display a secretary record into the secretary 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
|
|
|
*/
|
2018-01-23 12:08:37 +03:00
|
|
|
SecretariesHelper.prototype.display = function (secretary) {
|
2016-04-26 22:33:30 +03:00
|
|
|
$('#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);
|
2020-03-29 15:10:49 +03:00
|
|
|
$('#secretary-timezone').val(secretary.timezone);
|
2016-04-26 22:33:30 +03:00
|
|
|
|
|
|
|
$('#secretary-username').val(secretary.settings.username);
|
2016-07-19 00:46:15 +03:00
|
|
|
$('#secretary-calendar-view').val(secretary.settings.calendar_view);
|
2020-09-07 11:36:36 +03:00
|
|
|
$('#secretary-notifications').prop('checked', Boolean(Number(secretary.settings.notifications)));
|
2013-09-24 19:05:40 +03:00
|
|
|
|
2017-09-23 04:42:14 +03:00
|
|
|
$('#secretary-providers input:checkbox').prop('checked', false);
|
2020-05-12 21:52:32 +03:00
|
|
|
|
|
|
|
secretary.providers.forEach(function (secretaryProviderId) {
|
|
|
|
var $checkbox = $('#secretary-providers input[data-id="' + secretaryProviderId + '"]');
|
|
|
|
|
|
|
|
if (!$checkbox.length) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
$checkbox.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
|
|
|
*/
|
2018-01-23 12:08:37 +03:00
|
|
|
SecretariesHelper.prototype.filter = function (key, selectId, display) {
|
2016-04-26 22:33:30 +03:00
|
|
|
display = display || false;
|
|
|
|
|
2020-05-06 20:15:11 +03:00
|
|
|
var url = GlobalVariables.baseUrl + '/index.php/backend_api/ajax_filter_secretaries';
|
|
|
|
|
|
|
|
var data = {
|
2021-12-14 09:29:51 +03:00
|
|
|
csrf_token: GlobalVariables.csrfToken,
|
2020-04-06 21:34:32 +03:00
|
|
|
key: key,
|
|
|
|
limit: this.filterLimit
|
2016-07-15 21:52:21 +03:00
|
|
|
};
|
2016-04-26 22:33:30 +03:00
|
|
|
|
2021-11-06 19:38:37 +03:00
|
|
|
$.post(url, data).done(
|
|
|
|
function (response) {
|
2020-05-06 20:15:11 +03:00
|
|
|
this.filterResults = response;
|
|
|
|
|
2020-05-07 19:47:14 +03:00
|
|
|
$('#filter-secretaries .results').empty();
|
2020-05-12 21:52:32 +03:00
|
|
|
|
2021-11-06 19:38:37 +03:00
|
|
|
response.forEach(
|
|
|
|
function (secretary) {
|
|
|
|
$('#filter-secretaries .results').append(this.getFilterHtml(secretary)).append($('<hr/>'));
|
|
|
|
}.bind(this)
|
|
|
|
);
|
2020-05-06 20:15:11 +03:00
|
|
|
|
|
|
|
if (!response.length) {
|
2020-05-07 19:47:14 +03:00
|
|
|
$('#filter-secretaries .results').append(
|
|
|
|
$('<em/>', {
|
2021-12-13 09:52:09 +03:00
|
|
|
'text': App.Lang.no_records_found
|
2020-05-07 19:47:14 +03:00
|
|
|
})
|
|
|
|
);
|
2020-05-06 20:15:11 +03:00
|
|
|
} else if (response.length === this.filterLimit) {
|
|
|
|
$('<button/>', {
|
|
|
|
'type': 'button',
|
2021-11-23 10:33:43 +03:00
|
|
|
'class': 'btn btn-outline-secondary w-100 load-more text-center',
|
2021-12-13 09:52:09 +03:00
|
|
|
'text': App.Lang.load_more,
|
2020-05-06 20:15:11 +03:00
|
|
|
'click': function () {
|
|
|
|
this.filterLimit += 20;
|
|
|
|
this.filter(key, selectId, display);
|
|
|
|
}.bind(this)
|
2021-11-06 19:38:37 +03:00
|
|
|
}).appendTo('#filter-secretaries .results');
|
2020-05-06 20:15:11 +03:00
|
|
|
}
|
2013-09-24 19:05:40 +03:00
|
|
|
|
2020-05-06 20:15:11 +03:00
|
|
|
if (selectId) {
|
|
|
|
this.select(selectId, display);
|
|
|
|
}
|
2021-11-06 19:38:37 +03:00
|
|
|
}.bind(this)
|
|
|
|
);
|
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
|
|
|
*/
|
2018-01-23 12:08:37 +03:00
|
|
|
SecretariesHelper.prototype.getFilterHtml = function (secretary) {
|
2016-07-15 21:52:21 +03:00
|
|
|
var name = secretary.first_name + ' ' + secretary.last_name;
|
2020-05-07 19:47:14 +03:00
|
|
|
|
2016-07-15 21:52:21 +03:00
|
|
|
var info = secretary.email;
|
2015-10-09 00:12:59 +03:00
|
|
|
|
2020-05-06 20:15:11 +03:00
|
|
|
info = secretary.mobile_number ? info + ', ' + secretary.mobile_number : info;
|
2015-10-09 00:12:59 +03:00
|
|
|
|
2020-05-06 20:15:11 +03:00
|
|
|
info = secretary.phone_number ? info + ', ' + secretary.phone_number : info;
|
2015-10-09 00:12:59 +03:00
|
|
|
|
2020-05-07 19:47:14 +03:00
|
|
|
return $('<div/>', {
|
|
|
|
'class': 'secretary-row entry',
|
|
|
|
'data-id': secretary.id,
|
|
|
|
'html': [
|
|
|
|
$('<strong/>', {
|
|
|
|
'text': name
|
|
|
|
}),
|
|
|
|
$('<br/>'),
|
|
|
|
$('<span/>', {
|
|
|
|
'text': info
|
|
|
|
}),
|
2021-11-06 19:38:37 +03:00
|
|
|
$('<br/>')
|
2020-05-07 19:47:14 +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
|
|
|
/**
|
|
|
|
* 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
|
|
|
*/
|
2018-01-23 12:08:37 +03:00
|
|
|
SecretariesHelper.prototype.select = function (id, display) {
|
2016-04-26 22:33:30 +03:00
|
|
|
display = display || false;
|
|
|
|
|
2016-07-15 22:15:27 +03:00
|
|
|
$('#filter-secretaries .selected').removeClass('selected');
|
2015-10-09 00:12:59 +03:00
|
|
|
|
2020-05-12 21:52:32 +03:00
|
|
|
$('#filter-secretaries .secretary-row[data-id="' + id + '"]').addClass('selected');
|
2016-04-26 22:33:30 +03:00
|
|
|
|
|
|
|
if (display) {
|
2021-11-06 19:38:37 +03:00
|
|
|
var secretary = this.filterResults.find(
|
|
|
|
function (filterResult) {
|
|
|
|
return Number(filterResult.id) === Number(id);
|
|
|
|
}.bind(this)
|
|
|
|
);
|
2020-05-12 21:52:32 +03:00
|
|
|
|
|
|
|
this.display(secretary);
|
|
|
|
|
|
|
|
$('#edit-secretary, #delete-secretary').prop('disabled', false);
|
2016-04-26 22:33:30 +03:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
window.SecretariesHelper = SecretariesHelper;
|
|
|
|
})();
|