2021-11-18 07:58:09 +03:00
|
|
|
/* ----------------------------------------------------------------------------
|
|
|
|
* Easy!Appointments - Open Source Web Scheduler
|
|
|
|
*
|
|
|
|
* @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
|
2021-11-18 07:58:09 +03:00
|
|
|
* @since v1.0.0
|
|
|
|
* ---------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
window.BackendProviders = window.BackendProviders || {};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Backend Providers
|
|
|
|
*
|
|
|
|
* This module handles the js functionality of the providers backend page.
|
|
|
|
*
|
|
|
|
* @module BackendProviders
|
|
|
|
*/
|
|
|
|
(function (exports) {
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Minimum Password Length
|
|
|
|
*
|
|
|
|
* @type {Number}
|
|
|
|
*/
|
|
|
|
exports.MIN_PASSWORD_LENGTH = 7;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Contains the current tab record methods for the page.
|
|
|
|
*
|
|
|
|
* @type {ProvidersHelper}
|
|
|
|
*/
|
|
|
|
var helper = {};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Use this class instance for performing actions on the working plan.
|
|
|
|
*
|
|
|
|
* @type {WorkingPlan}
|
|
|
|
*/
|
|
|
|
exports.wp = {};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Initialize the backend providers page.
|
|
|
|
*
|
|
|
|
* @param {Boolean} defaultEventHandlers (OPTIONAL) Whether to bind the default event handlers.
|
|
|
|
*/
|
|
|
|
exports.initialize = function (defaultEventHandlers) {
|
|
|
|
defaultEventHandlers = defaultEventHandlers || true;
|
|
|
|
|
|
|
|
exports.wp = new WorkingPlan();
|
|
|
|
exports.wp.bindEventHandlers();
|
|
|
|
|
|
|
|
// Instantiate default helper object (admin).
|
|
|
|
helper = new ProvidersHelper();
|
|
|
|
helper.resetForm();
|
|
|
|
helper.filter('');
|
|
|
|
helper.bindEventHandlers();
|
|
|
|
|
|
|
|
// Fill the services and providers list boxes.
|
|
|
|
GlobalVariables.services.forEach(function (service) {
|
|
|
|
$('<div/>', {
|
|
|
|
'class': 'checkbox',
|
|
|
|
'html': [
|
|
|
|
$('<div/>', {
|
|
|
|
'class': 'checkbox form-check',
|
|
|
|
'html': [
|
|
|
|
$('<input/>', {
|
|
|
|
'class': 'form-check-input',
|
|
|
|
'type': 'checkbox',
|
|
|
|
'data-id': service.id,
|
|
|
|
'prop': {
|
|
|
|
'disabled': true
|
|
|
|
}
|
|
|
|
}),
|
|
|
|
$('<label/>', {
|
|
|
|
'class': 'form-check-label',
|
|
|
|
'text': service.name,
|
|
|
|
'for': service.id
|
|
|
|
})
|
|
|
|
]
|
|
|
|
})
|
|
|
|
]
|
|
|
|
}).appendTo('#provider-services');
|
|
|
|
});
|
|
|
|
|
|
|
|
// Bind event handlers.
|
|
|
|
if (defaultEventHandlers) {
|
|
|
|
bindEventHandlers();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Binds the default backend providers event handlers. Do not use this method on a different
|
|
|
|
* page because it needs the backend providers page DOM.
|
|
|
|
*/
|
|
|
|
function bindEventHandlers() {
|
|
|
|
/**
|
|
|
|
* Event: Provider Username "Blur"
|
|
|
|
*
|
|
|
|
* When the provider leaves the provider username input field we will need to check if the username
|
2021-12-13 09:52:09 +03:00
|
|
|
* is not taken by another record in the system.
|
2021-11-18 07:58:09 +03:00
|
|
|
*/
|
|
|
|
$('#provider-username').focusout(function () {
|
|
|
|
var $input = $(this);
|
|
|
|
|
|
|
|
if ($input.prop('readonly') === true || $input.val() === '') {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
var providerId = $input.parents().eq(2).find('.record-id').val();
|
|
|
|
|
|
|
|
if (!providerId) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
var url = GlobalVariables.baseUrl + '/index.php/backend_api/ajax_validate_username';
|
|
|
|
|
|
|
|
var data = {
|
2021-12-14 09:29:51 +03:00
|
|
|
csrf_token: GlobalVariables.csrfToken,
|
2021-11-18 07:58:09 +03:00
|
|
|
username: $input.val(),
|
|
|
|
user_id: providerId
|
|
|
|
};
|
|
|
|
|
|
|
|
$.post(url, data).done(function (response) {
|
|
|
|
if (response.is_valid === 'false') {
|
2021-11-23 12:10:09 +03:00
|
|
|
$input.addClass('is-invalid');
|
2021-11-18 07:58:09 +03:00
|
|
|
$input.attr('already-exists', 'true');
|
2021-12-13 09:52:09 +03:00
|
|
|
$input.parents().eq(3).find('.form-message').text(App.Lang.username_already_exists);
|
2021-11-18 07:58:09 +03:00
|
|
|
$input.parents().eq(3).find('.form-message').show();
|
|
|
|
} else {
|
2021-11-23 12:10:09 +03:00
|
|
|
$input.removeClass('is-invalid');
|
2021-11-18 07:58:09 +03:00
|
|
|
$input.attr('already-exists', 'false');
|
2021-12-13 09:52:09 +03:00
|
|
|
if ($input.parents().eq(3).find('.form-message').text() === App.Lang.username_already_exists) {
|
2021-11-18 07:58:09 +03:00
|
|
|
$input.parents().eq(3).find('.form-message').hide();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
})(window.BackendProviders);
|