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>
|
2020-03-11 12:10:59 +03:00
|
|
|
* @copyright Copyright (c) 2013 - 2020, 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
|
|
|
|
* ---------------------------------------------------------------------------- */
|
|
|
|
|
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
|
|
|
* This class contains the Admins helper class declaration, along with the "Admins" tab
|
2016-10-10 19:29:48 +03:00
|
|
|
* 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.
|
2015-10-09 00:12:59 +03:00
|
|
|
*
|
2016-04-26 22:33:30 +03:00
|
|
|
* @class AdminsHelper
|
2013-09-24 19:05:40 +03:00
|
|
|
*/
|
2018-01-23 12:08:37 +03:00
|
|
|
var AdminsHelper = 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
|
|
|
};
|
2015-10-09 00:12:59 +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 "Admins" tab.
|
2013-09-25 18:43:17 +03:00
|
|
|
*/
|
2018-01-23 12:08:37 +03:00
|
|
|
AdminsHelper.prototype.bindEventHandlers = function () {
|
2016-04-26 22:33:30 +03:00
|
|
|
/**
|
2016-10-10 19:29:48 +03:00
|
|
|
* Event: Filter Admins Form "Submit"
|
2016-04-26 22:33:30 +03:00
|
|
|
*
|
|
|
|
* Filter the admin records with the given key string.
|
|
|
|
*/
|
2018-01-23 12:08:37 +03:00
|
|
|
$('#admins').on('submit', '#filter-admins form', function () {
|
2016-04-26 22:33:30 +03:00
|
|
|
var key = $('#filter-admins .key').val();
|
2016-07-15 22:15:27 +03:00
|
|
|
$('#filter-admins .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"
|
|
|
|
*/
|
2018-01-23 12:08:37 +03:00
|
|
|
$('#admins').on('click', '#filter-admins .clear', function () {
|
2016-04-26 22:33:30 +03:00
|
|
|
this.filter('');
|
|
|
|
$('#filter-admins .key').val('');
|
|
|
|
this.resetForm();
|
|
|
|
}.bind(this));
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Event: Filter Admin Row "Click"
|
|
|
|
*
|
|
|
|
* Display the selected admin data to the user.
|
|
|
|
*/
|
2018-01-23 12:08:37 +03:00
|
|
|
$('#admins').on('click', '.admin-row', function (e) {
|
2016-04-26 22:33:30 +03:00
|
|
|
if ($('#filter-admins .filter').prop('disabled')) {
|
|
|
|
$('#filter-admins .results').css('color', '#AAA');
|
|
|
|
return; // exit because we are currently on edit mode
|
|
|
|
}
|
2013-09-24 19:05:40 +03:00
|
|
|
|
2016-07-15 21:52:21 +03:00
|
|
|
var adminId = $(e.currentTarget).attr('data-id');
|
|
|
|
var admin = {};
|
2016-05-14 13:49:35 +03:00
|
|
|
|
2018-01-23 12:08:37 +03:00
|
|
|
$.each(this.filterResults, function (index, item) {
|
2016-04-26 22:33:30 +03:00
|
|
|
if (item.id === adminId) {
|
|
|
|
admin = item;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
this.display(admin);
|
2016-07-15 22:15:27 +03:00
|
|
|
$('#filter-admins .selected').removeClass('selected');
|
|
|
|
$(e.currentTarget).addClass('selected');
|
2016-04-26 22:33:30 +03:00
|
|
|
$('#edit-admin, #delete-admin').prop('disabled', false);
|
|
|
|
}.bind(this));
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Event: Add New Admin Button "Click"
|
|
|
|
*/
|
2018-01-23 12:08:37 +03:00
|
|
|
$('#admins').on('click', '#add-admin', function () {
|
2016-04-26 22:33:30 +03:00
|
|
|
this.resetForm();
|
|
|
|
$('#admins .add-edit-delete-group').hide();
|
|
|
|
$('#admins .save-cancel-group').show();
|
2016-07-15 22:15:27 +03:00
|
|
|
$('#admins .record-details').find('input, textarea').prop('readonly', false);
|
2016-07-19 00:46:15 +03:00
|
|
|
$('#admins .record-details').find('select').prop('disabled', false);
|
2016-04-26 22:33:30 +03:00
|
|
|
$('#admin-password, #admin-password-confirm').addClass('required');
|
|
|
|
$('#admin-notifications').prop('disabled', false);
|
|
|
|
$('#filter-admins button').prop('disabled', true);
|
2013-09-25 18:43:17 +03:00
|
|
|
$('#filter-admins .results').css('color', '#AAA');
|
2016-04-26 22:33:30 +03:00
|
|
|
}.bind(this));
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Event: Edit Admin Button "Click"
|
|
|
|
*/
|
2018-01-23 12:08:37 +03:00
|
|
|
$('#admins').on('click', '#edit-admin', function () {
|
2016-04-26 22:33:30 +03:00
|
|
|
$('#admins .add-edit-delete-group').hide();
|
|
|
|
$('#admins .save-cancel-group').show();
|
2016-07-15 22:15:27 +03:00
|
|
|
$('#admins .record-details').find('input, textarea').prop('readonly', false);
|
2016-07-19 00:46:15 +03:00
|
|
|
$('#admins .record-details').find('select').prop('disabled', false);
|
2016-04-26 22:33:30 +03:00
|
|
|
$('#admin-password, #admin-password-confirm').removeClass('required');
|
|
|
|
$('#admin-notifications').prop('disabled', false);
|
2018-06-03 17:25:37 +03:00
|
|
|
$('#filter-admins button').prop('disabled', true);
|
2016-04-26 22:33:30 +03:00
|
|
|
$('#filter-admins .results').css('color', '#AAA');
|
|
|
|
});
|
2013-09-24 19:05:40 +03:00
|
|
|
|
2016-04-26 22:33:30 +03:00
|
|
|
/**
|
|
|
|
* Event: Delete Admin Button "Click"
|
|
|
|
*/
|
2018-01-23 12:08:37 +03:00
|
|
|
$('#admins').on('click', '#delete-admin', function () {
|
2016-07-15 21:52:21 +03:00
|
|
|
var adminId = $('#admin-id').val();
|
2016-04-26 22:33:30 +03:00
|
|
|
|
2017-06-16 09:51:05 +03:00
|
|
|
var buttons = [
|
|
|
|
{
|
2017-09-11 17:09:15 +03:00
|
|
|
text: EALang.delete,
|
2018-01-23 12:08:37 +03:00
|
|
|
click: function () {
|
2017-06-16 09:51:05 +03:00
|
|
|
this.delete(adminId);
|
|
|
|
$('#message_box').dialog('close');
|
|
|
|
}.bind(this)
|
|
|
|
},
|
|
|
|
{
|
2017-09-11 17:09:15 +03:00
|
|
|
text: EALang.cancel,
|
2018-01-23 12:08:37 +03:00
|
|
|
click: function () {
|
2017-06-16 09:51:05 +03:00
|
|
|
$('#message_box').dialog('close');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
];
|
2016-04-26 22:33:30 +03:00
|
|
|
|
2017-09-11 17:09:15 +03:00
|
|
|
GeneralFunctions.displayMessageBox(EALang.delete_admin,
|
2018-01-23 12:08:37 +03:00
|
|
|
EALang.delete_record_prompt, buttons);
|
2016-04-26 22:33:30 +03:00
|
|
|
}.bind(this));
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Event: Save Admin Button "Click"
|
|
|
|
*/
|
2018-01-23 12:08:37 +03:00
|
|
|
$('#admins').on('click', '#save-admin', function () {
|
2016-04-26 22:33:30 +03:00
|
|
|
var admin = {
|
|
|
|
first_name: $('#admin-first-name').val(),
|
|
|
|
last_name: $('#admin-last-name').val(),
|
|
|
|
email: $('#admin-email').val(),
|
|
|
|
mobile_number: $('#admin-mobile-number').val(),
|
|
|
|
phone_number: $('#admin-phone-number').val(),
|
|
|
|
address: $('#admin-address').val(),
|
|
|
|
city: $('#admin-city').val(),
|
|
|
|
state: $('#admin-state').val(),
|
|
|
|
zip_code: $('#admin-zip-code').val(),
|
|
|
|
notes: $('#admin-notes').val(),
|
2020-03-29 15:10:49 +03:00
|
|
|
timezone: $('#admin-timezone').val(),
|
2016-04-26 22:33:30 +03:00
|
|
|
settings: {
|
|
|
|
username: $('#admin-username').val(),
|
2016-07-19 00:46:15 +03:00
|
|
|
notifications: $('#admin-notifications').hasClass('active'),
|
|
|
|
calendar_view: $('#admin-calendar-view').val()
|
2016-04-26 22:33:30 +03:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
// Include password if changed.
|
|
|
|
if ($('#admin-password').val() !== '') {
|
|
|
|
admin.settings.password = $('#admin-password').val();
|
2013-09-24 19:05:40 +03:00
|
|
|
}
|
2015-10-09 00:12:59 +03:00
|
|
|
|
2016-04-26 22:33:30 +03:00
|
|
|
// Include id if changed.
|
|
|
|
if ($('#admin-id').val() !== '') {
|
|
|
|
admin.id = $('#admin-id').val();
|
|
|
|
}
|
2013-09-24 19:05:40 +03:00
|
|
|
|
2017-11-14 15:52:59 +03:00
|
|
|
if (!this.validate()) {
|
2016-04-26 22:33:30 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.save(admin);
|
|
|
|
}.bind(this));
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Event: Cancel Admin Button "Click"
|
|
|
|
*
|
|
|
|
* Cancel add or edit of an admin record.
|
|
|
|
*/
|
2018-01-23 12:08:37 +03:00
|
|
|
$('#admins').on('click', '#cancel-admin', function () {
|
2016-04-26 22:33:30 +03:00
|
|
|
var id = $('#admin-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 admin record to database.
|
|
|
|
*
|
2016-05-14 13:49:35 +03:00
|
|
|
* @param {Object} admin 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
|
|
|
*/
|
2018-01-23 12:08:37 +03:00
|
|
|
AdminsHelper.prototype.save = function (admin) {
|
2020-04-27 21:14:20 +03:00
|
|
|
var url = GlobalVariables.baseUrl + '/index.php/backend_api/ajax_save_admin';
|
|
|
|
var data = {
|
2016-07-15 21:52:21 +03:00
|
|
|
csrfToken: GlobalVariables.csrfToken,
|
|
|
|
admin: JSON.stringify(admin)
|
|
|
|
};
|
2016-04-26 22:33:30 +03:00
|
|
|
|
2020-04-27 21:14:20 +03:00
|
|
|
$.post(url, data)
|
|
|
|
.done(function (response) {
|
|
|
|
Backend.displayNotification(EALang.admin_saved);
|
|
|
|
this.resetForm();
|
|
|
|
$('#filter-admins .key').val('');
|
|
|
|
this.filter('', response.id, true);
|
|
|
|
}.bind(this))
|
|
|
|
.fail(GeneralFunctions.ajaxFailureHandler);
|
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 an admin record from database.
|
|
|
|
*
|
2016-05-14 13:49:35 +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
|
|
|
AdminsHelper.prototype.delete = function (id) {
|
2020-04-27 21:14:20 +03:00
|
|
|
var url = GlobalVariables.baseUrl + '/index.php/backend_api/ajax_delete_admin';
|
|
|
|
var data = {
|
2016-07-15 21:52:21 +03:00
|
|
|
csrfToken: GlobalVariables.csrfToken,
|
|
|
|
admin_id: id
|
|
|
|
};
|
2016-04-26 22:33:30 +03:00
|
|
|
|
2020-04-27 21:14:20 +03:00
|
|
|
$.post(url, data)
|
|
|
|
.done(function (response) {
|
|
|
|
Backend.displayNotification(EALang.admin_deleted);
|
|
|
|
this.resetForm();
|
|
|
|
this.filter($('#filter-admins .key').val());
|
|
|
|
}.bind(this))
|
|
|
|
.fail(GeneralFunctions.ajaxFailureHandler);
|
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 an admin record.
|
|
|
|
*
|
2016-05-14 13:49:35 +03:00
|
|
|
* @return {Boolean} Returns the validation result.
|
2013-09-24 19:05:40 +03:00
|
|
|
*/
|
2018-01-23 12:08:37 +03:00
|
|
|
AdminsHelper.prototype.validate = function () {
|
2017-11-14 15:52:59 +03:00
|
|
|
$('#admins .has-error').removeClass('has-error');
|
2016-04-26 22:33:30 +03:00
|
|
|
|
|
|
|
try {
|
|
|
|
// Validate required fields.
|
|
|
|
var missingRequired = false;
|
2016-05-14 13:49:35 +03:00
|
|
|
|
2018-01-23 12:08:37 +03:00
|
|
|
$('#admins .required').each(function () {
|
2016-04-26 22:33:30 +03:00
|
|
|
if ($(this).val() == '' || $(this).val() == undefined) {
|
2017-11-14 15:52:59 +03:00
|
|
|
$(this).closest('.form-group').addClass('has-error');
|
2016-04-26 22:33:30 +03:00
|
|
|
missingRequired = true;
|
|
|
|
}
|
|
|
|
});
|
2016-05-14 13:49:35 +03:00
|
|
|
|
2016-04-26 22:33:30 +03:00
|
|
|
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 ($('#admin-password').val() != $('#admin-password-confirm').val()) {
|
2017-11-14 15:52:59 +03:00
|
|
|
$('#admin-password, #admin-password-confirm').closest('.form-group').addClass('has-error');
|
2017-09-11 17:09:15 +03:00
|
|
|
throw EALang.passwords_mismatch;
|
2016-04-26 22:33:30 +03:00
|
|
|
}
|
2013-09-24 19:05:40 +03:00
|
|
|
|
2016-04-26 22:33:30 +03:00
|
|
|
if ($('#admin-password').val().length < BackendUsers.MIN_PASSWORD_LENGTH
|
2018-01-23 12:08:37 +03:00
|
|
|
&& $('#admin-password').val() != '') {
|
2017-11-14 15:52:59 +03:00
|
|
|
$('#admin-password, #admin-password-confirm').closest('.form-group').addClass('has-error');
|
2017-09-11 17:09:15 +03:00
|
|
|
throw EALang.password_length_notice.replace('$number', BackendUsers.MIN_PASSWORD_LENGTH);
|
2016-04-26 22:33:30 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// Validate user email.
|
|
|
|
if (!GeneralFunctions.validateEmail($('#admin-email').val())) {
|
2017-11-14 15:52:59 +03:00
|
|
|
$('#admin-email').closest('.form-group').addClass('has-error');
|
2017-09-11 17:09:15 +03:00
|
|
|
throw EALang.invalid_email;
|
2016-04-26 22:33:30 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// Check if username exists
|
2018-01-23 12:08:37 +03:00
|
|
|
if ($('#admin-username').attr('already-exists') == 'true') {
|
2017-11-14 15:52:59 +03:00
|
|
|
$('#admin-username').closest('.form-group').addClass('has-error');
|
2017-09-11 17:09:15 +03:00
|
|
|
throw EALang.username_already_exists;
|
2016-04-26 22:33:30 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
2018-01-23 12:08:37 +03:00
|
|
|
} catch (message) {
|
2017-11-14 15:52:59 +03:00
|
|
|
$('#admins .form-message')
|
|
|
|
.addClass('alert-danger')
|
|
|
|
.text(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
|
|
|
/**
|
|
|
|
* Resets the admin form back to its initial state.
|
|
|
|
*/
|
2018-01-23 12:08:37 +03:00
|
|
|
AdminsHelper.prototype.resetForm = function () {
|
2016-04-26 22:33:30 +03:00
|
|
|
$('#admins .add-edit-delete-group').show();
|
|
|
|
$('#admins .save-cancel-group').hide();
|
2016-07-15 22:15:27 +03:00
|
|
|
$('#admins .record-details').find('input, textarea').prop('readonly', true);
|
2016-07-19 00:46:15 +03:00
|
|
|
$('#admins .record-details').find('select').prop('disabled', true);
|
2016-04-26 22:33:30 +03:00
|
|
|
$('#admins .form-message').hide();
|
|
|
|
$('#admin-notifications').prop('disabled', true);
|
2016-07-15 22:15:27 +03:00
|
|
|
$('#admins .record-details').find('input, textarea').val('');
|
2016-04-26 22:33:30 +03:00
|
|
|
$('#admin-notifications').removeClass('active');
|
|
|
|
$('#edit-admin, #delete-admin').prop('disabled', true);
|
2013-09-24 19:05:40 +03:00
|
|
|
|
2016-07-15 22:15:27 +03:00
|
|
|
$('#filter-admins .selected').removeClass('selected');
|
2016-04-26 22:33:30 +03:00
|
|
|
$('#filter-admins button').prop('disabled', false);
|
|
|
|
$('#filter-admins .results').css('color', '');
|
|
|
|
};
|
2013-09-24 19:05:40 +03:00
|
|
|
|
|
|
|
/**
|
2016-04-26 22:33:30 +03:00
|
|
|
* Display a admin record into the admin form.
|
2015-10-09 00:12:59 +03:00
|
|
|
*
|
2016-05-14 13:49:35 +03:00
|
|
|
* @param {Object} admin Contains the admin record data.
|
2013-09-24 19:05:40 +03:00
|
|
|
*/
|
2018-01-23 12:08:37 +03:00
|
|
|
AdminsHelper.prototype.display = function (admin) {
|
2016-04-26 22:33:30 +03:00
|
|
|
$('#admin-id').val(admin.id);
|
|
|
|
$('#admin-first-name').val(admin.first_name);
|
|
|
|
$('#admin-last-name').val(admin.last_name);
|
|
|
|
$('#admin-email').val(admin.email);
|
|
|
|
$('#admin-mobile-number').val(admin.mobile_number);
|
|
|
|
$('#admin-phone-number').val(admin.phone_number);
|
|
|
|
$('#admin-address').val(admin.address);
|
|
|
|
$('#admin-city').val(admin.city);
|
|
|
|
$('#admin-state').val(admin.state);
|
|
|
|
$('#admin-zip-code').val(admin.zip_code);
|
|
|
|
$('#admin-notes').val(admin.notes);
|
2020-03-29 15:10:49 +03:00
|
|
|
$('#admin-timezone').val(admin.timezone);
|
2016-04-26 22:33:30 +03:00
|
|
|
|
|
|
|
$('#admin-username').val(admin.settings.username);
|
2016-07-19 00:46:15 +03:00
|
|
|
$('#admin-calendar-view').val(admin.settings.calendar_view);
|
2016-04-26 22:33:30 +03:00
|
|
|
if (admin.settings.notifications == true) {
|
|
|
|
$('#admin-notifications').addClass('active');
|
|
|
|
} else {
|
|
|
|
$('#admin-notifications').removeClass('active');
|
2013-09-25 18:43:17 +03:00
|
|
|
}
|
2015-05-28 00:42:40 +03:00
|
|
|
};
|
2015-10-09 00:12:59 +03:00
|
|
|
|
2016-04-26 22:33:30 +03:00
|
|
|
/**
|
|
|
|
* Filters admin records depending a key string.
|
|
|
|
*
|
2016-05-14 13:49:35 +03:00
|
|
|
* @param {String} key This string is used to filter the admin records of the database.
|
|
|
|
* @param {Number} selectId (OPTIONAL = undefined) This record id will be selected when
|
2016-04-26 22:33:30 +03:00
|
|
|
* the filter operation is finished.
|
2016-05-14 13:49:35 +03:00
|
|
|
* @param {Boolean} display (OPTIONAL = false) If true the selected record data are going
|
2016-04-26 22:33:30 +03:00
|
|
|
* to be displayed on the details column (requires a selected record though).
|
|
|
|
*/
|
2018-01-23 12:08:37 +03:00
|
|
|
AdminsHelper.prototype.filter = function (key, selectId, display) {
|
2016-04-26 22:33:30 +03:00
|
|
|
display = display || false;
|
|
|
|
|
2016-07-15 21:52:21 +03:00
|
|
|
var postUrl = GlobalVariables.baseUrl + '/index.php/backend_api/ajax_filter_admins';
|
|
|
|
var postData = {
|
|
|
|
csrfToken: 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
|
|
|
|
2018-01-23 12:08:37 +03:00
|
|
|
$.post(postUrl, postData, function (response) {
|
2016-04-26 22:33:30 +03:00
|
|
|
this.filterResults = response;
|
2013-09-24 19:05:40 +03:00
|
|
|
|
2016-04-26 22:33:30 +03:00
|
|
|
$('#filter-admins .results').html('');
|
2018-01-23 12:08:37 +03:00
|
|
|
$.each(response, function (index, admin) {
|
2016-04-26 22:33:30 +03:00
|
|
|
var html = this.getFilterHtml(admin);
|
|
|
|
$('#filter-admins .results').append(html);
|
|
|
|
}.bind(this));
|
|
|
|
|
|
|
|
if (response.length == 0) {
|
2017-09-11 17:09:15 +03:00
|
|
|
$('#filter-admins .results').html('<em>' + EALang.no_records_found + '</em>')
|
2020-04-06 21:34:32 +03:00
|
|
|
} else if (response.length === this.filterLimit) {
|
|
|
|
$('<button/>', {
|
|
|
|
'type': 'button',
|
|
|
|
'class': 'well btn-block load-more text-center',
|
|
|
|
'text': EALang.load_more,
|
|
|
|
'click': function () {
|
|
|
|
this.filterLimit += 20;
|
|
|
|
this.filter(key, selectId, display);
|
|
|
|
}.bind(this)
|
|
|
|
})
|
|
|
|
.appendTo('#filter-admins .results');
|
2013-09-24 19:05:40 +03:00
|
|
|
}
|
2015-10-09 00:12:59 +03:00
|
|
|
|
2016-04-26 22:33:30 +03:00
|
|
|
if (selectId != undefined) {
|
|
|
|
this.select(selectId, display);
|
|
|
|
}
|
|
|
|
}.bind(this), 'json').fail(GeneralFunctions.ajaxFailureHandler);
|
|
|
|
};
|
2015-10-09 00:12:59 +03:00
|
|
|
|
2016-04-26 22:33:30 +03:00
|
|
|
/**
|
|
|
|
* Get an admin row html code that is going to be displayed on the filter results list.
|
|
|
|
*
|
2016-05-14 13:49:35 +03:00
|
|
|
* @param {Object} admin Contains the admin 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
|
|
|
AdminsHelper.prototype.getFilterHtml = function (admin) {
|
2016-07-15 21:52:21 +03:00
|
|
|
var name = admin.first_name + ' ' + admin.last_name;
|
|
|
|
var info = admin.email;
|
2015-10-09 00:12:59 +03:00
|
|
|
|
2016-04-26 22:33:30 +03:00
|
|
|
info = (admin.mobile_number != '' && admin.mobile_number != null)
|
2018-01-23 12:08:37 +03:00
|
|
|
? info + ', ' + admin.mobile_number : info;
|
2015-10-09 00:12:59 +03:00
|
|
|
|
2016-04-26 22:33:30 +03:00
|
|
|
info = (admin.phone_number != '' && admin.phone_number != null)
|
2018-01-23 12:08:37 +03:00
|
|
|
? info + ', ' + admin.phone_number : info;
|
2015-10-09 00:12:59 +03:00
|
|
|
|
2016-04-26 22:33:30 +03:00
|
|
|
var html =
|
2018-01-23 12:08:37 +03:00
|
|
|
'<div class="admin-row entry" data-id="' + admin.id + '">' +
|
|
|
|
'<strong>' + name + '</strong><br>' +
|
|
|
|
info + '<br>' +
|
|
|
|
'</div><hr>';
|
2013-09-24 19:05:40 +03:00
|
|
|
|
2016-04-26 22:33:30 +03:00
|
|
|
return html;
|
2015-05-28 00:42:40 +03:00
|
|
|
};
|
2015-10-09 00:12:59 +03:00
|
|
|
|
2016-04-26 22:33:30 +03:00
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*
|
2016-05-14 13:49:35 +03:00
|
|
|
* @param {Number} id The record id to be selected from the filter results.
|
|
|
|
* @param {Boolean} display Optional (false), if true then the method will display the record
|
2016-04-26 22:33:30 +03:00
|
|
|
* on the form.
|
|
|
|
*/
|
2018-01-23 12:08:37 +03:00
|
|
|
AdminsHelper.prototype.select = function (id, display) {
|
2016-04-26 22:33:30 +03:00
|
|
|
display = display || false;
|
2015-10-09 00:12:59 +03:00
|
|
|
|
2016-07-15 22:15:27 +03:00
|
|
|
$('#filter-admins .selected').removeClass('selected');
|
2015-10-09 00:12:59 +03:00
|
|
|
|
2018-01-23 12:08:37 +03:00
|
|
|
$('.admin-row').each(function () {
|
2016-04-26 22:33:30 +03:00
|
|
|
if ($(this).attr('data-id') == id) {
|
2016-07-15 22:15:27 +03:00
|
|
|
$(this).addClass('selected');
|
2016-04-26 22:33:30 +03:00
|
|
|
return 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
|
|
|
if (display) {
|
2018-01-23 12:08:37 +03:00
|
|
|
$.each(this.filterResults, function (index, admin) {
|
2016-04-26 22:33:30 +03:00
|
|
|
if (admin.id == id) {
|
|
|
|
this.display(admin);
|
|
|
|
$('#edit-admin, #delete-admin').prop('disabled', false);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}.bind(this));
|
2013-09-25 18:43:17 +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
|
|
|
window.AdminsHelper = AdminsHelper;
|
2015-10-09 00:12:59 +03:00
|
|
|
|
2016-04-26 22:33:30 +03:00
|
|
|
})();
|