2016-07-17 15:43:50 +03:00
|
|
|
/* ----------------------------------------------------------------------------
|
|
|
|
* Easy!Appointments - Open Source Web Scheduler
|
|
|
|
*
|
|
|
|
* @package EasyAppointments
|
|
|
|
* @author A.Tselegidis <alextselegidis@gmail.com>
|
2020-03-11 12:10:59 +03:00
|
|
|
* @copyright Copyright (c) 2013 - 2020, Alex Tselegidis
|
2016-07-17 15:43:50 +03:00
|
|
|
* @license http://opensource.org/licenses/GPL-3.0 - GPLv3
|
|
|
|
* @link http://easyappointments.org
|
|
|
|
* @since v1.2.0
|
|
|
|
* ---------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Backend Calendar Unavailabilities Modal
|
|
|
|
*
|
|
|
|
* This module implements the unavailabilities modal functionality.
|
|
|
|
*
|
|
|
|
* @module BackendCalendarUnavailabilitiesModal
|
|
|
|
*/
|
|
|
|
window.BackendCalendarUnavailabilitiesModal = window.BackendCalendarUnavailabilitiesModal || {};
|
|
|
|
|
2018-01-23 12:08:37 +03:00
|
|
|
(function (exports) {
|
2016-07-17 15:43:50 +03:00
|
|
|
|
|
|
|
'use strict';
|
|
|
|
|
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.
|
|
|
|
*/
|
2018-01-23 12:08:37 +03:00
|
|
|
$('#manage-unavailable #save-unavailable').click(function () {
|
2016-07-17 15:43:50 +03:00
|
|
|
var $dialog = $('#manage-unavailable');
|
2017-11-14 15:52:59 +03:00
|
|
|
$dialog.find('.has-error').removeClass('has-error');
|
2016-10-24 01:06:06 +03:00
|
|
|
var start = $dialog.find('#unavailable-start').datetimepicker('getDate');
|
|
|
|
var end = Date.parse($dialog.find('#unavailable-end').datetimepicker('getDate'));
|
2016-07-17 15:43:50 +03:00
|
|
|
|
|
|
|
if (start > end) {
|
|
|
|
// Start time is after end time - display message to user.
|
|
|
|
$dialog.find('.modal-message')
|
2017-09-11 17:09:15 +03:00
|
|
|
.text(EALang.start_date_before_end_error)
|
2016-07-17 15:43:50 +03:00
|
|
|
.addClass('alert-danger')
|
|
|
|
.removeClass('hidden');
|
2017-11-14 15:52:59 +03:00
|
|
|
|
|
|
|
$dialog.find('#unavailable-start, #unavailable-end').closest('.form-group').addClass('has-error');
|
2016-07-17 15:43:50 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Unavailable period records go to the appointments table.
|
|
|
|
var unavailable = {
|
|
|
|
start_datetime: start.toString('yyyy-MM-dd HH:mm'),
|
|
|
|
end_datetime: end.toString('yyyy-MM-dd HH:mm'),
|
|
|
|
notes: $dialog.find('#unavailable-notes').val(),
|
2016-07-18 23:55:05 +03:00
|
|
|
id_users_provider: $('#unavailable-provider').val() // curr provider
|
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();
|
|
|
|
}
|
|
|
|
|
2020-07-01 09:48:57 +03:00
|
|
|
var successCallback = function () {
|
2016-07-17 15:43:50 +03:00
|
|
|
// Display success message to the user.
|
2020-05-03 23:40:29 +03:00
|
|
|
Backend.displayNotification(EALang.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.
|
|
|
|
$dialog.find('.alert').addClass('hidden');
|
|
|
|
$dialog.modal('hide');
|
|
|
|
$('#select-filter-item').trigger('change');
|
2016-07-17 15:43:50 +03:00
|
|
|
};
|
|
|
|
|
2018-01-23 12:08:37 +03:00
|
|
|
var errorCallback = function (jqXHR, textStatus, errorThrown) {
|
2016-07-17 15:43:50 +03:00
|
|
|
GeneralFunctions.displayMessageBox('Communication Error', 'Unfortunately ' +
|
2018-01-23 12:08:37 +03:00
|
|
|
'the operation could not complete due to server communication errors.');
|
2016-07-17 15:43:50 +03:00
|
|
|
|
2020-05-04 22:13:13 +03:00
|
|
|
$dialog.find('.modal-message').text(EALang.service_communication_error);
|
2016-07-17 15:43:50 +03:00
|
|
|
$dialog.find('.modal-message').addClass('alert-danger').removeClass('hidden');
|
|
|
|
};
|
|
|
|
|
|
|
|
BackendCalendarApi.saveUnavailable(unavailable, successCallback, errorCallback);
|
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Event: Manage Unavailable Dialog Cancel Button "Click"
|
|
|
|
*
|
|
|
|
* Closes the dialog without saveing any changes to the database.
|
|
|
|
*/
|
2018-01-23 12:08:37 +03:00
|
|
|
$('#manage-unavailable #cancel-unavailable').click(function () {
|
2016-07-17 15:43:50 +03:00
|
|
|
$('#manage-unavailable').modal('hide');
|
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*/
|
2018-01-23 12:08:37 +03:00
|
|
|
$('#insert-unavailable').click(function () {
|
2016-07-18 23:55:05 +03:00
|
|
|
BackendCalendarUnavailabilitiesModal.resetUnavailableDialog();
|
2016-07-17 15:43:50 +03:00
|
|
|
var $dialog = $('#manage-unavailable');
|
|
|
|
|
|
|
|
// Set the default datetime values.
|
|
|
|
var start = new Date();
|
|
|
|
var currentMin = parseInt(start.toString('mm'));
|
|
|
|
|
|
|
|
if (currentMin > 0 && currentMin < 15) {
|
2018-01-23 12:08:37 +03:00
|
|
|
start.set({'minute': 15});
|
2016-07-17 15:43:50 +03:00
|
|
|
} else if (currentMin > 15 && currentMin < 30) {
|
2018-01-23 12:08:37 +03:00
|
|
|
start.set({'minute': 30});
|
2016-07-17 15:43:50 +03:00
|
|
|
} else if (currentMin > 30 && currentMin < 45) {
|
2018-01-23 12:08:37 +03:00
|
|
|
start.set({'minute': 45});
|
2016-07-17 15:43:50 +03:00
|
|
|
} else {
|
2018-01-23 12:08:37 +03:00
|
|
|
start.addHours(1).set({'minute': 0});
|
2016-07-17 15:43:50 +03:00
|
|
|
}
|
|
|
|
|
2016-07-18 23:55:05 +03:00
|
|
|
if ($('.calendar-view').length === 0) {
|
2017-11-14 15:52:59 +03:00
|
|
|
$dialog.find('#unavailable-provider')
|
|
|
|
.val($('#select-filter-item').val())
|
|
|
|
.closest('.form-group')
|
2016-07-18 23:55:05 +03:00
|
|
|
.hide();
|
|
|
|
}
|
|
|
|
|
2016-07-17 15:43:50 +03:00
|
|
|
$dialog.find('#unavailable-start').val(GeneralFunctions.formatDate(start, GlobalVariables.dateFormat, true));
|
|
|
|
$dialog.find('#unavailable-end').val(GeneralFunctions.formatDate(start.addHours(1), GlobalVariables.dateFormat, true));
|
2017-09-11 17:09:15 +03:00
|
|
|
$dialog.find('.modal-header h3').text(EALang.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.
|
|
|
|
*/
|
2018-01-23 12:08:37 +03:00
|
|
|
exports.resetUnavailableDialog = function () {
|
2016-07-17 15:43:50 +03:00
|
|
|
var $dialog = $('#manage-unavailable');
|
|
|
|
|
|
|
|
$dialog.find('#unavailable-id').val('');
|
|
|
|
|
|
|
|
// Set default time values
|
|
|
|
var start = GeneralFunctions.formatDate(new Date(), GlobalVariables.dateFormat, true);
|
|
|
|
var end = GeneralFunctions.formatDate(new Date().addHours(1), GlobalVariables.dateFormat, true);
|
|
|
|
var dateFormat;
|
|
|
|
|
2018-01-23 12:08:37 +03:00
|
|
|
switch (GlobalVariables.dateFormat) {
|
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;
|
|
|
|
}
|
|
|
|
|
2018-06-29 01:41:17 +03:00
|
|
|
var fDay = GlobalVariables.firstWeekday;
|
|
|
|
var fDaynum = GeneralFunctions.getWeekDayId(fDay);
|
2016-07-17 15:43:50 +03:00
|
|
|
|
|
|
|
$dialog.find('#unavailable-start').datetimepicker({
|
|
|
|
dateFormat: dateFormat,
|
2018-03-28 15:41:27 +03:00
|
|
|
timeFormat: GlobalVariables.timeFormat === 'regular' ? 'h:mm TT' : 'HH:mm',
|
2016-07-17 15:43:50 +03:00
|
|
|
|
|
|
|
// Translation
|
2017-09-11 17:09:15 +03:00
|
|
|
dayNames: [EALang.sunday, EALang.monday, EALang.tuesday, EALang.wednesday,
|
2018-01-23 12:08:37 +03:00
|
|
|
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)],
|
2017-09-11 17:09:15 +03:00
|
|
|
monthNames: [EALang.january, EALang.february, EALang.march, EALang.april,
|
2018-01-23 12:08:37 +03:00
|
|
|
EALang.may, EALang.june, EALang.july, EALang.august, EALang.september,
|
|
|
|
EALang.october, EALang.november, EALang.december],
|
2017-09-11 17:09:15 +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,
|
2018-06-29 01:41:17 +03:00
|
|
|
firstDay: fDaynum
|
2016-07-17 15:43:50 +03:00
|
|
|
});
|
|
|
|
$dialog.find('#unavailable-start').val(start);
|
|
|
|
|
|
|
|
$dialog.find('#unavailable-end').datetimepicker({
|
|
|
|
dateFormat: dateFormat,
|
2018-03-28 15:41:27 +03:00
|
|
|
timeFormat: GlobalVariables.timeFormat === 'regular' ? 'h:mm TT' : 'HH:mm',
|
2016-07-17 15:43:50 +03:00
|
|
|
|
|
|
|
// Translation
|
2017-09-11 17:09:15 +03:00
|
|
|
dayNames: [EALang.sunday, EALang.monday, EALang.tuesday, EALang.wednesday,
|
2018-01-23 12:08:37 +03:00
|
|
|
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)],
|
2017-09-11 17:09:15 +03:00
|
|
|
monthNames: [EALang.january, EALang.february, EALang.march, EALang.april,
|
2018-01-23 12:08:37 +03:00
|
|
|
EALang.may, EALang.june, EALang.july, EALang.august, EALang.september,
|
|
|
|
EALang.october, EALang.november, EALang.december],
|
2017-09-11 17:09:15 +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,
|
2018-06-29 01:41:17 +03:00
|
|
|
firstDay: fDaynum
|
2016-07-17 15:43:50 +03:00
|
|
|
});
|
|
|
|
$dialog.find('#unavailable-end').val(end);
|
|
|
|
|
|
|
|
// Clear the unavailable notes field.
|
|
|
|
$dialog.find('#unavailable-notes').val('');
|
2017-10-31 14:56:29 +03:00
|
|
|
};
|
2016-07-17 15:43:50 +03:00
|
|
|
|
2018-01-23 12:08:37 +03:00
|
|
|
exports.initialize = function () {
|
|
|
|
var $unavailabilityProvider = $('#unavailable-provider');
|
2016-07-18 23:55:05 +03:00
|
|
|
|
|
|
|
for (var index in GlobalVariables.availableProviders) {
|
2018-01-23 12:08:37 +03:00
|
|
|
var provider = GlobalVariables.availableProviders[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();
|
2016-07-17 15:43:50 +03:00
|
|
|
};
|
|
|
|
|
2020-04-27 21:14:20 +03:00
|
|
|
})(window.BackendCalendarUnavailabilitiesModal);
|