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>
|
2016-01-02 15:47:04 +02:00
|
|
|
* @copyright Copyright (c) 2013 - 2016, 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
|
|
|
*/
|
2016-04-02 16:36:55 +03:00
|
|
|
(function(exports) {
|
|
|
|
|
|
|
|
'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
|
|
|
|
2016-07-15 21:21:25 +03:00
|
|
|
var servicesHelper = new ServicesHelper();
|
|
|
|
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
|
|
|
*
|
2016-05-15 13:09:13 +03:00
|
|
|
* @param {Boolean} bindEventHandlers Optional (true), determines whether to bind the default event handlers.
|
2013-07-17 19:29:51 +03:00
|
|
|
*/
|
2016-04-02 16:36:55 +03:00
|
|
|
exports.initialize = function(bindEventHandlers) {
|
|
|
|
bindEventHandlers = bindEventHandlers || true;
|
2015-10-09 00:12:59 +03:00
|
|
|
|
2013-07-17 19:29:51 +03:00
|
|
|
// Fill available service categories listbox.
|
|
|
|
$.each(GlobalVariables.categories, function(index, category) {
|
2013-07-18 00:10:42 +03:00
|
|
|
var option = new Option(category.name, category.id);
|
2013-07-17 19:29:51 +03:00
|
|
|
$('#service-category').append(option);
|
|
|
|
});
|
2013-12-20 19:44:44 +02:00
|
|
|
$('#service-category').append(new Option('- ' + EALang['no_category'] + ' -', null)).val('null');
|
2015-10-09 00:12:59 +03:00
|
|
|
|
2013-07-17 19:29:51 +03:00
|
|
|
$('#service-duration').spinner({
|
2016-04-02 16:36:55 +03:00
|
|
|
min: 0,
|
|
|
|
disabled: true // default
|
2013-07-17 19:29:51 +03:00
|
|
|
});
|
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('');
|
2015-10-09 00:12:59 +03:00
|
|
|
|
2013-10-10 19:50:33 +03:00
|
|
|
$('#filter-services .results').jScrollPane();
|
|
|
|
$('#filter-categories .results').jScrollPane();
|
2015-10-09 00:12:59 +03:00
|
|
|
|
2016-04-02 16:36:55 +03:00
|
|
|
if (bindEventHandlers) {
|
|
|
|
_bindEventHandlers();
|
|
|
|
}
|
|
|
|
};
|
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
|
|
|
*/
|
2016-04-02 16:36:55 +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.
|
|
|
|
*/
|
|
|
|
$('.tab').click(function() {
|
2013-10-11 18:58:46 +03:00
|
|
|
$(this).parent().find('.active').removeClass('active');
|
2013-07-17 19:29:51 +03:00
|
|
|
$(this).addClass('active');
|
|
|
|
$('.tab-content').hide();
|
2015-10-09 00:12:59 +03:00
|
|
|
|
2013-07-17 19:29:51 +03:00
|
|
|
if ($(this).hasClass('services-tab')) { // display services tab
|
|
|
|
$('#services').show();
|
2016-07-15 21:21:25 +03:00
|
|
|
helper = servicesHelper;
|
2013-07-17 19:29:51 +03:00
|
|
|
} else if ($(this).hasClass('categories-tab')) { // display categories tab
|
|
|
|
$('#categories').show();
|
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('');
|
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
|
|
|
});
|
2015-10-09 00:12:59 +03:00
|
|
|
|
2016-07-15 21:21:25 +03:00
|
|
|
servicesHelper.bindEventHandlers();
|
|
|
|
categoriesHelper.bindEventHandlers();
|
2016-04-02 16:36:55 +03:00
|
|
|
}
|
2015-10-09 00:12:59 +03:00
|
|
|
|
2013-09-13 16:21:03 +03:00
|
|
|
/**
|
2016-05-15 13:09:13 +03:00
|
|
|
* Update the service category listbox.
|
|
|
|
*
|
|
|
|
* Use this method every time a change is made to the service categories db table.
|
2013-09-13 16:21:03 +03:00
|
|
|
*/
|
2016-04-02 16:36:55 +03:00
|
|
|
exports.updateAvailableCategories = function() {
|
2016-07-15 21:52:21 +03:00
|
|
|
var postUrl = GlobalVariables.baseUrl + '/index.php/backend_api/ajax_filter_service_categories';
|
|
|
|
var postData = {
|
|
|
|
csrfToken: GlobalVariables.csrfToken,
|
|
|
|
key: ''
|
|
|
|
};
|
2015-10-09 00:12:59 +03:00
|
|
|
|
2013-09-13 16:21:03 +03:00
|
|
|
$.post(postUrl, postData, function(response) {
|
2016-04-02 16:36:55 +03:00
|
|
|
if (!GeneralFunctions.handleAjaxExceptions(response)) {
|
|
|
|
return;
|
|
|
|
}
|
2015-10-09 00:12:59 +03:00
|
|
|
|
2013-09-13 16:21:03 +03:00
|
|
|
GlobalVariables.categories = response;
|
|
|
|
var $select = $('#service-category');
|
|
|
|
$select.empty();
|
|
|
|
$.each(response, function(index, category) {
|
|
|
|
var option = new Option(category.name, category.id);
|
|
|
|
$select.append(option);
|
|
|
|
});
|
2013-12-20 19:44:44 +02:00
|
|
|
$select.append(new Option('- ' + EALang['no_category'] + ' -', null)).val('null');
|
2015-10-09 00:12:59 +03:00
|
|
|
}, 'json').fail(GeneralFunctions.ajaxFailureHandler);
|
2013-07-17 19:29:51 +03:00
|
|
|
}
|
2015-10-09 00:12:59 +03:00
|
|
|
|
2016-04-02 16:36:55 +03:00
|
|
|
})(window.BackendServices);
|