2016-04-02 16:36:55 +03:00
|
|
|
/* ----------------------------------------------------------------------------
|
2022-01-18 15:05:42 +03:00
|
|
|
* Easy!Appointments - Online Appointment Scheduler
|
2016-04-02 16:36:55 +03:00
|
|
|
*
|
|
|
|
* @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
|
2022-01-18 15:01:22 +03:00
|
|
|
* @since v1.5.0
|
2016-04-02 16:36:55 +03:00
|
|
|
* ---------------------------------------------------------------------------- */
|
|
|
|
|
2022-01-14 11:26:44 +03:00
|
|
|
/**
|
|
|
|
* Services page.
|
|
|
|
*
|
|
|
|
* This module implements the functionality of the services page.
|
|
|
|
*/
|
2022-01-10 11:09:49 +03:00
|
|
|
App.Pages.Services = (function () {
|
|
|
|
const $services = $('#services');
|
2022-01-18 11:29:56 +03:00
|
|
|
const $id = $('#id');
|
|
|
|
const $name = $('#name');
|
|
|
|
const $duration = $('#duration');
|
|
|
|
const $price = $('#price');
|
|
|
|
const $currency = $('#currency');
|
|
|
|
const $category = $('#category');
|
|
|
|
const $availabilitiesType = $('#availabilities-type');
|
|
|
|
const $attendantsNumber = $('#attendants-number');
|
|
|
|
const $location = $('#location');
|
|
|
|
const $description = $('#description');
|
2022-01-17 17:03:50 +03:00
|
|
|
const $filterServices = $('#filter-services');
|
2022-01-18 20:54:44 +03:00
|
|
|
const $color = $('#color');
|
2022-01-10 11:09:49 +03:00
|
|
|
let filterResults = {};
|
|
|
|
let filterLimit = 20;
|
2016-04-02 16:36:55 +03:00
|
|
|
|
2022-01-14 11:26:44 +03:00
|
|
|
/**
|
2022-01-17 17:03:50 +03:00
|
|
|
* Add page event listeners.
|
2022-01-14 11:26:44 +03:00
|
|
|
*/
|
2022-01-17 17:03:50 +03:00
|
|
|
function addEventListeners() {
|
2016-04-02 16:36:55 +03:00
|
|
|
/**
|
|
|
|
* Event: Filter Services Form "Submit"
|
2016-05-15 13:12:46 +03:00
|
|
|
*
|
|
|
|
* @param {jQuery.Event} event
|
2016-04-02 16:36:55 +03:00
|
|
|
*/
|
2022-01-17 23:32:17 +03:00
|
|
|
$services.on('submit', '#filter-services form', (event) => {
|
2020-12-08 14:23:37 +03:00
|
|
|
event.preventDefault();
|
2022-01-17 17:03:50 +03:00
|
|
|
const key = $filterServices.find('.key').val();
|
|
|
|
$filterServices.find('.selected').removeClass('selected');
|
2022-01-10 11:09:49 +03:00
|
|
|
resetForm();
|
|
|
|
filter(key);
|
2016-04-02 16:36:55 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Event: Filter Service Row "Click"
|
|
|
|
*
|
|
|
|
* Display the selected service data to the user.
|
|
|
|
*/
|
2022-01-17 23:32:17 +03:00
|
|
|
$services.on('click', '.service-row', (event) => {
|
2022-01-17 17:03:50 +03:00
|
|
|
if ($filterServices.find('.filter').prop('disabled')) {
|
|
|
|
$filterServices.find('.results').css('color', '#AAA');
|
2016-04-02 16:36:55 +03:00
|
|
|
return; // exit because we are on edit mode
|
|
|
|
}
|
|
|
|
|
2022-01-17 23:32:17 +03:00
|
|
|
const serviceId = $(event.currentTarget).attr('data-id');
|
2020-05-12 21:52:32 +03:00
|
|
|
|
2022-01-17 23:32:17 +03:00
|
|
|
const service = filterResults.find((filterResult) => Number(filterResult.id) === Number(serviceId));
|
2016-04-02 16:36:55 +03:00
|
|
|
|
2016-10-10 18:20:23 +03:00
|
|
|
// Add dedicated provider link.
|
2022-01-10 11:09:49 +03:00
|
|
|
const dedicatedUrl = App.Utils.Url.siteUrl('?service=' + encodeURIComponent(service.id));
|
|
|
|
|
|
|
|
const $link = $('<a/>', {
|
2020-05-07 19:47:14 +03:00
|
|
|
'href': dedicatedUrl,
|
|
|
|
'html': [
|
|
|
|
$('<span/>', {
|
2020-06-09 17:36:54 +03:00
|
|
|
'class': 'fas fa-link'
|
2020-05-07 19:47:14 +03:00
|
|
|
})
|
|
|
|
]
|
|
|
|
});
|
|
|
|
|
2022-01-17 17:03:50 +03:00
|
|
|
$services.find('.record-details h3').find('a').remove().end().append($link);
|
2016-10-10 18:20:23 +03:00
|
|
|
|
2022-01-10 11:09:49 +03:00
|
|
|
display(service);
|
2022-01-17 17:03:50 +03:00
|
|
|
$filterServices.find('.selected').removeClass('selected');
|
2022-01-17 23:32:17 +03:00
|
|
|
$(event.currentTarget).addClass('selected');
|
2016-04-02 16:36:55 +03:00
|
|
|
$('#edit-service, #delete-service').prop('disabled', false);
|
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Event: Add New Service Button "Click"
|
|
|
|
*/
|
2022-01-17 23:32:17 +03:00
|
|
|
$services.on('click', '#add-service', () => {
|
2022-01-10 11:09:49 +03:00
|
|
|
resetForm();
|
2022-01-17 17:03:50 +03:00
|
|
|
$services.find('.add-edit-delete-group').hide();
|
|
|
|
$services.find('.save-cancel-group').show();
|
|
|
|
$services.find('.record-details').find('input, select, textarea').prop('disabled', false);
|
2022-01-19 11:39:13 +03:00
|
|
|
$services.find('.record-details .form-label span').prop('hidden', false);
|
2022-01-17 17:03:50 +03:00
|
|
|
$filterServices.find('button').prop('disabled', true);
|
|
|
|
$filterServices.find('.results').css('color', '#AAA');
|
2020-12-05 12:05:20 +03:00
|
|
|
|
|
|
|
// Default values
|
2022-01-17 17:03:50 +03:00
|
|
|
$name.val('Service');
|
|
|
|
$duration.val('30');
|
|
|
|
$price.val('0');
|
|
|
|
$currency.val('');
|
|
|
|
$category.val('');
|
|
|
|
$availabilitiesType.val('flexible');
|
|
|
|
$attendantsNumber.val('1');
|
2016-04-02 16:36:55 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Event: Cancel Service Button "Click"
|
|
|
|
*
|
|
|
|
* Cancel add or edit of a service record.
|
|
|
|
*/
|
2022-01-17 23:32:17 +03:00
|
|
|
$services.on('click', '#cancel-service', () => {
|
2022-01-17 17:03:50 +03:00
|
|
|
const id = $id.val();
|
|
|
|
|
2022-01-10 11:09:49 +03:00
|
|
|
resetForm();
|
2022-01-17 17:03:50 +03:00
|
|
|
|
2016-04-02 16:36:55 +03:00
|
|
|
if (id !== '') {
|
2022-01-10 11:09:49 +03:00
|
|
|
select(id, true);
|
2016-04-02 16:36:55 +03:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Event: Save Service Button "Click"
|
|
|
|
*/
|
2022-01-17 23:32:17 +03:00
|
|
|
$services.on('click', '#save-service', () => {
|
2022-01-10 11:09:49 +03:00
|
|
|
const service = {
|
2022-01-17 17:03:50 +03:00
|
|
|
name: $name.val(),
|
|
|
|
duration: $duration.val(),
|
|
|
|
price: $price.val(),
|
|
|
|
currency: $currency.val(),
|
|
|
|
description: $description.val(),
|
|
|
|
location: $location.val(),
|
2022-01-18 20:54:44 +03:00
|
|
|
color: App.Components.ColorSelection.getColor($color),
|
2022-01-17 17:03:50 +03:00
|
|
|
availabilities_type: $availabilitiesType.val(),
|
|
|
|
attendants_number: $attendantsNumber.val(),
|
|
|
|
id_categories: $category.val() || null
|
2016-04-02 16:36:55 +03:00
|
|
|
};
|
|
|
|
|
2022-01-17 17:03:50 +03:00
|
|
|
if ($id.val() !== '') {
|
|
|
|
service.id = $id.val();
|
2016-04-02 16:36:55 +03:00
|
|
|
}
|
|
|
|
|
2022-01-10 11:09:49 +03:00
|
|
|
if (!validate()) {
|
2016-04-02 16:36:55 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-01-10 11:09:49 +03:00
|
|
|
save(service);
|
2016-04-02 16:36:55 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Event: Edit Service Button "Click"
|
|
|
|
*/
|
2022-01-17 23:32:17 +03:00
|
|
|
$services.on('click', '#edit-service', () => {
|
2022-01-17 17:03:50 +03:00
|
|
|
$services.find('.add-edit-delete-group').hide();
|
|
|
|
$services.find('.save-cancel-group').show();
|
|
|
|
$services.find('.record-details').find('input, select, textarea').prop('disabled', false);
|
2022-01-19 11:39:13 +03:00
|
|
|
$services.find('.record-details .form-label span').prop('hidden', false);
|
2022-01-17 17:03:50 +03:00
|
|
|
$filterServices.find('button').prop('disabled', true);
|
|
|
|
$filterServices.find('.results').css('color', '#AAA');
|
2022-01-18 20:54:44 +03:00
|
|
|
App.Components.ColorSelection.enable($color);
|
2016-04-02 16:36:55 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Event: Delete Service Button "Click"
|
|
|
|
*/
|
2022-01-17 23:32:17 +03:00
|
|
|
$services.on('click', '#delete-service', () => {
|
2022-01-17 17:03:50 +03:00
|
|
|
const serviceId = $id.val();
|
2022-01-10 11:09:49 +03:00
|
|
|
const buttons = [
|
2017-06-16 09:51:05 +03:00
|
|
|
{
|
2022-01-18 10:22:25 +03:00
|
|
|
text: lang('cancel'),
|
2022-01-17 17:03:50 +03:00
|
|
|
click: () => {
|
2020-09-07 11:08:18 +03:00
|
|
|
$('#message-box').dialog('close');
|
2017-06-16 09:51:05 +03:00
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
2022-01-18 10:22:25 +03:00
|
|
|
text: lang('delete'),
|
2022-01-17 17:03:50 +03:00
|
|
|
click: () => {
|
2022-01-10 11:09:49 +03:00
|
|
|
remove(serviceId);
|
2020-09-07 11:08:18 +03:00
|
|
|
$('#message-box').dialog('close');
|
2017-06-16 09:51:05 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
];
|
2016-04-02 16:36:55 +03:00
|
|
|
|
2022-01-18 10:22:25 +03:00
|
|
|
App.Utils.Message.show(lang('delete_service'), lang('delete_record_prompt'), buttons);
|
2016-04-02 16:36:55 +03:00
|
|
|
});
|
2022-01-10 11:09:49 +03:00
|
|
|
}
|
2020-12-08 14:23:37 +03:00
|
|
|
|
2016-04-02 16:36:55 +03:00
|
|
|
/**
|
|
|
|
* Save service record to database.
|
|
|
|
*
|
2016-05-15 13:12:46 +03:00
|
|
|
* @param {Object} service Contains the service record data. If an 'id' value is provided
|
2016-04-02 16:36:55 +03:00
|
|
|
* then the update operation is going to be executed.
|
|
|
|
*/
|
2022-01-10 11:09:49 +03:00
|
|
|
function save(service) {
|
|
|
|
App.Http.Services.save(service).then((response) => {
|
2022-01-18 10:22:25 +03:00
|
|
|
App.Layouts.Backend.displayNotification(lang('service_saved'));
|
2022-01-10 11:09:49 +03:00
|
|
|
resetForm();
|
2022-01-17 17:03:50 +03:00
|
|
|
$filterServices.find('.key').val('');
|
2022-01-10 11:09:49 +03:00
|
|
|
filter('', response.id, true);
|
|
|
|
});
|
|
|
|
}
|
2016-04-02 16:36:55 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Delete a service record from database.
|
|
|
|
*
|
2016-05-15 13:12:46 +03:00
|
|
|
* @param {Number} id Record ID to be deleted.
|
2016-04-02 16:36:55 +03:00
|
|
|
*/
|
2022-01-10 11:09:49 +03:00
|
|
|
function remove(id) {
|
|
|
|
App.Http.Services.destroy(id).then(() => {
|
2022-01-18 10:22:25 +03:00
|
|
|
App.Layouts.Backend.displayNotification(lang('service_deleted'));
|
2022-01-10 11:09:49 +03:00
|
|
|
resetForm();
|
2022-01-17 17:03:50 +03:00
|
|
|
filter($filterServices.find('.key').val());
|
2022-01-10 11:09:49 +03:00
|
|
|
});
|
|
|
|
}
|
2016-04-02 16:36:55 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Validates a service record.
|
|
|
|
*
|
2016-05-15 13:12:46 +03:00
|
|
|
* @return {Boolean} Returns the validation result.
|
2016-04-02 16:36:55 +03:00
|
|
|
*/
|
2022-01-10 11:09:49 +03:00
|
|
|
function validate() {
|
2022-01-17 17:03:50 +03:00
|
|
|
$services.find('.is-invalid').removeClass('is-invalid');
|
|
|
|
$services.find('.form-message').removeClass('alert-danger').hide();
|
2016-04-02 16:36:55 +03:00
|
|
|
|
|
|
|
try {
|
2021-03-25 13:32:10 +03:00
|
|
|
// Validate required fields.
|
2022-01-10 11:09:49 +03:00
|
|
|
let missingRequired = false;
|
2016-04-02 16:36:55 +03:00
|
|
|
|
2022-01-17 17:03:50 +03:00
|
|
|
$services.find('.required').each((index, requiredField) => {
|
2020-05-12 21:52:32 +03:00
|
|
|
if (!$(requiredField).val()) {
|
2021-11-23 12:10:09 +03:00
|
|
|
$(requiredField).addClass('is-invalid');
|
2016-04-02 16:36:55 +03:00
|
|
|
missingRequired = true;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
if (missingRequired) {
|
2022-01-18 10:22:25 +03:00
|
|
|
throw new Error(lang('fields_are_required'));
|
2016-04-02 16:36:55 +03:00
|
|
|
}
|
|
|
|
|
2021-03-25 13:32:10 +03:00
|
|
|
// Validate the duration.
|
2022-01-17 17:03:50 +03:00
|
|
|
if (Number($duration.val()) < 5) {
|
|
|
|
$duration.addClass('is-invalid');
|
2022-01-18 10:22:25 +03:00
|
|
|
throw new Error(lang('invalid_duration'));
|
2021-03-25 13:32:10 +03:00
|
|
|
}
|
|
|
|
|
2016-04-02 16:36:55 +03:00
|
|
|
return true;
|
2020-05-06 20:15:11 +03:00
|
|
|
} catch (error) {
|
2022-01-17 17:03:50 +03:00
|
|
|
$services.find('.form-message').addClass('alert-danger').text(error.message).show();
|
2016-04-02 16:36:55 +03:00
|
|
|
return false;
|
|
|
|
}
|
2022-01-10 11:09:49 +03:00
|
|
|
}
|
2016-04-02 16:36:55 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Resets the service tab form back to its initial state.
|
|
|
|
*/
|
2022-01-10 11:09:49 +03:00
|
|
|
function resetForm() {
|
2022-01-17 17:03:50 +03:00
|
|
|
$filterServices.find('.selected').removeClass('selected');
|
|
|
|
$filterServices.find('button').prop('disabled', false);
|
|
|
|
$filterServices.find('.results').css('color', '');
|
2020-09-08 09:57:07 +03:00
|
|
|
|
2022-01-17 17:03:50 +03:00
|
|
|
$services.find('.record-details').find('input, select, textarea').val('').prop('disabled', true);
|
2022-01-19 11:39:13 +03:00
|
|
|
$services.find('.record-details .form-label span').prop('hidden', true);
|
2022-01-17 17:03:50 +03:00
|
|
|
$services.find('.record-details h3 a').remove();
|
2020-09-08 09:57:07 +03:00
|
|
|
|
2022-01-17 17:03:50 +03:00
|
|
|
$services.find('.add-edit-delete-group').show();
|
|
|
|
$services.find('.save-cancel-group').hide();
|
2016-04-02 16:36:55 +03:00
|
|
|
$('#edit-service, #delete-service').prop('disabled', true);
|
2020-07-13 19:13:52 +03:00
|
|
|
|
2022-01-17 17:03:50 +03:00
|
|
|
$services.find('.record-details .is-invalid').removeClass('is-invalid');
|
|
|
|
$services.find('.record-details .form-message').hide();
|
2022-01-18 20:54:44 +03:00
|
|
|
|
|
|
|
App.Components.ColorSelection.disable($color);
|
2022-01-10 11:09:49 +03:00
|
|
|
}
|
2016-04-02 16:36:55 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Display a service record into the service form.
|
|
|
|
*
|
2016-05-15 13:12:46 +03:00
|
|
|
* @param {Object} service Contains the service record data.
|
2016-04-02 16:36:55 +03:00
|
|
|
*/
|
2022-01-10 11:09:49 +03:00
|
|
|
function display(service) {
|
2022-01-17 17:03:50 +03:00
|
|
|
$id.val(service.id);
|
|
|
|
$name.val(service.name);
|
|
|
|
$duration.val(service.duration);
|
|
|
|
$price.val(service.price);
|
|
|
|
$currency.val(service.currency);
|
|
|
|
$description.val(service.description);
|
|
|
|
$location.val(service.location);
|
|
|
|
$availabilitiesType.val(service.availabilities_type);
|
|
|
|
$attendantsNumber.val(service.attendants_number);
|
2022-01-18 20:54:44 +03:00
|
|
|
App.Components.ColorSelection.setColor($color, service.color);
|
2016-04-02 16:36:55 +03:00
|
|
|
|
2022-01-10 11:09:49 +03:00
|
|
|
const categoryId = service.id_categories !== null ? service.id_categories : '';
|
2022-01-17 17:03:50 +03:00
|
|
|
$category.val(categoryId);
|
2022-01-10 11:09:49 +03:00
|
|
|
}
|
2016-04-02 16:36:55 +03:00
|
|
|
|
|
|
|
/**
|
2021-11-18 07:13:13 +03:00
|
|
|
* Filters service records depending a string keyword.
|
2016-04-02 16:36:55 +03:00
|
|
|
*
|
2021-11-18 07:13:13 +03:00
|
|
|
* @param {String} keyword This is used to filter the service records of the database.
|
2016-05-15 13:12:46 +03:00
|
|
|
* @param {Number} selectId Optional, if set then after the filter operation the record with this
|
|
|
|
* ID will be selected (but not displayed).
|
2022-01-10 11:09:49 +03:00
|
|
|
* @param {Boolean} show Optional (false), if true then the selected record will be displayed on the form.
|
2016-04-02 16:36:55 +03:00
|
|
|
*/
|
2022-01-10 11:09:49 +03:00
|
|
|
function filter(keyword, selectId = null, show = false) {
|
|
|
|
App.Http.Services.search(keyword, filterLimit).then((response) => {
|
|
|
|
filterResults = response;
|
2016-04-02 16:36:55 +03:00
|
|
|
|
2022-01-17 17:03:50 +03:00
|
|
|
$filterServices.find('.results').empty();
|
2022-01-10 11:09:49 +03:00
|
|
|
|
2022-01-17 17:03:50 +03:00
|
|
|
response.forEach((service) => {
|
|
|
|
$filterServices.find('.results').append(getFilterHtml(service)).append($('<hr/>'));
|
2022-01-10 11:09:49 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
if (response.length === 0) {
|
2022-01-17 17:03:50 +03:00
|
|
|
$filterServices.find('.results').append(
|
2022-01-10 11:09:49 +03:00
|
|
|
$('<em/>', {
|
2022-01-18 10:22:25 +03:00
|
|
|
'text': lang('no_records_found')
|
2022-01-10 11:09:49 +03:00
|
|
|
})
|
|
|
|
);
|
|
|
|
} else if (response.length === filterLimit) {
|
|
|
|
$('<button/>', {
|
|
|
|
'type': 'button',
|
|
|
|
'class': 'btn btn-outline-secondary w-100 load-more text-center',
|
2022-01-18 10:22:25 +03:00
|
|
|
'text': lang('load_more'),
|
2022-01-17 17:03:50 +03:00
|
|
|
'click': () => {
|
2022-01-10 11:09:49 +03:00
|
|
|
filterLimit += 20;
|
|
|
|
filter(keyword, selectId, show);
|
2022-01-17 17:03:50 +03:00
|
|
|
}
|
2022-01-10 11:09:49 +03:00
|
|
|
}).appendTo('#filter-services .results');
|
|
|
|
}
|
|
|
|
|
|
|
|
if (selectId) {
|
|
|
|
select(selectId, show);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2016-04-02 16:36:55 +03:00
|
|
|
|
|
|
|
/**
|
2016-05-15 13:12:46 +03:00
|
|
|
* Get Filter HTML
|
|
|
|
*
|
|
|
|
* Get a service row HTML code that is going to be displayed on the filter results list.
|
|
|
|
*
|
|
|
|
* @param {Object} service Contains the service record data.
|
2016-04-02 16:36:55 +03:00
|
|
|
*
|
2016-05-15 13:12:46 +03:00
|
|
|
* @return {String} The HTML code that represents the record on the filter results list.
|
2016-04-02 16:36:55 +03:00
|
|
|
*/
|
2022-01-10 11:09:49 +03:00
|
|
|
function getFilterHtml(service) {
|
|
|
|
const name = service.name;
|
2020-05-07 19:47:14 +03:00
|
|
|
|
2022-01-10 11:09:49 +03:00
|
|
|
const info = service.duration + ' min - ' + service.price + ' ' + service.currency;
|
2020-05-07 19:47:14 +03:00
|
|
|
|
|
|
|
return $('<div/>', {
|
|
|
|
'class': 'service-row entry',
|
|
|
|
'data-id': service.id,
|
|
|
|
'html': [
|
|
|
|
$('<strong/>', {
|
|
|
|
'text': name
|
|
|
|
}),
|
|
|
|
$('<br/>'),
|
|
|
|
$('<span/>', {
|
|
|
|
'text': info
|
|
|
|
}),
|
|
|
|
$('<br/>')
|
|
|
|
]
|
|
|
|
});
|
2022-01-10 11:09:49 +03:00
|
|
|
}
|
2016-04-02 16:36:55 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Select a specific record from the current filter results. If the service id does not exist
|
|
|
|
* in the list then no record will be selected.
|
|
|
|
*
|
2016-05-15 13:12:46 +03:00
|
|
|
* @param {Number} id The record id to be selected from the filter results.
|
2022-01-10 11:09:49 +03:00
|
|
|
* @param {Boolean} show Optional (false), if true then the method will display the record on the form.
|
2016-04-02 16:36:55 +03:00
|
|
|
*/
|
2022-01-10 11:09:49 +03:00
|
|
|
function select(id, show = false) {
|
2022-01-17 17:03:50 +03:00
|
|
|
$filterServices.find('.selected').removeClass('selected');
|
2016-04-02 16:36:55 +03:00
|
|
|
|
2022-01-17 17:03:50 +03:00
|
|
|
$filterServices.find('.service-row[data-id="' + id + '"]').addClass('selected');
|
2016-04-02 16:36:55 +03:00
|
|
|
|
2022-01-10 11:09:49 +03:00
|
|
|
if (show) {
|
2022-01-17 23:32:17 +03:00
|
|
|
const service = filterResults.find((filterResult) => Number(filterResult.id) === Number(id));
|
2020-05-12 21:52:32 +03:00
|
|
|
|
2022-01-10 11:09:49 +03:00
|
|
|
display(service);
|
2020-05-12 21:52:32 +03:00
|
|
|
|
|
|
|
$('#edit-service, #delete-service').prop('disabled', false);
|
2016-04-02 16:36:55 +03:00
|
|
|
}
|
2022-01-10 11:09:49 +03:00
|
|
|
}
|
2016-04-02 16:36:55 +03:00
|
|
|
|
2022-01-10 11:09:49 +03:00
|
|
|
/**
|
|
|
|
* Update the service category list box.
|
|
|
|
*
|
|
|
|
* Use this method every time a change is made to the service categories db table.
|
|
|
|
*/
|
|
|
|
function updateAvailableCategories() {
|
|
|
|
App.Http.Categories.search('', 999).then((response) => {
|
2022-01-18 11:29:56 +03:00
|
|
|
$category.empty();
|
2022-01-10 11:09:49 +03:00
|
|
|
|
2022-01-17 17:03:50 +03:00
|
|
|
response.forEach((category) => {
|
2022-01-18 11:29:56 +03:00
|
|
|
$category.append(new Option(category.name, category.id));
|
2022-01-10 11:09:49 +03:00
|
|
|
});
|
|
|
|
|
2022-01-19 11:39:13 +03:00
|
|
|
$category.append(new Option('', '')).val('');
|
2022-01-10 11:09:49 +03:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-01-14 11:26:44 +03:00
|
|
|
/**
|
|
|
|
* Initialize the module.
|
|
|
|
*/
|
2022-01-14 10:31:12 +03:00
|
|
|
function initialize() {
|
2022-01-10 11:09:49 +03:00
|
|
|
resetForm();
|
|
|
|
filter('');
|
2022-01-17 17:03:50 +03:00
|
|
|
addEventListeners();
|
2022-01-10 11:09:49 +03:00
|
|
|
updateAvailableCategories();
|
|
|
|
}
|
|
|
|
|
2022-01-14 10:31:12 +03:00
|
|
|
document.addEventListener('DOMContentLoaded', initialize);
|
2022-01-10 11:09:49 +03:00
|
|
|
|
|
|
|
return {
|
|
|
|
filter,
|
|
|
|
save,
|
|
|
|
remove,
|
|
|
|
getFilterHtml,
|
|
|
|
resetForm,
|
|
|
|
select
|
|
|
|
};
|
2016-04-02 16:36:55 +03:00
|
|
|
})();
|