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
|
|
|
|
* ---------------------------------------------------------------------------- */
|
|
|
|
|
2016-04-02 16:36:55 +03:00
|
|
|
window.BackendServices = window.BackendServices || {};
|
|
|
|
|
2013-07-17 19:29:51 +03:00
|
|
|
/**
|
2016-05-15 13:09:13 +03:00
|
|
|
* Backend Services
|
|
|
|
*
|
2013-07-17 19:29:51 +03:00
|
|
|
* This namespace handles the js functionality of the backend services page.
|
2015-10-09 00:12:59 +03:00
|
|
|
*
|
2016-04-02 16:36:55 +03:00
|
|
|
* @module BackendServices
|
2013-07-17 19:29:51 +03:00
|
|
|
*/
|
2018-01-23 12:08:37 +03:00
|
|
|
(function (exports) {
|
2016-04-02 16:36:55 +03:00
|
|
|
|
|
|
|
'use strict';
|
|
|
|
|
2013-07-17 19:29:51 +03:00
|
|
|
/**
|
|
|
|
* Contains the basic record methods for the page.
|
2015-10-09 00:12:59 +03:00
|
|
|
*
|
2016-05-15 13:09:13 +03:00
|
|
|
* @type {ServicesHelper|CategoriesHelper}
|
2013-07-17 19:29:51 +03:00
|
|
|
*/
|
2016-04-02 16:36:55 +03:00
|
|
|
var helper;
|
2015-10-09 00:12:59 +03:00
|
|
|
|
2018-01-23 12:08:37 +03:00
|
|
|
var servicesHelper = new ServicesHelper();
|
2016-07-15 21:21:25 +03:00
|
|
|
var categoriesHelper = new CategoriesHelper();
|
|
|
|
|
2013-07-17 19:29:51 +03:00
|
|
|
/**
|
|
|
|
* Default initialize method of the page.
|
2015-10-09 00:12:59 +03:00
|
|
|
*
|
2020-05-06 20:23:49 +03:00
|
|
|
* @param {Boolean} [defaultEventHandlers] Optional (true), determines whether to bind the default event handlers.
|
2013-07-17 19:29:51 +03:00
|
|
|
*/
|
2020-05-06 20:23:49 +03:00
|
|
|
exports.initialize = function (defaultEventHandlers) {
|
|
|
|
defaultEventHandlers = defaultEventHandlers || true;
|
2015-10-09 00:12:59 +03:00
|
|
|
|
2013-07-17 19:29:51 +03:00
|
|
|
// Fill available service categories listbox.
|
2020-05-12 21:52:32 +03:00
|
|
|
GlobalVariables.categories.forEach(function (category) {
|
|
|
|
$('#service-category').append(new Option(category.name, category.id));
|
2013-07-17 19:29:51 +03:00
|
|
|
});
|
2020-05-12 21:52:32 +03:00
|
|
|
|
2017-09-11 17:09:15 +03:00
|
|
|
$('#service-category').append(new Option('- ' + EALang.no_category + ' -', null)).val('null');
|
2015-10-09 00:12:59 +03:00
|
|
|
|
2013-10-19 13:34:32 +03:00
|
|
|
// Instantiate helper object (service helper by default).
|
2016-07-15 22:09:38 +03:00
|
|
|
helper = servicesHelper;
|
2016-04-02 16:36:55 +03:00
|
|
|
helper.resetForm();
|
|
|
|
helper.filter('');
|
2020-12-08 14:23:37 +03:00
|
|
|
helper.bindEventHandlers();
|
2015-10-09 00:12:59 +03:00
|
|
|
|
2020-05-06 20:23:49 +03:00
|
|
|
if (defaultEventHandlers) {
|
|
|
|
bindEventHandlers();
|
2016-04-02 16:36:55 +03:00
|
|
|
}
|
|
|
|
};
|
2015-10-09 00:12:59 +03:00
|
|
|
|
2013-07-17 19:29:51 +03:00
|
|
|
/**
|
2016-05-15 13:09:13 +03:00
|
|
|
* Binds the default event handlers of the backend services page.
|
|
|
|
*
|
|
|
|
* Do not use this method if you include the "BackendServices" namespace on another page.
|
2013-07-17 19:29:51 +03:00
|
|
|
*/
|
2020-05-06 20:23:49 +03:00
|
|
|
function bindEventHandlers() {
|
2013-07-17 19:29:51 +03:00
|
|
|
/**
|
|
|
|
* Event: Page Tab Button "Click"
|
2015-10-09 00:12:59 +03:00
|
|
|
*
|
2013-07-17 19:29:51 +03:00
|
|
|
* Changes the displayed tab.
|
|
|
|
*/
|
2018-01-23 12:08:37 +03:00
|
|
|
$('a[data-toggle="tab"]').on('shown.bs.tab', function () {
|
2020-12-08 14:23:37 +03:00
|
|
|
if (helper) {
|
|
|
|
helper.unbindEventHandlers();
|
|
|
|
}
|
|
|
|
|
2017-09-22 15:53:41 +03:00
|
|
|
if ($(this).attr('href') === '#services') {
|
2016-07-15 21:21:25 +03:00
|
|
|
helper = servicesHelper;
|
2017-09-22 15:53:41 +03:00
|
|
|
} else if ($(this).attr('href') === '#categories') {
|
2016-07-15 21:21:25 +03:00
|
|
|
helper = categoriesHelper;
|
2013-07-17 19:29:51 +03:00
|
|
|
}
|
2015-10-09 00:12:59 +03:00
|
|
|
|
2016-04-02 16:36:55 +03:00
|
|
|
helper.resetForm();
|
|
|
|
helper.filter('');
|
2020-12-08 14:23:37 +03:00
|
|
|
helper.bindEventHandlers();
|
2013-07-19 18:29:59 +03:00
|
|
|
$('.filter-key').val('');
|
2013-11-07 13:25:59 +02:00
|
|
|
Backend.placeFooterToBottom();
|
2013-07-17 19:29:51 +03:00
|
|
|
});
|
2016-04-02 16:36:55 +03:00
|
|
|
}
|
2015-10-09 00:12:59 +03:00
|
|
|
|
2013-09-13 16:21:03 +03:00
|
|
|
/**
|
2020-12-08 14:23:37 +03:00
|
|
|
* Update the service category list box.
|
2016-05-15 13:09:13 +03:00
|
|
|
*
|
|
|
|
* Use this method every time a change is made to the service categories db table.
|
2013-09-13 16:21:03 +03:00
|
|
|
*/
|
2018-01-23 12:08:37 +03:00
|
|
|
exports.updateAvailableCategories = function () {
|
2017-09-22 15:53:41 +03:00
|
|
|
var url = GlobalVariables.baseUrl + '/index.php/backend_api/ajax_filter_service_categories';
|
2020-05-06 20:15:11 +03:00
|
|
|
|
2017-09-22 15:53:41 +03:00
|
|
|
var data = {
|
2016-07-15 21:52:21 +03:00
|
|
|
csrfToken: GlobalVariables.csrfToken,
|
|
|
|
key: ''
|
|
|
|
};
|
2015-10-09 00:12:59 +03:00
|
|
|
|
2020-05-06 20:15:11 +03:00
|
|
|
$.post(url, data)
|
|
|
|
.done(function (response) {
|
|
|
|
GlobalVariables.categories = response;
|
|
|
|
var $select = $('#service-category');
|
2020-05-12 21:52:32 +03:00
|
|
|
|
2020-05-06 20:15:11 +03:00
|
|
|
$select.empty();
|
2020-05-12 21:52:32 +03:00
|
|
|
|
|
|
|
response.forEach(function (category) {
|
|
|
|
$select.append(new Option(category.name, category.id));
|
2020-05-06 20:15:11 +03:00
|
|
|
});
|
2020-05-12 21:52:32 +03:00
|
|
|
|
2020-05-06 20:15:11 +03:00
|
|
|
$select.append(new Option('- ' + EALang.no_category + ' -', null)).val('null');
|
2020-12-02 20:57:49 +03:00
|
|
|
});
|
2017-09-22 15:53:41 +03:00
|
|
|
};
|
2016-04-02 16:36:55 +03:00
|
|
|
})(window.BackendServices);
|