2016-07-17 14:46:38 +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 14:46:38 +03:00
|
|
|
|
* @license http://opensource.org/licenses/GPL-3.0 - GPLv3
|
|
|
|
|
* @link http://easyappointments.org
|
|
|
|
|
* @since v1.2.0
|
|
|
|
|
* ---------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Backend Calendar
|
|
|
|
|
*
|
|
|
|
|
* This module implements the default calendar view of backend.
|
|
|
|
|
*
|
|
|
|
|
* @module BackendCalendarDefaultView
|
|
|
|
|
*/
|
|
|
|
|
window.BackendCalendarDefaultView = window.BackendCalendarDefaultView || {};
|
|
|
|
|
|
2017-10-31 12:37:00 +03:00
|
|
|
|
(function (exports) {
|
2016-07-17 14:46:38 +03:00
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
|
|
// Constants
|
2017-10-31 12:37:00 +03:00
|
|
|
|
var FILTER_TYPE_PROVIDER = 'provider';
|
2016-07-17 14:46:38 +03:00
|
|
|
|
var FILTER_TYPE_SERVICE = 'service';
|
|
|
|
|
|
2016-07-17 15:43:50 +03:00
|
|
|
|
// Variables
|
|
|
|
|
var lastFocusedEventData; // Contains event data for later use.
|
|
|
|
|
|
2016-07-17 14:46:38 +03:00
|
|
|
|
/**
|
2017-10-31 12:37:00 +03:00
|
|
|
|
* Bind event handlers for the calendar view.
|
2016-07-17 14:46:38 +03:00
|
|
|
|
*/
|
2020-05-06 20:23:49 +03:00
|
|
|
|
function bindEventHandlers() {
|
2017-10-31 12:37:00 +03:00
|
|
|
|
var $calendarPage = $('#calendar-page');
|
2016-07-17 15:43:50 +03:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Event: Reload Button "Click"
|
|
|
|
|
*
|
|
|
|
|
* When the user clicks the reload button an the calendar items need to be refreshed.
|
|
|
|
|
*/
|
2017-10-31 12:37:00 +03:00
|
|
|
|
$('#reload-appointments').click(function () {
|
2020-05-06 20:23:49 +03:00
|
|
|
|
refreshCalendarAppointments(
|
2020-04-08 11:29:47 +03:00
|
|
|
|
$('#calendar'),
|
|
|
|
|
$('#select-filter-item').val(),
|
|
|
|
|
$('#select-filter-item').find('option:selected').attr('type'),
|
|
|
|
|
$('#calendar').fullCalendar('getView').start,
|
|
|
|
|
$('#calendar').fullCalendar('getView').end);
|
2016-07-17 15:43:50 +03:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Event: Popover Close Button "Click"
|
|
|
|
|
*
|
|
|
|
|
* Hides the open popover element.
|
|
|
|
|
*/
|
2017-10-31 12:37:00 +03:00
|
|
|
|
$calendarPage.on('click', '.close-popover', function () {
|
2020-05-12 21:52:32 +03:00
|
|
|
|
$(this).parents('.popover').popover('destroy');
|
2016-07-17 15:43:50 +03:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Event: Popover Edit Button "Click"
|
|
|
|
|
*
|
|
|
|
|
* Enables the edit dialog of the selected calendar event.
|
|
|
|
|
*/
|
2017-10-31 12:37:00 +03:00
|
|
|
|
$calendarPage.on('click', '.edit-popover', function () {
|
2020-05-12 21:52:32 +03:00
|
|
|
|
$(this).parents('.popover').popover('destroy');
|
2016-07-17 15:43:50 +03:00
|
|
|
|
|
|
|
|
|
var $dialog;
|
|
|
|
|
|
2020-05-06 20:15:11 +03:00
|
|
|
|
if (lastFocusedEventData.data.is_unavailable === '0') {
|
2016-07-17 15:43:50 +03:00
|
|
|
|
var appointment = lastFocusedEventData.data;
|
|
|
|
|
$dialog = $('#manage-appointment');
|
|
|
|
|
|
2016-07-18 23:55:05 +03:00
|
|
|
|
BackendCalendarAppointmentsModal.resetAppointmentDialog();
|
2016-07-17 15:43:50 +03:00
|
|
|
|
|
|
|
|
|
// Apply appointment data and show modal dialog.
|
2017-09-11 17:09:15 +03:00
|
|
|
|
$dialog.find('.modal-header h3').text(EALang.edit_appointment_title);
|
2017-10-31 12:37:00 +03:00
|
|
|
|
$dialog.find('#appointment-id').val(appointment.id);
|
|
|
|
|
$dialog.find('#select-service').val(appointment.id_services).trigger('change');
|
|
|
|
|
$dialog.find('#select-provider').val(appointment.id_users_provider);
|
2016-07-17 15:43:50 +03:00
|
|
|
|
|
|
|
|
|
// Set the start and end datetime of the appointment.
|
2017-10-31 12:37:00 +03:00
|
|
|
|
var startDatetime = Date.parseExact(appointment.start_datetime, 'yyyy-MM-dd HH:mm:ss');
|
2016-07-17 15:43:50 +03:00
|
|
|
|
$dialog.find('#start-datetime').datetimepicker('setDate', startDatetime);
|
|
|
|
|
|
2017-10-31 12:37:00 +03:00
|
|
|
|
var endDatetime = Date.parseExact(appointment.end_datetime, 'yyyy-MM-dd HH:mm:ss');
|
2016-07-17 15:43:50 +03:00
|
|
|
|
$dialog.find('#end-datetime').datetimepicker('setDate', endDatetime);
|
|
|
|
|
|
2017-10-31 12:37:00 +03:00
|
|
|
|
var customer = appointment.customer;
|
|
|
|
|
$dialog.find('#customer-id').val(appointment.id_users_customer);
|
|
|
|
|
$dialog.find('#first-name').val(customer.first_name);
|
|
|
|
|
$dialog.find('#last-name').val(customer.last_name);
|
|
|
|
|
$dialog.find('#email').val(customer.email);
|
|
|
|
|
$dialog.find('#phone-number').val(customer.phone_number);
|
|
|
|
|
$dialog.find('#address').val(customer.address);
|
|
|
|
|
$dialog.find('#city').val(customer.city);
|
|
|
|
|
$dialog.find('#zip-code').val(customer.zip_code);
|
2019-06-08 17:43:21 +03:00
|
|
|
|
$dialog.find('#appointment-location').val(appointment.location);
|
2017-10-31 12:37:00 +03:00
|
|
|
|
$dialog.find('#appointment-notes').val(appointment.notes);
|
|
|
|
|
$dialog.find('#customer-notes').val(customer.notes);
|
2016-07-17 15:43:50 +03:00
|
|
|
|
} else {
|
|
|
|
|
var unavailable = lastFocusedEventData.data;
|
|
|
|
|
|
|
|
|
|
// Replace string date values with actual date objects.
|
2017-10-31 13:13:53 +03:00
|
|
|
|
unavailable.start_datetime = lastFocusedEventData.start.format('YYYY-MM-DD HH:mm:ss');
|
2018-04-19 17:50:28 +03:00
|
|
|
|
var startDatetime = Date.parseExact(unavailable.start_datetime, 'yyyy-MM-dd HH:mm:ss');
|
2017-10-31 13:13:53 +03:00
|
|
|
|
unavailable.end_datetime = lastFocusedEventData.end.format('YYYY-MM-DD HH:mm:ss');
|
2018-04-19 17:50:28 +03:00
|
|
|
|
var endDatetime = Date.parseExact(unavailable.end_datetime, 'yyyy-MM-dd HH:mm:ss');
|
2016-07-17 15:43:50 +03:00
|
|
|
|
|
|
|
|
|
$dialog = $('#manage-unavailable');
|
2016-07-18 23:55:05 +03:00
|
|
|
|
BackendCalendarUnavailabilitiesModal.resetUnavailableDialog();
|
2016-07-17 15:43:50 +03:00
|
|
|
|
|
2016-10-10 19:29:48 +03:00
|
|
|
|
// Apply unavailable data to dialog.
|
2016-07-17 15:43:50 +03:00
|
|
|
|
$dialog.find('.modal-header h3').text('Edit Unavailable Period');
|
2018-04-19 17:50:28 +03:00
|
|
|
|
$dialog.find('#unavailable-start').datetimepicker('setDate', startDatetime);
|
2016-07-17 15:43:50 +03:00
|
|
|
|
$dialog.find('#unavailable-id').val(unavailable.id);
|
2016-07-18 23:55:05 +03:00
|
|
|
|
$dialog.find('#unavailable-provider').val(unavailable.id_users_provider);
|
2018-04-19 17:50:28 +03:00
|
|
|
|
$dialog.find('#unavailable-end').datetimepicker('setDate', endDatetime);
|
2016-07-17 15:43:50 +03:00
|
|
|
|
$dialog.find('#unavailable-notes').val(unavailable.notes);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// :: DISPLAY EDIT DIALOG
|
|
|
|
|
$dialog.modal('show');
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Event: Popover Delete Button "Click"
|
|
|
|
|
*
|
2016-10-10 19:29:48 +03:00
|
|
|
|
* Displays a prompt on whether the user wants the appointment to be deleted. If he confirms the
|
2017-10-31 12:37:00 +03:00
|
|
|
|
* deletion then an AJAX call is made to the server and deletes the appointment from the database.
|
2016-07-17 15:43:50 +03:00
|
|
|
|
*/
|
2017-10-31 12:37:00 +03:00
|
|
|
|
$calendarPage.on('click', '.delete-popover', function () {
|
2020-05-12 21:52:32 +03:00
|
|
|
|
$(this).parents('.popover').popover('destroy');
|
2016-07-17 15:43:50 +03:00
|
|
|
|
|
2020-05-06 20:15:11 +03:00
|
|
|
|
var url;
|
|
|
|
|
var data;
|
|
|
|
|
|
2018-04-12 16:03:46 +03:00
|
|
|
|
// If id_role parameter exists the popover is an extra working day.
|
|
|
|
|
if (lastFocusedEventData.data.hasOwnProperty('id_roles')) {
|
|
|
|
|
// Do not display confirmation prompt.
|
2020-05-06 20:15:11 +03:00
|
|
|
|
url = GlobalVariables.baseUrl + '/index.php/backend_api/ajax_delete_extra_period';
|
|
|
|
|
|
|
|
|
|
data = {
|
2018-04-12 16:03:46 +03:00
|
|
|
|
csrfToken: GlobalVariables.csrfToken,
|
|
|
|
|
extra_period: lastFocusedEventData.start.format('YYYY-MM-DD'),
|
|
|
|
|
provider_id: lastFocusedEventData.data.id
|
|
|
|
|
};
|
|
|
|
|
|
2020-05-06 20:15:11 +03:00
|
|
|
|
$.post(url, data)
|
|
|
|
|
.done(function () {
|
|
|
|
|
$('#message_box').dialog('close');
|
2018-04-12 16:03:46 +03:00
|
|
|
|
|
2020-05-06 20:15:11 +03:00
|
|
|
|
var extraWorkingPlan = jQuery.parseJSON(lastFocusedEventData.data.settings.extra_working_plan);
|
|
|
|
|
delete extraWorkingPlan[lastFocusedEventData.start.format('YYYY-MM-DD')];
|
|
|
|
|
lastFocusedEventData.data.settings.extra_working_plan = JSON.stringify(extraWorkingPlan);
|
2018-04-12 16:03:46 +03:00
|
|
|
|
|
2020-05-06 20:15:11 +03:00
|
|
|
|
// Refresh calendar event items.
|
|
|
|
|
$('#select-filter-item').trigger('change');
|
|
|
|
|
})
|
|
|
|
|
.fail(GeneralFunctions.ajaxFailureHandler);
|
2018-04-12 16:03:46 +03:00
|
|
|
|
}
|
2020-05-06 20:15:11 +03:00
|
|
|
|
else if (lastFocusedEventData.data.is_unavailable === '0') {
|
2017-10-31 12:37:00 +03:00
|
|
|
|
var buttons = [
|
|
|
|
|
{
|
|
|
|
|
text: 'OK',
|
|
|
|
|
click: function () {
|
2020-05-06 20:15:11 +03:00
|
|
|
|
url = GlobalVariables.baseUrl + '/index.php/backend_api/ajax_delete_appointment';
|
|
|
|
|
|
|
|
|
|
data = {
|
2017-10-31 12:37:00 +03:00
|
|
|
|
csrfToken: GlobalVariables.csrfToken,
|
|
|
|
|
appointment_id: lastFocusedEventData.data.id,
|
|
|
|
|
delete_reason: $('#delete-reason').val()
|
|
|
|
|
};
|
|
|
|
|
|
2020-05-06 20:15:11 +03:00
|
|
|
|
$.post(url, data)
|
|
|
|
|
.done(function () {
|
|
|
|
|
$('#message_box').dialog('close');
|
2017-10-31 12:37:00 +03:00
|
|
|
|
|
2020-05-06 20:15:11 +03:00
|
|
|
|
// Refresh calendar event items.
|
|
|
|
|
$('#select-filter-item').trigger('change');
|
|
|
|
|
})
|
|
|
|
|
.fail(GeneralFunctions.ajaxFailureHandler);
|
2016-07-17 15:43:50 +03:00
|
|
|
|
}
|
2017-10-31 12:37:00 +03:00
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
text: EALang.cancel,
|
|
|
|
|
click: function () {
|
|
|
|
|
$('#message_box').dialog('close');
|
2016-07-17 15:43:50 +03:00
|
|
|
|
}
|
2017-10-31 12:37:00 +03:00
|
|
|
|
}
|
|
|
|
|
];
|
2016-07-17 15:43:50 +03:00
|
|
|
|
|
|
|
|
|
|
2017-09-11 17:09:15 +03:00
|
|
|
|
GeneralFunctions.displayMessageBox(EALang.delete_appointment_title,
|
2017-10-31 12:37:00 +03:00
|
|
|
|
EALang.write_appointment_removal_reason, buttons);
|
2016-07-17 15:43:50 +03:00
|
|
|
|
|
|
|
|
|
$('#message_box').append('<textarea id="delete-reason" rows="3"></textarea>');
|
|
|
|
|
$('#delete-reason').css('width', '100%');
|
|
|
|
|
} else {
|
2016-10-10 19:29:48 +03:00
|
|
|
|
// Do not display confirmation prompt.
|
2020-05-06 20:15:11 +03:00
|
|
|
|
url = GlobalVariables.baseUrl + '/index.php/backend_api/ajax_delete_unavailable';
|
|
|
|
|
|
|
|
|
|
data = {
|
2016-07-17 15:43:50 +03:00
|
|
|
|
csrfToken: GlobalVariables.csrfToken,
|
2017-10-31 12:37:00 +03:00
|
|
|
|
unavailable_id: lastFocusedEventData.data.id
|
2016-07-17 15:43:50 +03:00
|
|
|
|
};
|
|
|
|
|
|
2020-05-06 20:15:11 +03:00
|
|
|
|
$.post(url, data)
|
|
|
|
|
.done(function () {
|
|
|
|
|
$('#message_box').dialog('close');
|
2016-07-17 15:43:50 +03:00
|
|
|
|
|
2020-05-06 20:15:11 +03:00
|
|
|
|
// Refresh calendar event items.
|
|
|
|
|
$('#select-filter-item').trigger('change');
|
|
|
|
|
})
|
|
|
|
|
.fail(GeneralFunctions.ajaxFailureHandler);
|
2016-07-17 15:43:50 +03:00
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2016-07-17 14:46:38 +03:00
|
|
|
|
/**
|
|
|
|
|
* Event: Calendar Filter Item "Change"
|
|
|
|
|
*
|
|
|
|
|
* Load the appointments that correspond to the select filter item and display them on the calendar.
|
|
|
|
|
*/
|
2017-10-31 12:37:00 +03:00
|
|
|
|
$('#select-filter-item').change(function () {
|
2016-07-17 14:46:38 +03:00
|
|
|
|
// If current value is service, then the sync buttons must be disabled.
|
|
|
|
|
if ($('#select-filter-item option:selected').attr('type') === FILTER_TYPE_SERVICE) {
|
2020-05-10 00:29:16 +03:00
|
|
|
|
$('#google-sync, #enable-sync, #insert-appointment, #insert-dropdown').prop('disabled', true);
|
2018-02-23 17:29:53 +03:00
|
|
|
|
$('#calendar').fullCalendar('option', 'selectable', false);
|
|
|
|
|
$('#calendar').fullCalendar('option', 'editable', false);
|
2016-07-17 14:46:38 +03:00
|
|
|
|
} else {
|
2020-05-10 00:29:16 +03:00
|
|
|
|
$('#google-sync, #enable-sync, #insert-appointment, #insert-dropdown').prop('disabled', false);
|
2018-05-23 00:33:34 +03:00
|
|
|
|
$('#calendar').fullCalendar('option', 'selectable', true);
|
2018-02-23 17:29:53 +03:00
|
|
|
|
$('#calendar').fullCalendar('option', 'editable', true);
|
2016-07-17 14:46:38 +03:00
|
|
|
|
|
2020-03-29 16:08:07 +03:00
|
|
|
|
var providerId = $('#select-filter-item').val();
|
|
|
|
|
|
2020-05-07 20:00:33 +03:00
|
|
|
|
var provider = GlobalVariables.availableProviders.find(function(availableProvider) {
|
2020-05-06 20:15:11 +03:00
|
|
|
|
return Number(availableProvider.id) === Number(providerId);
|
2020-05-07 20:00:33 +03:00
|
|
|
|
});
|
2020-03-29 16:08:07 +03:00
|
|
|
|
|
|
|
|
|
if (provider && provider.timezone) {
|
|
|
|
|
$('.provider-timezone').text(GlobalVariables.timezones[provider.timezone]);
|
|
|
|
|
}
|
|
|
|
|
|
2016-07-17 14:46:38 +03:00
|
|
|
|
// If the user has already the sync enabled then apply the proper style changes.
|
|
|
|
|
if ($('#select-filter-item option:selected').attr('google-sync') === 'true') {
|
|
|
|
|
$('#enable-sync').addClass('btn-danger enabled');
|
2017-09-11 17:09:15 +03:00
|
|
|
|
$('#enable-sync span:eq(1)').text(EALang.disable_sync);
|
2016-07-17 14:46:38 +03:00
|
|
|
|
$('#google-sync').prop('disabled', false);
|
|
|
|
|
} else {
|
|
|
|
|
$('#enable-sync').removeClass('btn-danger enabled');
|
2017-09-11 17:09:15 +03:00
|
|
|
|
$('#enable-sync span:eq(1)').text(EALang.enable_sync);
|
2016-07-17 14:46:38 +03:00
|
|
|
|
$('#google-sync').prop('disabled', true);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get Calendar Component Height
|
|
|
|
|
*
|
|
|
|
|
* This method calculates the proper calendar height, in order to be displayed correctly, even when the
|
|
|
|
|
* browser window is resizing.
|
|
|
|
|
*
|
|
|
|
|
* @return {Number} Returns the calendar element height in pixels.
|
|
|
|
|
*/
|
2020-05-06 20:23:49 +03:00
|
|
|
|
function getCalendarHeight() {
|
2016-07-17 14:46:38 +03:00
|
|
|
|
var result = window.innerHeight - $('#footer').outerHeight() - $('#header').outerHeight()
|
2017-10-31 12:37:00 +03:00
|
|
|
|
- $('#calendar-toolbar').outerHeight() - 60; // 60 for fine tuning
|
2016-07-17 14:46:38 +03:00
|
|
|
|
return (result > 500) ? result : 500; // Minimum height is 500px
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-01 10:13:22 +03:00
|
|
|
|
/**
|
|
|
|
|
* Get the event notes for the popup widget.
|
|
|
|
|
*
|
|
|
|
|
* @param {Event} event
|
|
|
|
|
*/
|
|
|
|
|
function getEventNotes(event) {
|
|
|
|
|
if (!event.data || !event.data.notes) {
|
|
|
|
|
return '-';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var notes = event.data.notes;
|
|
|
|
|
|
|
|
|
|
return notes.length > 100 ? notes.substring(0, 100) + '...' : notes;
|
|
|
|
|
}
|
|
|
|
|
|
2016-07-17 14:46:38 +03:00
|
|
|
|
/**
|
|
|
|
|
* Calendar Event "Click" Callback
|
|
|
|
|
*
|
|
|
|
|
* When the user clicks on an appointment object on the calendar, then a data preview popover is display
|
|
|
|
|
* above the calendar item.
|
|
|
|
|
*/
|
2020-05-06 20:23:49 +03:00
|
|
|
|
function calendarEventClick(event, jsEvent, view) {
|
2020-05-12 21:52:32 +03:00
|
|
|
|
$('.popover').popover('destroy'); // Close all open popovers.
|
2016-07-17 14:46:38 +03:00
|
|
|
|
|
2020-05-07 19:47:14 +03:00
|
|
|
|
var $html;
|
2016-07-17 14:46:38 +03:00
|
|
|
|
var displayEdit;
|
|
|
|
|
var displayDelete;
|
|
|
|
|
|
|
|
|
|
// Depending where the user clicked the event (title or empty space) we
|
|
|
|
|
// need to use different selectors to reach the parent element.
|
|
|
|
|
var $parent = $(jsEvent.target.offsetParent);
|
|
|
|
|
var $altParent = $(jsEvent.target).parents().eq(1);
|
|
|
|
|
|
2017-10-31 13:13:53 +03:00
|
|
|
|
if ($(this).hasClass('fc-unavailable') || $parent.hasClass('fc-unavailable') || $altParent.hasClass('fc-unavailable')) {
|
2016-07-17 14:46:38 +03:00
|
|
|
|
displayEdit = (($parent.hasClass('fc-custom') || $altParent.hasClass('fc-custom'))
|
2020-05-06 20:15:11 +03:00
|
|
|
|
&& GlobalVariables.user.privileges.appointments.edit === true)
|
2017-10-31 12:37:00 +03:00
|
|
|
|
? '' : 'hide';
|
2016-07-17 14:46:38 +03:00
|
|
|
|
displayDelete = (($parent.hasClass('fc-custom') || $altParent.hasClass('fc-custom'))
|
2020-05-06 20:15:11 +03:00
|
|
|
|
&& GlobalVariables.user.privileges.appointments.delete === true)
|
2017-10-31 12:37:00 +03:00
|
|
|
|
? '' : 'hide'; // Same value at the time.
|
2016-07-17 14:46:38 +03:00
|
|
|
|
|
2020-05-07 19:47:14 +03:00
|
|
|
|
$html = $('<div/>', {
|
|
|
|
|
'html': [
|
|
|
|
|
$('<strong/>', {
|
|
|
|
|
'text': EALang.start
|
|
|
|
|
}),
|
|
|
|
|
$('<span/>', {
|
|
|
|
|
'text': GeneralFunctions.formatDate(event.start.format('YYYY-MM-DD HH:mm:ss'), GlobalVariables.dateFormat, true)
|
|
|
|
|
}),
|
|
|
|
|
$('<br/>'),
|
|
|
|
|
|
|
|
|
|
$('<strong/>', {
|
|
|
|
|
'text': EALang.end
|
|
|
|
|
}),
|
|
|
|
|
$('<span/>', {
|
|
|
|
|
'text': GeneralFunctions.formatDate(event.end.format('YYYY-MM-DD HH:mm:ss'), GlobalVariables.dateFormat, true)
|
|
|
|
|
}),
|
|
|
|
|
$('<br/>'),
|
|
|
|
|
|
2020-07-01 10:13:22 +03:00
|
|
|
|
$('<strong/>', {
|
|
|
|
|
'text': EALang.notes
|
|
|
|
|
}),
|
2020-05-07 19:47:14 +03:00
|
|
|
|
$('<span/>', {
|
2020-07-01 10:13:22 +03:00
|
|
|
|
'text': getEventNotes(event)
|
2020-05-07 19:47:14 +03:00
|
|
|
|
}),
|
|
|
|
|
$('<br/>'),
|
|
|
|
|
|
|
|
|
|
$('<hr/>'),
|
|
|
|
|
|
|
|
|
|
$('<div/>', {
|
|
|
|
|
'class': 'text-center',
|
|
|
|
|
'html': [
|
|
|
|
|
$('<button/>', {
|
|
|
|
|
'class': 'edit-popover btn btn-primary ' + displayEdit,
|
|
|
|
|
'text': EALang.edit
|
|
|
|
|
}),
|
|
|
|
|
$('<button/>', {
|
|
|
|
|
'class': 'delete-popover btn btn-danger ' + displayDelete,
|
|
|
|
|
'text': EALang.delete
|
|
|
|
|
}),
|
|
|
|
|
$('<button/>', {
|
|
|
|
|
'class': 'close-popover btn btn-default',
|
|
|
|
|
'text': EALang.close
|
|
|
|
|
})
|
|
|
|
|
]
|
|
|
|
|
})
|
|
|
|
|
]
|
|
|
|
|
});
|
2018-04-12 16:03:46 +03:00
|
|
|
|
} else if ($(this).hasClass('fc-extra') || $parent.hasClass('fc-extra') || $altParent.hasClass('fc-extra')) {
|
|
|
|
|
displayDelete = (($parent.hasClass('fc-custom') || $altParent.hasClass('fc-custom'))
|
2020-05-06 20:15:11 +03:00
|
|
|
|
&& GlobalVariables.user.privileges.appointments.delete === true)
|
2018-04-12 16:03:46 +03:00
|
|
|
|
? '' : 'hide'; // Same value at the time.
|
|
|
|
|
|
2020-05-07 19:47:14 +03:00
|
|
|
|
$html = $('<div/>', {
|
|
|
|
|
'html': [
|
|
|
|
|
$('<strong/>', {
|
|
|
|
|
'text': EALang.provider
|
|
|
|
|
}),
|
|
|
|
|
$('<span/>', {
|
|
|
|
|
'text': event.data ? event.data.first_name + ' ' + event.data.last_name : '-'
|
|
|
|
|
}),
|
|
|
|
|
$('<br/>'),
|
|
|
|
|
|
|
|
|
|
$('<strong/>', {
|
|
|
|
|
'text': EALang.start
|
|
|
|
|
}),
|
|
|
|
|
$('<span/>', {
|
|
|
|
|
'text': GeneralFunctions.formatDate(event.start.format('YYYY-MM-DD HH:mm:ss'), GlobalVariables.dateFormat, true)
|
|
|
|
|
}),
|
|
|
|
|
$('<br/>'),
|
|
|
|
|
|
|
|
|
|
$('<strong/>', {
|
|
|
|
|
'text': EALang.end
|
|
|
|
|
}),
|
|
|
|
|
$('<span/>', {
|
|
|
|
|
'text': GeneralFunctions.formatDate(event.end.format('YYYY-MM-DD HH:mm:ss'), GlobalVariables.dateFormat, true)
|
|
|
|
|
}),
|
|
|
|
|
$('<br/>'),
|
|
|
|
|
|
|
|
|
|
$('<strong/>', {
|
|
|
|
|
'text': EALang.timezone
|
|
|
|
|
}),
|
|
|
|
|
$('<span/>', {
|
|
|
|
|
'text': GlobalVariables.timezones[event.data.provider.timezone]
|
|
|
|
|
}),
|
|
|
|
|
$('<br/>'),
|
|
|
|
|
|
|
|
|
|
$('<hr/>'),
|
|
|
|
|
|
|
|
|
|
$('<div/>', {
|
|
|
|
|
'class': 'text-center',
|
|
|
|
|
'html': [
|
|
|
|
|
$('<button/>', {
|
|
|
|
|
'class': 'delete-popover btn btn-danger ' + displayDelete,
|
|
|
|
|
'text': EALang.delete
|
|
|
|
|
}),
|
|
|
|
|
$('<button/>', {
|
|
|
|
|
'class': 'close-popover btn btn-default',
|
|
|
|
|
'text': EALang.close
|
|
|
|
|
})
|
|
|
|
|
]
|
|
|
|
|
})
|
|
|
|
|
]
|
|
|
|
|
});
|
2016-07-17 14:46:38 +03:00
|
|
|
|
} else {
|
2020-05-06 20:15:11 +03:00
|
|
|
|
displayEdit = (GlobalVariables.user.privileges.appointments.edit === true)
|
2017-10-31 12:37:00 +03:00
|
|
|
|
? '' : 'hide';
|
2020-05-06 20:15:11 +03:00
|
|
|
|
displayDelete = (GlobalVariables.user.privileges.appointments.delete === true)
|
2017-10-31 12:37:00 +03:00
|
|
|
|
? '' : 'hide';
|
2016-07-17 14:46:38 +03:00
|
|
|
|
|
2020-05-07 19:47:14 +03:00
|
|
|
|
$html = $('<div/>', {
|
|
|
|
|
'html': [
|
|
|
|
|
$('<strong/>', {
|
|
|
|
|
'text': EALang.start
|
|
|
|
|
}),
|
|
|
|
|
$('<span/>', {
|
|
|
|
|
'text': GeneralFunctions.formatDate(event.start.format('YYYY-MM-DD HH:mm:ss'), GlobalVariables.dateFormat, true)
|
|
|
|
|
}),
|
|
|
|
|
$('<br/>'),
|
|
|
|
|
|
|
|
|
|
$('<strong/>', {
|
|
|
|
|
'text': EALang.end
|
|
|
|
|
}),
|
|
|
|
|
$('<span/>', {
|
|
|
|
|
'text': GeneralFunctions.formatDate(event.end.format('YYYY-MM-DD HH:mm:ss'), GlobalVariables.dateFormat, true)
|
|
|
|
|
}),
|
|
|
|
|
$('<br/>'),
|
|
|
|
|
|
|
|
|
|
$('<strong/>', {
|
|
|
|
|
'text': EALang.timezone
|
|
|
|
|
}),
|
|
|
|
|
$('<span/>', {
|
|
|
|
|
'text': GlobalVariables.timezones[event.data.provider.timezone]
|
|
|
|
|
}),
|
|
|
|
|
$('<br/>'),
|
|
|
|
|
|
|
|
|
|
$('<strong/>', {
|
|
|
|
|
'text': EALang.service
|
|
|
|
|
}),
|
|
|
|
|
$('<span/>', {
|
|
|
|
|
'text': event.data.service.name
|
|
|
|
|
}),
|
|
|
|
|
$('<br/>'),
|
|
|
|
|
|
|
|
|
|
$('<strong/>', {
|
|
|
|
|
'text': EALang.provider
|
|
|
|
|
}),
|
|
|
|
|
GeneralFunctions.renderMapIcon(event.data.provider),
|
|
|
|
|
$('<span/>', {
|
|
|
|
|
'text': event.data.provider.first_name + ' ' + event.data.provider.last_name
|
|
|
|
|
}),
|
|
|
|
|
$('<br/>'),
|
|
|
|
|
|
|
|
|
|
$('<strong/>', {
|
|
|
|
|
'text': EALang.customer
|
|
|
|
|
}),
|
|
|
|
|
GeneralFunctions.renderMapIcon(event.data.customer),
|
|
|
|
|
$('<span/>', {
|
|
|
|
|
'text': event.data.customer.first_name + ' ' + event.data.customer.last_name
|
|
|
|
|
}),
|
|
|
|
|
$('<br/>'),
|
|
|
|
|
|
|
|
|
|
$('<strong/>', {
|
|
|
|
|
'text': EALang.email
|
|
|
|
|
}),
|
|
|
|
|
GeneralFunctions.renderMailIcon(event.data.customer.email),
|
|
|
|
|
$('<span/>', {
|
|
|
|
|
'text': event.data.customer.email
|
|
|
|
|
}),
|
|
|
|
|
$('<br/>'),
|
|
|
|
|
|
|
|
|
|
$('<strong/>', {
|
|
|
|
|
'text': EALang.phone_number
|
|
|
|
|
}),
|
|
|
|
|
GeneralFunctions.renderPhoneIcon(event.data.customer.phone_number),
|
|
|
|
|
$('<span/>', {
|
|
|
|
|
'text': event.data.customer.phone_number
|
|
|
|
|
}),
|
|
|
|
|
$('<br/>'),
|
|
|
|
|
|
2020-07-01 10:13:22 +03:00
|
|
|
|
$('<strong/>', {
|
|
|
|
|
'text': EALang.notes
|
|
|
|
|
}),
|
|
|
|
|
$('<span/>', {
|
|
|
|
|
'text': getEventNotes(event)
|
|
|
|
|
}),
|
|
|
|
|
$('<br/>'),
|
|
|
|
|
|
2020-05-07 19:47:14 +03:00
|
|
|
|
$('<hr/>'),
|
|
|
|
|
|
|
|
|
|
$('<div/>', {
|
|
|
|
|
'class': 'text-center',
|
|
|
|
|
'html': [
|
|
|
|
|
$('<button/>', {
|
|
|
|
|
'class': 'edit-popover btn btn-primary ' + displayEdit,
|
|
|
|
|
'text': EALang.edit
|
|
|
|
|
}),
|
|
|
|
|
$('<button/>', {
|
|
|
|
|
'class': 'delete-popover btn btn-danger ' + displayDelete,
|
|
|
|
|
'text': EALang.delete
|
|
|
|
|
}),
|
|
|
|
|
$('<button/>', {
|
|
|
|
|
'class': 'close-popover btn btn-default',
|
|
|
|
|
'text': EALang.close
|
|
|
|
|
})
|
|
|
|
|
]
|
|
|
|
|
})
|
|
|
|
|
]
|
|
|
|
|
});
|
2016-07-17 14:46:38 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$(jsEvent.target).popover({
|
|
|
|
|
placement: 'top',
|
|
|
|
|
title: event.title,
|
2020-05-07 19:47:14 +03:00
|
|
|
|
content: $html,
|
2016-07-17 14:46:38 +03:00
|
|
|
|
html: true,
|
2016-07-18 23:55:05 +03:00
|
|
|
|
container: '#calendar',
|
2016-07-17 14:46:38 +03:00
|
|
|
|
trigger: 'manual'
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
lastFocusedEventData = event;
|
2017-10-31 12:37:00 +03:00
|
|
|
|
|
2016-07-17 14:46:38 +03:00
|
|
|
|
$(jsEvent.target).popover('toggle');
|
|
|
|
|
|
2017-10-31 12:37:00 +03:00
|
|
|
|
// Fix popover position.
|
|
|
|
|
if ($('.popover').length > 0 && $('.popover').position().top < 200) {
|
|
|
|
|
$('.popover').css('top', '200px');
|
2016-07-17 14:46:38 +03:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Calendar Event "Resize" Callback
|
|
|
|
|
*
|
|
|
|
|
* The user can change the duration of an event by resizing an appointment object on the calendar. This
|
|
|
|
|
* change needs to be stored to the database too and this is done via an ajax call.
|
|
|
|
|
*
|
|
|
|
|
* @see updateAppointmentData()
|
|
|
|
|
*/
|
2020-05-06 20:23:49 +03:00
|
|
|
|
function calendarEventResize(event, delta, revertFunc, jsEvent, ui, view) {
|
2020-05-06 20:15:11 +03:00
|
|
|
|
if (GlobalVariables.user.privileges.appointments.edit === false) {
|
2016-07-17 14:46:38 +03:00
|
|
|
|
revertFunc();
|
2017-09-11 17:09:15 +03:00
|
|
|
|
Backend.displayNotification(EALang.no_privileges_edit_appointments);
|
2016-07-17 14:46:38 +03:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-18 00:06:42 +03:00
|
|
|
|
var $calendar = $('#calendar');
|
|
|
|
|
|
2016-07-17 14:46:38 +03:00
|
|
|
|
if ($('#notification').is(':visible')) {
|
|
|
|
|
$('#notification').hide('bind');
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-06 20:15:11 +03:00
|
|
|
|
if (event.data.is_unavailable === false) {
|
2016-07-17 14:46:38 +03:00
|
|
|
|
// Prepare appointment data.
|
2018-01-18 00:06:42 +03:00
|
|
|
|
event.data.end_datetime = Date.parseExact(
|
|
|
|
|
event.data.end_datetime, 'yyyy-MM-dd HH:mm:ss')
|
|
|
|
|
.add({days: delta.days(), hours: delta.hours(), minutes: delta.minutes()})
|
|
|
|
|
.toString('yyyy-MM-dd HH:mm:ss');
|
|
|
|
|
|
2016-07-17 14:46:38 +03:00
|
|
|
|
var appointment = GeneralFunctions.clone(event.data);
|
|
|
|
|
|
2017-10-31 12:37:00 +03:00
|
|
|
|
// Must delete the following because only appointment data should be provided to the AJAX call.
|
|
|
|
|
delete appointment.customer;
|
|
|
|
|
delete appointment.provider;
|
|
|
|
|
delete appointment.service;
|
2016-07-17 14:46:38 +03:00
|
|
|
|
|
|
|
|
|
// Success callback
|
2017-10-31 12:37:00 +03:00
|
|
|
|
var successCallback = function (response) {
|
2016-07-17 14:46:38 +03:00
|
|
|
|
// Display success notification to user.
|
2017-10-31 12:37:00 +03:00
|
|
|
|
var undoFunction = function () {
|
2018-01-18 00:06:42 +03:00
|
|
|
|
appointment.end_datetime = event.data.end_datetime = Date.parseExact(
|
2017-10-31 12:37:00 +03:00
|
|
|
|
appointment.end_datetime, 'yyyy-MM-dd HH:mm:ss')
|
2017-11-17 17:18:00 +03:00
|
|
|
|
.add({days: -delta.days(), hours: -delta.hours(), minutes: -delta.minutes()})
|
2017-10-31 12:37:00 +03:00
|
|
|
|
.toString('yyyy-MM-dd HH:mm:ss');
|
|
|
|
|
|
|
|
|
|
var url = GlobalVariables.baseUrl + '/index.php/backend_api/ajax_save_appointment';
|
|
|
|
|
|
|
|
|
|
var data = {
|
2016-07-17 14:46:38 +03:00
|
|
|
|
csrfToken: GlobalVariables.csrfToken,
|
|
|
|
|
appointment_data: JSON.stringify(appointment)
|
|
|
|
|
};
|
|
|
|
|
|
2020-05-06 20:15:11 +03:00
|
|
|
|
$.post(url, data)
|
|
|
|
|
.done(function () {
|
|
|
|
|
$('#notification').hide('blind');
|
|
|
|
|
revertFunc();
|
|
|
|
|
})
|
|
|
|
|
.fail(GeneralFunctions.ajaxFailureHandler);
|
2016-07-17 14:46:38 +03:00
|
|
|
|
};
|
|
|
|
|
|
2017-09-11 17:09:15 +03:00
|
|
|
|
Backend.displayNotification(EALang.appointment_updated, [
|
2016-07-17 14:46:38 +03:00
|
|
|
|
{
|
|
|
|
|
'label': 'Undo',
|
|
|
|
|
'function': undoFunction
|
|
|
|
|
}
|
|
|
|
|
]);
|
|
|
|
|
$('#footer').css('position', 'static'); // Footer position fix.
|
2018-01-18 00:06:42 +03:00
|
|
|
|
|
|
|
|
|
// Update the event data for later use.
|
|
|
|
|
$calendar.fullCalendar('updateEvent', event);
|
2016-07-17 14:46:38 +03:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// Update appointment data.
|
2020-05-06 20:15:11 +03:00
|
|
|
|
BackendCalendarApi.saveAppointment(appointment, null, successCallback);
|
2016-07-17 14:46:38 +03:00
|
|
|
|
} else {
|
2016-10-10 19:29:48 +03:00
|
|
|
|
// Update unavailable time period.
|
2016-07-17 14:46:38 +03:00
|
|
|
|
var unavailable = {
|
|
|
|
|
id: event.data.id,
|
2017-10-31 13:34:06 +03:00
|
|
|
|
start_datetime: event.start.format('YYYY-MM-DD HH:mm:ss'),
|
|
|
|
|
end_datetime: event.end.format('YYYY-MM-DD HH:mm:ss'),
|
2016-07-17 14:46:38 +03:00
|
|
|
|
id_users_provider: event.data.id_users_provider
|
|
|
|
|
};
|
|
|
|
|
|
2018-01-18 00:06:42 +03:00
|
|
|
|
event.data.end_datetime = unavailable.end_datetime;
|
|
|
|
|
|
2016-07-17 14:46:38 +03:00
|
|
|
|
// Define success callback function.
|
2017-10-31 12:37:00 +03:00
|
|
|
|
var successCallback = function (response) {
|
2016-07-17 14:46:38 +03:00
|
|
|
|
// Display success notification to user.
|
2017-10-31 12:37:00 +03:00
|
|
|
|
var undoFunction = function () {
|
2018-01-23 12:08:37 +03:00
|
|
|
|
unavailable.end_datetime = event.data.end_datetime = Date.parseExact(
|
2017-10-31 12:37:00 +03:00
|
|
|
|
unavailable.end_datetime, 'yyyy-MM-dd HH:mm:ss')
|
2017-10-31 13:34:06 +03:00
|
|
|
|
.add({minutes: -delta.minutes()})
|
2017-10-31 12:37:00 +03:00
|
|
|
|
.toString('yyyy-MM-dd HH:mm:ss');
|
2016-07-17 14:46:38 +03:00
|
|
|
|
|
2017-09-23 04:49:46 +03:00
|
|
|
|
var url = GlobalVariables.baseUrl + '/index.php/backend_api/ajax_save_unavailable';
|
2020-05-06 20:15:11 +03:00
|
|
|
|
|
2017-09-23 04:49:46 +03:00
|
|
|
|
var data = {
|
2016-07-17 14:46:38 +03:00
|
|
|
|
csrfToken: GlobalVariables.csrfToken,
|
|
|
|
|
unavailable: JSON.stringify(unavailable)
|
|
|
|
|
};
|
|
|
|
|
|
2020-05-06 20:15:11 +03:00
|
|
|
|
$.post(url, data)
|
|
|
|
|
.done(function () {
|
|
|
|
|
$('#notification').hide('blind');
|
|
|
|
|
revertFunc();
|
|
|
|
|
})
|
|
|
|
|
.fail(GeneralFunctions.ajaxFailureHandler);
|
2016-07-17 14:46:38 +03:00
|
|
|
|
};
|
|
|
|
|
|
2017-09-11 17:09:15 +03:00
|
|
|
|
Backend.displayNotification(EALang.unavailable_updated, [
|
2016-07-17 14:46:38 +03:00
|
|
|
|
{
|
|
|
|
|
'label': 'Undo',
|
|
|
|
|
'function': undoFunction
|
|
|
|
|
}
|
|
|
|
|
]);
|
2017-10-31 12:37:00 +03:00
|
|
|
|
|
2016-07-17 14:46:38 +03:00
|
|
|
|
$('#footer').css('position', 'static'); // Footer position fix.
|
2018-01-18 00:06:42 +03:00
|
|
|
|
|
|
|
|
|
// Update the event data for later use.
|
|
|
|
|
$calendar.fullCalendar('updateEvent', event);
|
2016-07-17 14:46:38 +03:00
|
|
|
|
};
|
|
|
|
|
|
2017-10-31 12:37:00 +03:00
|
|
|
|
BackendCalendarApi.saveUnavailable(unavailable, successCallback);
|
2016-07-17 14:46:38 +03:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Calendar Window "Resize" Callback
|
|
|
|
|
*
|
2016-10-10 19:29:48 +03:00
|
|
|
|
* The calendar element needs to be re-sized too in order to fit into the window. Nevertheless, if the window
|
2016-07-17 14:46:38 +03:00
|
|
|
|
* becomes very small the the calendar won't shrink anymore.
|
|
|
|
|
*
|
2020-05-06 20:23:49 +03:00
|
|
|
|
* @see getCalendarHeight()
|
2016-07-17 14:46:38 +03:00
|
|
|
|
*/
|
2020-05-06 20:23:49 +03:00
|
|
|
|
function calendarWindowResize(view) {
|
|
|
|
|
$('#calendar').fullCalendar('option', 'height', getCalendarHeight());
|
2016-07-17 14:46:38 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Calendar Day "Click" Callback
|
|
|
|
|
*
|
2016-10-10 19:29:48 +03:00
|
|
|
|
* When the user clicks on a day square on the calendar, then he will automatically be transferred to that
|
2016-07-17 14:46:38 +03:00
|
|
|
|
* day view calendar.
|
|
|
|
|
*/
|
2020-05-06 20:23:49 +03:00
|
|
|
|
function calendarDayClick(date, jsEvent, view) {
|
2017-11-02 16:11:41 +03:00
|
|
|
|
if (!date.hasTime()) {
|
2016-07-17 14:46:38 +03:00
|
|
|
|
$('#calendar').fullCalendar('changeView', 'agendaDay');
|
2017-11-02 16:11:41 +03:00
|
|
|
|
$('#calendar').fullCalendar('gotoDate', date);
|
2016-07-17 14:46:38 +03:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Calendar Event "Drop" Callback
|
|
|
|
|
*
|
|
|
|
|
* This event handler is triggered whenever the user drags and drops an event into a different position
|
|
|
|
|
* on the calendar. We need to update the database with this change. This is done via an ajax call.
|
|
|
|
|
*/
|
2020-05-06 20:23:49 +03:00
|
|
|
|
function calendarEventDrop(event, delta, revertFunc, jsEvent, ui, view) {
|
2020-05-06 20:15:11 +03:00
|
|
|
|
if (GlobalVariables.user.privileges.appointments.edit === false) {
|
2016-07-17 14:46:38 +03:00
|
|
|
|
revertFunc();
|
2017-09-11 17:09:15 +03:00
|
|
|
|
Backend.displayNotification(EALang.no_privileges_edit_appointments);
|
2016-07-17 14:46:38 +03:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ($('#notification').is(':visible')) {
|
|
|
|
|
$('#notification').hide('bind');
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-06 20:15:11 +03:00
|
|
|
|
if (event.data.is_unavailable === '0') {
|
2016-07-17 14:46:38 +03:00
|
|
|
|
// Prepare appointment data.
|
|
|
|
|
var appointment = GeneralFunctions.clone(event.data);
|
|
|
|
|
|
|
|
|
|
// Must delete the following because only appointment data should be provided to the ajax call.
|
2017-10-31 12:37:00 +03:00
|
|
|
|
delete appointment.customer;
|
|
|
|
|
delete appointment.provider;
|
|
|
|
|
delete appointment.service;
|
2016-07-17 14:46:38 +03:00
|
|
|
|
|
2017-10-31 12:37:00 +03:00
|
|
|
|
appointment.start_datetime = Date.parseExact(
|
|
|
|
|
appointment.start_datetime, 'yyyy-MM-dd HH:mm:ss')
|
2017-10-31 13:34:06 +03:00
|
|
|
|
.add({days: delta.days(), hours: delta.hours(), minutes: delta.minutes()})
|
2017-10-31 12:37:00 +03:00
|
|
|
|
.toString('yyyy-MM-dd HH:mm:ss');
|
2016-07-17 14:46:38 +03:00
|
|
|
|
|
2017-10-31 12:37:00 +03:00
|
|
|
|
appointment.end_datetime = Date.parseExact(
|
|
|
|
|
appointment.end_datetime, 'yyyy-MM-dd HH:mm:ss')
|
2017-10-31 13:34:06 +03:00
|
|
|
|
.add({days: delta.days(), hours: delta.hours(), minutes: delta.minutes()})
|
2017-10-31 12:37:00 +03:00
|
|
|
|
.toString('yyyy-MM-dd HH:mm:ss');
|
2016-07-17 14:46:38 +03:00
|
|
|
|
|
2017-10-31 12:37:00 +03:00
|
|
|
|
event.data.start_datetime = appointment.start_datetime;
|
|
|
|
|
event.data.end_datetime = appointment.end_datetime;
|
2016-07-17 14:46:38 +03:00
|
|
|
|
|
|
|
|
|
// Define success callback function.
|
2017-10-31 12:37:00 +03:00
|
|
|
|
var successCallback = function (response) {
|
2016-07-17 14:46:38 +03:00
|
|
|
|
// Define the undo function, if the user needs to reset the last change.
|
2017-10-31 12:37:00 +03:00
|
|
|
|
var undoFunction = function () {
|
|
|
|
|
appointment.start_datetime = Date.parseExact(
|
|
|
|
|
appointment.start_datetime, 'yyyy-MM-dd HH:mm:ss')
|
2017-10-31 13:34:06 +03:00
|
|
|
|
.add({days: -delta.days(), hours: -delta.hours(), minutes: -delta.minutes()})
|
2017-10-31 12:37:00 +03:00
|
|
|
|
.toString('yyyy-MM-dd HH:mm:ss');
|
|
|
|
|
|
|
|
|
|
appointment.end_datetime = Date.parseExact(
|
|
|
|
|
appointment.end_datetime, 'yyyy-MM-dd HH:mm:ss')
|
2017-10-31 13:34:06 +03:00
|
|
|
|
.add({days: -delta.days(), hours: -delta.hours(), minutes: -delta.minutes()})
|
2017-10-31 12:37:00 +03:00
|
|
|
|
.toString('yyyy-MM-dd HH:mm:ss');
|
|
|
|
|
|
|
|
|
|
event.data.start_datetime = appointment.start_datetime;
|
|
|
|
|
event.data.end_datetime = appointment.end_datetime;
|
|
|
|
|
|
|
|
|
|
var url = GlobalVariables.baseUrl + '/index.php/backend_api/ajax_save_appointment';
|
2020-05-06 20:15:11 +03:00
|
|
|
|
|
2017-10-31 12:37:00 +03:00
|
|
|
|
var data = {
|
2016-07-17 14:46:38 +03:00
|
|
|
|
csrfToken: GlobalVariables.csrfToken,
|
|
|
|
|
appointment_data: JSON.stringify(appointment)
|
|
|
|
|
};
|
|
|
|
|
|
2020-05-06 20:15:11 +03:00
|
|
|
|
$.post(url, data)
|
|
|
|
|
.done(function () {
|
|
|
|
|
$('#notification').hide('blind');
|
|
|
|
|
revertFunc();
|
|
|
|
|
})
|
|
|
|
|
.fail(GeneralFunctions.ajaxFailureHandler);
|
2016-07-17 14:46:38 +03:00
|
|
|
|
};
|
|
|
|
|
|
2017-09-11 17:09:15 +03:00
|
|
|
|
Backend.displayNotification(EALang.appointment_updated, [
|
2016-07-17 14:46:38 +03:00
|
|
|
|
{
|
|
|
|
|
'label': 'Undo',
|
|
|
|
|
'function': undoFunction
|
|
|
|
|
}
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$('#footer').css('position', 'static'); // Footer position fix.
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// Update appointment data.
|
2020-05-06 20:15:11 +03:00
|
|
|
|
BackendCalendarApi.saveAppointment(appointment, null, successCallback);
|
2016-07-17 14:46:38 +03:00
|
|
|
|
} else {
|
|
|
|
|
// Update unavailable time period.
|
|
|
|
|
var unavailable = {
|
|
|
|
|
id: event.data.id,
|
2017-10-31 13:34:06 +03:00
|
|
|
|
start_datetime: event.start.format('YYYY-MM-DD HH:mm:ss'),
|
|
|
|
|
end_datetime: event.end.format('YYYY-MM-DD HH:mm:ss'),
|
2016-07-17 14:46:38 +03:00
|
|
|
|
id_users_provider: event.data.id_users_provider
|
|
|
|
|
};
|
|
|
|
|
|
2017-10-31 12:37:00 +03:00
|
|
|
|
var successCallback = function (response) {
|
|
|
|
|
var undoFunction = function () {
|
|
|
|
|
unavailable.start_datetime = Date.parseExact(
|
|
|
|
|
unavailable.start_datetime, 'yyyy-MM-dd HH:mm:ss')
|
2017-10-31 13:34:06 +03:00
|
|
|
|
.add({days: -delta.days(), minutes: -delta.minutes()})
|
2017-10-31 12:37:00 +03:00
|
|
|
|
.toString('yyyy-MM-dd HH:mm:ss');
|
2016-07-17 14:46:38 +03:00
|
|
|
|
|
2017-10-31 12:37:00 +03:00
|
|
|
|
unavailable.end_datetime = Date.parseExact(
|
|
|
|
|
unavailable.end_datetime, 'yyyy-MM-dd HH:mm:ss')
|
2017-10-31 13:34:06 +03:00
|
|
|
|
.add({days: -delta.days(), minutes: -delta.minutes()})
|
2017-10-31 12:37:00 +03:00
|
|
|
|
.toString('yyyy-MM-dd HH:mm:ss');
|
2016-07-17 14:46:38 +03:00
|
|
|
|
|
2017-10-31 12:37:00 +03:00
|
|
|
|
event.data.start_datetime = unavailable.start_datetime;
|
|
|
|
|
event.data.end_datetime = unavailable.end_datetime;
|
2016-07-17 14:46:38 +03:00
|
|
|
|
|
2017-10-31 12:37:00 +03:00
|
|
|
|
var url = GlobalVariables.baseUrl + '/index.php/backend_api/ajax_save_unavailable';
|
|
|
|
|
var data = {
|
2016-07-17 14:46:38 +03:00
|
|
|
|
csrfToken: GlobalVariables.csrfToken,
|
|
|
|
|
unavailable: JSON.stringify(unavailable)
|
|
|
|
|
};
|
|
|
|
|
|
2020-05-06 20:15:11 +03:00
|
|
|
|
$.post(url, data)
|
|
|
|
|
.done(function () {
|
|
|
|
|
$('#notification').hide('blind');
|
|
|
|
|
revertFunc();
|
|
|
|
|
})
|
|
|
|
|
.fail(GeneralFunctions.ajaxFailureHandler);
|
2016-07-17 14:46:38 +03:00
|
|
|
|
};
|
|
|
|
|
|
2017-09-11 17:09:15 +03:00
|
|
|
|
Backend.displayNotification(EALang.unavailable_updated, [
|
2016-07-17 14:46:38 +03:00
|
|
|
|
{
|
|
|
|
|
label: 'Undo',
|
|
|
|
|
function: undoFunction
|
|
|
|
|
}
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$('#footer').css('position', 'static'); // Footer position fix.
|
|
|
|
|
};
|
|
|
|
|
|
2017-10-31 12:37:00 +03:00
|
|
|
|
BackendCalendarApi.saveUnavailable(unavailable, successCallback);
|
2016-07-17 14:46:38 +03:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2017-10-31 12:37:00 +03:00
|
|
|
|
* Calendar "View Render" Callback
|
2016-07-17 14:46:38 +03:00
|
|
|
|
*
|
|
|
|
|
* Whenever the calendar changes or refreshes its view certain actions need to be made, in order to
|
|
|
|
|
* display proper information to the user.
|
|
|
|
|
*/
|
2020-05-06 20:23:49 +03:00
|
|
|
|
function calendarViewRender() {
|
2016-07-17 14:46:38 +03:00
|
|
|
|
if ($('#select-filter-item').val() === null) {
|
2017-10-31 12:37:00 +03:00
|
|
|
|
return;
|
2016-07-17 14:46:38 +03:00
|
|
|
|
}
|
|
|
|
|
|
2020-05-06 20:23:49 +03:00
|
|
|
|
refreshCalendarAppointments(
|
2017-10-31 12:37:00 +03:00
|
|
|
|
$('#calendar'),
|
|
|
|
|
$('#select-filter-item').val(),
|
|
|
|
|
$('#select-filter-item option:selected').attr('type'),
|
|
|
|
|
$('#calendar').fullCalendar('getView').start,
|
|
|
|
|
$('#calendar').fullCalendar('getView').end);
|
2016-07-17 14:46:38 +03:00
|
|
|
|
|
|
|
|
|
$(window).trigger('resize'); // Places the footer on the bottom.
|
|
|
|
|
|
|
|
|
|
// Remove all open popovers.
|
2020-05-12 21:52:32 +03:00
|
|
|
|
$('.close-popover').each(function (index, closePopoverButton) {
|
|
|
|
|
$(closePopoverButton).parents('.popover').popover('destroy');
|
2016-07-17 14:46:38 +03:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// Add new pop overs.
|
2020-05-12 21:52:32 +03:00
|
|
|
|
$('.fv-events').each(function (index, eventElement) {
|
|
|
|
|
$(eventElement).popover();
|
2016-07-17 14:46:38 +03:00
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Convert titles to HTML
|
|
|
|
|
*
|
|
|
|
|
* On some calendar events the titles contain html markup that is not displayed properly due to the
|
2017-10-31 12:37:00 +03:00
|
|
|
|
* FullCalendar plugin. This plugin sets the .fc-event-title value by using the $.text() method and
|
2016-10-10 19:29:48 +03:00
|
|
|
|
* not the $.html() method. So in order for the title to display the html properly we convert all the
|
2016-07-17 14:46:38 +03:00
|
|
|
|
* .fc-event-titles where needed into html.
|
|
|
|
|
*/
|
2020-05-06 20:23:49 +03:00
|
|
|
|
function convertTitlesToHtml() {
|
2016-07-17 14:46:38 +03:00
|
|
|
|
// Convert the titles to html code.
|
2020-05-12 21:52:32 +03:00
|
|
|
|
$('.fc-custom').each(function (index, customEventElement) {
|
|
|
|
|
var title = $(customEventElement).find('.fc-event-title').text();
|
|
|
|
|
$(customEventElement).find('.fc-event-title').html(title);
|
|
|
|
|
var time = $(customEventElement).find('.fc-event-time').text();
|
|
|
|
|
$(customEventElement).find('.fc-event-time').html(time);
|
2016-07-17 14:46:38 +03:00
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Refresh Calendar Appointments
|
|
|
|
|
*
|
|
|
|
|
* This method reloads the registered appointments for the selected date period and filter type.
|
|
|
|
|
*
|
|
|
|
|
* @param {Object} $calendar The calendar jQuery object.
|
|
|
|
|
* @param {Number} recordId The selected record id.
|
|
|
|
|
* @param {String} filterType The filter type, could be either FILTER_TYPE_PROVIDER or FILTER_TYPE_SERVICE.
|
|
|
|
|
* @param {Date} startDate Visible start date of the calendar.
|
|
|
|
|
* @param {Date} endDate Visible end date of the calendar.
|
|
|
|
|
*/
|
2020-05-06 20:23:49 +03:00
|
|
|
|
function refreshCalendarAppointments($calendar, recordId, filterType, startDate, endDate) {
|
2017-10-31 12:37:00 +03:00
|
|
|
|
var url = GlobalVariables.baseUrl + '/index.php/backend_api/ajax_get_calendar_appointments';
|
2020-05-06 20:15:11 +03:00
|
|
|
|
|
2017-10-31 12:37:00 +03:00
|
|
|
|
var data = {
|
2016-07-17 14:46:38 +03:00
|
|
|
|
csrfToken: GlobalVariables.csrfToken,
|
|
|
|
|
record_id: recordId,
|
2017-10-31 12:37:00 +03:00
|
|
|
|
start_date: startDate.format('YYYY-MM-DD'),
|
|
|
|
|
end_date: endDate.format('YYYY-MM-DD'),
|
2016-07-17 14:46:38 +03:00
|
|
|
|
filter_type: filterType
|
|
|
|
|
};
|
|
|
|
|
|
2020-04-06 21:48:11 +03:00
|
|
|
|
$('#loading').css('visibility', 'hidden');
|
2020-04-06 21:34:32 +03:00
|
|
|
|
|
2020-05-06 20:15:11 +03:00
|
|
|
|
return $.post(url, data)
|
|
|
|
|
.done(function (response) {
|
|
|
|
|
// Add appointments to calendar.
|
|
|
|
|
var calendarEvents = [];
|
2020-05-12 21:52:32 +03:00
|
|
|
|
|
2020-05-06 20:15:11 +03:00
|
|
|
|
var $calendar = $('#calendar');
|
|
|
|
|
|
2020-05-12 21:52:32 +03:00
|
|
|
|
response.appointments.forEach(function (appointment) {
|
2020-05-06 20:15:11 +03:00
|
|
|
|
var event = {
|
|
|
|
|
id: appointment.id,
|
|
|
|
|
title: appointment.service.name + ' - '
|
|
|
|
|
+ appointment.customer.first_name + ' '
|
|
|
|
|
+ appointment.customer.last_name,
|
|
|
|
|
start: moment(appointment.start_datetime),
|
|
|
|
|
end: moment(appointment.end_datetime),
|
|
|
|
|
allDay: false,
|
|
|
|
|
data: appointment // Store appointment data for later use.
|
|
|
|
|
};
|
2016-07-17 14:46:38 +03:00
|
|
|
|
|
2020-05-06 20:15:11 +03:00
|
|
|
|
calendarEvents.push(event);
|
|
|
|
|
});
|
2016-07-17 14:46:38 +03:00
|
|
|
|
|
2020-05-06 20:15:11 +03:00
|
|
|
|
$calendar.fullCalendar('removeEvents');
|
|
|
|
|
$calendar.fullCalendar('addEventSource', calendarEvents);
|
|
|
|
|
|
|
|
|
|
var weekDays = [
|
|
|
|
|
'sunday',
|
|
|
|
|
'monday',
|
|
|
|
|
'tuesday',
|
|
|
|
|
'wednesday',
|
|
|
|
|
'thursday',
|
|
|
|
|
'friday',
|
|
|
|
|
'saturday'
|
|
|
|
|
];
|
2017-10-31 12:37:00 +03:00
|
|
|
|
|
2020-05-06 20:15:11 +03:00
|
|
|
|
// :: ADD PROVIDER'S UNAVAILABLE TIME PERIODS
|
|
|
|
|
var calendarView = $calendar.fullCalendar('getView').name;
|
|
|
|
|
|
|
|
|
|
if (filterType === FILTER_TYPE_PROVIDER && calendarView !== 'month') {
|
2020-05-12 21:52:32 +03:00
|
|
|
|
GlobalVariables.availableProviders.forEach(function (provider, index) {
|
2020-05-06 20:15:11 +03:00
|
|
|
|
if (Number(provider.id) === Number(recordId)) {
|
2020-05-12 21:52:32 +03:00
|
|
|
|
var workingPlan = {};
|
2020-05-06 20:15:11 +03:00
|
|
|
|
var workingPlanBulk = jQuery.parseJSON(provider.settings.working_plan);
|
|
|
|
|
var extraWorkingPlan = jQuery.parseJSON(provider.settings.extra_working_plan);
|
|
|
|
|
var unavailablePeriod;
|
|
|
|
|
|
|
|
|
|
// Sort the working plan starting with the first day as set in General settings to correctly
|
|
|
|
|
// align breaks in the calendar display.
|
|
|
|
|
var firstWeekdayNumber = GeneralFunctions.getWeekDayId(GlobalVariables.firstWeekday);
|
|
|
|
|
workingPlan = GeneralFunctions.sortWeekDictionary(workingPlanBulk, firstWeekdayNumber);
|
|
|
|
|
|
|
|
|
|
switch (calendarView) {
|
|
|
|
|
case 'agendaDay':
|
|
|
|
|
var selectedDayName = GeneralFunctions
|
|
|
|
|
.getWeekdayName(parseInt($calendar.fullCalendar('getView').start.format('d')));
|
|
|
|
|
|
|
|
|
|
// Add custom unavailable periods.
|
2020-05-12 21:52:32 +03:00
|
|
|
|
response.unavailables.forEach(function (unavailable, index) {
|
2020-05-06 20:15:11 +03:00
|
|
|
|
var notes = unavailable.notes ? ' - ' + unavailable.notes : '';
|
|
|
|
|
|
|
|
|
|
if (unavailable.notes.length > 30) {
|
|
|
|
|
notes = unavailable.notes.substring(0, 30) + '...'
|
|
|
|
|
}
|
2017-10-31 12:37:00 +03:00
|
|
|
|
|
2020-05-06 20:15:11 +03:00
|
|
|
|
var unavailablePeriod = {
|
|
|
|
|
title: EALang.unavailable + notes,
|
|
|
|
|
start: moment(unavailable.start_datetime),
|
|
|
|
|
end: moment(unavailable.end_datetime),
|
2018-04-12 17:46:45 +03:00
|
|
|
|
allDay: false,
|
2020-05-06 20:15:11 +03:00
|
|
|
|
color: '#879DB4',
|
|
|
|
|
editable: true,
|
|
|
|
|
className: 'fc-unavailable fc-custom',
|
|
|
|
|
data: unavailable
|
2018-04-12 17:46:45 +03:00
|
|
|
|
};
|
2017-10-31 12:37:00 +03:00
|
|
|
|
|
2018-04-12 17:46:45 +03:00
|
|
|
|
$calendar.fullCalendar('renderEvent', unavailablePeriod, false);
|
2020-05-06 20:15:11 +03:00
|
|
|
|
});
|
2018-04-12 17:46:45 +03:00
|
|
|
|
|
2020-05-06 20:15:11 +03:00
|
|
|
|
// Non-working day.
|
|
|
|
|
if (workingPlan[selectedDayName] === null) {
|
|
|
|
|
// Extra working plan day.
|
|
|
|
|
var selectedDay = $calendar.fullCalendar('getView').intervalStart.clone();
|
|
|
|
|
selectedDay.locale('en');
|
|
|
|
|
if (extraWorkingPlan && selectedDay.format() in extraWorkingPlan) {
|
|
|
|
|
workingPlan[selectedDay.format('dddd').toLowerCase()] = extraWorkingPlan[selectedDay.format('YYYY-MM-DD')];
|
2017-10-31 12:37:00 +03:00
|
|
|
|
|
2020-05-06 20:15:11 +03:00
|
|
|
|
var start_extra = selectedDay.format('YYYY-MM-DD') + ' ' + extraWorkingPlan[selectedDay.format('YYYY-MM-DD')].start;
|
|
|
|
|
var end_extra = selectedDay.format('YYYY-MM-DD') + ' ' + extraWorkingPlan[selectedDay.format('YYYY-MM-DD')].end;
|
2018-04-12 16:03:46 +03:00
|
|
|
|
|
|
|
|
|
var extraPeriod = {
|
|
|
|
|
title: EALang.extra_period,
|
|
|
|
|
start: moment(start_extra, 'YYYY-MM-DD HH:mm', true),
|
|
|
|
|
end: moment(end_extra, 'YYYY-MM-DD HH:mm', true).add(1, 'day'),
|
|
|
|
|
allDay: true,
|
|
|
|
|
color: '#879DB4',
|
|
|
|
|
editable: false,
|
|
|
|
|
className: 'fc-extra fc-custom',
|
|
|
|
|
data: provider
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
$calendar.fullCalendar('renderEvent', extraPeriod, false);
|
|
|
|
|
} else {
|
|
|
|
|
unavailablePeriod = {
|
|
|
|
|
title: EALang.not_working,
|
2020-05-06 20:15:11 +03:00
|
|
|
|
start: $calendar.fullCalendar('getView').intervalStart.clone(),
|
|
|
|
|
end: $calendar.fullCalendar('getView').intervalEnd.clone(),
|
2018-04-12 16:03:46 +03:00
|
|
|
|
allDay: false,
|
|
|
|
|
color: '#BEBEBE',
|
|
|
|
|
editable: false,
|
|
|
|
|
className: 'fc-unavailable'
|
|
|
|
|
};
|
|
|
|
|
|
2020-05-06 20:15:11 +03:00
|
|
|
|
$calendar.fullCalendar('renderEvent', unavailablePeriod, false);
|
2018-04-12 16:03:46 +03:00
|
|
|
|
|
2020-05-06 20:15:11 +03:00
|
|
|
|
return; // Go to next loop.
|
2018-04-12 16:03:46 +03:00
|
|
|
|
}
|
2016-07-17 14:46:38 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Add unavailable period before work starts.
|
2020-05-06 20:15:11 +03:00
|
|
|
|
var calendarDateStart = moment($calendar.fullCalendar('getView').start.format('YYYY-MM-DD') + ' 00:00:00');
|
|
|
|
|
var startHour = workingPlan[selectedDayName].start.split(':');
|
|
|
|
|
var workDateStart = calendarDateStart.clone();
|
|
|
|
|
workDateStart.hour(parseInt(startHour[0]));
|
|
|
|
|
workDateStart.minute(parseInt(startHour[1]));
|
|
|
|
|
|
|
|
|
|
if (calendarDateStart < workDateStart) {
|
|
|
|
|
var unavailablePeriodBeforeWorkStarts = {
|
2017-09-11 17:09:15 +03:00
|
|
|
|
title: EALang.not_working,
|
2020-05-06 20:15:11 +03:00
|
|
|
|
start: calendarDateStart,
|
|
|
|
|
end: workDateStart,
|
2016-07-17 14:46:38 +03:00
|
|
|
|
allDay: false,
|
|
|
|
|
color: '#BEBEBE',
|
|
|
|
|
editable: false,
|
|
|
|
|
className: 'fc-unavailable'
|
|
|
|
|
};
|
2020-05-06 20:15:11 +03:00
|
|
|
|
$calendar.fullCalendar('renderEvent', unavailablePeriodBeforeWorkStarts, false);
|
2016-07-17 14:46:38 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Add unavailable period after work ends.
|
2020-05-06 20:15:11 +03:00
|
|
|
|
var calendarDateEnd = moment($calendar.fullCalendar('getView').end.format('YYYY-MM-DD') + ' 00:00:00');
|
|
|
|
|
var endHour = workingPlan[selectedDayName].end.split(':');
|
|
|
|
|
var workDateEnd = calendarDateStart.clone();
|
2017-10-31 12:37:00 +03:00
|
|
|
|
|
2020-05-06 20:15:11 +03:00
|
|
|
|
workDateEnd.hour(parseInt(endHour[0]));
|
|
|
|
|
workDateEnd.minute(parseInt(endHour[1]));
|
|
|
|
|
|
|
|
|
|
if (calendarDateEnd > workDateEnd) {
|
|
|
|
|
var unavailablePeriodAfterWorkEnds = {
|
2017-09-11 17:09:15 +03:00
|
|
|
|
title: EALang.not_working,
|
2020-05-06 20:15:11 +03:00
|
|
|
|
start: workDateEnd,
|
|
|
|
|
end: calendarDateEnd,
|
2016-07-17 14:46:38 +03:00
|
|
|
|
allDay: false,
|
|
|
|
|
color: '#BEBEBE',
|
|
|
|
|
editable: false,
|
2018-04-30 14:49:16 +03:00
|
|
|
|
className: 'fc-unavailable'
|
2016-07-17 14:46:38 +03:00
|
|
|
|
};
|
2017-10-31 12:37:00 +03:00
|
|
|
|
|
2020-05-06 20:15:11 +03:00
|
|
|
|
$calendar.fullCalendar('renderEvent', unavailablePeriodAfterWorkEnds, false);
|
2016-07-17 14:46:38 +03:00
|
|
|
|
}
|
|
|
|
|
|
2020-05-06 20:15:11 +03:00
|
|
|
|
// Add unavailable periods for breaks.
|
2016-07-17 14:46:38 +03:00
|
|
|
|
var breakStart;
|
|
|
|
|
var breakEnd;
|
2017-10-31 12:37:00 +03:00
|
|
|
|
|
2020-05-12 21:52:32 +03:00
|
|
|
|
workingPlan[selectedDayName].breaks.forEach(function (currentBreak) {
|
2017-10-31 12:37:00 +03:00
|
|
|
|
var breakStartString = currentBreak.start.split(':');
|
2020-05-06 20:15:11 +03:00
|
|
|
|
breakStart = calendarDateStart.clone();
|
2017-10-31 12:37:00 +03:00
|
|
|
|
breakStart.hour(parseInt(breakStartString[0]));
|
|
|
|
|
breakStart.minute(parseInt(breakStartString[1]));
|
|
|
|
|
|
|
|
|
|
var breakEndString = currentBreak.end.split(':');
|
2020-05-06 20:15:11 +03:00
|
|
|
|
breakEnd = calendarDateStart.clone();
|
2017-10-31 12:37:00 +03:00
|
|
|
|
breakEnd.hour(parseInt(breakEndString[0]));
|
|
|
|
|
breakEnd.minute(parseInt(breakEndString[1]));
|
|
|
|
|
|
2016-07-17 14:46:38 +03:00
|
|
|
|
var unavailablePeriod = {
|
2017-09-11 17:09:15 +03:00
|
|
|
|
title: EALang.break,
|
2020-05-06 20:15:11 +03:00
|
|
|
|
start: breakStart,
|
|
|
|
|
end: breakEnd,
|
2016-07-17 14:46:38 +03:00
|
|
|
|
allDay: false,
|
|
|
|
|
color: '#BEBEBE',
|
|
|
|
|
editable: false,
|
|
|
|
|
className: 'fc-unavailable fc-break'
|
|
|
|
|
};
|
2017-10-31 12:37:00 +03:00
|
|
|
|
|
2016-07-17 14:46:38 +03:00
|
|
|
|
$calendar.fullCalendar('renderEvent', unavailablePeriod, false);
|
|
|
|
|
});
|
|
|
|
|
|
2020-05-06 20:15:11 +03:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 'agendaWeek':
|
|
|
|
|
var currentDateStart = $calendar.fullCalendar('getView').start.clone();
|
|
|
|
|
var currentDateEnd = currentDateStart.clone().add(1, 'days');
|
|
|
|
|
|
|
|
|
|
// Add custom unavailable periods (they are always displayed on the calendar, even if
|
|
|
|
|
// the provider won't work on that day).
|
2020-05-12 21:52:32 +03:00
|
|
|
|
response.unavailables.forEach(function (unavailable) {
|
2020-05-06 20:15:11 +03:00
|
|
|
|
var notes = unavailable.notes ? ' - ' + unavailable.notes : '';
|
|
|
|
|
|
|
|
|
|
if (unavailable.notes.length > 30) {
|
|
|
|
|
notes = unavailable.notes.substring(0, 30) + '...'
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
unavailablePeriod = {
|
|
|
|
|
title: EALang.unavailable + notes,
|
|
|
|
|
start: moment(unavailable.start_datetime),
|
|
|
|
|
end: moment(unavailable.end_datetime),
|
|
|
|
|
allDay: false,
|
|
|
|
|
color: '#879DB4',
|
|
|
|
|
editable: true,
|
|
|
|
|
className: 'fc-unavailable fc-custom',
|
|
|
|
|
data: unavailable
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
$calendar.fullCalendar('renderEvent', unavailablePeriod, false);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
$.each(workingPlan, function (index, workingDay) {
|
|
|
|
|
if (workingDay === null) {
|
|
|
|
|
// Check if the day is an extra working day added to the working plan
|
|
|
|
|
if (extraWorkingPlan && currentDateStart.format('YYYY-MM-DD') in extraWorkingPlan) {
|
|
|
|
|
workingDay = extraWorkingPlan[currentDateStart.format('YYYY-MM-DD')]
|
|
|
|
|
|
2020-05-12 21:52:32 +03:00
|
|
|
|
var extraPeriodStart = currentDateStart.format('YYYY-MM-DD') + ' ' + extraWorkingPlan[currentDateStart.format('YYYY-MM-DD')].start;
|
|
|
|
|
var extraPeriodEnd = currentDateStart.format('YYYY-MM-DD') + ' ' + extraWorkingPlan[currentDateStart.format('YYYY-MM-DD')].end;
|
2020-05-06 20:15:11 +03:00
|
|
|
|
|
|
|
|
|
var extraPeriod = {
|
|
|
|
|
title: EALang.extra_period,
|
2020-05-12 21:52:32 +03:00
|
|
|
|
start: moment(extraPeriodStart, 'YYYY-MM-DD HH:mm', true),
|
|
|
|
|
end: moment(extraPeriodEnd, 'YYYY-MM-DD HH:mm', true).add(1, 'day'),
|
2020-05-06 20:15:11 +03:00
|
|
|
|
allDay: true,
|
|
|
|
|
color: '#879DB4',
|
|
|
|
|
editable: false,
|
|
|
|
|
className: 'fc-extra fc-custom',
|
|
|
|
|
data: provider
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
$calendar.fullCalendar('renderEvent', extraPeriod, false);
|
|
|
|
|
} else {
|
|
|
|
|
// Add a full day unavailable event.
|
|
|
|
|
unavailablePeriod = {
|
|
|
|
|
title: EALang.not_working,
|
|
|
|
|
start: moment(currentDateStart.format('YYYY-MM-DD')),
|
|
|
|
|
end: moment(currentDateEnd.format('YYYY-MM-DD')),
|
|
|
|
|
allDay: false,
|
|
|
|
|
color: '#BEBEBE',
|
|
|
|
|
editable: false,
|
|
|
|
|
className: 'fc-unavailable'
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
$calendar.fullCalendar('renderEvent', unavailablePeriod, true);
|
|
|
|
|
currentDateStart.add(1, 'days');
|
|
|
|
|
currentDateEnd.add(1, 'days');
|
|
|
|
|
|
|
|
|
|
return; // Go to the next loop.
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var start;
|
|
|
|
|
var end;
|
|
|
|
|
|
|
|
|
|
// Add unavailable period before work starts.
|
|
|
|
|
var workingDayStartString = workingDay.start.split(':');
|
|
|
|
|
start = currentDateStart.clone();
|
|
|
|
|
start.hour(parseInt(workingDayStartString[0]));
|
|
|
|
|
start.minute(parseInt(workingDayStartString[1]));
|
|
|
|
|
|
|
|
|
|
if (currentDateStart < start) {
|
|
|
|
|
unavailablePeriod = {
|
|
|
|
|
title: EALang.not_working,
|
|
|
|
|
start: moment(currentDateStart.format('YYYY-MM-DD') + ' 00:00:00'),
|
|
|
|
|
end: moment(currentDateStart.format('YYYY-MM-DD') + ' ' + workingDay.start + ':00'),
|
|
|
|
|
allDay: false,
|
|
|
|
|
color: '#BEBEBE',
|
|
|
|
|
editable: false,
|
|
|
|
|
className: 'fc-unavailable'
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
$calendar.fullCalendar('renderEvent', unavailablePeriod, true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Add unavailable period after work ends.
|
|
|
|
|
var workingDayEndString = workingDay.end.split(':');
|
|
|
|
|
end = currentDateStart.clone();
|
|
|
|
|
end.hour(parseInt(workingDayEndString[0]));
|
|
|
|
|
end.minute(parseInt(workingDayEndString[1]));
|
|
|
|
|
|
|
|
|
|
if (currentDateEnd > end) {
|
|
|
|
|
unavailablePeriod = {
|
|
|
|
|
title: EALang.not_working,
|
|
|
|
|
start: moment(currentDateStart.format('YYYY-MM-DD') + ' ' + workingDay.end + ':00'),
|
|
|
|
|
end: moment(currentDateEnd.format('YYYY-MM-DD') + ' 00:00:00'),
|
|
|
|
|
allDay: false,
|
|
|
|
|
color: '#BEBEBE',
|
|
|
|
|
editable: false,
|
|
|
|
|
className: 'fc-unavailable'
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
$calendar.fullCalendar('renderEvent', unavailablePeriod, false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Add unavailable periods during day breaks.
|
|
|
|
|
var breakStart;
|
|
|
|
|
var breakEnd;
|
|
|
|
|
|
2020-05-12 21:52:32 +03:00
|
|
|
|
workingDay.breaks.forEach(function (currentBreak, index) {
|
2020-05-06 20:15:11 +03:00
|
|
|
|
var breakStartString = currentBreak.start.split(':');
|
|
|
|
|
breakStart = currentDateStart.clone();
|
|
|
|
|
breakStart.hour(parseInt(breakStartString[0]));
|
|
|
|
|
breakStart.minute(parseInt(breakStartString[1]));
|
|
|
|
|
|
|
|
|
|
var breakEndString = currentBreak.end.split(':');
|
|
|
|
|
breakEnd = currentDateStart.clone();
|
|
|
|
|
breakEnd.hour(parseInt(breakEndString[0]));
|
|
|
|
|
breakEnd.minute(parseInt(breakEndString[1]));
|
|
|
|
|
|
|
|
|
|
var unavailablePeriod = {
|
|
|
|
|
title: EALang.break,
|
|
|
|
|
start: moment(currentDateStart.format('YYYY-MM-DD') + ' ' + currentBreak.start),
|
|
|
|
|
end: moment(currentDateStart.format('YYYY-MM-DD') + ' ' + currentBreak.end),
|
|
|
|
|
allDay: false,
|
|
|
|
|
color: '#BEBEBE',
|
|
|
|
|
editable: false,
|
|
|
|
|
className: 'fc-unavailable fc-break'
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
$calendar.fullCalendar('renderEvent', unavailablePeriod, false);
|
|
|
|
|
});
|
2017-10-31 12:37:00 +03:00
|
|
|
|
|
2020-05-06 20:15:11 +03:00
|
|
|
|
currentDateStart.add(1, 'days');
|
|
|
|
|
currentDateEnd.add(1, 'days');
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
}
|
2016-07-17 14:46:38 +03:00
|
|
|
|
}
|
2020-05-06 20:15:11 +03:00
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
})
|
2020-04-06 21:34:32 +03:00
|
|
|
|
.fail(GeneralFunctions.ajaxFailureHandler)
|
|
|
|
|
.always(function() {
|
2020-04-06 21:48:11 +03:00
|
|
|
|
$('#loading').css('visibility', '')
|
2020-04-06 21:34:32 +03:00
|
|
|
|
});
|
2016-07-17 14:46:38 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2017-10-31 12:37:00 +03:00
|
|
|
|
exports.initialize = function () {
|
|
|
|
|
// Dynamic date formats.
|
2016-07-17 14:46:38 +03:00
|
|
|
|
var columnFormat = {};
|
|
|
|
|
|
2017-10-31 12:37:00 +03:00
|
|
|
|
switch (GlobalVariables.dateFormat) {
|
2016-07-17 14:46:38 +03:00
|
|
|
|
case 'DMY':
|
2017-10-31 12:37:00 +03:00
|
|
|
|
columnFormat = 'ddd D/M';
|
2016-07-17 14:46:38 +03:00
|
|
|
|
break;
|
2017-10-31 12:37:00 +03:00
|
|
|
|
|
2016-07-17 14:46:38 +03:00
|
|
|
|
case 'MDY':
|
|
|
|
|
case 'YMD':
|
2017-10-31 12:37:00 +03:00
|
|
|
|
columnFormat = 'ddd M/D';
|
2016-07-17 14:46:38 +03:00
|
|
|
|
break;
|
2017-10-31 12:37:00 +03:00
|
|
|
|
|
2016-07-17 14:46:38 +03:00
|
|
|
|
default:
|
|
|
|
|
throw new Error('Invalid date format setting provided!', GlobalVariables.dateFormat);
|
|
|
|
|
}
|
|
|
|
|
|
2018-03-06 14:20:47 +03:00
|
|
|
|
// Time formats
|
|
|
|
|
var timeFormat = '';
|
|
|
|
|
var slotTimeFormat= '';
|
|
|
|
|
|
|
|
|
|
switch (GlobalVariables.timeFormat) {
|
2018-03-08 16:55:51 +03:00
|
|
|
|
case 'military':
|
2018-03-06 14:20:47 +03:00
|
|
|
|
timeFormat = 'H:mm';
|
|
|
|
|
slotTimeFormat = 'H(:mm)';
|
|
|
|
|
break;
|
2018-03-08 16:55:51 +03:00
|
|
|
|
case 'regular':
|
2018-03-17 20:00:55 +03:00
|
|
|
|
timeFormat = 'h:mm a';
|
|
|
|
|
slotTimeFormat = 'h(:mm) a';
|
2018-03-06 14:20:47 +03:00
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
throw new Error('Invalid time format setting provided!', GlobalVariables.timeFormat);
|
|
|
|
|
}
|
|
|
|
|
|
2016-07-17 14:46:38 +03:00
|
|
|
|
var defaultView = window.innerWidth < 468 ? 'agendaDay' : 'agendaWeek';
|
|
|
|
|
|
2020-04-27 21:14:20 +03:00
|
|
|
|
var firstWeekday = GlobalVariables.firstWeekday;
|
|
|
|
|
var firstWeekdayNumber = GeneralFunctions.getWeekDayId(firstWeekday);
|
2018-06-29 01:41:17 +03:00
|
|
|
|
|
2016-07-17 14:46:38 +03:00
|
|
|
|
// Initialize page calendar
|
|
|
|
|
$('#calendar').fullCalendar({
|
|
|
|
|
defaultView: defaultView,
|
2020-05-06 20:23:49 +03:00
|
|
|
|
height: getCalendarHeight(),
|
2016-07-17 14:46:38 +03:00
|
|
|
|
editable: true,
|
2020-04-27 21:14:20 +03:00
|
|
|
|
firstDay: firstWeekdayNumber,
|
2017-11-08 17:17:29 +03:00
|
|
|
|
snapDuration: '00:30:00',
|
2018-03-06 14:20:47 +03:00
|
|
|
|
timeFormat: timeFormat,
|
|
|
|
|
slotLabelFormat: slotTimeFormat,
|
2017-09-11 17:09:15 +03:00
|
|
|
|
allDayText: EALang.all_day,
|
2016-07-17 14:46:38 +03:00
|
|
|
|
columnFormat: columnFormat,
|
2017-10-31 12:37:00 +03:00
|
|
|
|
titleFormat: 'MMMM YYYY',
|
2016-07-17 14:46:38 +03:00
|
|
|
|
header: {
|
|
|
|
|
left: 'prev,next today',
|
|
|
|
|
center: 'title',
|
|
|
|
|
right: 'agendaDay,agendaWeek,month'
|
|
|
|
|
},
|
|
|
|
|
|
2017-11-08 17:17:29 +03:00
|
|
|
|
// Selectable
|
|
|
|
|
selectable: true,
|
|
|
|
|
selectHelper: true,
|
2018-01-23 12:08:37 +03:00
|
|
|
|
select: function (start, end, jsEvent, view) {
|
2017-11-08 17:17:29 +03:00
|
|
|
|
if (!start.hasTime() || !end.hasTime()) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$('#insert-appointment').trigger('click');
|
|
|
|
|
|
|
|
|
|
// Preselect service & provider.
|
2020-05-06 20:15:11 +03:00
|
|
|
|
var service;
|
|
|
|
|
|
2017-11-08 17:17:29 +03:00
|
|
|
|
if ($('#select-filter-item option:selected').attr('type') === FILTER_TYPE_SERVICE) {
|
2020-05-06 20:15:11 +03:00
|
|
|
|
service = GlobalVariables.availableServices.find(function (service) {
|
|
|
|
|
return Number(service.id) === Number($('#select-filter-item').val());
|
2017-11-08 17:17:29 +03:00
|
|
|
|
});
|
|
|
|
|
$('#select-service').val(service.id).trigger('change');
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
var provider = GlobalVariables.availableProviders.find(function (provider) {
|
2020-05-06 20:15:11 +03:00
|
|
|
|
return Number(provider.id) === Number($('#select-filter-item').val());
|
2017-11-08 17:17:29 +03:00
|
|
|
|
});
|
|
|
|
|
|
2020-05-06 20:15:11 +03:00
|
|
|
|
service = GlobalVariables.availableServices.find(function (service) {
|
2017-11-08 17:17:29 +03:00
|
|
|
|
return provider.services.indexOf(service.id) !== -1
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
$('#select-service').val(service.id).trigger('change');
|
|
|
|
|
$('#select-provider').val(provider.id).trigger('change');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Preselect time
|
2020-07-06 19:07:43 +03:00
|
|
|
|
$('#start-datetime').datepicker('setDate', new Date(start.format('YYYY/MM/DD HH:mm:ss')));
|
|
|
|
|
$('#end-datetime').datepicker('setDate', new Date(end.format('YYYY/MM/DD HH:mm:ss')));
|
2017-11-08 17:17:29 +03:00
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
},
|
|
|
|
|
|
2016-07-17 14:46:38 +03:00
|
|
|
|
// Translations
|
2017-09-11 17:09:15 +03:00
|
|
|
|
monthNames: [EALang.january, EALang.february, EALang.march, EALang.april,
|
2017-10-31 12:37:00 +03:00
|
|
|
|
EALang.may, EALang.june, EALang.july, EALang.august,
|
|
|
|
|
EALang.september, EALang.october, EALang.november,
|
|
|
|
|
EALang.december],
|
|
|
|
|
monthNamesShort: [EALang.january.substr(0, 3), EALang.february.substr(0, 3),
|
|
|
|
|
EALang.march.substr(0, 3), EALang.april.substr(0, 3),
|
|
|
|
|
EALang.may.substr(0, 3), EALang.june.substr(0, 3),
|
|
|
|
|
EALang.july.substr(0, 3), EALang.august.substr(0, 3),
|
|
|
|
|
EALang.september.substr(0, 3), EALang.october.substr(0, 3),
|
|
|
|
|
EALang.november.substr(0, 3), EALang.december.substr(0, 3)],
|
2017-09-11 17:09:15 +03:00
|
|
|
|
dayNames: [EALang.sunday, EALang.monday, EALang.tuesday, EALang.wednesday,
|
2017-10-31 12:37:00 +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)],
|
2016-07-17 14:46:38 +03:00
|
|
|
|
buttonText: {
|
2017-09-11 17:09:15 +03:00
|
|
|
|
today: EALang.today,
|
|
|
|
|
day: EALang.day,
|
|
|
|
|
week: EALang.week,
|
|
|
|
|
month: EALang.month
|
2016-07-17 14:46:38 +03:00
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
// Calendar events need to be declared on initialization.
|
2020-05-06 20:23:49 +03:00
|
|
|
|
windowResize: calendarWindowResize,
|
|
|
|
|
viewRender: calendarViewRender,
|
|
|
|
|
dayClick: calendarDayClick,
|
|
|
|
|
eventClick: calendarEventClick,
|
|
|
|
|
eventResize: calendarEventResize,
|
|
|
|
|
eventDrop: calendarEventDrop,
|
|
|
|
|
eventAfterAllRender: convertTitlesToHtml
|
2016-07-17 14:46:38 +03:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// Trigger once to set the proper footer position after calendar initialization.
|
2020-05-06 20:23:49 +03:00
|
|
|
|
calendarWindowResize();
|
2016-07-17 14:46:38 +03:00
|
|
|
|
|
2017-10-31 12:37:00 +03:00
|
|
|
|
// Fill the select list boxes of the page.
|
2016-07-17 14:46:38 +03:00
|
|
|
|
if (GlobalVariables.availableProviders.length > 0) {
|
2020-05-07 19:47:14 +03:00
|
|
|
|
$('<optgroup/>', {
|
|
|
|
|
'label': EALang.providers,
|
|
|
|
|
'type': 'providers-group',
|
|
|
|
|
'html': GlobalVariables.availableProviders.map(function (availableProvider) {
|
|
|
|
|
var hasGoogleSync = availableProvider.settings.google_sync === '1' ? 'true' : 'false';
|
|
|
|
|
|
|
|
|
|
return $('<option/>', {
|
|
|
|
|
'value': availableProvider.id,
|
|
|
|
|
'type': FILTER_TYPE_PROVIDER,
|
|
|
|
|
'google-sync': hasGoogleSync,
|
|
|
|
|
'text': availableProvider.first_name + ' ' + availableProvider.last_name
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
.appendTo('#select-filter-item');
|
2016-07-17 14:46:38 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (GlobalVariables.availableServices.length > 0) {
|
2020-05-07 19:47:14 +03:00
|
|
|
|
$('<optgroup/>', {
|
|
|
|
|
'label': EALang.services,
|
|
|
|
|
'type': 'services-group',
|
|
|
|
|
'html': GlobalVariables.availableServices.map(function (availableService) {
|
|
|
|
|
return $('<option/>', {
|
|
|
|
|
'value': availableService.id,
|
|
|
|
|
'type': FILTER_TYPE_SERVICE,
|
|
|
|
|
'text': availableService.name
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
.appendTo('#select-filter-item');
|
2016-07-17 14:46:38 +03:00
|
|
|
|
}
|
|
|
|
|
|
2017-10-31 12:37:00 +03:00
|
|
|
|
// Check permissions.
|
2020-05-06 20:15:11 +03:00
|
|
|
|
if (GlobalVariables.user.role_slug === Backend.DB_SLUG_PROVIDER) {
|
2016-07-17 14:46:38 +03:00
|
|
|
|
$('#select-filter-item optgroup:eq(0)')
|
2017-10-31 12:37:00 +03:00
|
|
|
|
.find('option[value="' + GlobalVariables.user.id + '"]')
|
|
|
|
|
.prop('selected', true);
|
2016-07-17 14:46:38 +03:00
|
|
|
|
$('#select-filter-item').prop('disabled', true);
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-06 20:15:11 +03:00
|
|
|
|
if (GlobalVariables.user.role_slug === Backend.DB_SLUG_SECRETARY) {
|
2016-07-17 14:46:38 +03:00
|
|
|
|
$('#select-filter-item optgroup:eq(1)').remove();
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-06 20:15:11 +03:00
|
|
|
|
if (GlobalVariables.user.role_slug === Backend.DB_SLUG_SECRETARY) {
|
2016-07-17 14:46:38 +03:00
|
|
|
|
// Remove the providers that are not connected to the secretary.
|
2017-10-31 12:37:00 +03:00
|
|
|
|
$('#select-filter-item option[type="provider"]').each(function (index, option) {
|
2020-05-12 21:52:32 +03:00
|
|
|
|
var provider = GlobalVariables.secretaryProviders.find(function(secretaryProviderId) {
|
|
|
|
|
return Number($(option).val()) === Number(secretaryProviderId);
|
2016-07-17 14:46:38 +03:00
|
|
|
|
});
|
|
|
|
|
|
2020-05-12 21:52:32 +03:00
|
|
|
|
if (!provider) {
|
2016-07-17 14:46:38 +03:00
|
|
|
|
$(option).remove();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2020-05-06 20:15:11 +03:00
|
|
|
|
if (!$('#select-filter-item option[type="provider"]').length) {
|
2016-07-17 14:46:38 +03:00
|
|
|
|
$('#select-filter-item optgroup[type="providers-group"]').remove();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Bind the default event handlers.
|
2020-05-06 20:23:49 +03:00
|
|
|
|
bindEventHandlers();
|
2017-10-31 12:37:00 +03:00
|
|
|
|
|
2016-07-17 14:46:38 +03:00
|
|
|
|
$('#select-filter-item').trigger('change');
|
|
|
|
|
|
|
|
|
|
// Display the edit dialog if an appointment hash is provided.
|
2020-05-06 20:15:11 +03:00
|
|
|
|
if (GlobalVariables.editAppointment) {
|
2016-07-17 14:46:38 +03:00
|
|
|
|
var $dialog = $('#manage-appointment');
|
|
|
|
|
var appointment = GlobalVariables.editAppointment;
|
2016-07-18 23:55:05 +03:00
|
|
|
|
BackendCalendarAppointmentsModal.resetAppointmentDialog();
|
2016-07-17 14:46:38 +03:00
|
|
|
|
|
2017-09-11 17:09:15 +03:00
|
|
|
|
$dialog.find('.modal-header h3').text(EALang.edit_appointment_title);
|
2017-10-31 12:37:00 +03:00
|
|
|
|
$dialog.find('#appointment-id').val(appointment.id);
|
|
|
|
|
$dialog.find('#select-service').val(appointment.id_services).change();
|
|
|
|
|
$dialog.find('#select-provider').val(appointment.id_users_provider);
|
2016-07-17 14:46:38 +03:00
|
|
|
|
|
|
|
|
|
// Set the start and end datetime of the appointment.
|
2017-10-31 12:37:00 +03:00
|
|
|
|
var startDatetime = Date.parseExact(appointment.start_datetime, 'yyyy-MM-dd HH:mm:ss');
|
2016-07-17 14:46:38 +03:00
|
|
|
|
$dialog.find('#start-datetime').val(GeneralFunctions.formatDate(startDatetime, GlobalVariables.dateFormat, true));
|
|
|
|
|
|
2017-10-31 12:37:00 +03:00
|
|
|
|
var endDatetime = Date.parseExact(appointment.end_datetime, 'yyyy-MM-dd HH:mm:ss');
|
2016-07-17 14:46:38 +03:00
|
|
|
|
$dialog.find('#end-datetime').val(GeneralFunctions.formatDate(endDatetime, GlobalVariables.dateFormat, true));
|
|
|
|
|
|
2017-10-31 12:37:00 +03:00
|
|
|
|
var customer = appointment.customer;
|
|
|
|
|
$dialog.find('#customer-id').val(appointment.id_users_customer);
|
|
|
|
|
$dialog.find('#first-name').val(customer.first_name);
|
|
|
|
|
$dialog.find('#last-name').val(customer.last_name);
|
|
|
|
|
$dialog.find('#email').val(customer.email);
|
|
|
|
|
$dialog.find('#phone-number').val(customer.phone_number);
|
|
|
|
|
$dialog.find('#address').val(customer.address);
|
|
|
|
|
$dialog.find('#city').val(customer.city);
|
|
|
|
|
$dialog.find('#zip-code').val(customer.zip_code);
|
2019-06-08 17:43:21 +03:00
|
|
|
|
$dialog.find('#appointment-location').val(appointment.location);
|
2017-10-31 12:37:00 +03:00
|
|
|
|
$dialog.find('#appointment-notes').val(appointment.notes);
|
|
|
|
|
$dialog.find('#customer-notes').val(customer.notes);
|
2016-07-17 14:46:38 +03:00
|
|
|
|
|
|
|
|
|
$dialog.modal('show');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Apply qtip to control tooltips.
|
|
|
|
|
$('#calendar-toolbar button').qtip({
|
|
|
|
|
position: {
|
|
|
|
|
my: 'top center',
|
|
|
|
|
at: 'bottom center'
|
|
|
|
|
},
|
|
|
|
|
style: {
|
|
|
|
|
classes: 'qtip-green qtip-shadow custom-qtip'
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
$('#select-filter-item').qtip({
|
|
|
|
|
position: {
|
|
|
|
|
my: 'middle left',
|
|
|
|
|
at: 'middle right'
|
|
|
|
|
},
|
|
|
|
|
style: {
|
|
|
|
|
classes: 'qtip-green qtip-shadow custom-qtip'
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2020-05-06 20:15:11 +03:00
|
|
|
|
if (!$('#select-filter-item option').length) {
|
2016-07-17 14:46:38 +03:00
|
|
|
|
$('#calendar-actions button').prop('disabled', true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Fine tune the footer's position only for this page.
|
|
|
|
|
if (window.innerHeight < 700) {
|
|
|
|
|
$('#footer').css('position', 'static');
|
2017-10-31 12:37:00 +03:00
|
|
|
|
}
|
2020-03-18 22:30:15 +03:00
|
|
|
|
|
|
|
|
|
// Automatically refresh the calendar page every 10 seconds (without loading animation).
|
|
|
|
|
var $calendar = $('#calendar');
|
|
|
|
|
var $selectFilterItem = $('#select-filter-item');
|
|
|
|
|
|
|
|
|
|
setInterval(function () {
|
2020-05-06 20:23:49 +03:00
|
|
|
|
refreshCalendarAppointments(
|
2020-03-18 22:30:15 +03:00
|
|
|
|
$calendar,
|
|
|
|
|
$selectFilterItem.val(),
|
|
|
|
|
$selectFilterItem.find('option:selected').attr('type'),
|
|
|
|
|
$calendar.fullCalendar('getView').start,
|
2020-04-06 21:34:32 +03:00
|
|
|
|
$calendar.fullCalendar('getView').end);
|
2020-03-18 22:30:15 +03:00
|
|
|
|
}, 10000);
|
2016-07-17 14:46:38 +03:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
})(window.BackendCalendarDefaultView);
|