MaketRandevu/assets/js/backend_services.js

112 lines
3.6 KiB
JavaScript
Raw Normal View History

2015-07-20 22:41:24 +03:00
/* ----------------------------------------------------------------------------
* Easy!Appointments - Open Source Web Scheduler
*
2015-07-20 22:41:24 +03:00
* @package EasyAppointments
* @author A.Tselegidis <alextselegidis@gmail.com>
* @copyright Copyright (c) 2013 - 2020, Alex Tselegidis
* @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
* ---------------------------------------------------------------------------- */
window.BackendServices = window.BackendServices || {};
/**
* Backend Services
*
* This namespace handles the js functionality of the backend services page.
*
* @module BackendServices
*/
2018-01-23 12:08:37 +03:00
(function (exports) {
'use strict';
/**
* Contains the basic record methods for the page.
*
* @type {ServicesHelper|CategoriesHelper}
*/
var helper;
2018-01-23 12:08:37 +03:00
var servicesHelper = new ServicesHelper();
var categoriesHelper = new CategoriesHelper();
/**
* Default initialize method of the page.
*
* @param {Boolean} bindEventHandlers Optional (true), determines whether to bind the default event handlers.
*/
2018-01-23 12:08:37 +03:00
exports.initialize = function (bindEventHandlers) {
bindEventHandlers = bindEventHandlers || true;
// Fill available service categories listbox.
2018-01-23 12:08:37 +03:00
$.each(GlobalVariables.categories, function (index, category) {
var option = new Option(category.name, category.id);
$('#service-category').append(option);
});
$('#service-category').append(new Option('- ' + EALang.no_category + ' -', null)).val('null');
// Instantiate helper object (service helper by default).
helper = servicesHelper;
helper.resetForm();
helper.filter('');
if (bindEventHandlers) {
_bindEventHandlers();
}
};
/**
* Binds the default event handlers of the backend services page.
*
* Do not use this method if you include the "BackendServices" namespace on another page.
*/
function _bindEventHandlers() {
/**
* Event: Page Tab Button "Click"
*
* Changes the displayed tab.
*/
2018-01-23 12:08:37 +03:00
$('a[data-toggle="tab"]').on('shown.bs.tab', function () {
if ($(this).attr('href') === '#services') {
helper = servicesHelper;
} else if ($(this).attr('href') === '#categories') {
helper = categoriesHelper;
}
helper.resetForm();
helper.filter('');
$('.filter-key').val('');
Backend.placeFooterToBottom();
});
2018-01-23 12:08:37 +03:00
servicesHelper.bindEventHandlers();
categoriesHelper.bindEventHandlers();
}
/**
* Update the service category listbox.
*
* Use this method every time a change is made to the service categories db table.
*/
2018-01-23 12:08:37 +03:00
exports.updateAvailableCategories = function () {
var url = GlobalVariables.baseUrl + '/index.php/backend_api/ajax_filter_service_categories';
var data = {
2016-07-15 21:52:21 +03:00
csrfToken: GlobalVariables.csrfToken,
key: ''
};
2018-01-23 12:08:37 +03:00
$.post(url, data, function (response) {
GlobalVariables.categories = response;
var $select = $('#service-category');
$select.empty();
2018-01-23 12:08:37 +03:00
$.each(response, function (index, category) {
var option = new Option(category.name, category.id);
$select.append(option);
});
$select.append(new Option('- ' + EALang.no_category + ' -', null)).val('null');
}, 'json').fail(GeneralFunctions.ajaxFailureHandler);
};
})(window.BackendServices);