2016-07-17 15:43:50 +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-07-17 15:43:50 +03:00
|
|
|
* @since v1.2.0
|
|
|
|
* ---------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
/**
|
2020-10-21 21:36:37 +03:00
|
|
|
* Backend Calendar Unavailability Events Modal
|
2016-07-17 15:43:50 +03:00
|
|
|
*
|
2020-10-21 21:36:37 +03:00
|
|
|
* This module implements the unavailability events modal functionality.
|
2016-07-17 15:43:50 +03:00
|
|
|
*
|
2022-01-12 13:22:54 +03:00
|
|
|
* Old Module Name: BackendCalendarUnavailabilityEventsModal
|
2016-07-17 15:43:50 +03:00
|
|
|
*/
|
2022-01-12 13:22:54 +03:00
|
|
|
App.Components.ManageUnavailabilitiesModal = (function () {
|
2020-05-06 20:23:49 +03:00
|
|
|
function bindEventHandlers() {
|
2016-07-17 15:43:50 +03:00
|
|
|
/**
|
|
|
|
* Event: Manage Unavailable Dialog Save Button "Click"
|
|
|
|
*
|
|
|
|
* Stores the unavailable period changes or inserts a new record.
|
|
|
|
*/
|
2022-01-12 13:22:54 +03:00
|
|
|
$('#manage-unavailable #save-unavailable').on('click', () => {
|
|
|
|
const $dialog = $('#manage-unavailable');
|
2020-09-28 15:17:47 +03:00
|
|
|
$dialog.find('.modal-message').addClass('d-none');
|
2021-11-23 12:10:09 +03:00
|
|
|
$dialog.find('.is-invalid').removeClass('is-invalid');
|
2020-09-28 15:17:47 +03:00
|
|
|
|
2022-01-12 13:22:54 +03:00
|
|
|
const startMoment = moment($dialog.find('#unavailable-start').datetimepicker('getDate'));
|
2020-09-28 15:17:47 +03:00
|
|
|
|
2021-11-24 11:23:36 +03:00
|
|
|
if (!startMoment.isValid()) {
|
2021-11-23 12:10:09 +03:00
|
|
|
$dialog.find('#unavailable-start').addClass('is-invalid');
|
2021-11-24 11:23:36 +03:00
|
|
|
|
2020-09-28 15:17:47 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-01-12 13:22:54 +03:00
|
|
|
const endMoment = moment($dialog.find('#unavailable-end').datetimepicker('getDate'));
|
2016-07-17 15:43:50 +03:00
|
|
|
|
2021-11-24 11:23:36 +03:00
|
|
|
if (!endMoment.isValid()) {
|
2021-11-23 12:10:09 +03:00
|
|
|
$dialog.find('#unavailable-end').addClass('is-invalid');
|
2021-11-24 11:23:36 +03:00
|
|
|
|
2020-09-28 15:17:47 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-11-24 11:23:36 +03:00
|
|
|
if (startMoment.isAfter(endMoment)) {
|
2016-07-17 15:43:50 +03:00
|
|
|
// Start time is after end time - display message to user.
|
2021-11-06 19:38:37 +03:00
|
|
|
$dialog
|
|
|
|
.find('.modal-message')
|
2021-12-13 09:52:09 +03:00
|
|
|
.text(App.Lang.start_date_before_end_error)
|
2016-07-17 15:43:50 +03:00
|
|
|
.addClass('alert-danger')
|
2020-06-18 21:37:11 +03:00
|
|
|
.removeClass('d-none');
|
2017-11-14 15:52:59 +03:00
|
|
|
|
2021-11-23 12:10:09 +03:00
|
|
|
$dialog.find('#unavailable-start, #unavailable-end').addClass('is-invalid');
|
2021-11-24 11:23:36 +03:00
|
|
|
|
2016-07-17 15:43:50 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Unavailable period records go to the appointments table.
|
2022-01-12 13:22:54 +03:00
|
|
|
const unavailable = {
|
2021-11-24 11:23:36 +03:00
|
|
|
start_datetime: startMoment.format('YYYY-MM-DD HH:mm:ss'),
|
|
|
|
end_datetime: endMoment.format('YYYY-MM-DD HH:mm:ss'),
|
2016-07-17 15:43:50 +03:00
|
|
|
notes: $dialog.find('#unavailable-notes').val(),
|
2021-11-24 11:23:36 +03:00
|
|
|
id_users_provider: $('#unavailable-provider').val()
|
2016-07-17 15:43:50 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
if ($dialog.find('#unavailable-id').val() !== '') {
|
|
|
|
// Set the id value, only if we are editing an appointment.
|
|
|
|
unavailable.id = $dialog.find('#unavailable-id').val();
|
|
|
|
}
|
|
|
|
|
2022-01-12 13:22:54 +03:00
|
|
|
const successCallback = () => {
|
2016-07-17 15:43:50 +03:00
|
|
|
// Display success message to the user.
|
2021-12-13 09:52:09 +03:00
|
|
|
Backend.displayNotification(App.Lang.unavailable_saved);
|
2016-07-17 15:43:50 +03:00
|
|
|
|
2020-05-03 23:40:29 +03:00
|
|
|
// Close the modal dialog and refresh the calendar appointments.
|
2020-06-18 21:37:11 +03:00
|
|
|
$dialog.find('.alert').addClass('d-none');
|
2021-11-24 11:23:36 +03:00
|
|
|
|
2020-05-03 23:40:29 +03:00
|
|
|
$dialog.modal('hide');
|
2021-11-24 11:23:36 +03:00
|
|
|
|
2020-05-03 23:40:29 +03:00
|
|
|
$('#select-filter-item').trigger('change');
|
2016-07-17 15:43:50 +03:00
|
|
|
};
|
|
|
|
|
2022-01-12 13:22:54 +03:00
|
|
|
App.Http.Calendar.saveUnavailable(unavailable, successCallback, null);
|
2016-07-17 15:43:50 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Event : Insert Unavailable Time Period Button "Click"
|
|
|
|
*
|
|
|
|
* When the user clicks this button a popup dialog appears and the use can set a time period where
|
|
|
|
* he cannot accept any appointments.
|
|
|
|
*/
|
2022-01-12 13:22:54 +03:00
|
|
|
$('#insert-unavailable').on('click', () => {
|
|
|
|
resetUnavailableDialog();
|
|
|
|
|
|
|
|
const $dialog = $('#manage-unavailable');
|
2016-07-17 15:43:50 +03:00
|
|
|
|
|
|
|
// Set the default datetime values.
|
2022-01-12 13:22:54 +03:00
|
|
|
const startMoment = moment();
|
2021-11-24 10:34:26 +03:00
|
|
|
|
2022-01-12 13:22:54 +03:00
|
|
|
const currentMin = parseInt(startMoment.format('mm'));
|
2016-07-17 15:43:50 +03:00
|
|
|
|
|
|
|
if (currentMin > 0 && currentMin < 15) {
|
2021-11-24 10:34:26 +03:00
|
|
|
startMoment.set({minutes: 15});
|
2016-07-17 15:43:50 +03:00
|
|
|
} else if (currentMin > 15 && currentMin < 30) {
|
2021-11-24 10:34:26 +03:00
|
|
|
startMoment.set({minutes: 30});
|
2016-07-17 15:43:50 +03:00
|
|
|
} else if (currentMin > 30 && currentMin < 45) {
|
2021-11-24 10:34:26 +03:00
|
|
|
startMoment.set({minutes: 45});
|
2016-07-17 15:43:50 +03:00
|
|
|
} else {
|
2021-11-24 10:34:26 +03:00
|
|
|
startMoment.add(1, 'hour').set({minutes: 0});
|
2016-07-17 15:43:50 +03:00
|
|
|
}
|
|
|
|
|
2016-07-18 23:55:05 +03:00
|
|
|
if ($('.calendar-view').length === 0) {
|
2021-11-06 19:38:37 +03:00
|
|
|
$dialog.find('#unavailable-provider').val($('#select-filter-item').val()).closest('.form-group').hide();
|
2016-07-18 23:55:05 +03:00
|
|
|
}
|
|
|
|
|
2021-11-06 19:38:37 +03:00
|
|
|
$dialog
|
|
|
|
.find('#unavailable-start')
|
2022-01-12 13:22:54 +03:00
|
|
|
.val(App.Utils.Date.format(startMoment.toDate(), App.Vars.date_format, App.Vars.time_format, true));
|
2021-11-06 19:38:37 +03:00
|
|
|
$dialog
|
|
|
|
.find('#unavailable-end')
|
2021-11-24 10:34:26 +03:00
|
|
|
.val(
|
2022-01-12 13:22:54 +03:00
|
|
|
App.Utils.Date.format(
|
|
|
|
startMoment.add(1, 'hour').toDate(),
|
|
|
|
App.Vars.date_format,
|
|
|
|
App.Vars.time_format,
|
|
|
|
true
|
|
|
|
)
|
2021-11-24 10:34:26 +03:00
|
|
|
);
|
2021-12-13 09:52:09 +03:00
|
|
|
$dialog.find('.modal-header h3').text(App.Lang.new_unavailable_title);
|
2016-07-17 15:43:50 +03:00
|
|
|
$dialog.modal('show');
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Reset unavailable dialog form.
|
|
|
|
*
|
|
|
|
* Reset the "#manage-unavailable" dialog. Use this method to bring the dialog to the initial state
|
|
|
|
* before it becomes visible to the user.
|
|
|
|
*/
|
2022-01-12 13:22:54 +03:00
|
|
|
function resetUnavailableDialog() {
|
|
|
|
const $dialog = $('#manage-unavailable');
|
2016-07-17 15:43:50 +03:00
|
|
|
|
|
|
|
$dialog.find('#unavailable-id').val('');
|
|
|
|
|
|
|
|
// Set default time values
|
2022-01-12 13:22:54 +03:00
|
|
|
const start = App.Utils.Date.format(moment().toDate(), App.Vars.date_format, App.Vars.time_format, true);
|
2021-11-24 10:34:26 +03:00
|
|
|
|
2022-01-12 13:22:54 +03:00
|
|
|
const end = App.Utils.Date.format(
|
|
|
|
moment().add(1, 'hour').toDate(),
|
|
|
|
App.Vars.date_format,
|
|
|
|
App.Vars.time_format,
|
|
|
|
true
|
|
|
|
);
|
2021-11-24 10:34:26 +03:00
|
|
|
|
2022-01-12 13:22:54 +03:00
|
|
|
let dateFormat;
|
2016-07-17 15:43:50 +03:00
|
|
|
|
2022-01-12 13:22:54 +03:00
|
|
|
switch (App.Vars.date_format) {
|
2016-07-17 15:43:50 +03:00
|
|
|
case 'DMY':
|
|
|
|
dateFormat = 'dd/mm/yy';
|
|
|
|
break;
|
|
|
|
case 'MDY':
|
|
|
|
dateFormat = 'mm/dd/yy';
|
|
|
|
break;
|
|
|
|
case 'YMD':
|
|
|
|
dateFormat = 'yy/mm/dd';
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2022-01-12 13:22:54 +03:00
|
|
|
const firstWeekday = App.Vars.first_weekday;
|
|
|
|
|
|
|
|
const firstWeekdayId = App.Utils.Date.getWeekdayId(firstWeekday);
|
2016-07-17 15:43:50 +03:00
|
|
|
|
|
|
|
$dialog.find('#unavailable-start').datetimepicker({
|
|
|
|
dateFormat: dateFormat,
|
2022-01-12 13:22:54 +03:00
|
|
|
timeFormat: App.Vars.time_format === 'regular' ? 'h:mm tt' : 'HH:mm',
|
2016-07-17 15:43:50 +03:00
|
|
|
|
|
|
|
// Translation
|
2021-11-06 19:38:37 +03:00
|
|
|
dayNames: [
|
2021-12-13 09:52:09 +03:00
|
|
|
App.Lang.sunday,
|
|
|
|
App.Lang.monday,
|
|
|
|
App.Lang.tuesday,
|
|
|
|
App.Lang.wednesday,
|
|
|
|
App.Lang.thursday,
|
|
|
|
App.Lang.friday,
|
|
|
|
App.Lang.saturday
|
2021-11-06 19:38:37 +03:00
|
|
|
],
|
|
|
|
dayNamesShort: [
|
2021-12-13 09:52:09 +03:00
|
|
|
App.Lang.sunday.substr(0, 3),
|
|
|
|
App.Lang.monday.substr(0, 3),
|
|
|
|
App.Lang.tuesday.substr(0, 3),
|
|
|
|
App.Lang.wednesday.substr(0, 3),
|
|
|
|
App.Lang.thursday.substr(0, 3),
|
|
|
|
App.Lang.friday.substr(0, 3),
|
|
|
|
App.Lang.saturday.substr(0, 3)
|
2021-11-06 19:38:37 +03:00
|
|
|
],
|
|
|
|
dayNamesMin: [
|
2021-12-13 09:52:09 +03:00
|
|
|
App.Lang.sunday.substr(0, 2),
|
|
|
|
App.Lang.monday.substr(0, 2),
|
|
|
|
App.Lang.tuesday.substr(0, 2),
|
|
|
|
App.Lang.wednesday.substr(0, 2),
|
|
|
|
App.Lang.thursday.substr(0, 2),
|
|
|
|
App.Lang.friday.substr(0, 2),
|
|
|
|
App.Lang.saturday.substr(0, 2)
|
2021-11-06 19:38:37 +03:00
|
|
|
],
|
|
|
|
monthNames: [
|
2021-12-13 09:52:09 +03:00
|
|
|
App.Lang.january,
|
|
|
|
App.Lang.february,
|
|
|
|
App.Lang.march,
|
|
|
|
App.Lang.april,
|
|
|
|
App.Lang.may,
|
|
|
|
App.Lang.june,
|
|
|
|
App.Lang.july,
|
|
|
|
App.Lang.august,
|
|
|
|
App.Lang.september,
|
|
|
|
App.Lang.october,
|
|
|
|
App.Lang.november,
|
|
|
|
App.Lang.december
|
2021-11-06 19:38:37 +03:00
|
|
|
],
|
2021-12-13 09:52:09 +03:00
|
|
|
prevText: App.Lang.previous,
|
|
|
|
nextText: App.Lang.next,
|
|
|
|
currentText: App.Lang.now,
|
|
|
|
closeText: App.Lang.close,
|
|
|
|
timeOnlyTitle: App.Lang.select_time,
|
|
|
|
timeText: App.Lang.time,
|
|
|
|
hourText: App.Lang.hour,
|
|
|
|
minuteText: App.Lang.minutes,
|
2022-01-12 13:22:54 +03:00
|
|
|
firstDay: firstWeekdayId
|
2016-07-17 15:43:50 +03:00
|
|
|
});
|
|
|
|
$dialog.find('#unavailable-start').val(start);
|
|
|
|
|
|
|
|
$dialog.find('#unavailable-end').datetimepicker({
|
|
|
|
dateFormat: dateFormat,
|
2022-01-12 13:22:54 +03:00
|
|
|
timeFormat: App.Vars.time_format === 'regular' ? 'h:mm tt' : 'HH:mm',
|
2016-07-17 15:43:50 +03:00
|
|
|
|
|
|
|
// Translation
|
2021-11-06 19:38:37 +03:00
|
|
|
dayNames: [
|
2021-12-13 09:52:09 +03:00
|
|
|
App.Lang.sunday,
|
|
|
|
App.Lang.monday,
|
|
|
|
App.Lang.tuesday,
|
|
|
|
App.Lang.wednesday,
|
|
|
|
App.Lang.thursday,
|
|
|
|
App.Lang.friday,
|
|
|
|
App.Lang.saturday
|
2021-11-06 19:38:37 +03:00
|
|
|
],
|
|
|
|
dayNamesShort: [
|
2021-12-13 09:52:09 +03:00
|
|
|
App.Lang.sunday.substr(0, 3),
|
|
|
|
App.Lang.monday.substr(0, 3),
|
|
|
|
App.Lang.tuesday.substr(0, 3),
|
|
|
|
App.Lang.wednesday.substr(0, 3),
|
|
|
|
App.Lang.thursday.substr(0, 3),
|
|
|
|
App.Lang.friday.substr(0, 3),
|
|
|
|
App.Lang.saturday.substr(0, 3)
|
2021-11-06 19:38:37 +03:00
|
|
|
],
|
|
|
|
dayNamesMin: [
|
2021-12-13 09:52:09 +03:00
|
|
|
App.Lang.sunday.substr(0, 2),
|
|
|
|
App.Lang.monday.substr(0, 2),
|
|
|
|
App.Lang.tuesday.substr(0, 2),
|
|
|
|
App.Lang.wednesday.substr(0, 2),
|
|
|
|
App.Lang.thursday.substr(0, 2),
|
|
|
|
App.Lang.friday.substr(0, 2),
|
|
|
|
App.Lang.saturday.substr(0, 2)
|
2021-11-06 19:38:37 +03:00
|
|
|
],
|
|
|
|
monthNames: [
|
2021-12-13 09:52:09 +03:00
|
|
|
App.Lang.january,
|
|
|
|
App.Lang.february,
|
|
|
|
App.Lang.march,
|
|
|
|
App.Lang.april,
|
|
|
|
App.Lang.may,
|
|
|
|
App.Lang.june,
|
|
|
|
App.Lang.july,
|
|
|
|
App.Lang.august,
|
|
|
|
App.Lang.september,
|
|
|
|
App.Lang.october,
|
|
|
|
App.Lang.november,
|
|
|
|
App.Lang.december
|
2021-11-06 19:38:37 +03:00
|
|
|
],
|
2021-12-13 09:52:09 +03:00
|
|
|
prevText: App.Lang.previous,
|
|
|
|
nextText: App.Lang.next,
|
|
|
|
currentText: App.Lang.now,
|
|
|
|
closeText: App.Lang.close,
|
|
|
|
timeOnlyTitle: App.Lang.select_time,
|
|
|
|
timeText: App.Lang.time,
|
|
|
|
hourText: App.Lang.hour,
|
|
|
|
minuteText: App.Lang.minutes,
|
2022-01-12 13:22:54 +03:00
|
|
|
firstDay: firstWeekdayId
|
2016-07-17 15:43:50 +03:00
|
|
|
});
|
|
|
|
$dialog.find('#unavailable-end').val(end);
|
|
|
|
|
|
|
|
// Clear the unavailable notes field.
|
|
|
|
$dialog.find('#unavailable-notes').val('');
|
2022-01-12 13:22:54 +03:00
|
|
|
}
|
2016-07-17 15:43:50 +03:00
|
|
|
|
2022-01-12 13:22:54 +03:00
|
|
|
function initialize() {
|
|
|
|
const $unavailabilityProvider = $('#unavailable-provider');
|
2016-07-18 23:55:05 +03:00
|
|
|
|
2022-01-12 13:22:54 +03:00
|
|
|
for (const index in App.Vars.available_providers) {
|
|
|
|
const provider = App.Vars.available_providers[index];
|
2016-07-18 23:55:05 +03:00
|
|
|
|
|
|
|
$unavailabilityProvider.append(new Option(provider.first_name + ' ' + provider.last_name, provider.id));
|
|
|
|
}
|
|
|
|
|
2020-05-06 20:23:49 +03:00
|
|
|
bindEventHandlers();
|
2022-01-12 13:22:54 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
resetUnavailableDialog,
|
|
|
|
initialize
|
2016-07-17 15:43:50 +03:00
|
|
|
};
|
2022-01-12 13:22:54 +03:00
|
|
|
})();
|