2016-07-17 15:43:50 +03:00
|
|
|
/* ----------------------------------------------------------------------------
|
2022-01-18 15:05:42 +03:00
|
|
|
* Easy!Appointments - Online Appointment Scheduler
|
2016-07-17 15:43:50 +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-07-17 15:43:50 +03:00
|
|
|
* ---------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
/**
|
2022-01-14 11:26:44 +03:00
|
|
|
* Unavailabilities modal component.
|
2016-07-17 15:43:50 +03:00
|
|
|
*
|
2022-01-14 11:26:44 +03:00
|
|
|
* This module implements the unavailabilities modal functionality.
|
2016-07-17 15:43:50 +03:00
|
|
|
*
|
2022-01-14 10:43:53 +03:00
|
|
|
* Old Name: BackendCalendarUnavailabilityEventsModal
|
2016-07-17 15:43:50 +03:00
|
|
|
*/
|
2022-01-14 10:43:53 +03:00
|
|
|
App.Components.UnavailabilitiesModal = (function () {
|
2022-01-17 06:46:18 +03:00
|
|
|
const $unavailabilitiesModal = $('#unavailabilities-modal');
|
2022-01-18 17:55:21 +03:00
|
|
|
const $id = $('#unavailability-id');
|
|
|
|
const $startDatetime = $('#unavailability-start');
|
|
|
|
const $endDatetime = $('#unavailability-end');
|
|
|
|
const $selectProvider = $('#unavailability-provider');
|
|
|
|
const $notes = $('#unavailability-notes');
|
2022-01-17 06:46:18 +03:00
|
|
|
const $saveUnavailability = $('#save-unavailability');
|
|
|
|
const $insertUnavailability = $('#insert-unavailability');
|
|
|
|
const $selectFilterItem = $('#select-filter-item');
|
2022-01-18 17:55:21 +03:00
|
|
|
const $reloadAppointments = $('#reload-appointments');
|
2022-01-17 06:46:18 +03:00
|
|
|
|
2022-01-14 11:26:44 +03:00
|
|
|
/**
|
2022-01-17 06:46:18 +03:00
|
|
|
* Add the component event listeners.
|
2022-01-14 11:26:44 +03:00
|
|
|
*/
|
2022-01-17 06:46:18 +03:00
|
|
|
function addEventListeners() {
|
2016-07-17 15:43:50 +03:00
|
|
|
/**
|
2022-01-18 14:54:41 +03:00
|
|
|
* Event: Manage Unavailability Dialog Save Button "Click"
|
2016-07-17 15:43:50 +03:00
|
|
|
*
|
2022-01-18 14:54:41 +03:00
|
|
|
* Stores the unavailability period changes or inserts a new record.
|
2016-07-17 15:43:50 +03:00
|
|
|
*/
|
2022-01-17 06:46:18 +03:00
|
|
|
$saveUnavailability.on('click', () => {
|
|
|
|
$unavailabilitiesModal.find('.modal-message').addClass('d-none');
|
|
|
|
$unavailabilitiesModal.find('.is-invalid').removeClass('is-invalid');
|
2020-09-28 15:17:47 +03:00
|
|
|
|
2022-01-18 17:55:21 +03:00
|
|
|
const startMoment = moment($startDatetime.datetimepicker('getDate'));
|
2020-09-28 15:17:47 +03:00
|
|
|
|
2021-11-24 11:23:36 +03:00
|
|
|
if (!startMoment.isValid()) {
|
2022-01-18 17:55:21 +03:00
|
|
|
$startDatetime.addClass('is-invalid');
|
2020-09-28 15:17:47 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-01-18 17:55:21 +03:00
|
|
|
const endMoment = moment($endDatetime.datetimepicker('getDate'));
|
2016-07-17 15:43:50 +03:00
|
|
|
|
2021-11-24 11:23:36 +03:00
|
|
|
if (!endMoment.isValid()) {
|
2022-01-18 17:55:21 +03:00
|
|
|
$endDatetime.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.
|
2022-01-17 06:46:18 +03:00
|
|
|
$unavailabilitiesModal
|
2021-11-06 19:38:37 +03:00
|
|
|
.find('.modal-message')
|
2022-01-18 10:22:25 +03:00
|
|
|
.text(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
|
|
|
|
2022-01-18 17:55:21 +03:00
|
|
|
$startDatetime.addClass('is-invalid');
|
2022-01-17 06:46:18 +03:00
|
|
|
|
2022-01-18 17:55:21 +03:00
|
|
|
$endDatetime.addClass('is-invalid');
|
2021-11-24 11:23:36 +03:00
|
|
|
|
2016-07-17 15:43:50 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-01-18 14:54:41 +03:00
|
|
|
// Unavailability period records go to the appointments table.
|
2022-01-17 06:46:18 +03:00
|
|
|
const unavailability = {
|
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'),
|
2022-01-17 06:46:18 +03:00
|
|
|
notes: $unavailabilitiesModal.find('#unavailability-notes').val(),
|
|
|
|
id_users_provider: $('#unavailability-provider').val()
|
2016-07-17 15:43:50 +03:00
|
|
|
};
|
|
|
|
|
2022-01-18 17:55:21 +03:00
|
|
|
if ($id.val() !== '') {
|
2016-07-17 15:43:50 +03:00
|
|
|
// Set the id value, only if we are editing an appointment.
|
2022-01-18 17:55:21 +03:00
|
|
|
unavailability.id = $id.val();
|
2016-07-17 15:43:50 +03:00
|
|
|
}
|
|
|
|
|
2022-01-12 13:22:54 +03:00
|
|
|
const successCallback = () => {
|
2016-07-17 15:43:50 +03:00
|
|
|
// Display success message to the user.
|
2022-01-18 14:54:41 +03:00
|
|
|
App.Layouts.Backend.displayNotification(lang('unavailability_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.
|
2022-01-17 06:46:18 +03:00
|
|
|
$unavailabilitiesModal.find('.alert').addClass('d-none');
|
2021-11-24 11:23:36 +03:00
|
|
|
|
2022-01-17 06:46:18 +03:00
|
|
|
$unavailabilitiesModal.modal('hide');
|
2021-11-24 11:23:36 +03:00
|
|
|
|
2022-01-18 19:38:25 +03:00
|
|
|
$reloadAppointments.trigger('click');
|
2016-07-17 15:43:50 +03:00
|
|
|
};
|
|
|
|
|
2022-01-18 14:54:41 +03:00
|
|
|
App.Http.Calendar.saveUnavailability(unavailability, successCallback, null);
|
2016-07-17 15:43:50 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
2022-01-18 14:54:41 +03:00
|
|
|
* Event : Insert Unavailability Time Period Button "Click"
|
2016-07-17 15:43:50 +03:00
|
|
|
*
|
|
|
|
* 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-17 06:46:18 +03:00
|
|
|
$insertUnavailability.on('click', () => {
|
|
|
|
resetModal();
|
2022-01-12 13:22:54 +03:00
|
|
|
|
2022-01-14 10:43:53 +03:00
|
|
|
const $dialog = $('#unavailabilities-modal');
|
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) {
|
2022-01-18 17:55:21 +03:00
|
|
|
$selectProvider.val($selectFilterItem.val()).closest('.form-group').hide();
|
2016-07-18 23:55:05 +03:00
|
|
|
}
|
|
|
|
|
2022-01-18 17:55:21 +03:00
|
|
|
$startDatetime.val(
|
2022-01-18 10:18:22 +03:00
|
|
|
App.Utils.Date.format(startMoment.toDate(), vars('date_format'), vars('time_format'), true)
|
2022-01-17 06:46:18 +03:00
|
|
|
);
|
2022-01-18 17:55:21 +03:00
|
|
|
$endDatetime.val(
|
2022-01-17 06:46:18 +03:00
|
|
|
App.Utils.Date.format(
|
|
|
|
startMoment.add(1, 'hour').toDate(),
|
2022-01-18 10:18:22 +03:00
|
|
|
vars('date_format'),
|
|
|
|
vars('time_format'),
|
2022-01-17 06:46:18 +03:00
|
|
|
true
|
|
|
|
)
|
|
|
|
);
|
2022-01-18 14:54:41 +03:00
|
|
|
$dialog.find('.modal-header h3').text(lang('new_unavailability_title'));
|
2016-07-17 15:43:50 +03:00
|
|
|
$dialog.modal('show');
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2022-01-18 14:54:41 +03:00
|
|
|
* Reset unavailability dialog form.
|
2016-07-17 15:43:50 +03:00
|
|
|
*
|
2022-01-14 10:43:53 +03:00
|
|
|
* Reset the "#unavailabilities-modal" dialog. Use this method to bring the dialog to the initial state
|
2016-07-17 15:43:50 +03:00
|
|
|
* before it becomes visible to the user.
|
|
|
|
*/
|
2022-01-17 06:46:18 +03:00
|
|
|
function resetModal() {
|
2022-01-18 17:55:21 +03:00
|
|
|
$id.val('');
|
2016-07-17 15:43:50 +03:00
|
|
|
|
|
|
|
// Set default time values
|
2022-01-18 10:18:22 +03:00
|
|
|
const start = App.Utils.Date.format(moment().toDate(), vars('date_format'), 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(),
|
2022-01-18 10:18:22 +03:00
|
|
|
vars('date_format'),
|
|
|
|
vars('time_format'),
|
2022-01-12 13:22:54 +03:00
|
|
|
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-18 10:18:22 +03:00
|
|
|
switch (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-18 10:18:22 +03:00
|
|
|
const firstWeekday = vars('first_weekday');
|
2022-01-12 13:22:54 +03:00
|
|
|
|
|
|
|
const firstWeekdayId = App.Utils.Date.getWeekdayId(firstWeekday);
|
2016-07-17 15:43:50 +03:00
|
|
|
|
2022-01-18 17:55:21 +03:00
|
|
|
$startDatetime.datetimepicker({
|
2016-07-17 15:43:50 +03:00
|
|
|
dateFormat: dateFormat,
|
2022-01-18 10:18:22 +03:00
|
|
|
timeFormat: 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: [
|
2022-01-18 10:22:25 +03:00
|
|
|
lang('sunday'),
|
|
|
|
lang('monday'),
|
|
|
|
lang('tuesday'),
|
|
|
|
lang('wednesday'),
|
|
|
|
lang('thursday'),
|
|
|
|
lang('friday'),
|
|
|
|
lang('saturday')
|
2021-11-06 19:38:37 +03:00
|
|
|
],
|
|
|
|
dayNamesShort: [
|
2022-01-18 10:22:25 +03:00
|
|
|
lang('sunday').substr(0, 3),
|
|
|
|
lang('monday').substr(0, 3),
|
|
|
|
lang('tuesday').substr(0, 3),
|
|
|
|
lang('wednesday').substr(0, 3),
|
|
|
|
lang('thursday').substr(0, 3),
|
|
|
|
lang('friday').substr(0, 3),
|
|
|
|
lang('saturday').substr(0, 3)
|
2021-11-06 19:38:37 +03:00
|
|
|
],
|
|
|
|
dayNamesMin: [
|
2022-01-18 10:22:25 +03:00
|
|
|
lang('sunday').substr(0, 2),
|
|
|
|
lang('monday').substr(0, 2),
|
|
|
|
lang('tuesday').substr(0, 2),
|
|
|
|
lang('wednesday').substr(0, 2),
|
|
|
|
lang('thursday').substr(0, 2),
|
|
|
|
lang('friday').substr(0, 2),
|
|
|
|
lang('saturday').substr(0, 2)
|
2021-11-06 19:38:37 +03:00
|
|
|
],
|
|
|
|
monthNames: [
|
2022-01-18 10:22:25 +03:00
|
|
|
lang('january'),
|
|
|
|
lang('february'),
|
|
|
|
lang('march'),
|
|
|
|
lang('april'),
|
|
|
|
lang('may'),
|
|
|
|
lang('june'),
|
|
|
|
lang('july'),
|
|
|
|
lang('august'),
|
|
|
|
lang('september'),
|
|
|
|
lang('october'),
|
|
|
|
lang('november'),
|
|
|
|
lang('december')
|
2021-11-06 19:38:37 +03:00
|
|
|
],
|
2022-01-18 10:22:25 +03:00
|
|
|
prevText: lang('previous'),
|
|
|
|
nextText: lang('next'),
|
|
|
|
currentText: lang('now'),
|
|
|
|
closeText: lang('close'),
|
|
|
|
timeOnlyTitle: lang('select_time'),
|
|
|
|
timeText: lang('time'),
|
|
|
|
hourText: lang('hour'),
|
|
|
|
minuteText: lang('minutes'),
|
2022-01-12 13:22:54 +03:00
|
|
|
firstDay: firstWeekdayId
|
2016-07-17 15:43:50 +03:00
|
|
|
});
|
2022-01-18 17:55:21 +03:00
|
|
|
$startDatetime.val(start);
|
2016-07-17 15:43:50 +03:00
|
|
|
|
2022-01-18 17:55:21 +03:00
|
|
|
$endDatetime.datetimepicker({
|
2016-07-17 15:43:50 +03:00
|
|
|
dateFormat: dateFormat,
|
2022-01-18 10:18:22 +03:00
|
|
|
timeFormat: 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: [
|
2022-01-18 10:22:25 +03:00
|
|
|
lang('sunday'),
|
|
|
|
lang('monday'),
|
|
|
|
lang('tuesday'),
|
|
|
|
lang('wednesday'),
|
|
|
|
lang('thursday'),
|
|
|
|
lang('friday'),
|
|
|
|
lang('saturday')
|
2021-11-06 19:38:37 +03:00
|
|
|
],
|
|
|
|
dayNamesShort: [
|
2022-01-18 10:22:25 +03:00
|
|
|
lang('sunday').substr(0, 3),
|
|
|
|
lang('monday').substr(0, 3),
|
|
|
|
lang('tuesday').substr(0, 3),
|
|
|
|
lang('wednesday').substr(0, 3),
|
|
|
|
lang('thursday').substr(0, 3),
|
|
|
|
lang('friday').substr(0, 3),
|
|
|
|
lang('saturday').substr(0, 3)
|
2021-11-06 19:38:37 +03:00
|
|
|
],
|
|
|
|
dayNamesMin: [
|
2022-01-18 10:22:25 +03:00
|
|
|
lang('sunday').substr(0, 2),
|
|
|
|
lang('monday').substr(0, 2),
|
|
|
|
lang('tuesday').substr(0, 2),
|
|
|
|
lang('wednesday').substr(0, 2),
|
|
|
|
lang('thursday').substr(0, 2),
|
|
|
|
lang('friday').substr(0, 2),
|
|
|
|
lang('saturday').substr(0, 2)
|
2021-11-06 19:38:37 +03:00
|
|
|
],
|
|
|
|
monthNames: [
|
2022-01-18 10:22:25 +03:00
|
|
|
lang('january'),
|
|
|
|
lang('february'),
|
|
|
|
lang('march'),
|
|
|
|
lang('april'),
|
|
|
|
lang('may'),
|
|
|
|
lang('june'),
|
|
|
|
lang('july'),
|
|
|
|
lang('august'),
|
|
|
|
lang('september'),
|
|
|
|
lang('october'),
|
|
|
|
lang('november'),
|
|
|
|
lang('december')
|
2021-11-06 19:38:37 +03:00
|
|
|
],
|
2022-01-18 10:22:25 +03:00
|
|
|
prevText: lang('previous'),
|
|
|
|
nextText: lang('next'),
|
|
|
|
currentText: lang('now'),
|
|
|
|
closeText: lang('close'),
|
|
|
|
timeOnlyTitle: lang('select_time'),
|
|
|
|
timeText: lang('time'),
|
|
|
|
hourText: lang('hour'),
|
|
|
|
minuteText: lang('minutes'),
|
2022-01-12 13:22:54 +03:00
|
|
|
firstDay: firstWeekdayId
|
2016-07-17 15:43:50 +03:00
|
|
|
});
|
2022-01-18 17:55:21 +03:00
|
|
|
$endDatetime.val(end);
|
2016-07-17 15:43:50 +03:00
|
|
|
|
2022-01-18 14:54:41 +03:00
|
|
|
// Clear the unavailability notes field.
|
2022-01-18 17:55:21 +03:00
|
|
|
$notes.val('');
|
2022-01-12 13:22:54 +03:00
|
|
|
}
|
2016-07-17 15:43:50 +03:00
|
|
|
|
2022-01-14 11:26:44 +03:00
|
|
|
/**
|
|
|
|
* Initialize the module.
|
|
|
|
*/
|
2022-01-12 13:22:54 +03:00
|
|
|
function initialize() {
|
2022-01-18 10:18:22 +03:00
|
|
|
for (const index in vars('available_providers')) {
|
|
|
|
const provider = vars('available_providers')[index];
|
2016-07-18 23:55:05 +03:00
|
|
|
|
2022-01-18 17:55:21 +03:00
|
|
|
$selectProvider.append(new Option(provider.first_name + ' ' + provider.last_name, provider.id));
|
2016-07-18 23:55:05 +03:00
|
|
|
}
|
|
|
|
|
2022-01-17 06:46:18 +03:00
|
|
|
addEventListeners();
|
2022-01-12 13:22:54 +03:00
|
|
|
}
|
|
|
|
|
2022-01-17 06:46:18 +03:00
|
|
|
document.addEventListener('DOMContentLoaded', initialize);
|
|
|
|
|
2022-01-12 13:22:54 +03:00
|
|
|
return {
|
2022-01-17 06:46:18 +03:00
|
|
|
resetModal,
|
2022-01-12 13:22:54 +03:00
|
|
|
initialize
|
2016-07-17 15:43:50 +03:00
|
|
|
};
|
2022-01-12 13:22:54 +03:00
|
|
|
})();
|