2022-01-11 12:50:24 +03:00
|
|
|
/* ----------------------------------------------------------------------------
|
2022-01-18 15:05:42 +03:00
|
|
|
* Easy!Appointments - Online Appointment Scheduler
|
2022-01-11 12:50:24 +03:00
|
|
|
*
|
|
|
|
* @package EasyAppointments
|
|
|
|
* @author A.Tselegidis <alextselegidis@gmail.com>
|
|
|
|
* @copyright Copyright (c) Alex Tselegidis
|
|
|
|
* @license https://opensource.org/licenses/GPL-3.0 - GPLv3
|
|
|
|
* @link https://easyappointments.org
|
|
|
|
* @since v1.5.0
|
|
|
|
* ---------------------------------------------------------------------------- */
|
|
|
|
|
2022-01-14 11:26:44 +03:00
|
|
|
/**
|
|
|
|
* Working plan exceptions modal component.
|
|
|
|
*
|
|
|
|
* This module implements the working plan exceptions modal functionality.
|
|
|
|
*/
|
2022-01-11 12:50:24 +03:00
|
|
|
App.Components.WorkingPlanExceptionsModal = (function () {
|
|
|
|
const $modal = $('#working-plan-exceptions-modal');
|
|
|
|
const $date = $('#working-plan-exceptions-date');
|
|
|
|
const $start = $('#working-plan-exceptions-start');
|
|
|
|
const $end = $('#working-plan-exceptions-end');
|
|
|
|
const $breaks = $('#working-plan-exceptions-breaks');
|
|
|
|
const $save = $('#working-plan-exceptions-save');
|
2023-02-20 10:06:12 +03:00
|
|
|
const $addBreak = $('.working-plan-exceptions-add-break');
|
2023-07-10 09:22:55 +03:00
|
|
|
const $isNonWorkingDay = $('#working-plan-exceptions-is-non-working-day');
|
|
|
|
|
|
|
|
const moment = window.moment;
|
|
|
|
|
2022-01-11 12:50:24 +03:00
|
|
|
let deferred = null;
|
|
|
|
let enableSubmit = false;
|
|
|
|
let enableCancel = false;
|
2020-10-20 16:03:48 +03:00
|
|
|
|
2022-01-14 11:26:44 +03:00
|
|
|
/**
|
|
|
|
* Reset the modal fields back to the original empty state.
|
|
|
|
*/
|
2020-10-20 16:03:48 +03:00
|
|
|
function resetModal() {
|
2023-02-20 10:06:12 +03:00
|
|
|
$addBreak.prop('disabled', false);
|
2020-10-20 16:03:48 +03:00
|
|
|
$date.val('');
|
|
|
|
$start.val('');
|
|
|
|
$end.val('');
|
2023-07-10 09:22:55 +03:00
|
|
|
$breaks.find('tbody').html(renderNoBreaksRow());
|
|
|
|
$isNonWorkingDay.prop('checked', false);
|
|
|
|
toggleFieldsByNonWorkingDay(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Render a single table row as a placeholder to empty breaks table.
|
|
|
|
*/
|
|
|
|
function renderNoBreaksRow() {
|
|
|
|
return $(`
|
|
|
|
<tr>
|
|
|
|
<td colspan="3" class="text-center">
|
|
|
|
${lang('no_breaks')}
|
|
|
|
</td>
|
|
|
|
</tr>
|
|
|
|
`);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Toggle the state of the fields depending on the non-working day checkbox value.
|
|
|
|
*
|
|
|
|
* @param {Boolean} isNonWorkingDay
|
|
|
|
*/
|
|
|
|
function toggleFieldsByNonWorkingDay(isNonWorkingDay) {
|
|
|
|
$start.prop('disabled', isNonWorkingDay).toggleClass('text-decoration-line-through', isNonWorkingDay);
|
|
|
|
$end.prop('disabled', isNonWorkingDay).toggleClass('text-decoration-line-through', isNonWorkingDay);
|
|
|
|
$addBreak.prop('disabled', isNonWorkingDay);
|
|
|
|
$breaks.find('button').prop('disabled', isNonWorkingDay);
|
|
|
|
$breaks.toggleClass('text-decoration-line-through', isNonWorkingDay)
|
2020-10-20 16:03:48 +03:00
|
|
|
}
|
|
|
|
|
2022-01-14 11:26:44 +03:00
|
|
|
/**
|
|
|
|
* Validate the modal form fields and return false if the validation fails.
|
|
|
|
*
|
|
|
|
* @returns {Boolean}
|
|
|
|
*/
|
2020-10-20 16:03:48 +03:00
|
|
|
function validate() {
|
|
|
|
$modal.find('.is-invalid').removeClass('is-invalid');
|
|
|
|
|
2023-02-02 10:54:47 +03:00
|
|
|
const date = $date[0]._flatpickr.selectedDates[0];
|
2020-10-20 16:03:48 +03:00
|
|
|
|
|
|
|
if (!date) {
|
|
|
|
$date.addClass('is-invalid');
|
|
|
|
}
|
|
|
|
|
2023-02-02 10:54:47 +03:00
|
|
|
const start = $start[0]._flatpickr.selectedDates[0];
|
2020-10-20 16:03:48 +03:00
|
|
|
|
|
|
|
if (!start) {
|
|
|
|
$start.addClass('is-invalid');
|
|
|
|
}
|
|
|
|
|
2023-02-02 10:54:47 +03:00
|
|
|
const end = $end[0]._flatpickr.selectedDates[0];
|
2020-10-20 16:03:48 +03:00
|
|
|
|
|
|
|
if (!end) {
|
|
|
|
$end.addClass('is-invalid');
|
|
|
|
}
|
|
|
|
|
|
|
|
return !$modal.find('.is-invalid').length;
|
|
|
|
}
|
|
|
|
|
2022-01-14 11:26:44 +03:00
|
|
|
/**
|
|
|
|
* Event: On Modal "Hidden"
|
|
|
|
*
|
|
|
|
* This event is used to automatically reset the modal back to the original state.
|
|
|
|
*/
|
2020-10-20 16:03:48 +03:00
|
|
|
function onModalHidden() {
|
|
|
|
resetModal();
|
|
|
|
}
|
|
|
|
|
2022-01-14 11:26:44 +03:00
|
|
|
/**
|
|
|
|
* Serialize the entered break entries.
|
|
|
|
*
|
|
|
|
* @returns {Array}
|
|
|
|
*/
|
2020-10-20 16:03:48 +03:00
|
|
|
function getBreaks() {
|
2022-01-11 12:50:24 +03:00
|
|
|
const breaks = [];
|
2020-10-20 16:03:48 +03:00
|
|
|
|
2022-01-18 13:14:45 +03:00
|
|
|
$breaks.find('tbody tr').each((index, tr) => {
|
2022-01-11 12:50:24 +03:00
|
|
|
const $tr = $(tr);
|
2020-10-20 16:03:48 +03:00
|
|
|
|
|
|
|
if ($tr.find('input:text').length) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2022-01-11 12:50:24 +03:00
|
|
|
const start = $tr.find('.working-plan-exceptions-break-start').text();
|
|
|
|
const end = $tr.find('.working-plan-exceptions-break-end').text();
|
2020-10-20 16:03:48 +03:00
|
|
|
|
|
|
|
breaks.push({
|
2022-01-18 10:18:22 +03:00
|
|
|
start: moment(start, vars('time_format') === 'regular' ? 'h:mm a' : 'HH:mm').format('HH:mm'),
|
|
|
|
end: moment(end, vars('time_format') === 'regular' ? 'h:mm a' : 'HH:mm').format('HH:mm')
|
2020-10-20 16:03:48 +03:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
// Sort breaks increasingly by hour within day
|
2022-01-18 13:14:45 +03:00
|
|
|
breaks.sort((break1, break2) => {
|
2020-10-20 16:03:48 +03:00
|
|
|
// We can do a direct string comparison since we have time based on 24 hours clock.
|
2021-11-06 19:38:37 +03:00
|
|
|
return break1.start.localeCompare(break2.start);
|
2020-10-20 16:03:48 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
return breaks;
|
|
|
|
}
|
|
|
|
|
2022-01-14 11:26:44 +03:00
|
|
|
/**
|
|
|
|
* Event: On Save "Click"
|
|
|
|
*
|
|
|
|
* Serialize the entire working plan exception and resolved the promise so that external code can save it.
|
|
|
|
*/
|
2020-10-20 16:03:48 +03:00
|
|
|
function onSaveClick() {
|
|
|
|
if (!deferred) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!validate()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-02-02 10:54:47 +03:00
|
|
|
const date = moment($date[0]._flatpickr.selectedDates[0]).format('YYYY-MM-DD');
|
2020-10-20 16:03:48 +03:00
|
|
|
|
2023-07-10 09:22:55 +03:00
|
|
|
const isNonWorkingDay = $isNonWorkingDay.prop('checked');
|
|
|
|
|
|
|
|
const workingPlanException = isNonWorkingDay ? null : {
|
2023-02-02 10:54:47 +03:00
|
|
|
start: moment($start[0]._flatpickr.selectedDates[0]).format('HH:mm'),
|
|
|
|
end: moment($end[0]._flatpickr.selectedDates[0]).format('HH:mm'),
|
2020-10-20 16:03:48 +03:00
|
|
|
breaks: getBreaks()
|
|
|
|
};
|
|
|
|
|
|
|
|
deferred.resolve(date, workingPlanException);
|
|
|
|
|
|
|
|
$modal.modal('hide');
|
2023-07-10 09:22:55 +03:00
|
|
|
|
2020-10-20 16:03:48 +03:00
|
|
|
resetModal();
|
|
|
|
}
|
|
|
|
|
2022-01-14 11:26:44 +03:00
|
|
|
/**
|
|
|
|
* Enable the inline-editable table cell functionality for the provided target element..
|
|
|
|
*
|
|
|
|
* @param {jQuery} $target
|
|
|
|
*/
|
2020-10-20 16:03:48 +03:00
|
|
|
function editableTimeCell($target) {
|
2021-11-06 19:38:37 +03:00
|
|
|
$target.editable(
|
2022-01-18 13:14:45 +03:00
|
|
|
(value) => {
|
2021-11-06 19:38:37 +03:00
|
|
|
// Do not return the value because the user needs to press the "Save" button.
|
|
|
|
return value;
|
2020-10-20 16:03:48 +03:00
|
|
|
},
|
2021-11-06 19:38:37 +03:00
|
|
|
{
|
|
|
|
event: 'edit',
|
|
|
|
height: '30px',
|
|
|
|
submit: $('<button/>', {
|
|
|
|
'type': 'button',
|
|
|
|
'class': 'd-none submit-editable',
|
2022-01-18 10:22:25 +03:00
|
|
|
'text': lang('save')
|
2021-11-06 19:38:37 +03:00
|
|
|
}).get(0).outerHTML,
|
|
|
|
cancel: $('<button/>', {
|
|
|
|
'type': 'button',
|
|
|
|
'class': 'd-none cancel-editable',
|
2022-01-18 10:22:25 +03:00
|
|
|
'text': lang('cancel')
|
2021-11-06 19:38:37 +03:00
|
|
|
}).get(0).outerHTML,
|
|
|
|
onblur: 'ignore',
|
2022-01-18 13:14:45 +03:00
|
|
|
onreset: () => {
|
2021-11-06 19:38:37 +03:00
|
|
|
if (!enableCancel) {
|
|
|
|
return false; // disable ESC button
|
|
|
|
}
|
|
|
|
},
|
2022-01-18 13:14:45 +03:00
|
|
|
onsubmit: () => {
|
2021-11-06 19:38:37 +03:00
|
|
|
if (!enableSubmit) {
|
|
|
|
return false; // disable Enter button
|
|
|
|
}
|
2020-10-20 16:03:48 +03:00
|
|
|
}
|
|
|
|
}
|
2021-11-06 19:38:37 +03:00
|
|
|
);
|
2020-10-20 16:03:48 +03:00
|
|
|
}
|
|
|
|
|
2022-01-14 11:26:44 +03:00
|
|
|
/**
|
|
|
|
* Open the modal and start adding a new working plan exception.
|
|
|
|
*
|
2022-01-18 17:50:09 +03:00
|
|
|
* @returns {*|jQuery.Deferred}
|
2022-01-14 11:26:44 +03:00
|
|
|
*/
|
2020-10-20 16:03:48 +03:00
|
|
|
function add() {
|
2022-01-11 12:50:24 +03:00
|
|
|
deferred = $.Deferred();
|
2020-10-20 16:03:48 +03:00
|
|
|
|
2023-02-20 10:06:12 +03:00
|
|
|
$date[0]._flatpickr.setDate(new Date());
|
|
|
|
$start[0]._flatpickr.setDate(moment('08:00', 'HH:mm').toDate());
|
|
|
|
$end[0]._flatpickr.setDate(moment('20:00', 'HH:mm').toDate());
|
2020-10-20 16:03:48 +03:00
|
|
|
|
2023-07-10 09:22:55 +03:00
|
|
|
$isNonWorkingDay.prop('checked', false);
|
|
|
|
|
|
|
|
$breaks.find('tbody').html(renderNoBreaksRow());
|
|
|
|
|
2020-10-20 16:03:48 +03:00
|
|
|
$modal.modal('show');
|
|
|
|
|
|
|
|
return deferred.promise();
|
|
|
|
}
|
|
|
|
|
2022-01-14 11:26:44 +03:00
|
|
|
/**
|
|
|
|
* Modify the provided working plan exception for the selected date.
|
|
|
|
*
|
|
|
|
* @param {String} date
|
|
|
|
* @param {Object} workingPlanException
|
|
|
|
*
|
2022-01-18 17:50:09 +03:00
|
|
|
* @return {*|jQuery.Deferred}
|
2022-01-14 11:26:44 +03:00
|
|
|
*/
|
2020-10-20 16:03:48 +03:00
|
|
|
function edit(date, workingPlanException) {
|
2022-01-11 12:50:24 +03:00
|
|
|
deferred = $.Deferred();
|
2020-10-20 16:03:48 +03:00
|
|
|
|
2023-07-10 09:22:55 +03:00
|
|
|
const isNonWorkingDay = !Boolean(workingPlanException);
|
|
|
|
|
2023-02-20 10:06:12 +03:00
|
|
|
$date[0]._flatpickr.setDate(moment(date, 'YYYY-MM-DD').toDate());
|
2020-10-20 16:03:48 +03:00
|
|
|
|
2023-07-10 09:22:55 +03:00
|
|
|
if (isNonWorkingDay === false) {
|
|
|
|
$start[0]._flatpickr.setDate(moment(workingPlanException.start, 'HH:mm').toDate());
|
|
|
|
$end[0]._flatpickr.setDate(moment(workingPlanException.end, 'HH:mm').toDate());
|
2020-10-20 16:03:48 +03:00
|
|
|
|
2023-07-10 09:22:55 +03:00
|
|
|
if (!workingPlanException.breaks) {
|
|
|
|
$breaks.find('tbody').html(renderNoBreaksRow());
|
|
|
|
}
|
|
|
|
|
|
|
|
workingPlanException.breaks.forEach((workingPlanExceptionBreak) => {
|
|
|
|
renderBreakRow(workingPlanExceptionBreak).appendTo($breaks.find('tbody'));
|
|
|
|
});
|
|
|
|
|
|
|
|
editableTimeCell(
|
|
|
|
$breaks.find('tbody .working-plan-exceptions-break-start, tbody .working-plan-exceptions-break-end')
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
$start[0]._flatpickr.setDate(moment('08:00', 'HH:mm').toDate());
|
|
|
|
$end[0]._flatpickr.setDate(moment('20:00', 'HH:mm').toDate());
|
|
|
|
$breaks.find('tbody').html(renderNoBreaksRow());
|
|
|
|
}
|
|
|
|
|
|
|
|
$isNonWorkingDay.prop('checked', isNonWorkingDay);
|
|
|
|
|
|
|
|
toggleFieldsByNonWorkingDay(isNonWorkingDay);
|
2020-10-20 16:03:48 +03:00
|
|
|
|
|
|
|
$modal.modal('show');
|
|
|
|
|
|
|
|
return deferred.promise();
|
|
|
|
}
|
|
|
|
|
2022-01-14 11:26:44 +03:00
|
|
|
/**
|
|
|
|
* Render a break table row based on the provided break period object.
|
|
|
|
*
|
|
|
|
* @param {Object} breakPeriod
|
|
|
|
*
|
|
|
|
* @return {jQuery}
|
|
|
|
*/
|
2020-10-20 16:03:48 +03:00
|
|
|
function renderBreakRow(breakPeriod) {
|
2022-01-18 10:18:22 +03:00
|
|
|
const timeFormat = vars('time_format') === 'regular' ? 'h:mm a' : 'HH:mm';
|
2020-10-20 16:03:48 +03:00
|
|
|
|
|
|
|
return $('<tr/>', {
|
|
|
|
'html': [
|
|
|
|
$('<td/>', {
|
|
|
|
'class': 'working-plan-exceptions-break-start editable',
|
2021-11-25 10:40:48 +03:00
|
|
|
'text': moment(breakPeriod.start, 'HH:mm').format(timeFormat)
|
2020-10-20 16:03:48 +03:00
|
|
|
}),
|
|
|
|
$('<td/>', {
|
|
|
|
'class': 'working-plan-exceptions-break-end editable',
|
2021-11-25 10:40:48 +03:00
|
|
|
'text': moment(breakPeriod.end, 'HH:mm').format(timeFormat)
|
2020-10-20 16:03:48 +03:00
|
|
|
}),
|
|
|
|
$('<td/>', {
|
|
|
|
'html': [
|
|
|
|
$('<button/>', {
|
|
|
|
'type': 'button',
|
2021-11-23 10:43:40 +03:00
|
|
|
'class': 'btn btn-outline-secondary btn-sm me-2 working-plan-exceptions-edit-break',
|
2022-01-18 10:22:25 +03:00
|
|
|
'title': lang('edit'),
|
2020-10-20 16:03:48 +03:00
|
|
|
'html': [
|
|
|
|
$('<span/>', {
|
2020-12-08 01:10:49 +03:00
|
|
|
'class': 'fas fa-edit'
|
2020-10-20 16:03:48 +03:00
|
|
|
})
|
|
|
|
]
|
|
|
|
}),
|
|
|
|
$('<button/>', {
|
|
|
|
'type': 'button',
|
|
|
|
'class': 'btn btn-outline-secondary btn-sm working-plan-exceptions-delete-break',
|
2022-01-18 10:22:25 +03:00
|
|
|
'title': lang('delete'),
|
2020-10-20 16:03:48 +03:00
|
|
|
'html': [
|
|
|
|
$('<span/>', {
|
2020-12-08 01:10:49 +03:00
|
|
|
'class': 'fas fa-trash-alt'
|
2020-10-20 16:03:48 +03:00
|
|
|
})
|
|
|
|
]
|
|
|
|
}),
|
|
|
|
$('<button/>', {
|
|
|
|
'type': 'button',
|
2021-11-23 10:43:40 +03:00
|
|
|
'class': 'btn btn-outline-secondary btn-sm me-2 working-plan-exceptions-save-break d-none',
|
2022-01-18 10:22:25 +03:00
|
|
|
'title': lang('save'),
|
2020-10-20 16:03:48 +03:00
|
|
|
'html': [
|
|
|
|
$('<span/>', {
|
2020-12-08 01:10:49 +03:00
|
|
|
'class': 'fas fa-check-circle'
|
2020-10-20 16:03:48 +03:00
|
|
|
})
|
|
|
|
]
|
|
|
|
}),
|
|
|
|
$('<button/>', {
|
|
|
|
'type': 'button',
|
|
|
|
'class': 'btn btn-outline-secondary btn-sm working-plan-exceptions-cancel-break d-none',
|
2022-01-18 10:22:25 +03:00
|
|
|
'title': lang('cancel'),
|
2020-10-20 16:03:48 +03:00
|
|
|
'html': [
|
|
|
|
$('<span/>', {
|
|
|
|
'class': 'fas fa-ban'
|
|
|
|
})
|
|
|
|
]
|
|
|
|
})
|
|
|
|
]
|
|
|
|
})
|
|
|
|
]
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-01-14 11:26:44 +03:00
|
|
|
/**
|
|
|
|
* Event: Add Break "Click"
|
|
|
|
*/
|
2020-10-20 16:03:48 +03:00
|
|
|
function onAddBreakClick() {
|
2022-01-11 12:50:24 +03:00
|
|
|
const $newBreak = renderBreakRow({
|
2020-10-20 16:03:48 +03:00
|
|
|
start: '12:00',
|
|
|
|
end: '14:00'
|
2021-11-06 19:38:37 +03:00
|
|
|
}).appendTo('#working-plan-exceptions-breaks tbody');
|
2020-10-20 16:03:48 +03:00
|
|
|
|
|
|
|
// Bind editable and event handlers.
|
|
|
|
editableTimeCell($newBreak.find('.working-plan-exceptions-break-start, .working-plan-exceptions-break-end'));
|
|
|
|
$newBreak.find('.working-plan-exceptions-edit-break').trigger('click');
|
2023-02-20 10:06:12 +03:00
|
|
|
$addBreak.prop('disabled', true);
|
2020-10-20 16:03:48 +03:00
|
|
|
}
|
|
|
|
|
2022-01-14 11:26:44 +03:00
|
|
|
/**
|
|
|
|
* Event: Edit Break "Click"
|
|
|
|
*/
|
2020-10-20 16:03:48 +03:00
|
|
|
function onEditBreakClick() {
|
|
|
|
// Reset previous editable table cells.
|
2022-01-11 12:50:24 +03:00
|
|
|
const $previousEdits = $(this).closest('table').find('.editable');
|
2020-10-20 16:03:48 +03:00
|
|
|
|
2022-01-18 13:14:45 +03:00
|
|
|
$previousEdits.each((index, editable) => {
|
2020-10-20 16:03:48 +03:00
|
|
|
if (editable.reset) {
|
|
|
|
editable.reset();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
// Make all cells in current row editable.
|
2022-01-11 12:50:24 +03:00
|
|
|
let $tr = $(this).closest('tr');
|
2020-10-20 16:03:48 +03:00
|
|
|
$tr.children().trigger('edit');
|
2023-02-07 09:14:35 +03:00
|
|
|
App.Utils.UI.initializeTimepicker(
|
2021-11-06 19:38:37 +03:00
|
|
|
$tr.find('.working-plan-exceptions-break-start input, .working-plan-exceptions-break-end input')
|
|
|
|
);
|
2020-10-20 16:03:48 +03:00
|
|
|
$(this).closest('tr').find('.working-plan-exceptions-break-start').focus();
|
|
|
|
|
|
|
|
// Show save - cancel buttons.
|
2020-12-08 14:23:37 +03:00
|
|
|
$tr = $(this).closest('tr');
|
2020-10-20 16:03:48 +03:00
|
|
|
$tr.find('.working-plan-exceptions-edit-break, .working-plan-exceptions-delete-break').addClass('d-none');
|
|
|
|
$tr.find('.working-plan-exceptions-save-break, .working-plan-exceptions-cancel-break').removeClass('d-none');
|
2021-11-06 19:38:37 +03:00
|
|
|
$tr.find('select,input:text').addClass('form-control input-sm');
|
2020-10-20 16:03:48 +03:00
|
|
|
|
2023-02-20 10:06:12 +03:00
|
|
|
$addBreak.prop('disabled', true);
|
2020-10-20 16:03:48 +03:00
|
|
|
}
|
|
|
|
|
2022-01-14 11:26:44 +03:00
|
|
|
/**
|
|
|
|
* Event: Delete Break "Click"
|
|
|
|
*/
|
2020-10-20 16:03:48 +03:00
|
|
|
function onDeleteBreakClick() {
|
|
|
|
$(this).closest('tr').remove();
|
|
|
|
}
|
|
|
|
|
2022-01-14 11:26:44 +03:00
|
|
|
/**
|
|
|
|
* Event: Save Break "Click"
|
|
|
|
*/
|
2020-10-20 16:03:48 +03:00
|
|
|
function onSaveBreakClick() {
|
|
|
|
// Break's start time must always be prior to break's end.
|
2022-01-11 12:50:24 +03:00
|
|
|
const $tr = $(this).closest('tr');
|
|
|
|
const start = moment(
|
2021-11-24 10:34:26 +03:00
|
|
|
$tr.find('.working-plan-exceptions-break-start input').val(),
|
2022-01-18 10:18:22 +03:00
|
|
|
vars('time_format') === 'regular' ? 'h:mm a' : 'HH:mm'
|
2021-11-24 10:34:26 +03:00
|
|
|
);
|
2022-01-11 12:50:24 +03:00
|
|
|
const end = moment(
|
2021-11-24 10:34:26 +03:00
|
|
|
$tr.find('.working-plan-exceptions-break-end input').val(),
|
2022-01-18 10:18:22 +03:00
|
|
|
vars('time_format') === 'regular' ? 'h:mm a' : 'HH:mm'
|
2021-11-24 10:34:26 +03:00
|
|
|
);
|
2020-10-20 16:03:48 +03:00
|
|
|
|
|
|
|
if (start > end) {
|
2021-11-06 19:38:37 +03:00
|
|
|
$tr.find('.working-plan-exceptions-break-end input').val(
|
2022-01-18 10:18:22 +03:00
|
|
|
start.add(1, 'hour').format(vars('time_format') === 'regular' ? 'h:mm a' : 'HH:mm')
|
2021-11-06 19:38:37 +03:00
|
|
|
);
|
2020-10-20 16:03:48 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
enableSubmit = true;
|
|
|
|
$tr.find('.editable .submit-editable').trigger('click');
|
|
|
|
enableSubmit = false;
|
|
|
|
|
|
|
|
$tr.find('.working-plan-exceptions-save-break, .working-plan-exceptions-cancel-break').addClass('d-none');
|
2021-11-06 19:38:37 +03:00
|
|
|
$tr.closest('table')
|
|
|
|
.find('.working-plan-exceptions-edit-break, .working-plan-exceptions-delete-break')
|
|
|
|
.removeClass('d-none');
|
2023-02-20 10:06:12 +03:00
|
|
|
$addBreak.prop('disabled', false);
|
2020-10-20 16:03:48 +03:00
|
|
|
}
|
|
|
|
|
2022-01-14 11:26:44 +03:00
|
|
|
/**
|
|
|
|
* Event: Cancel Break "Click"
|
|
|
|
*/
|
2020-10-20 16:03:48 +03:00
|
|
|
function onCancelBreakClick() {
|
2022-01-11 12:50:24 +03:00
|
|
|
const $tr = $(this).closest('tr');
|
2020-10-20 16:03:48 +03:00
|
|
|
enableCancel = true;
|
|
|
|
$tr.find('.cancel-editable').trigger('click');
|
|
|
|
enableCancel = false;
|
|
|
|
|
2021-11-06 19:38:37 +03:00
|
|
|
$breaks
|
|
|
|
.find('.working-plan-exceptions-edit-break, .working-plan-exceptions-delete-break')
|
|
|
|
.removeClass('d-none');
|
2020-10-20 16:03:48 +03:00
|
|
|
$tr.find('.working-plan-exceptions-save-break, .working-plan-exceptions-cancel-break').addClass('d-none');
|
2023-02-20 10:06:12 +03:00
|
|
|
$addBreak.prop('disabled', false);
|
2020-10-20 16:03:48 +03:00
|
|
|
}
|
|
|
|
|
2023-07-10 09:22:55 +03:00
|
|
|
/**
|
|
|
|
* Event: Is Non Working Day "Change"
|
|
|
|
*/
|
|
|
|
function onIsNonWorkingDayChange() {
|
|
|
|
const isNonWorkingDay = $isNonWorkingDay.prop('checked');
|
|
|
|
|
|
|
|
toggleFieldsByNonWorkingDay(isNonWorkingDay);
|
|
|
|
}
|
|
|
|
|
2022-01-14 11:26:44 +03:00
|
|
|
/**
|
|
|
|
* Initialize the module.
|
|
|
|
*/
|
2022-01-14 10:31:12 +03:00
|
|
|
function initialize() {
|
2022-05-26 16:17:33 +03:00
|
|
|
App.Utils.UI.initializeDatepicker($date);
|
|
|
|
App.Utils.UI.initializeTimepicker($start);
|
|
|
|
App.Utils.UI.initializeTimepicker($end);
|
2020-10-20 16:03:48 +03:00
|
|
|
|
2022-01-11 12:50:24 +03:00
|
|
|
$modal
|
|
|
|
.on('hidden.bs.modal', onModalHidden)
|
|
|
|
.on('click', '.working-plan-exceptions-add-break', onAddBreakClick)
|
|
|
|
.on('click', '.working-plan-exceptions-edit-break', onEditBreakClick)
|
|
|
|
.on('click', '.working-plan-exceptions-delete-break', onDeleteBreakClick)
|
|
|
|
.on('click', '.working-plan-exceptions-save-break', onSaveBreakClick)
|
|
|
|
.on('click', '.working-plan-exceptions-cancel-break', onCancelBreakClick);
|
2020-10-20 16:03:48 +03:00
|
|
|
|
2022-01-11 12:50:24 +03:00
|
|
|
$save.on('click', onSaveClick);
|
2023-07-10 09:22:55 +03:00
|
|
|
|
|
|
|
$isNonWorkingDay.on('change', onIsNonWorkingDayChange);
|
2022-01-11 12:50:24 +03:00
|
|
|
}
|
|
|
|
|
2022-01-14 10:31:12 +03:00
|
|
|
document.addEventListener('DOMContentLoaded', initialize);
|
2020-10-20 16:03:48 +03:00
|
|
|
|
2022-01-11 12:50:24 +03:00
|
|
|
return {
|
|
|
|
add,
|
|
|
|
edit
|
2020-10-20 16:03:48 +03:00
|
|
|
};
|
2022-01-11 12:50:24 +03:00
|
|
|
})();
|