/* ---------------------------------------------------------------------------- * Easy!Appointments - Online Appointment Scheduler * * @package EasyAppointments * @author A.Tselegidis * @copyright Copyright (c) Alex Tselegidis * @license https://opensource.org/licenses/GPL-3.0 - GPLv3 * @link https://easyappointments.org * @since v1.5.0 * ---------------------------------------------------------------------------- */ /** * Blocked-periods page. * * This module implements the functionality of the blocked-periods page. */ App.Pages.BlockedPeriods = (function () { const $blockedPeriods = $('#blocked-periods'); const $filterBlockedPeriods = $('#filter-blocked-periods'); const $id = $('#id'); const $name = $('#name'); const $description = $('#description'); let filterResults = {}; let filterLimit = 20; /** * Add the page event listeners. */ function addEventListeners() { /** * Event: Filter Blocked Periods Form "Submit" * * @param {jQuery.Event} event */ $blockedPeriods.on('submit', '#filter-blocked-periods form', (event) => { event.preventDefault(); const key = $('#filter-blocked-periods .key').val(); $('.selected').removeClass('selected'); resetForm(); filter(key); }); /** * Event: Filter Blocked-Periods Row "Click" * * Displays the selected row data on the right side of the page. * * @param {jQuery.Event} event */ $blockedPeriods.on('click', '.blocked-period-row', (event) => { if ($('#filter-blocked-periods .filter').prop('disabled')) { $('#filter-blocked-periods .results').css('color', '#AAA'); return; // exit because we are on edit mode } const blockedPeriodId = $(event.currentTarget).attr('data-id'); const blockedPeriod = filterResults.find((filterResult) => Number(filterResult.id) === Number(blockedPeriodId)); display(blockedPeriod); $('#filter-blocked-periods .selected').removeClass('selected'); $(event.currentTarget).addClass('selected'); $('#edit-blocked-period, #delete-blocked-period').prop('disabled', false); }); /** * Event: Add Blocked-Period Button "Click" */ $blockedPeriods.on('click', '#add-blocked-period', () => { resetForm(); $blockedPeriods.find('.add-edit-delete-group').hide(); $blockedPeriods.find('.save-cancel-group').show(); $blockedPeriods.find('.record-details').find('input, select, textarea').prop('disabled', false); $blockedPeriods.find('.record-details .form-label span').prop('hidden', false); $filterBlockedPeriods.find('button').prop('disabled', true); $filterBlockedPeriods.find('.results').css('color', '#AAA'); }); /** * Event: Edit Blocked-Period Button "Click" */ $blockedPeriods.on('click', '#edit-blocked-period', () => { $blockedPeriods.find('.add-edit-delete-group').hide(); $blockedPeriods.find('.save-cancel-group').show(); $blockedPeriods.find('.record-details').find('input, select, textarea').prop('disabled', false); $blockedPeriods.find('.record-details .form-label span').prop('hidden', false); $filterBlockedPeriods.find('button').prop('disabled', true); $filterBlockedPeriods.find('.results').css('color', '#AAA'); }); /** * Event: Delete Blocked-Period Button "Click" */ $blockedPeriods.on('click', '#delete-blocked-period', () => { const blockedPeriodId = $id.val(); const buttons = [ { text: lang('cancel'), click: (event, messageModal) => { messageModal.dispose(); } }, { text: lang('delete'), click: (event, messageModal) => { remove(blockedPeriodId); messageModal.dispose(); } } ]; App.Utils.Message.show(lang('delete_blocked_period'), lang('delete_record_prompt'), buttons); }); /** * Event: Blocked period Save Button "Click" */ $blockedPeriods.on('click', '#save-blocked-period', () => { const blockedPeriod = { name: $name.val(), description: $description.val() }; if ($id.val() !== '') { blockedPeriod.id = $id.val(); } if (!validate()) { return; } save(blockedPeriod); }); /** * Event: Cancel Blocked-Period Button "Click" */ $blockedPeriods.on('click', '#cancel-blocked-period', () => { const id = $id.val(); resetForm(); if (id !== '') { select(id, true); } }); } /** * Filter blocked periods records. * * @param {String} keyword This key string is used to filter the blocked-period records. * @param {Number} selectId Optional, if set then after the filter operation the record with the given ID will be * selected (but not displayed). * @param {Boolean} show Optional (false), if true then the selected record will be displayed on the form. */ function filter(keyword, selectId = null, show = false) { App.Http.BlockedPeriods.search(keyword, filterLimit).then((response) => { filterResults = response; $('#filter-blocked-periods .results').empty(); response.forEach((blockedPeriod) => { $('#filter-blocked-periods .results').append(getFilterHtml(blockedPeriod)).append($('
')); }); if (response.length === 0) { $('#filter-blocked-periods .results').append( $('', { 'text': lang('no_records_found') }) ); } else if (response.length === filterLimit) { $('