2022-01-07 11:23:21 +03:00
|
|
|
/* ----------------------------------------------------------------------------
|
2022-01-18 15:05:42 +03:00
|
|
|
* Easy!Appointments - Online Appointment Scheduler
|
2022-01-07 11:23:21 +03:00
|
|
|
*
|
|
|
|
* @package EasyAppointments
|
|
|
|
* @author A.Tselegidis <alextselegidis@gmail.com>
|
|
|
|
* @copyright Copyright (c) Alex Tselegidis
|
|
|
|
* @license https://opensource.org/licenses/GPL-3.0 - GPLv3
|
|
|
|
* @link https://easyappointments.org
|
2022-01-18 15:01:22 +03:00
|
|
|
* @since v1.5.0
|
2022-01-07 11:23:21 +03:00
|
|
|
* ---------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
/**
|
2022-01-14 11:26:44 +03:00
|
|
|
* Admins page.
|
2022-01-07 11:23:21 +03:00
|
|
|
*
|
2022-01-14 11:26:44 +03:00
|
|
|
* This module implements the functionality of admins page.
|
2022-01-07 11:23:21 +03:00
|
|
|
*/
|
|
|
|
App.Pages.Admins = (function () {
|
|
|
|
const $admins = $('#admins');
|
2022-01-18 12:33:59 +03:00
|
|
|
const $id = $('#id');
|
|
|
|
const $firstName = $('#first-name');
|
|
|
|
const $lastName = $('#last-name');
|
|
|
|
const $email = $('#email');
|
|
|
|
const $mobileNumber = $('#mobile-number');
|
|
|
|
const $phoneNumber = $('#phone-number');
|
|
|
|
const $address = $('#address');
|
|
|
|
const $city = $('#city');
|
|
|
|
const $state = $('#state');
|
|
|
|
const $zipCode = $('#zip-code');
|
|
|
|
const $notes = $('#notes');
|
2022-05-20 19:13:26 +03:00
|
|
|
const $language = $('#language');
|
2022-01-18 12:33:59 +03:00
|
|
|
const $timezone = $('#timezone');
|
|
|
|
const $username = $('#username');
|
|
|
|
const $password = $('#password');
|
|
|
|
const $passwordConfirmation = $('#password-confirm');
|
|
|
|
const $notifications = $('#notifications');
|
|
|
|
const $calendarView = $('#calendar-view');
|
2022-01-17 07:39:12 +03:00
|
|
|
const $filterAdmins = $('#filter-admins');
|
2022-01-07 11:23:21 +03:00
|
|
|
let filterResults = {};
|
|
|
|
let filterLimit = 20;
|
|
|
|
|
|
|
|
/**
|
2022-01-17 07:39:12 +03:00
|
|
|
* Add the page event listeners.
|
2022-01-07 11:23:21 +03:00
|
|
|
*/
|
2022-01-17 07:39:12 +03:00
|
|
|
function addEventListeners() {
|
2022-01-07 11:23:21 +03:00
|
|
|
/**
|
|
|
|
* Event: Admin Username "Blur"
|
|
|
|
*
|
|
|
|
* When the admin leaves the username input field we will need to check if the username
|
|
|
|
* is not taken by another record in the system.
|
2022-01-18 13:14:45 +03:00
|
|
|
*
|
|
|
|
* @param {jQuery.Event} event
|
2022-01-07 11:23:21 +03:00
|
|
|
*/
|
2022-01-18 13:14:45 +03:00
|
|
|
$admins.on('blur', '#username', (event) => {
|
|
|
|
const $input = $(event.currentTarget);
|
2022-01-07 11:23:21 +03:00
|
|
|
|
|
|
|
if ($input.prop('readonly') === true || $input.val() === '') {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const adminId = $input.parents().eq(2).find('.record-id').val();
|
|
|
|
|
|
|
|
if (!adminId) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const username = $input.val();
|
|
|
|
|
|
|
|
App.Http.Account.validateUsername(adminId, username).done((response) => {
|
|
|
|
if (response.is_valid === 'false') {
|
|
|
|
$input.addClass('is-invalid');
|
|
|
|
$input.attr('already-exists', 'true');
|
2022-01-18 10:22:25 +03:00
|
|
|
$input.parents().eq(3).find('.form-message').text(lang('username_already_exists'));
|
2022-01-07 11:23:21 +03:00
|
|
|
$input.parents().eq(3).find('.form-message').show();
|
|
|
|
} else {
|
|
|
|
$input.removeClass('is-invalid');
|
|
|
|
$input.attr('already-exists', 'false');
|
2022-01-18 10:22:25 +03:00
|
|
|
if ($input.parents().eq(3).find('.form-message').text() === lang('username_already_exists')) {
|
2022-01-07 11:23:21 +03:00
|
|
|
$input.parents().eq(3).find('.form-message').hide();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Event: Filter Admins Form "Submit"
|
|
|
|
*
|
|
|
|
* Filter the admin records with the given key string.
|
|
|
|
*
|
|
|
|
* @param {jQuery.Event} event
|
|
|
|
*/
|
2022-01-18 13:14:45 +03:00
|
|
|
$admins.on('submit', '#filter-admins form', (event) => {
|
2022-01-07 11:23:21 +03:00
|
|
|
event.preventDefault();
|
|
|
|
const key = $('#filter-admins .key').val();
|
|
|
|
$('#filter-admins .selected').removeClass('selected');
|
|
|
|
resetForm();
|
|
|
|
filter(key);
|
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Event: Filter Admin Row "Click"
|
|
|
|
*
|
|
|
|
* Display the selected admin data to the user.
|
|
|
|
*/
|
2022-01-18 13:14:45 +03:00
|
|
|
$admins.on('click', '.admin-row', (event) => {
|
2022-01-07 11:23:21 +03:00
|
|
|
if ($('#filter-admins .filter').prop('disabled')) {
|
|
|
|
$('#filter-admins .results').css('color', '#AAA');
|
|
|
|
return; // exit because we are currently on edit mode
|
|
|
|
}
|
|
|
|
|
|
|
|
const adminId = $(event.currentTarget).attr('data-id');
|
|
|
|
|
2022-01-18 13:14:45 +03:00
|
|
|
const admin = filterResults.find((filterResult) => Number(filterResult.id) === Number(adminId));
|
2022-01-07 11:23:21 +03:00
|
|
|
|
|
|
|
display(admin);
|
|
|
|
$('#filter-admins .selected').removeClass('selected');
|
|
|
|
$(event.currentTarget).addClass('selected');
|
|
|
|
$('#edit-admin, #delete-admin').prop('disabled', false);
|
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Event: Add New Admin Button "Click"
|
|
|
|
*/
|
2022-01-18 13:14:45 +03:00
|
|
|
$admins.on('click', '#add-admin', () => {
|
2022-01-07 11:23:21 +03:00
|
|
|
resetForm();
|
2022-01-17 07:39:12 +03:00
|
|
|
$admins.find('.add-edit-delete-group').hide();
|
|
|
|
$admins.find('.save-cancel-group').show();
|
2022-01-19 11:39:13 +03:00
|
|
|
$admins.find('.record-details').find('input, select, textarea').prop('disabled', false);
|
|
|
|
$admins.find('.record-details .form-label span').prop('hidden', false);
|
2022-01-18 12:33:59 +03:00
|
|
|
$('#password, #password-confirm').addClass('required');
|
2022-01-07 11:23:21 +03:00
|
|
|
$('#filter-admins button').prop('disabled', true);
|
|
|
|
$('#filter-admins .results').css('color', '#AAA');
|
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Event: Edit Admin Button "Click"
|
|
|
|
*/
|
2022-01-18 13:14:45 +03:00
|
|
|
$admins.on('click', '#edit-admin', () => {
|
2022-01-17 07:39:12 +03:00
|
|
|
$admins.find('.add-edit-delete-group').hide();
|
|
|
|
$admins.find('.save-cancel-group').show();
|
2022-01-19 11:39:13 +03:00
|
|
|
$admins.find('.record-details').find('input, select, textarea').prop('disabled', false);
|
|
|
|
$admins.find('.record-details .form-label span').prop('hidden', false);
|
2022-01-18 12:33:59 +03:00
|
|
|
$('#password, #password-confirm').removeClass('required');
|
2022-01-07 11:23:21 +03:00
|
|
|
$('#filter-admins button').prop('disabled', true);
|
|
|
|
$('#filter-admins .results').css('color', '#AAA');
|
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Event: Delete Admin Button "Click"
|
|
|
|
*/
|
2022-01-18 13:14:45 +03:00
|
|
|
$admins.on('click', '#delete-admin', () => {
|
2022-01-18 12:33:59 +03:00
|
|
|
const adminId = $id.val();
|
2022-01-07 11:23:21 +03:00
|
|
|
|
|
|
|
const buttons = [
|
|
|
|
{
|
2022-01-18 10:22:25 +03:00
|
|
|
text: lang('cancel'),
|
2022-01-18 13:14:45 +03:00
|
|
|
click: () => {
|
2022-01-07 11:23:21 +03:00
|
|
|
$('#message-box').dialog('close');
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
2022-01-18 10:22:25 +03:00
|
|
|
text: lang('delete'),
|
2022-01-18 13:14:45 +03:00
|
|
|
click: () => {
|
2022-01-07 11:23:21 +03:00
|
|
|
remove(adminId);
|
|
|
|
$('#message-box').dialog('close');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
];
|
|
|
|
|
2022-01-18 10:22:25 +03:00
|
|
|
App.Utils.Message.show(lang('delete_admin'), lang('delete_record_prompt'), buttons);
|
2022-01-07 11:23:21 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Event: Save Admin Button "Click"
|
|
|
|
*/
|
2022-01-18 13:14:45 +03:00
|
|
|
$admins.on('click', '#save-admin', () => {
|
2022-01-07 11:23:21 +03:00
|
|
|
const admin = {
|
2022-01-17 07:39:12 +03:00
|
|
|
first_name: $firstName.val(),
|
|
|
|
last_name: $lastName.val(),
|
|
|
|
email: $email.val(),
|
|
|
|
mobile_number: $mobileNumber.val(),
|
|
|
|
phone_number: $phoneNumber.val(),
|
|
|
|
address: $address.val(),
|
|
|
|
city: $city.val(),
|
|
|
|
state: $state.val(),
|
|
|
|
zip_code: $zipCode.val(),
|
|
|
|
notes: $notes.val(),
|
2022-05-20 19:13:26 +03:00
|
|
|
language: $language.val(),
|
2022-01-17 07:39:12 +03:00
|
|
|
timezone: $timezone.val(),
|
2022-01-07 11:23:21 +03:00
|
|
|
settings: {
|
2022-01-17 07:39:12 +03:00
|
|
|
username: $username.val(),
|
|
|
|
notifications: Number($notifications.prop('checked')),
|
|
|
|
calendar_view: $calendarView.val()
|
2022-01-07 11:23:21 +03:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
// Include password if changed.
|
2022-01-17 07:39:12 +03:00
|
|
|
if ($password.val() !== '') {
|
|
|
|
admin.settings.password = $password.val();
|
2022-01-07 11:23:21 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// Include id if changed.
|
2022-01-17 16:27:46 +03:00
|
|
|
if ($id.val() !== '') {
|
2022-01-18 12:33:59 +03:00
|
|
|
admin.id = $id.val();
|
2022-01-07 11:23:21 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!validate()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
save(admin);
|
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Event: Cancel Admin Button "Click"
|
|
|
|
*
|
|
|
|
* Cancel add or edit of an admin record.
|
|
|
|
*/
|
2022-01-18 13:14:45 +03:00
|
|
|
$admins.on('click', '#cancel-admin', () => {
|
2022-01-17 16:27:46 +03:00
|
|
|
const id = $id.val();
|
2022-01-17 07:39:12 +03:00
|
|
|
|
2022-01-07 11:23:21 +03:00
|
|
|
resetForm();
|
2022-01-17 07:39:12 +03:00
|
|
|
|
2022-01-07 11:23:21 +03:00
|
|
|
if (id) {
|
|
|
|
select(id, true);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Save admin record to database.
|
|
|
|
*
|
|
|
|
* @param {Object} admin Contains the admin record data. If an 'id' value is provided
|
|
|
|
* then the update operation is going to be executed.
|
|
|
|
*/
|
|
|
|
function save(admin) {
|
|
|
|
App.Http.Admins.save(admin).then((response) => {
|
2022-01-18 10:22:25 +03:00
|
|
|
App.Layouts.Backend.displayNotification(lang('admin_saved'));
|
2022-01-07 11:23:21 +03:00
|
|
|
resetForm();
|
|
|
|
$('#filter-admins .key').val('');
|
|
|
|
filter('', response.id, true);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Delete an admin record from database.
|
|
|
|
*
|
|
|
|
* @param {Number} id Record id to be deleted.
|
|
|
|
*/
|
|
|
|
function remove(id) {
|
|
|
|
App.Http.Admins.destroy(id).then(() => {
|
2022-01-18 10:22:25 +03:00
|
|
|
App.Layouts.Backend.displayNotification(lang('admin_deleted'));
|
2022-01-07 11:23:21 +03:00
|
|
|
resetForm();
|
|
|
|
filter($('#filter-admins .key').val());
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Validates an admin record.
|
|
|
|
*
|
|
|
|
* @return {Boolean} Returns the validation result.
|
|
|
|
*/
|
|
|
|
function validate() {
|
2022-01-17 07:39:12 +03:00
|
|
|
$admins.find('.is-invalid').removeClass('is-invalid');
|
2022-01-07 11:23:21 +03:00
|
|
|
|
|
|
|
try {
|
|
|
|
// Validate required fields.
|
|
|
|
let missingRequired = false;
|
|
|
|
|
2022-01-18 13:14:45 +03:00
|
|
|
$admins.find('.required').each((index, requiredField) => {
|
2022-01-07 11:23:21 +03:00
|
|
|
if (!$(requiredField).val()) {
|
|
|
|
$(requiredField).addClass('is-invalid');
|
|
|
|
missingRequired = true;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
if (missingRequired) {
|
|
|
|
throw new Error('Fields with * are required.');
|
|
|
|
}
|
|
|
|
|
|
|
|
// Validate passwords.
|
2022-01-17 07:39:12 +03:00
|
|
|
if ($password.val() !== $passwordConfirmation.val()) {
|
2022-01-18 12:33:59 +03:00
|
|
|
$('#password, #password-confirm').addClass('is-invalid');
|
2022-01-18 10:22:25 +03:00
|
|
|
throw new Error(lang('passwords_mismatch'));
|
2022-01-07 11:23:21 +03:00
|
|
|
}
|
|
|
|
|
2022-01-18 10:18:22 +03:00
|
|
|
if ($password.val().length < vars('min_password_length') && $password.val() !== '') {
|
2022-01-18 12:33:59 +03:00
|
|
|
$('#password, #password-confirm').addClass('is-invalid');
|
2022-01-18 10:22:25 +03:00
|
|
|
throw new Error(lang('password_length_notice').replace('$number', vars('min_password_length')));
|
2022-01-07 11:23:21 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// Validate user email.
|
2022-01-17 07:39:12 +03:00
|
|
|
if (!App.Utils.Validation.email($email.val())) {
|
|
|
|
$email.addClass('is-invalid');
|
2022-01-18 10:22:25 +03:00
|
|
|
throw new Error(lang('invalid_email'));
|
2022-01-07 11:23:21 +03:00
|
|
|
}
|
|
|
|
|
2022-01-24 17:48:20 +03:00
|
|
|
// Validate phone number.
|
|
|
|
const phoneNumber = $phoneNumber.val();
|
|
|
|
|
|
|
|
if (phoneNumber && !App.Utils.Validation.phone(phoneNumber)) {
|
|
|
|
$phoneNumber.addClass('is-invalid');
|
|
|
|
throw new Error(lang('invalid_phone'));
|
|
|
|
}
|
|
|
|
|
|
|
|
// Validate mobile number.
|
|
|
|
const mobileNumber = $mobileNumber.val();
|
|
|
|
|
|
|
|
if (mobileNumber && !App.Utils.Validation.phone(mobileNumber)) {
|
|
|
|
$mobileNumber.addClass('is-invalid');
|
|
|
|
throw new Error(lang('invalid_phone'));
|
|
|
|
}
|
|
|
|
|
2022-01-07 11:23:21 +03:00
|
|
|
// Check if username exists
|
2022-01-17 07:39:12 +03:00
|
|
|
if ($username.attr('already-exists') === 'true') {
|
|
|
|
$username.addClass('is-invalid');
|
2022-01-18 10:22:25 +03:00
|
|
|
throw new Error(lang('username_already_exists'));
|
2022-01-07 11:23:21 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
} catch (error) {
|
2022-01-17 07:39:12 +03:00
|
|
|
$admins.find('.form-message').addClass('alert-danger').text(error.message).show();
|
2022-01-07 11:23:21 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Resets the admin form back to its initial state.
|
|
|
|
*/
|
|
|
|
function resetForm() {
|
|
|
|
$('#filter-admins .selected').removeClass('selected');
|
|
|
|
$('#filter-admins button').prop('disabled', false);
|
|
|
|
$('#filter-admins .results').css('color', '');
|
|
|
|
|
2022-01-17 07:39:12 +03:00
|
|
|
$admins.find('.add-edit-delete-group').show();
|
|
|
|
$admins.find('.save-cancel-group').hide();
|
|
|
|
$admins.find('.record-details').find('input, select, textarea').val('').prop('disabled', true);
|
2022-01-19 11:39:13 +03:00
|
|
|
$admins.find('.record-details .form-label span').prop('hidden', true);
|
2022-01-18 12:33:59 +03:00
|
|
|
$admins.find('.record-details #calendar-view').val('default');
|
2022-05-20 19:13:26 +03:00
|
|
|
$admins.find('.record-details #language').val('english');
|
2022-01-18 12:33:59 +03:00
|
|
|
$admins.find('.record-details #timezone').val('UTC');
|
2022-01-07 11:23:21 +03:00
|
|
|
$('#edit-admin, #delete-admin').prop('disabled', true);
|
|
|
|
|
|
|
|
$('#admins .is-invalid').removeClass('is-invalid');
|
|
|
|
$('#admins .form-message').hide();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Display a admin record into the admin form.
|
|
|
|
*
|
|
|
|
* @param {Object} admin Contains the admin record data.
|
|
|
|
*/
|
|
|
|
function display(admin) {
|
2022-01-17 16:27:46 +03:00
|
|
|
$id.val(admin.id);
|
2022-01-17 07:39:12 +03:00
|
|
|
$firstName.val(admin.first_name);
|
|
|
|
$lastName.val(admin.last_name);
|
|
|
|
$email.val(admin.email);
|
|
|
|
$mobileNumber.val(admin.mobile_number);
|
|
|
|
$phoneNumber.val(admin.phone_number);
|
|
|
|
$address.val(admin.address);
|
|
|
|
$city.val(admin.city);
|
|
|
|
$state.val(admin.state);
|
|
|
|
$zipCode.val(admin.zip_code);
|
|
|
|
$notes.val(admin.notes);
|
2022-05-20 19:13:26 +03:00
|
|
|
$language.val(admin.language);
|
2022-01-17 07:39:12 +03:00
|
|
|
$timezone.val(admin.timezone);
|
|
|
|
|
|
|
|
$username.val(admin.settings.username);
|
|
|
|
$calendarView.val(admin.settings.calendar_view);
|
|
|
|
$notifications.prop('checked', Boolean(Number(admin.settings.notifications)));
|
2022-01-07 11:23:21 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Filters admin records by a keyword string.
|
|
|
|
*
|
|
|
|
* @param {String} keyword This string is used to filter the admin records of the database.
|
|
|
|
* @param {Number} [selectId] (OPTIONAL = undefined) This record id will be selected when
|
|
|
|
* the filter operation is finished.
|
|
|
|
* @param {Boolean} [show] (OPTIONAL = false) If true the selected record data are going
|
|
|
|
* to be displayed on the details column (requires a selected record though).
|
|
|
|
*/
|
|
|
|
function filter(keyword, selectId = null, show = false) {
|
|
|
|
App.Http.Admins.search(keyword, filterLimit).then((response) => {
|
|
|
|
filterResults = response;
|
|
|
|
|
2022-01-17 07:39:12 +03:00
|
|
|
$filterAdmins.find('.results').empty();
|
2022-01-07 11:23:21 +03:00
|
|
|
|
2022-01-18 13:14:45 +03:00
|
|
|
response.forEach((admin) => {
|
|
|
|
$filterAdmins.find('.results').append(getFilterHtml(admin)).append($('<hr/>'));
|
2022-01-07 11:23:21 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
if (!response.length) {
|
2022-01-17 07:39:12 +03:00
|
|
|
$filterAdmins.find('.results').append(
|
2022-01-07 11:23:21 +03:00
|
|
|
$('<em/>', {
|
2022-01-18 10:22:25 +03:00
|
|
|
'text': lang('no_records_found')
|
2022-01-07 11:23:21 +03:00
|
|
|
})
|
|
|
|
);
|
|
|
|
} else if (response.length === filterLimit) {
|
|
|
|
$('<button/>', {
|
|
|
|
'type': 'button',
|
|
|
|
'class': 'btn btn-outline-secondary w-100 load-more text-center',
|
2022-01-18 10:22:25 +03:00
|
|
|
'text': lang('load_more'),
|
2022-01-18 13:14:45 +03:00
|
|
|
'click': () => {
|
2022-01-07 11:23:21 +03:00
|
|
|
filterLimit += 20;
|
|
|
|
filter(keyword, selectId, show);
|
|
|
|
}
|
|
|
|
}).appendTo('#filter-admins .results');
|
|
|
|
}
|
|
|
|
|
|
|
|
if (selectId) {
|
|
|
|
select(selectId, show);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get an admin row html code that is going to be displayed on the filter results list.
|
|
|
|
*
|
|
|
|
* @param {Object} admin Contains the admin record data.
|
|
|
|
*
|
|
|
|
* @return {String} The html code that represents the record on the filter results list.
|
|
|
|
*/
|
|
|
|
function getFilterHtml(admin) {
|
|
|
|
const name = admin.first_name + ' ' + admin.last_name;
|
|
|
|
|
|
|
|
let info = admin.email;
|
|
|
|
|
|
|
|
info = admin.mobile_number ? info + ', ' + admin.mobile_number : info;
|
|
|
|
|
|
|
|
info = admin.phone_number ? info + ', ' + admin.phone_number : info;
|
|
|
|
|
|
|
|
return $('<div/>', {
|
|
|
|
'class': 'admin-row entry',
|
|
|
|
'data-id': admin.id,
|
|
|
|
'html': [
|
|
|
|
$('<strong/>', {
|
|
|
|
'text': name
|
|
|
|
}),
|
|
|
|
$('<br/>'),
|
2022-01-25 02:11:51 +03:00
|
|
|
$('<small/>', {
|
|
|
|
'class': 'text-muted',
|
2022-01-07 11:23:21 +03:00
|
|
|
'text': info
|
|
|
|
}),
|
|
|
|
$('<br/>')
|
|
|
|
]
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Select a specific record from the current filter results. If the admin id does not exist
|
|
|
|
* in the list then no record will be selected.
|
|
|
|
*
|
|
|
|
* @param {Number} id The record id to be selected from the filter results.
|
|
|
|
* @param {Boolean} show Optional (false), if true then the method will display the record
|
|
|
|
* on the form.
|
|
|
|
*/
|
|
|
|
function select(id, show = false) {
|
2022-01-17 07:39:12 +03:00
|
|
|
$filterAdmins.find('.selected').removeClass('selected');
|
2022-01-07 11:23:21 +03:00
|
|
|
|
2022-01-17 07:39:12 +03:00
|
|
|
$filterAdmins.find('.admin-row[data-id="' + id + '"]').addClass('selected');
|
2022-01-07 11:23:21 +03:00
|
|
|
|
|
|
|
if (show) {
|
2022-01-18 13:14:45 +03:00
|
|
|
const admin = filterResults.find((filterResult) => Number(filterResult.id) === Number(id));
|
2022-01-07 11:23:21 +03:00
|
|
|
|
|
|
|
display(admin);
|
|
|
|
|
|
|
|
$('#edit-admin, #delete-admin').prop('disabled', false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-14 11:26:44 +03:00
|
|
|
/**
|
|
|
|
* Initialize the module.
|
|
|
|
*/
|
2022-01-14 10:31:12 +03:00
|
|
|
function initialize() {
|
2022-01-07 11:23:21 +03:00
|
|
|
resetForm();
|
|
|
|
filter('');
|
2022-01-17 07:39:12 +03:00
|
|
|
addEventListeners();
|
2022-01-07 11:23:21 +03:00
|
|
|
}
|
|
|
|
|
2022-01-14 10:31:12 +03:00
|
|
|
document.addEventListener('DOMContentLoaded', initialize);
|
2022-01-07 11:23:21 +03:00
|
|
|
|
2022-01-10 11:07:40 +03:00
|
|
|
return {
|
|
|
|
filter,
|
|
|
|
save,
|
|
|
|
remove,
|
|
|
|
getFilterHtml,
|
|
|
|
resetForm,
|
|
|
|
select
|
|
|
|
};
|
2022-01-07 11:23:21 +03:00
|
|
|
})();
|