2020-10-20 16:03:48 +03:00
|
|
|
/* ----------------------------------------------------------------------------
|
|
|
|
* Easy!Appointments - Open Source Web Scheduler
|
|
|
|
*
|
|
|
|
* @package EasyAppointments
|
|
|
|
* @author A.Tselegidis <alextselegidis@gmail.com>
|
|
|
|
* @copyright Copyright (c) 2013 - 2020, Alex Tselegidis
|
|
|
|
* @license http://opensource.org/licenses/GPL-3.0 - GPLv3
|
|
|
|
* @link http://easyappointments.org
|
|
|
|
* @since v1.2.0
|
|
|
|
* ---------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Backend Calendar Working plan exceptions Modal
|
|
|
|
*
|
|
|
|
* This module implements the working plan exceptions modal functionality.
|
|
|
|
*
|
|
|
|
* @module BackendCalendarWorkingPlanExceptionsModal
|
|
|
|
*/
|
|
|
|
window.BackendCalendarWorkingPlanExceptionsModal = window.BackendCalendarWorkingPlanExceptionsModal || {};
|
|
|
|
|
|
|
|
(function (exports) {
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
function bindEventHandlers() {
|
|
|
|
/**
|
|
|
|
* Event: Manage Modal Save Button "Click"
|
|
|
|
*
|
|
|
|
* Stores the working plan exception changes or inserts a new record.
|
|
|
|
*/
|
|
|
|
$('#manage-working-plan-exceptions #save-working-plan-exception').on('click', function () {
|
2021-11-23 12:06:13 +03:00
|
|
|
$('#manage-working-plan-exceptions .modal-message').prop('hidden', true);
|
2020-10-20 16:03:48 +03:00
|
|
|
|
2021-11-23 12:10:09 +03:00
|
|
|
$('#manage-working-plan-exceptions').find('.is-invalid').removeClass('is-invalid');
|
2020-10-20 16:03:48 +03:00
|
|
|
|
|
|
|
var date = $('#working-plan-exception-date').datetimepicker('getDate');
|
|
|
|
|
|
|
|
if (!date) {
|
2021-11-23 12:10:09 +03:00
|
|
|
$('#working-plan-exception-date').addClass('is-invalid');
|
2020-10-20 16:03:48 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
var start = $('#working-plan-exception-start').datetimepicker('getDate');
|
|
|
|
|
|
|
|
if (!start) {
|
2021-11-23 12:10:09 +03:00
|
|
|
$('#working-plan-exception-start').addClass('is-invalid');
|
2020-10-20 16:03:48 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-11-24 10:34:26 +03:00
|
|
|
var end = moment($('#working-plan-exception-end').datetimepicker('getDate')).toDate();
|
2020-10-20 16:03:48 +03:00
|
|
|
|
|
|
|
if (!end) {
|
2021-11-23 12:10:09 +03:00
|
|
|
$('#working-plan-exception-end').addClass('is-invalid');
|
2020-10-20 16:03:48 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (start > end) {
|
|
|
|
// Start time is after end time - display message to user.
|
|
|
|
$('#manage-working-plan-exceptions .modal-message')
|
|
|
|
.text(EALang.start_date_before_end_error)
|
|
|
|
.addClass('alert-danger')
|
2021-11-23 12:06:13 +03:00
|
|
|
.prop('hidden', false);
|
2020-10-20 16:03:48 +03:00
|
|
|
|
2021-11-23 12:10:09 +03:00
|
|
|
$('#working-plan-exception-start').addClass('is-invalid');
|
|
|
|
$('#working-plan-exception-end').addClass('is-invalid');
|
2020-10-20 16:03:48 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
var workingPlanException = {
|
2021-11-25 10:40:48 +03:00
|
|
|
start: moment(start).format('HH:mm'),
|
|
|
|
end: moment(end).format('HH:mm'),
|
2020-10-20 16:03:48 +03:00
|
|
|
breaks: []
|
|
|
|
};
|
|
|
|
|
|
|
|
var successCallback = function () {
|
|
|
|
// Display success message to the user.
|
|
|
|
Backend.displayNotification(EALang.working_plan_exception_saved);
|
|
|
|
|
|
|
|
// Close the modal modal and update the local provider.
|
2021-11-23 12:06:13 +03:00
|
|
|
$('#manage-working-plan-exceptions .modal-message').prop('hidden', true);
|
2020-10-20 16:03:48 +03:00
|
|
|
$('#manage-working-plan-exceptions').modal('hide');
|
|
|
|
|
|
|
|
var providerId = $('#working-plan-exception-provider').val();
|
2020-12-09 15:17:45 +03:00
|
|
|
var provider = GlobalVariables.availableProviders.find(function (availableProvider) {
|
2020-10-20 16:03:48 +03:00
|
|
|
return Number(availableProvider.id) === Number(providerId);
|
|
|
|
});
|
|
|
|
|
|
|
|
if (!provider) {
|
|
|
|
throw new Error('Provider could not be found: ' + providerId);
|
|
|
|
}
|
|
|
|
|
2021-11-25 10:40:48 +03:00
|
|
|
var selectedDate = moment(date).format('yyyy-MM-dd');
|
2020-12-14 21:38:57 +03:00
|
|
|
var workingPlanExceptions = JSON.parse(provider.settings.working_plan_exceptions);
|
2020-10-20 16:03:48 +03:00
|
|
|
|
|
|
|
workingPlanExceptions[selectedDate] = {
|
2021-11-25 10:40:48 +03:00
|
|
|
start: moment(start).format('HH:mm'),
|
|
|
|
end: moment(end).format('HH:mm'),
|
2021-11-06 19:38:37 +03:00
|
|
|
breaks: []
|
2020-10-20 16:03:48 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
provider.settings.working_plan_exceptions = JSON.stringify(workingPlanExceptions);
|
|
|
|
|
|
|
|
$('#select-filter-item').trigger('change'); // Update the calendar.
|
|
|
|
};
|
|
|
|
|
|
|
|
BackendCalendarApi.saveWorkingPlanException(date, workingPlanException, provider.id, successCallback, null);
|
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Event: Insert Custom Working Time Period Button "Click"
|
|
|
|
*
|
|
|
|
* When the user clicks this button a popup modal appears and the use can set a time period where he cannot
|
|
|
|
* accept any appointments.
|
|
|
|
*/
|
|
|
|
$('#insert-working-plan-exception').on('click', function () {
|
|
|
|
BackendCalendarWorkingPlanExceptionsModal.resetWorkingPlanExceptionModal();
|
|
|
|
|
|
|
|
if ($('.calendar-view').length === 0) {
|
2021-11-06 19:38:37 +03:00
|
|
|
$('#manage-working-plan-exceptions')
|
|
|
|
.find('#working-plan-exception-provider')
|
2020-10-20 16:03:48 +03:00
|
|
|
.val($('#select-filter-item').val())
|
|
|
|
.closest('.form-group')
|
|
|
|
.hide();
|
|
|
|
}
|
|
|
|
|
2021-11-06 19:38:37 +03:00
|
|
|
$('#working-plan-exception-date').val(
|
|
|
|
GeneralFunctions.formatDate(new Date(), GlobalVariables.dateFormat, false)
|
|
|
|
);
|
2020-10-20 16:03:48 +03:00
|
|
|
$('#working-plan-exception-start').val(GlobalVariables.timeFormat === 'regular' ? '8:00 AM' : '08:00');
|
|
|
|
$('#working-plan-exception-end').val(GlobalVariables.timeFormat === 'regular' ? '8:00 PM' : '20:00');
|
|
|
|
$('#manage-working-plan-exceptions').find('.modal-header h3').text(EALang.new_working_plan_exception_title);
|
|
|
|
$('#manage-working-plan-exceptions').modal('show');
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Reset working plan exception modal form.
|
|
|
|
*
|
|
|
|
* Reset the "#manage-working-plan-exceptions" modal. Use this method to bring the modal to the initial state
|
|
|
|
* before it becomes visible to the user.
|
|
|
|
*/
|
|
|
|
exports.resetWorkingPlanExceptionModal = function () {
|
|
|
|
$('#manage-working-plan-exceptions').find('#working-plan-exception-id').val('');
|
|
|
|
|
|
|
|
// Set the default datetime values.
|
|
|
|
var date = new Date();
|
2021-11-06 19:38:37 +03:00
|
|
|
var start = GlobalVariables.timeFormat === 'regular' ? '8:00 AM' : '08:00';
|
|
|
|
var end = GlobalVariables.timeFormat === 'regular' ? '8:00 PM' : '20:00';
|
2020-10-20 16:03:48 +03:00
|
|
|
|
|
|
|
var dateFormat;
|
|
|
|
|
|
|
|
switch (GlobalVariables.dateFormat) {
|
|
|
|
case 'DMY':
|
|
|
|
dateFormat = 'dd/mm/yy';
|
|
|
|
break;
|
|
|
|
case 'MDY':
|
|
|
|
dateFormat = 'mm/dd/yy';
|
|
|
|
break;
|
|
|
|
case 'YMD':
|
|
|
|
dateFormat = 'yy/mm/dd';
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
$('#working-plan-exception-date').datepicker({
|
|
|
|
dateFormat: dateFormat,
|
|
|
|
|
|
|
|
// Translation
|
2021-11-06 19:38:37 +03:00
|
|
|
dayNames: [
|
|
|
|
EALang.sunday,
|
|
|
|
EALang.monday,
|
|
|
|
EALang.tuesday,
|
|
|
|
EALang.wednesday,
|
|
|
|
EALang.thursday,
|
|
|
|
EALang.friday,
|
|
|
|
EALang.saturday
|
|
|
|
],
|
|
|
|
dayNamesShort: [
|
|
|
|
EALang.sunday.substr(0, 3),
|
|
|
|
EALang.monday.substr(0, 3),
|
|
|
|
EALang.tuesday.substr(0, 3),
|
|
|
|
EALang.wednesday.substr(0, 3),
|
|
|
|
EALang.thursday.substr(0, 3),
|
|
|
|
EALang.friday.substr(0, 3),
|
|
|
|
EALang.saturday.substr(0, 3)
|
|
|
|
],
|
|
|
|
dayNamesMin: [
|
|
|
|
EALang.sunday.substr(0, 2),
|
|
|
|
EALang.monday.substr(0, 2),
|
|
|
|
EALang.tuesday.substr(0, 2),
|
|
|
|
EALang.wednesday.substr(0, 2),
|
|
|
|
EALang.thursday.substr(0, 2),
|
|
|
|
EALang.friday.substr(0, 2),
|
|
|
|
EALang.saturday.substr(0, 2)
|
|
|
|
],
|
|
|
|
monthNames: [
|
|
|
|
EALang.january,
|
|
|
|
EALang.february,
|
|
|
|
EALang.march,
|
|
|
|
EALang.april,
|
|
|
|
EALang.may,
|
|
|
|
EALang.june,
|
|
|
|
EALang.july,
|
|
|
|
EALang.august,
|
|
|
|
EALang.september,
|
|
|
|
EALang.october,
|
|
|
|
EALang.november,
|
|
|
|
EALang.december
|
|
|
|
],
|
2020-10-20 16:03:48 +03:00
|
|
|
prevText: EALang.previous,
|
|
|
|
nextText: EALang.next,
|
|
|
|
currentText: EALang.now,
|
|
|
|
closeText: EALang.close,
|
|
|
|
timeOnlyTitle: EALang.select_time,
|
|
|
|
timeText: EALang.time,
|
|
|
|
hourText: EALang.hour,
|
|
|
|
minuteText: EALang.minutes,
|
|
|
|
firstDay: 0
|
|
|
|
});
|
|
|
|
$('#working-plan-exception-date').val(GeneralFunctions.formatDate(date, GlobalVariables.dateFormat, false));
|
|
|
|
|
|
|
|
$('#working-plan-exception-start').timepicker({
|
|
|
|
timeFormat: GlobalVariables.timeFormat === 'regular' ? 'h:mm tt' : GlobalVariables.timeFormat,
|
|
|
|
|
|
|
|
// Translation
|
|
|
|
prevText: EALang.previous,
|
|
|
|
nextText: EALang.next,
|
|
|
|
currentText: EALang.now,
|
|
|
|
closeText: EALang.close,
|
|
|
|
timeOnlyTitle: EALang.select_time,
|
|
|
|
timeText: EALang.time,
|
|
|
|
hourText: EALang.hour,
|
|
|
|
minuteText: EALang.minutes,
|
|
|
|
firstDay: 0
|
|
|
|
});
|
|
|
|
$('#working-plan-exception-start').val(start);
|
|
|
|
|
|
|
|
$('#working-plan-exception-end').timepicker({
|
|
|
|
timeFormat: GlobalVariables.timeFormat === 'regular' ? 'h:mm tt' : GlobalVariables.timeFormat,
|
|
|
|
// Translation
|
|
|
|
prevText: EALang.previous,
|
|
|
|
nextText: EALang.next,
|
|
|
|
currentText: EALang.now,
|
|
|
|
closeText: EALang.close,
|
|
|
|
timeOnlyTitle: EALang.select_time,
|
|
|
|
timeText: EALang.time,
|
|
|
|
hourText: EALang.hour,
|
|
|
|
minuteText: EALang.minutes,
|
|
|
|
firstDay: 0
|
|
|
|
});
|
|
|
|
$('#working-plan-exception-end').val(end);
|
|
|
|
};
|
|
|
|
|
|
|
|
exports.initialize = function () {
|
|
|
|
GlobalVariables.availableProviders.forEach(function (availableProvider) {
|
2021-11-06 19:38:37 +03:00
|
|
|
$('#working-plan-exception-provider').append(
|
|
|
|
new Option(availableProvider.first_name + ' ' + availableProvider.last_name, availableProvider.id)
|
|
|
|
);
|
2020-10-20 16:03:48 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
bindEventHandlers();
|
|
|
|
};
|
|
|
|
})(window.BackendCalendarWorkingPlanExceptionsModal);
|