Enhancements in the backend_users_admins.js comments.

This commit is contained in:
Alex Tselegidis 2016-05-14 12:49:35 +02:00
parent d3b59256fb
commit c3b7ea9383

View file

@ -33,7 +33,7 @@
* *
* Filter the admin records with the given key string. * Filter the admin records with the given key string.
*/ */
$('#admins').on('submit', '#filter-admins form', function(event) { $('#admins').on('submit', '#filter-admins form', function() {
var key = $('#filter-admins .key').val(); var key = $('#filter-admins .key').val();
$('#filter-admins .selected-row').removeClass('selected-row'); $('#filter-admins .selected-row').removeClass('selected-row');
this.resetForm(); this.resetForm();
@ -55,7 +55,7 @@
* *
* Display the selected admin data to the user. * Display the selected admin data to the user.
*/ */
$('#admins').on('click', '.admin-row', function(e) { $('#admins').on('click', '.admin-row', function() {
if ($('#filter-admins .filter').prop('disabled')) { if ($('#filter-admins .filter').prop('disabled')) {
$('#filter-admins .results').css('color', '#AAA'); $('#filter-admins .results').css('color', '#AAA');
return; // exit because we are currently on edit mode return; // exit because we are currently on edit mode
@ -63,6 +63,7 @@
var adminId = $(e.currentTarget).attr('data-id'), var adminId = $(e.currentTarget).attr('data-id'),
admin = {}; admin = {};
$.each(this.filterResults, function(index, item) { $.each(this.filterResults, function(index, item) {
if (item.id === adminId) { if (item.id === adminId) {
admin = item; admin = item;
@ -108,13 +109,14 @@
* Event: Delete Admin Button "Click" * Event: Delete Admin Button "Click"
*/ */
$('#admins').on('click', '#delete-admin', function() { $('#admins').on('click', '#delete-admin', function() {
var adminId = $('#admin-id').val(); var adminId = $('#admin-id').val(),
messageBtns = {};
var messageBtns = {};
messageBtns[EALang['delete']] = function() { messageBtns[EALang['delete']] = function() {
this.delete(adminId); this.delete(adminId);
$('#message_box').dialog('close'); $('#message_box').dialog('close');
}.bind(this); }.bind(this);
messageBtns[EALang['cancel']] = function() { messageBtns[EALang['cancel']] = function() {
$('#message_box').dialog('close'); $('#message_box').dialog('close');
}; };
@ -178,7 +180,7 @@
/** /**
* Save admin record to database. * Save admin record to database.
* *
* @param {object} admin Contains the admin record data. If an 'id' value is provided * @param {Object} admin Contains the admin record data. If an 'id' value is provided
* then the update operation is going to be executed. * then the update operation is going to be executed.
*/ */
AdminsHelper.prototype.save = function(admin) { AdminsHelper.prototype.save = function(admin) {
@ -202,7 +204,7 @@
/** /**
* Delete an admin record from database. * Delete an admin record from database.
* *
* @param {int} id Record id to be deleted. * @param {Number} id Record id to be deleted.
*/ */
AdminsHelper.prototype.delete = function(id) { AdminsHelper.prototype.delete = function(id) {
var postUrl = GlobalVariables.baseUrl + '/index.php/backend_api/ajax_delete_admin', var postUrl = GlobalVariables.baseUrl + '/index.php/backend_api/ajax_delete_admin',
@ -224,8 +226,9 @@
/** /**
* Validates an admin record. * Validates an admin record.
* *
* @param {object} admin Contains the admin data to be validated. * @param {Object} admin Contains the admin data to be validated.
* @returns {bool} Returns the validation result. *
* @return {Boolean} Returns the validation result.
*/ */
AdminsHelper.prototype.validate = function(admin) { AdminsHelper.prototype.validate = function(admin) {
$('#admins .required').css('border', ''); $('#admins .required').css('border', '');
@ -234,12 +237,14 @@
try { try {
// Validate required fields. // Validate required fields.
var missingRequired = false; var missingRequired = false;
$('#admins .required').each(function() { $('#admins .required').each(function() {
if ($(this).val() == '' || $(this).val() == undefined) { if ($(this).val() == '' || $(this).val() == undefined) {
$(this).css('border', '2px solid red'); $(this).css('border', '2px solid red');
missingRequired = true; missingRequired = true;
} }
}); });
if (missingRequired) { if (missingRequired) {
throw 'Fields with * are required.'; throw 'Fields with * are required.';
} }
@ -299,7 +304,7 @@
/** /**
* Display a admin record into the admin form. * Display a admin record into the admin form.
* *
* @param {object} admin Contains the admin record data. * @param {Object} admin Contains the admin record data.
*/ */
AdminsHelper.prototype.display = function(admin) { AdminsHelper.prototype.display = function(admin) {
$('#admin-id').val(admin.id); $('#admin-id').val(admin.id);
@ -325,10 +330,10 @@
/** /**
* Filters admin records depending a key string. * Filters admin records depending a key string.
* *
* @param {string} key This string is used to filter the admin records of the database. * @param {String} key This string is used to filter the admin records of the database.
* @param {numeric} selectId (OPTIONAL = undefined) This record id will be selected when * @param {Number} selectId (OPTIONAL = undefined) This record id will be selected when
* the filter operation is finished. * the filter operation is finished.
* @param {bool} display (OPTIONAL = false) If true the selected record data are going * @param {Boolean} display (OPTIONAL = false) If true the selected record data are going
* to be displayed on the details column (requires a selected record though). * to be displayed on the details column (requires a selected record though).
*/ */
AdminsHelper.prototype.filter = function(key, selectId, display) { AdminsHelper.prototype.filter = function(key, selectId, display) {
@ -368,8 +373,9 @@
/** /**
* Get an admin row html code that is going to be displayed on the filter results list. * 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. * @param {Object} admin Contains the admin record data.
* @returns {string} The html code that represents the record on the filter results list. *
* @return {String} The html code that represents the record on the filter results list.
*/ */
AdminsHelper.prototype.getFilterHtml = function(admin) { AdminsHelper.prototype.getFilterHtml = function(admin) {
var name = admin.first_name + ' ' + admin.last_name, var name = admin.first_name + ' ' + admin.last_name,
@ -394,8 +400,8 @@
* Select a specific record from the current filter results. If the admin id does not exist * 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. * in the list then no record will be selected.
* *
* @param {numeric} id The record id to be selected from the filter results. * @param {Number} 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 * @param {Boolean} display Optional (false), if true then the method will display the record
* on the form. * on the form.
*/ */
AdminsHelper.prototype.select = function(id, display) { AdminsHelper.prototype.select = function(id, display) {