2016-04-02 16:36:55 +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
|
2016-04-02 16:36:55 +03:00
|
|
|
* @since v1.0.0
|
|
|
|
* ---------------------------------------------------------------------------- */
|
|
|
|
|
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-17 17:03:50 +03:00
|
|
|
const $name = $('#service-name');
|
|
|
|
const $duration = $('#service-duration');
|
|
|
|
const $price = $('#service-price');
|
|
|
|
const $currency = $('#service-currency');
|
|
|
|
const $category = $('#service-category');
|
|
|
|
const $availabilitiesType = $('#service-availabilities-type');
|
|
|
|
const $attendantsNumber = $('#service-attendants-number');
|
|
|
|
const $location = $('#service-location');
|
|
|
|
const $description = $('#service-description');
|
|
|
|
const $filterServices = $('#filter-services');
|
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-10 11:09:49 +03:00
|
|
|
$services.on('submit', '#filter-services form', function (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-10 11:09:49 +03:00
|
|
|
$services.on('click', '.service-row', function () {
|
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-10 11:09:49 +03:00
|
|
|
const serviceId = $(this).attr('data-id');
|
2020-05-12 21:52:32 +03:00
|
|
|
|
2022-01-10 11:09:49 +03:00
|
|
|
const service = filterResults.find(function (filterResult) {
|
2020-05-12 21:52:32 +03:00
|
|
|
return 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');
|
2016-07-15 22:09:38 +03:00
|
|
|
$(this).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-10 11:09:49 +03:00
|
|
|
$services.on('click', '#add-service', function () {
|
|
|
|
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);
|
|
|
|
$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-10 11:09:49 +03:00
|
|
|
$services.on('click', '#cancel-service', function () {
|
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-10 11:09:49 +03:00
|
|
|
$services.on('click', '#save-service', function () {
|
|
|
|
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(),
|
|
|
|
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-10 11:09:49 +03:00
|
|
|
$services.on('click', '#edit-service', function () {
|
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);
|
|
|
|
$filterServices.find('button').prop('disabled', true);
|
|
|
|
$filterServices.find('.results').css('color', '#AAA');
|
2016-04-02 16:36:55 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Event: Delete Service Button "Click"
|
|
|
|
*/
|
2022-01-10 11:09:49 +03:00
|
|
|
$services.on('click', '#delete-service', function () {
|
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
|
|
|
{
|
2021-12-13 09:52:09 +03:00
|
|
|
text: App.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
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
2021-12-13 09:52:09 +03:00
|
|
|
text: App.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-10 11:09:49 +03:00
|
|
|
App.Utils.Message.show(App.Lang.delete_service, App.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-17 07:26:57 +03:00
|
|
|
App.Layouts.Backend.displayNotification(App.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-17 07:26:57 +03:00
|
|
|
App.Layouts.Backend.displayNotification(App.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) {
|
2021-12-13 09:52:09 +03:00
|
|
|
throw new Error(App.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');
|
2021-12-13 09:52:09 +03:00
|
|
|
throw new Error(App.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);
|
|
|
|
$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-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);
|
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/>', {
|
|
|
|
'text': App.Lang.no_records_found
|
|
|
|
})
|
|
|
|
);
|
|
|
|
} else if (response.length === filterLimit) {
|
|
|
|
$('<button/>', {
|
|
|
|
'type': 'button',
|
|
|
|
'class': 'btn btn-outline-secondary w-100 load-more text-center',
|
|
|
|
'text': App.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) {
|
|
|
|
const service = filterResults.find(function (filterResult) {
|
2020-05-12 21:52:32 +03:00
|
|
|
return Number(filterResult.id) === Number(id);
|
|
|
|
});
|
|
|
|
|
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) => {
|
|
|
|
var $select = $('#service-category');
|
|
|
|
|
|
|
|
$select.empty();
|
|
|
|
|
2022-01-17 17:03:50 +03:00
|
|
|
response.forEach((category) => {
|
2022-01-10 11:09:49 +03:00
|
|
|
$select.append(new Option(category.name, category.id));
|
|
|
|
});
|
|
|
|
|
|
|
|
$select.append(new Option('- ' + App.Lang.no_category + ' -', '')).val('');
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
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
|
|
|
})();
|