mirror of
https://github.com/alextselegidis/easyappointments.git
synced 2024-11-10 10:02:33 +03:00
Code refactoring and improvements for the calendar related utilities page.
This commit is contained in:
parent
c9f4a8303a
commit
6a89e11d39
3 changed files with 44 additions and 47 deletions
|
@ -81,38 +81,37 @@ App.Utils.CalendarDefaultView = (function () {
|
|||
const workingPlanException = lastFocusedEventData.data.workingPlanException;
|
||||
const provider = lastFocusedEventData.data.provider;
|
||||
|
||||
App.Components.WorkingPlanExceptionsModal.edit(date, workingPlanException).done(function (
|
||||
date,
|
||||
workingPlanException
|
||||
) {
|
||||
const successCallback = function () {
|
||||
App.Layouts.Backend.displayNotification(App.Lang.working_plan_exception_saved);
|
||||
App.Components.WorkingPlanExceptionsModal.edit(date, workingPlanException).done(
|
||||
(date, workingPlanException) => {
|
||||
const successCallback = () => {
|
||||
App.Layouts.Backend.displayNotification(App.Lang.working_plan_exception_saved);
|
||||
|
||||
const workingPlanExceptions = JSON.parse(provider.settings.working_plan_exceptions) || {};
|
||||
const workingPlanExceptions = JSON.parse(provider.settings.working_plan_exceptions) || {};
|
||||
|
||||
workingPlanExceptions[date] = workingPlanException;
|
||||
workingPlanExceptions[date] = workingPlanException;
|
||||
|
||||
for (const index in App.Vars.available_providers) {
|
||||
const availableProvider = App.Vars.available_providers[index];
|
||||
for (const index in App.Vars.available_providers) {
|
||||
const availableProvider = App.Vars.available_providers[index];
|
||||
|
||||
if (Number(availableProvider.id) === Number(provider.id)) {
|
||||
availableProvider.settings.working_plan_exceptions =
|
||||
JSON.stringify(workingPlanExceptions);
|
||||
break;
|
||||
if (Number(availableProvider.id) === Number(provider.id)) {
|
||||
availableProvider.settings.working_plan_exceptions =
|
||||
JSON.stringify(workingPlanExceptions);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$selectFilterItem.trigger('change'); // Update the calendar.
|
||||
};
|
||||
$selectFilterItem.trigger('change'); // Update the calendar.
|
||||
};
|
||||
|
||||
App.Http.Calendar.saveWorkingPlanException(
|
||||
date,
|
||||
workingPlanException,
|
||||
provider.id,
|
||||
successCallback,
|
||||
null
|
||||
);
|
||||
});
|
||||
App.Http.Calendar.saveWorkingPlanException(
|
||||
date,
|
||||
workingPlanException,
|
||||
provider.id,
|
||||
successCallback,
|
||||
null
|
||||
);
|
||||
}
|
||||
);
|
||||
} else if (!lastFocusedEventData.data.is_unavailable) {
|
||||
const appointment = lastFocusedEventData.data;
|
||||
|
||||
|
@ -224,7 +223,7 @@ App.Utils.CalendarDefaultView = (function () {
|
|||
},
|
||||
{
|
||||
text: 'OK',
|
||||
click: function () {
|
||||
click: () => {
|
||||
url = App.Utils.Url.siteUrl('calendar/ajax_delete_appointment');
|
||||
|
||||
data = {
|
||||
|
@ -294,9 +293,9 @@ App.Utils.CalendarDefaultView = (function () {
|
|||
|
||||
const providerId = $selectFilterItem.val();
|
||||
|
||||
const provider = App.Vars.available_providers.find(function (availableProvider) {
|
||||
return Number(availableProvider.id) === Number(providerId);
|
||||
});
|
||||
const provider = App.Vars.available_providers.find(
|
||||
(availableProvider) => Number(availableProvider.id) === Number(providerId)
|
||||
);
|
||||
|
||||
if (provider && provider.timezone) {
|
||||
$('.provider-timezone').text(App.Vars.timezones[provider.timezone]);
|
||||
|
@ -1629,7 +1628,7 @@ App.Utils.CalendarDefaultView = (function () {
|
|||
$('<optgroup label=""/>', {
|
||||
'label': App.Lang.providers,
|
||||
'type': 'providers-group',
|
||||
'html': App.Vars.available_providers.map(function (availableProvider) {
|
||||
'html': App.Vars.available_providers.map((availableProvider) => {
|
||||
const hasGoogleSync = availableProvider.settings.google_sync === '1' ? 'true' : 'false';
|
||||
|
||||
return $('<option/>', {
|
||||
|
|
|
@ -18,9 +18,9 @@
|
|||
*/
|
||||
App.Utils.CalendarGoogleSync = (function () {
|
||||
/**
|
||||
* Bind the event handlers.
|
||||
* Add the utility event listeners.
|
||||
*/
|
||||
function bindEventHandlers() {
|
||||
function addEventListeners() {
|
||||
/**
|
||||
* Event: Enable - Disable Synchronization Button "Click"
|
||||
*
|
||||
|
@ -182,7 +182,7 @@ App.Utils.CalendarGoogleSync = (function () {
|
|||
* Initialize the module.
|
||||
*/
|
||||
function initialize() {
|
||||
bindEventHandlers();
|
||||
addEventListeners();
|
||||
}
|
||||
|
||||
document.addEventListener('DOMContentLoaded', initialize);
|
||||
|
|
|
@ -22,9 +22,9 @@ App.Utils.CalendarTableView = (function () {
|
|||
let lastFocusedEventData;
|
||||
|
||||
/**
|
||||
* Bind the event handlers.
|
||||
* Add the utility event listeners.
|
||||
*/
|
||||
function bindEventHandlers() {
|
||||
function addEventListeners() {
|
||||
const $calendarToolbar = $('#calendar-toolbar');
|
||||
const $calendar = $('#calendar');
|
||||
|
||||
|
@ -82,7 +82,7 @@ App.Utils.CalendarTableView = (function () {
|
|||
.find('.date-column-title')
|
||||
.text(App.Utils.Date.format(date, App.Vars.date_format, App.Vars.time_format));
|
||||
|
||||
$dateColumn.find('.provider-column').each(function (index, providerColumn) {
|
||||
$dateColumn.find('.provider-column').each((index, providerColumn) => {
|
||||
const $providerColumn = $(providerColumn);
|
||||
const provider = $providerColumn.data('provider');
|
||||
|
||||
|
@ -277,7 +277,7 @@ App.Utils.CalendarTableView = (function () {
|
|||
const buttons = [
|
||||
{
|
||||
text: App.Lang.cancel,
|
||||
click: function () {
|
||||
click: () => {
|
||||
$('#message-box').dialog('close');
|
||||
}
|
||||
},
|
||||
|
@ -444,9 +444,7 @@ App.Utils.CalendarTableView = (function () {
|
|||
$filterProvider.select2();
|
||||
|
||||
const services = GlobalVariables.availableServices.filter((service) => {
|
||||
const provider = providers.find(function (provider) {
|
||||
return provider.services.indexOf(service.id) !== -1;
|
||||
});
|
||||
const provider = providers.find((provider) => provider.services.indexOf(service.id) !== -1);
|
||||
|
||||
return App.Vars.role_slug === App.Layouts.Backend.DB_SLUG_ADMIN || provider;
|
||||
});
|
||||
|
@ -689,8 +687,8 @@ App.Utils.CalendarTableView = (function () {
|
|||
throw new Error('Invalid time format setting provided!' + GlobalVariables.timeFormat);
|
||||
}
|
||||
|
||||
const firstWeekday = GlobalVariables.firstWeekday;
|
||||
const firstWeekdayNumber = GeneralFunctions.getWeekDayId(firstWeekday);
|
||||
const firstWeekday = App.Vars.first_weekday;
|
||||
const firstWeekdayNumber = App.Utils.Date.getWeekdayId(firstWeekday);
|
||||
|
||||
$wrapper.fullCalendar({
|
||||
defaultView: 'agendaDay',
|
||||
|
@ -1517,7 +1515,7 @@ App.Utils.CalendarTableView = (function () {
|
|||
.add({days: delta.days(), hours: delta.hours(), minutes: delta.minutes()})
|
||||
.format('YYYY-MM-DD HH:mm:ss');
|
||||
|
||||
const appointment = GeneralFunctions.clone(event.data);
|
||||
const appointment = {...event.data};
|
||||
|
||||
// Must delete the following because only appointment data should be provided to the AJAX call.
|
||||
delete appointment.customer;
|
||||
|
@ -1631,7 +1629,7 @@ App.Utils.CalendarTableView = (function () {
|
|||
|
||||
if (event.data.is_unavailable === '0') {
|
||||
// Prepare appointment data.
|
||||
const appointment = GeneralFunctions.clone(event.data);
|
||||
const appointment = {...event.data};
|
||||
|
||||
// Must delete the following because only appointment data should be provided to the ajax call.
|
||||
delete appointment.customer;
|
||||
|
@ -1671,7 +1669,7 @@ App.Utils.CalendarTableView = (function () {
|
|||
appointment_data: JSON.stringify(appointment)
|
||||
};
|
||||
|
||||
$.post(url, data).done(function () {
|
||||
$.post(url, data).done(() => {
|
||||
$('#notification').hide('blind');
|
||||
});
|
||||
|
||||
|
@ -1766,7 +1764,7 @@ App.Utils.CalendarTableView = (function () {
|
|||
|
||||
let width = 0;
|
||||
|
||||
$dateColumn.each(function (index, dateColumn) {
|
||||
$dateColumn.each((index, dateColumn) => {
|
||||
width += $(dateColumn).outerWidth();
|
||||
});
|
||||
|
||||
|
@ -1823,7 +1821,7 @@ App.Utils.CalendarTableView = (function () {
|
|||
|
||||
$('#insert-working-plan-exception').hide();
|
||||
|
||||
bindEventHandlers();
|
||||
addEventListeners();
|
||||
|
||||
// Hide Google Calendar Sync buttons cause they can not be used within this view.
|
||||
$('#enable-sync, #google-sync').hide();
|
||||
|
|
Loading…
Reference in a new issue