-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
calendar_default_view.js
executable file
·1656 lines (1405 loc) · 68 KB
/
calendar_default_view.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* ----------------------------------------------------------------------------
* Easy!Appointments - Online Appointment Scheduler
*
* @package EasyAppointments
* @author A.Tselegidis <alextselegidis@gmail.com>
* @copyright Copyright (c) Alex Tselegidis
* @license https://opensource.org/licenses/GPL-3.0 - GPLv3
* @link https://easyappointments.org
* @since v1.5.0
* ---------------------------------------------------------------------------- */
/**
* Default calendar view utility.
*
* This module implements the functionality of the default calendar view.
*
* Old Name: BackendCalendarDefaultView
*/
App.Utils.CalendarDefaultView = (function () {
const $calendarPage = $('#calendar-page');
const $reloadAppointments = $('#reload-appointments');
const $calendar = $('#calendar');
const $selectFilterItem = $('#select-filter-item');
const $appointmentsModal = $('#appointments-modal');
const $unavailabilitiesModal = $('#unavailabilities-modal');
const $header = $('#header');
const $footer = $('#footer');
const $notification = $('#notification');
const $calendarToolbar = $('#calendar-toolbar');
const FILTER_TYPE_ALL = 'all';
const FILTER_TYPE_PROVIDER = 'provider';
const FILTER_TYPE_SERVICE = 'service';
const moment = window.moment;
let $popoverTarget;
let fullCalendar = null;
let lastFocusedEventData; // Contains event data for later use.
/**
* Add the utility event listeners.
*/
function addEventListeners() {
/**
* Event: Reload Button "Click"
*
* When the user clicks the reload button, the calendar items need to be refreshed.
*/
$reloadAppointments.on('click', () => {
const calendarView = fullCalendar.view;
if ($popoverTarget) {
$popoverTarget.popover('dispose');
}
refreshCalendarAppointments(
$calendar,
$selectFilterItem.val(),
$selectFilterItem.find('option:selected').attr('type'),
calendarView.currentStart,
calendarView.currentEnd,
);
});
/**
* Event: Popover Close Button "Click"
*
* Hides the open popover element.
*/
$calendarPage.on('click', '.close-popover', () => {
if ($popoverTarget) {
$popoverTarget.popover('dispose');
}
});
/**
* Event: Popover Edit Button "Click"
*
* Enables the edit dialog of the selected calendar event.
*
* @param {jQuery.Event} event
*/
$calendarPage.on('click', '.edit-popover', (event) => {
if ($popoverTarget) {
$popoverTarget.popover('dispose');
}
let startMoment;
let endMoment;
const data = lastFocusedEventData.extendedProps.data;
if (data.hasOwnProperty('workingPlanException')) {
const date = lastFocusedEventData.extendedProps.data.date;
const workingPlanException = lastFocusedEventData.extendedProps.data.workingPlanException;
const provider = lastFocusedEventData.extendedProps.data.provider;
App.Components.WorkingPlanExceptionsModal.edit(date, workingPlanException).done(
(date, workingPlanException) => {
const successCallback = () => {
App.Layouts.Backend.displayNotification(lang('working_plan_exception_saved'));
const workingPlanExceptions = JSON.parse(provider.settings.working_plan_exceptions) || {};
workingPlanExceptions[date] = workingPlanException;
for (const index in vars('available_providers')) {
const availableProvider = vars('available_providers')[index];
if (Number(availableProvider.id) === Number(provider.id)) {
availableProvider.settings.working_plan_exceptions =
JSON.stringify(workingPlanExceptions);
break;
}
}
$reloadAppointments.trigger('click'); // Update the calendar.
};
App.Http.Calendar.saveWorkingPlanException(
date,
workingPlanException,
provider.id,
successCallback,
null,
);
},
);
} else if (!lastFocusedEventData.extendedProps.data.is_unavailability) {
const appointment = lastFocusedEventData.extendedProps.data;
App.Components.AppointmentsModal.resetModal();
// Apply appointment data and show modal dialog.
$appointmentsModal.find('.modal-header h3').text(lang('edit_appointment_title'));
$appointmentsModal.find('#appointment-id').val(appointment.id);
$appointmentsModal.find('#select-service').val(appointment.id_services).trigger('change');
$appointmentsModal.find('#select-provider').val(appointment.id_users_provider);
// Set the start and end datetime of the appointment.
startMoment = moment(appointment.start_datetime);
App.Utils.UI.setDateTimePickerValue($appointmentsModal.find('#start-datetime'), startMoment.toDate());
endMoment = moment(appointment.end_datetime);
App.Utils.UI.setDateTimePickerValue($appointmentsModal.find('#end-datetime'), endMoment.toDate());
const customer = appointment.customer;
$appointmentsModal.find('#customer-id').val(appointment.id_users_customer);
$appointmentsModal.find('#first-name').val(customer.first_name);
$appointmentsModal.find('#last-name').val(customer.last_name);
$appointmentsModal.find('#email').val(customer.email);
$appointmentsModal.find('#phone-number').val(customer.phone_number);
$appointmentsModal.find('#address').val(customer.address);
$appointmentsModal.find('#city').val(customer.city);
$appointmentsModal.find('#zip-code').val(customer.zip_code);
$appointmentsModal.find('#language').val(customer.language);
$appointmentsModal.find('#timezone').val(customer.timezone);
$appointmentsModal.find('#appointment-location').val(appointment.location);
$appointmentsModal.find('#appointment-status').val(appointment.status);
$appointmentsModal.find('#appointment-notes').val(appointment.notes);
$appointmentsModal.find('#customer-notes').val(customer.notes);
$appointmentsModal.find('#custom-field-1').val(customer.custom_field_1);
$appointmentsModal.find('#custom-field-2').val(customer.custom_field_2);
$appointmentsModal.find('#custom-field-3').val(customer.custom_field_3);
$appointmentsModal.find('#custom-field-4').val(customer.custom_field_4);
$appointmentsModal.find('#custom-field-5').val(customer.custom_field_5);
App.Components.ColorSelection.setColor(
$appointmentsModal.find('#appointment-color'),
appointment.color,
);
$appointmentsModal.modal('show');
} else {
const unavailability = lastFocusedEventData.extendedProps.data;
// Replace string date values with actual date objects.
unavailability.start_datetime = moment(lastFocusedEventData.start).format('YYYY-MM-DD HH:mm:ss');
startMoment = moment(unavailability.start_datetime);
unavailability.end_datetime = moment(lastFocusedEventData.end).format('YYYY-MM-DD HH:mm:ss');
endMoment = moment(unavailability.end_datetime);
App.Components.UnavailabilitiesModal.resetModal();
// Apply unavailability data to dialog.
$unavailabilitiesModal.find('.modal-header h3').text(lang('edit_unavailability_title'));
App.Utils.UI.setDateTimePickerValue(
$unavailabilitiesModal.find('#unavailability-start'),
startMoment.toDate(),
);
App.Utils.UI.setDateTimePickerValue(
$unavailabilitiesModal.find('#unavailability-end'),
endMoment.toDate(),
);
$unavailabilitiesModal.find('#unavailability-id').val(unavailability.id);
$unavailabilitiesModal.find('#unavailability-provider').val(unavailability.id_users_provider);
$unavailabilitiesModal.find('#unavailability-notes').val(unavailability.notes);
$unavailabilitiesModal.modal('show');
}
});
/**
* Event: Popover Delete Button "Click"
*
* Displays a prompt on whether the user wants the appointment to be deleted. If he confirms the
* deletion then an AJAX call is made to the server and deletes the appointment from the database.
*
* @param {jQuery.Event} event
*/
$calendarPage.on('click', '.delete-popover', (event) => {
if ($popoverTarget) {
$popoverTarget.popover('dispose');
}
if (lastFocusedEventData.extendedProps.data.workingPlanException !== undefined) {
const providerId = $selectFilterItem.val();
const provider = vars('available_providers').find(
(availableProvider) => Number(availableProvider.id) === Number(providerId),
);
if (!provider) {
throw new Error('Provider could not be found: ' + providerId);
}
const successCallback = () => {
App.Layouts.Backend.displayNotification(lang('working_plan_exception_deleted'));
const workingPlanExceptions = JSON.parse(provider.settings.working_plan_exceptions) || {};
delete workingPlanExceptions[date];
for (const index in vars('available_providers')) {
const availableProvider = vars('available_providers')[index];
if (Number(availableProvider.id) === Number(providerId)) {
availableProvider.settings.working_plan_exceptions = JSON.stringify(workingPlanExceptions);
break;
}
}
$reloadAppointments.trigger('click'); // Update the calendar.
};
const date = moment(lastFocusedEventData.start).format('YYYY-MM-DD');
App.Http.Calendar.deleteWorkingPlanException(date, providerId, successCallback);
} else if (!lastFocusedEventData.extendedProps.data.is_unavailability) {
const buttons = [
{
text: lang('cancel'),
click: (event, messageModal) => {
messageModal.dispose();
},
},
{
text: lang('delete'),
click: (event, messageModal) => {
const appointmentId = lastFocusedEventData.extendedProps.data.id;
const cancellationReason = $('#cancellation-reason').val();
App.Http.Calendar.deleteAppointment(appointmentId, cancellationReason).done(() => {
messageModal.dispose();
// Refresh calendar event items.
$reloadAppointments.trigger('click');
});
},
},
];
App.Utils.Message.show(
lang('delete_appointment_title'),
lang('write_appointment_removal_reason'),
buttons,
);
$('<textarea/>', {
'class': 'form-control w-100',
'id': 'cancellation-reason',
'rows': '3',
}).appendTo('#message-modal .modal-body');
} else {
// Do not display confirmation prompt.
const unavailabilityId = lastFocusedEventData.extendedProps.data.id;
App.Http.Calendar.deleteUnavailability(unavailabilityId).done(() => {
// Refresh calendar event items.
$reloadAppointments.trigger('click');
});
}
});
/**
* Event: Calendar Filter Item "Change"
*
* Load the appointments that correspond to the select filter item and display them on the calendar.
*/
$selectFilterItem.on('change', () => {
// If current value is service, then the sync buttons must be disabled.
if (
$selectFilterItem.find('option:selected').attr('type') === FILTER_TYPE_SERVICE ||
$selectFilterItem.val() === 'all'
) {
$('#google-sync, #enable-sync, #insert-appointment, #insert-dropdown').prop('disabled', true);
} else {
$('#google-sync, #enable-sync, #insert-appointment, #insert-dropdown').prop('disabled', false);
const providerId = $selectFilterItem.val();
const provider = vars('available_providers').find(
(availableProvider) => Number(availableProvider.id) === Number(providerId),
);
if (provider && provider.timezone) {
$('.provider-timezone').text(vars('timezones')[provider.timezone]);
}
// If the user has already the sync enabled then apply the proper style changes.
if ($selectFilterItem.find('option:selected').attr('google-sync') === 'true') {
$('#enable-sync').removeClass('btn-light').addClass('btn-secondary enabled');
$('#enable-sync span').text(lang('disable_sync'));
$('#google-sync').prop('disabled', false);
} else {
$('#enable-sync').removeClass('btn-secondary enabled').addClass('btn-light');
$('#enable-sync span').text(lang('enable_sync'));
$('#google-sync').prop('disabled', true);
}
$('#insert-working-plan-exception').toggle(
providerId !== App.Utils.CalendarDefaultView.FILTER_TYPE_ALL,
);
}
$reloadAppointments.trigger('click');
window.localStorage.setItem('EasyAppointments.SelectFilterItem', $selectFilterItem.val());
});
}
/**
* 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.
*/
function getCalendarHeight() {
const result =
window.innerHeight - $footer.outerHeight() - $header.outerHeight() - $calendarToolbar.outerHeight() - 60; // 60 for fine tuning
return result > 780 ? result : 780; // Minimum height is 800px
}
/**
* Get the event notes for the popup widget.
*
* @param {Event} event
*/
function getEventNotes(event) {
if (!event.extendedProps || !event.extendedProps.data || !event.extendedProps.data.notes) {
return '-';
}
const notes = event.extendedProps.data.notes;
return notes.length > 100 ? notes.substring(0, 100) + '...' : notes;
}
/**
* 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.
*
* @param {Object} info
*/
function onEventClick(info) {
const $target = $(info.el);
if ($popoverTarget) {
$popoverTarget.popover('dispose');
}
let $html;
let displayEdit;
let displayDelete;
// Depending on where the user clicked the event (title or empty space) we
// need to use different selectors to reach the parent element.
if ($target.hasClass('fc-unavailability')) {
displayEdit =
$target.hasClass('fc-custom') && vars('privileges').appointments.edit === true ? '' : 'd-none';
displayDelete =
$target.hasClass('fc-custom') && vars('privileges').appointments.delete === true ? 'me-2' : 'd-none'; // Same value at the time.
let startDateTimeObject = info.event.start;
let endDateTimeObject = info.event.end || info.event.start;
if (info.event.extendedProps.data) {
startDateTimeObject = new Date(info.event.extendedProps.data.start_datetime);
endDateTimeObject = new Date(info.event.extendedProps.data.end_datetime);
}
$html = $('<div/>', {
'html': [
$('<strong/>', {
'class': 'd-inline-block me-2',
'text': lang('start'),
}),
$('<span/>', {
'text': App.Utils.Date.format(
moment(startDateTimeObject).format('YYYY-MM-DD HH:mm:ss'),
vars('date_format'),
vars('time_format'),
true,
),
}),
$('<br/>'),
$('<strong/>', {
'class': 'd-inline-block me-2',
'text': lang('end'),
}),
$('<span/>', {
'text': App.Utils.Date.format(
moment(endDateTimeObject).format('YYYY-MM-DD HH:mm:ss'),
vars('date_format'),
vars('time_format'),
true,
),
}),
$('<br/>'),
$('<strong/>', {
'class': 'd-inline-block me-2',
'text': lang('notes'),
}),
$('<span/>', {
'text': getEventNotes(info.event),
}),
$('<br/>'),
$('<hr/>'),
$('<div/>', {
'class': 'd-flex justify-content-center',
'html': [
$('<button/>', {
'class': 'close-popover btn btn-outline-secondary me-2',
'html': [
$('<i/>', {
'class': 'fas fa-ban me-2',
}),
$('<span/>', {
'text': lang('close'),
}),
],
}),
$('<button/>', {
'class': 'delete-popover btn btn-outline-secondary ' + displayDelete,
'html': [
$('<i/>', {
'class': 'fas fa-trash-alt me-2',
}),
$('<span/>', {
'text': lang('delete'),
}),
],
}),
$('<button/>', {
'class': 'edit-popover btn btn-primary ' + displayEdit,
'html': [
$('<i/>', {
'class': 'fas fa-edit me-2',
}),
$('<span/>', {
'text': lang('edit'),
}),
],
}),
],
}),
],
});
} else if ($target.hasClass('fc-working-plan-exception')) {
displayDelete =
$target.hasClass('fc-custom') && vars('privileges').appointments.delete === true ? 'me-2' : 'd-none';
const {date, workingPlanException, provider} = info.event.extendedProps.data;
const startTime = workingPlanException?.start;
const endTime = workingPlanException?.end;
$html = $('<div/>', {
'html': [
$('<strong/>', {
'class': 'd-inline-block me-2',
'text': lang('provider'),
}),
$('<span/>', {
'text': `${provider.first_name} ${provider.last_name}`,
}),
$('<br/>'),
$('<strong/>', {
'class': 'd-inline-block me-2',
'text': lang('start'),
}),
$('<span/>', {
'text': startTime
? App.Utils.Date.format(
`${date} ${startTime}`,
vars('date_format'),
vars('time_format'),
true,
)
: '-',
}),
$('<br/>'),
$('<strong/>', {
'class': 'd-inline-block me-2',
'text': lang('end'),
}),
$('<span/>', {
'text': endTime
? App.Utils.Date.format(
`${date} ${endTime}`,
vars('date_format'),
vars('time_format'),
true,
)
: '-',
}),
$('<br/>'),
$('<strong/>', {
'class': 'd-inline-block me-2',
'text': lang('timezone'),
}),
$('<span/>', {
'text': startTime ? vars('timezones')[provider.timezone] : '-',
}),
$('<br/>'),
$('<hr/>'),
$('<div/>', {
'class': 'd-flex justify-content-between',
'html': [
$('<button/>', {
'class': 'close-popover btn btn-outline-secondary me-2',
'html': [
$('<i/>', {
'class': 'fas fa-ban me-2',
}),
$('<span/>', {
'text': lang('close'),
}),
],
}),
$('<button/>', {
'class': 'delete-popover btn btn-outline-secondary ' + displayDelete,
'html': [
$('<i/>', {
'class': 'fas fa-trash-alt me-2',
}),
$('<span/>', {
'text': lang('delete'),
}),
],
}),
$('<button/>', {
'class': 'edit-popover btn btn-primary',
'html': [
$('<i/>', {
'class': 'fas fa-edit me-2',
}),
$('<span/>', {
'text': lang('edit'),
}),
],
}),
],
}),
],
});
} else {
displayEdit = vars('privileges').appointments.edit === true ? '' : 'd-none';
displayDelete = vars('privileges').appointments.delete === true ? 'me-2' : 'd-none';
const customerInfo = [];
if (info.event.extendedProps.data.customer.first_name) {
customerInfo.push(info.event.extendedProps.data.customer.first_name);
}
if (info.event.extendedProps.data.customer.last_name) {
customerInfo.push(info.event.extendedProps.data.customer.last_name);
}
$html = $('<div/>', {
'html': [
$('<strong/>', {
'class': 'd-inline-block me-2',
'text': lang('start'),
}),
$('<span/>', {
'text': App.Utils.Date.format(
moment(info.event.start).format('YYYY-MM-DD HH:mm:ss'),
vars('date_format'),
vars('time_format'),
true,
),
}),
$('<br/>'),
$('<strong/>', {
'class': 'd-inline-block me-2',
'text': lang('end'),
}),
$('<span/>', {
'text': App.Utils.Date.format(
moment(info.event.end).format('YYYY-MM-DD HH:mm:ss'),
vars('date_format'),
vars('time_format'),
true,
),
}),
$('<br/>'),
$('<strong/>', {
'class': 'd-inline-block me-2',
'text': lang('timezone'),
}),
$('<span/>', {
'text': vars('timezones')[info.event.extendedProps.data.provider.timezone],
}),
$('<br/>'),
$('<strong/>', {
'class': 'd-inline-block me-2',
'text': lang('status'),
}),
$('<span/>', {
'text': info.event.extendedProps.data.status || '-',
}),
$('<br/>'),
$('<strong/>', {
'class': 'd-inline-block me-2',
'text': lang('service'),
}),
$('<span/>', {
'text': info.event.extendedProps.data.service.name,
}),
$('<br/>'),
$('<strong/>', {
'class': 'd-inline-block me-2',
'text': lang('provider'),
}),
App.Utils.CalendarEventPopover.renderMapIcon(info.event.extendedProps.data.provider),
$('<span/>', {
'text':
info.event.extendedProps.data.provider.first_name +
' ' +
info.event.extendedProps.data.provider.last_name,
}),
$('<br/>'),
$('<strong/>', {
'class': 'd-inline-block me-2',
'text': lang('customer'),
}),
App.Utils.CalendarEventPopover.renderMapIcon(info.event.extendedProps.data.customer),
$('<span/>', {
'class': 'd-inline-block',
'text': customerInfo.length ? customerInfo.join(' ') : '-',
}),
$('<br/>'),
$('<strong/>', {
'class': 'd-inline-block me-2',
'text': lang('email'),
}),
App.Utils.CalendarEventPopover.renderMailIcon(info.event.extendedProps.data.customer.email),
$('<span/>', {
'class': 'd-inline-block',
'text': info.event.extendedProps.data.customer.email || '-',
}),
$('<br/>'),
$('<strong/>', {
'class': 'd-inline-block me-2',
'text': lang('phone'),
}),
App.Utils.CalendarEventPopover.renderPhoneIcon(info.event.extendedProps.data.customer.phone_number),
$('<span/>', {
'class': 'd-inline-block',
'text': info.event.extendedProps.data.customer.phone_number || '-',
}),
$('<br/>'),
$('<strong/>', {
'class': 'd-inline-block me-2',
'text': lang('notes'),
}),
$('<span/>', {
'text': getEventNotes(info.event),
}),
$('<br/>'),
$('<hr/>'),
$('<div/>', {
'class': 'd-flex justify-content-center',
'html': [
$('<button/>', {
'class': 'close-popover btn btn-outline-secondary me-2',
'html': [
$('<i/>', {
'class': 'fas fa-ban me-2',
}),
$('<span/>', {
'text': lang('close'),
}),
],
}),
$('<button/>', {
'class': 'delete-popover btn btn-outline-secondary ' + displayDelete,
'html': [
$('<i/>', {
'class': 'fas fa-trash-alt me-2',
}),
$('<span/>', {
'text': lang('delete'),
}),
],
}),
$('<button/>', {
'class': 'edit-popover btn btn-primary ' + displayEdit,
'html': [
$('<i/>', {
'class': 'fas fa-edit me-2',
}),
$('<span/>', {
'text': lang('edit'),
}),
],
}),
],
}),
],
});
}
$target.popover({
placement: 'top',
title: App.Utils.String.escapeHtml(info.event.title),
content: $html,
html: true,
container: '#calendar',
trigger: 'manual',
});
lastFocusedEventData = info.event;
$target.popover('show');
$popoverTarget = $target;
// Fix popover position.
const $popover = $calendarPage.find('.popover');
if ($popover.length > 0 && $popover.position().top < 200) {
$popover.css('top', '200px');
}
}
/**
* 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()
*
* @param {Object} info
*/
function onEventResize(info) {
if (vars('privileges').appointments.edit === false) {
info.revert();
App.Layouts.Backend.displayNotification(lang('no_privileges_edit_appointments'));
return;
}
let successCallback;
if ($notification.is(':visible')) {
$notification.hide('bind');
}
if (!info.event.extendedProps.data.is_unavailability) {
// Prepare appointment data.
info.event.extendedProps.data.end_datetime = moment(info.event.extendedProps.data.end_datetime)
.add({days: info.endDelta.days, milliseconds: info.endDelta.milliseconds})
.format('YYYY-MM-DD HH:mm:ss');
const appointment = {...info.event.extendedProps.data};
appointment.is_unavailability = Number(appointment.is_unavailability);
// Must delete the following because only appointment data should be provided to the AJAX call.
delete appointment.customer;
delete appointment.provider;
delete appointment.service;
// Success callback
successCallback = () => {
// Display success notification to user.
const undoFunction = () => {
appointment.end_datetime = info.event.extendedProps.data.end_datetime = moment(
appointment.end_datetime,
)
.add({days: -info.endDelta.days, milliseconds: -info.endDelta.milliseconds})
.format('YYYY-MM-DD HH:mm:ss');
App.Http.Calendar.saveAppointment(appointment).done(() => {
$notification.hide('blind');
});
info.revert();
};
App.Layouts.Backend.displayNotification(lang('appointment_updated'), [
{
'label': lang('undo'),
'function': undoFunction,
},
]);
// Update the event data for later use.
info.event.setProp('data', info.event.extendedProps.data);
};
// Update appointment data.
App.Http.Calendar.saveAppointment(appointment, null, successCallback);
} else {
// Update unavailability time period.
const unavailability = {
id: info.event.extendedProps.data.id,
start_datetime: moment(info.event.start).format('YYYY-MM-DD HH:mm:ss'),
end_datetime: moment(info.event.end).format('YYYY-MM-DD HH:mm:ss'),
id_users_provider: info.event.extendedProps.data.id_users_provider,
};
info.event.extendedProps.data.end_datetime = unavailability.end_datetime;
// Define success callback function.
successCallback = () => {
// Display success notification to user.
const undoFunction = () => {
unavailability.end_datetime = info.event.extendedProps.data.end_datetime = moment(
unavailability.end_datetime,
)
.add({days: -info.delta.days, milliseconds: -info.delta.milliseconds})
.format('YYYY-MM-DD HH:mm:ss');
App.Http.Calendar.saveAppointment(unavailability).done(() => {
$notification.hide('blind');
});
info.revert();
};
App.Layouts.Backend.displayNotification(lang('unavailability_updated'), [
{
'label': lang('undo'),
'function': undoFunction,
},
]);
// Update the event data for later use.
info.event.setProp('data', info.event.extendedProps.data);
};
App.Http.Calendar.saveUnavailability(unavailability, successCallback, null);
}
}
/**
* Calendar Window "Resize" Callback
*
* The calendar element needs to be re-sized too in order to fit into the window. Nevertheless, if the window
* becomes very small the calendar won't shrink anymore.
*
* @see getCalendarHeight()
*/
function onWindowResize() {
fullCalendar.setOption('height', getCalendarHeight());
}
/**
* Calendar Day "Click" Callback
*
* When the user clicks on a day square on the calendar, then he will automatically be transferred to that
* day view calendar.
*
* @param {Object} info
*/
function onDateClick(info) {
if (info.allDay) {
fullCalendar.changeView('timeGridDay');
fullCalendar.gotoDate(info.date);
}
}
/**
* 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.
*
* @param {Object} info
*/
function onEventDrop(info) {
if (vars('privileges').appointments.edit === false) {
info.revert();
App.Layouts.Backend.displayNotification(lang('no_privileges_edit_appointments'));
return;
}
if ($notification.is(':visible')) {
$notification.hide('bind');
}
let successCallback;
if (!info.event.extendedProps.data.is_unavailability) {
// Prepare appointment data.
const appointment = {...info.event.extendedProps.data};
// Must delete the following because only appointment data should be provided to the ajax call.
delete appointment.customer;
delete appointment.provider;
delete appointment.service;
appointment.start_datetime = moment(appointment.start_datetime)
.add({days: info.delta.days, millisecond: info.delta.milliseconds})
.format('YYYY-MM-DD HH:mm:ss');
appointment.end_datetime = moment(appointment.end_datetime)
.add({days: info.delta.days, millisecond: info.delta.milliseconds})
.format('YYYY-MM-DD HH:mm:ss');
appointment.is_unavailability = Number(appointment.is_unavailability);
info.event.extendedProps.data.start_datetime = appointment.start_datetime;
info.event.extendedProps.data.end_datetime = appointment.end_datetime;
// Define success callback function.
successCallback = () => {
// Define the undo function, if the user needs to reset the last change.
const undoFunction = () => {
appointment.start_datetime = moment(appointment.start_datetime)
.add({
days: -info.delta.days,
milliseconds: -info.delta.milliseconds,
})
.format('YYYY-MM-DD HH:mm:ss');
appointment.end_datetime = moment(appointment.end_datetime)
.add({days: -info.delta.days, milliseconds: -info.delta.milliseconds})
.format('YYYY-MM-DD HH:mm:ss');
info.event.extendedProps.data.start_datetime = appointment.start_datetime;
info.event.extendedProps.data.end_datetime = appointment.end_datetime;
App.Http.Calendar.saveAppointment(appointment).done(() => {
$notification.hide('blind');
});
info.revert();
};
App.Layouts.Backend.displayNotification(lang('appointment_updated'), [
{
'label': lang('undo'),
'function': undoFunction,
},
]);
};
// Update appointment data.
App.Http.Calendar.saveAppointment(appointment, null, successCallback);
} else {
// Update unavailability time period.
const unavailability = {