-
Notifications
You must be signed in to change notification settings - Fork 247
/
Copy pathEditorMixin.js
877 lines (832 loc) Β· 23.6 KB
/
EditorMixin.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
/**
* SPDX-FileCopyrightText: 2019 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
import { getRFCProperties } from '../models/rfcProps.js'
import logger from '../utils/logger.js'
import { getPrefixedRoute } from '../utils/router.js'
import { dateFactory } from '../utils/date.js'
import { uidToHexColor } from '../utils/color.js'
import { translate as t } from '@nextcloud/l10n'
import { removeMailtoPrefix } from '../utils/attendee.js'
import { showError } from '@nextcloud/dialogs'
import usePrincipalsStore from '../store/principals.js'
import useSettingsStore from '../store/settings.js'
import useCalendarsStore from '../store/calendars.js'
import useCalendarObjectsStore from '../store/calendarObjects.js'
import useCalendarObjectInstanceStore from '../store/calendarObjectInstance.js'
import { mapStores, mapState } from 'pinia'
/**
* This is a mixin for the editor. It contains common Vue stuff, that is
* required both in the popover as well as the sidebar.
*
* See inline for more documentation
*/
export default {
props: {
// Whether or not the calendar is embedded in a widget
isWidget: {
type: Boolean,
default: false,
},
},
data() {
return {
// Indicator whether or not the event is currently loading, saving or being deleted
isLoading: true,
// Indicator whether or not the event is currently saving
isSaving: false,
// Indicator whether or not loading the event failed
isError: false,
// Error message in case there was an error
error: null,
// The calendar-id of the selected calendar
calendarId: null,
// Whether or not an action is required on leave
requiresActionOnRouteLeave: true,
// Whether or not the this and all future option will be forced
// This is the case when editing the recurrence-rule of an existing recurring event
forceThisAndAllFuture: false,
// Whether or not the master item is being edited
isEditingMasterItem: false,
// Whether or not it is a recurrence-exception
isRecurrenceException: false,
}
},
computed: {
...mapState(useSettingsStore, {
currentUserTimezone: 'getResolvedTimezone',
}),
...mapState(useCalendarsStore, ['initialCalendarsLoaded']),
...mapState(useCalendarObjectInstanceStore, ['calendarObject', 'calendarObjectInstance']),
...mapStores(useCalendarsStore, usePrincipalsStore, useCalendarObjectsStore, useCalendarObjectInstanceStore, useSettingsStore),
eventComponent() {
return this.calendarObjectInstance?.eventComponent
},
/**
* Returns the events title or an empty string if the event is still loading
*
* @return {string}
*/
title() {
return this.calendarObjectInstance?.title ?? ''
},
/**
* Returns the location or null if the event is still loading
*
* @return {string|null}
*/
location() {
return this.calendarObjectInstance?.location ?? null
},
/**
* Returns the description or null if the event is still loading
*
* @return {string|null}
*/
description() {
return this.calendarObjectInstance?.description ?? null
},
/**
* Returns the start-date (without timezone) or null if the event is still loading
*
* @return {Date|null}
*/
startDate() {
return this.calendarObjectInstance?.startDate ?? null
},
/**
* Returns the timezone of the event's start-date or null if the event is still loading
*
* @return {string|null}
*/
startTimezone() {
return this.calendarObjectInstance?.startTimezoneId ?? null
},
/**
* Returns the end-date (without timezone) or null if the event is still loading
*
* @return {Date|null}
*/
endDate() {
return this.calendarObjectInstance?.endDate ?? null
},
/**
* Returns the timezone of the event's end-date or null if the event is still loading
*
* @return {string|null}
*/
endTimezone() {
return this.calendarObjectInstance?.endTimezoneId ?? null
},
/**
* Returns whether or not the event is all-day or null if the event is still loading
*
* @return {boolean}
*/
isAllDay() {
return this.calendarObjectInstance?.isAllDay ?? false
},
/**
* Returns whether or not the user is allowed to modify the all-day setting
*
* @return {boolean}
*/
canModifyAllDay() {
return this.calendarObjectInstance?.canModifyAllDay ?? false
},
/**
* Returns the color the illustration should be colored in
*
* @return {string}
*/
illustrationColor() {
return this.color || this.selectedCalendarColor
},
/**
* Returns the color of the calendar selected by the user
* This is used to color illustration
*
* @return {string|*}
*/
selectedCalendarColor() {
if (!this.selectedCalendar) {
const calendars = this.calendarsStore.sortedCalendars
if (calendars.length > 0) {
return calendars[0].color
}
return uidToHexColor('')
}
return this.selectedCalendar.color
},
/**
* Returns the custom color of this event
*
* @return {null | string}
*/
color() {
return this.calendarObjectInstance?.customColor ?? null
},
/**
* Returns whether or not to display save buttons
*
* @return {boolean}
*/
showSaveButtons() {
return this.isReadOnly === false
},
/**
* Returns whether or not to allow editing the event
*
* @return {boolean}
*/
isReadOnly() {
if (!this.calendarObject) {
return true
}
const calendar = this.calendarsStore.getCalendarById(this.calendarObject.calendarId)
if (!calendar) {
return true
}
return calendar.readOnly
},
isSharedWithMe() {
if (!this.calendarObject) {
return true
}
const calendar = this.calendarsStore.getCalendarById(this.calendarObject.calendarId)
if (!calendar) {
return true
}
return calendar.isSharedWithMe
},
/**
* Returns whether the user is an attendee of the event
*
* @return {boolean}
*/
isViewedByAttendee() {
return this.userAsAttendee !== null
},
/**
* Returns the attendee property corresponding to the current user
*
* @return {?object}
*/
userAsAttendee() {
if (this.isReadOnly || !this.principalsStore.getCurrentUserPrincipalEmail || !this.calendarObjectInstance.organizer) {
return null
}
const principal = removeMailtoPrefix(this.principalsStore.getCurrentUserPrincipalEmail)
for (const attendee of this.calendarObjectInstance.attendees) {
if (removeMailtoPrefix(attendee.uri) === principal) {
return attendee
}
}
return null
},
/**
* Returns all calendars selectable by the user
*
* @return {object[]}
*/
calendars() {
if (this.isReadOnly && this.calendarObject) {
return [
this.calendarsStore.getCalendarById(this.calendarObject.calendarId),
]
}
return this.calendarsStore.sortedCalendars
},
/**
* Returns the object of the selected calendar
*
* @return {object}
*/
selectedCalendar() {
return this.calendarsStore.getCalendarById(this.calendarId)
},
/**
* Returns whether or not the user is allowed to delete this event
*
* @return {boolean}
*/
canDelete() {
if (!this.calendarObject) {
return false
}
if (this.isReadOnly) {
return false
}
if (this.isLoading) {
return false
}
return this.calendarObject.existsOnServer
},
/**
* Returns whether or not the user is allowed to create recurrence exceptions for this event
*
* @return {boolean}
*/
canCreateRecurrenceException() {
if (!this.eventComponent) {
return false
}
return this.eventComponent.canCreateRecurrenceExceptions()
},
/**
* Returns whether the calendar of the event can be modified
*
* @return {boolean}
*/
canModifyCalendar() {
const eventComponent = this.calendarObjectInstance.eventComponent
if (!eventComponent) {
return true
}
return !eventComponent.isPartOfRecurrenceSet() || eventComponent.isExactForkOfPrimary
},
/**
* Returns a an object with properties from RFCs including
* their displayName, a description, options, etc.
*
* @return {{geo, color, timeTransparency, description, resources, location, categories, accessClass, priority, status}}
*/
rfcProps() {
return getRFCProperties()
},
/**
* Returns whether or not this event can be downloaded from the server
*
* @return {boolean}
*/
hasDownloadURL() {
if (!this.calendarObject) {
return false
}
if (this.isLoading) {
return false
}
return this.calendarObject.existsOnServer
},
/**
* Returns the download url as a string or null if event is loading or does not exist on the server (yet)
*
* @return {string|null}
*/
downloadURL() {
if (!this.calendarObject) {
return null
}
if (!this.calendarObject.dav) {
return null
}
return this.calendarObject.dav.url + '?export'
},
/**
* Returns whether or not this is a new event
*
* @return {boolean}
*/
isNew() {
if (!this.calendarObject) {
return true
}
if (!this.calendarObject.dav) {
return true
}
return false
},
},
methods: {
/**
* Changes the selected calendar
* Does not move the calendar-object yet, that's done in save
*
* @param {object} selectedCalendar The new calendar selected by the user
*/
changeCalendar(selectedCalendar) {
this.calendarId = selectedCalendar.id
// If this is a new event that does not exist on the server yet,
// override the internally stored calendarId. If we did not do this,
// it would create the event in the default calendar first and move it
// to the desired calendar as a second step.
if (this.calendarObject && !this.calendarObject.existsOnServer) {
this.calendarObject.calendarId = selectedCalendar.id
}
},
/**
* This will force the user to update this and all future occurrences when saving
*/
forceModifyingFuture() {
this.forceThisAndAllFuture = true
},
/**
* Closes the editor and returns to normal calendar-view
*/
closeEditor() {
if (this.isWidget) {
this.calendarsStore.closeWidgetEventDetails()
return
}
const params = Object.assign({}, this.$route.params)
delete params.object
delete params.recurrenceId
this.$router.push({
name: getPrefixedRoute(this.$route.name, 'CalendarView'),
params,
})
this.calendarObjectInstanceStore.resetCalendarObjectInstanceObjectIdAndRecurrenceId()
},
/**
* Closes the editor and returns to normal calendar-view without running any action.
* This is useful if the calendar-object-instance has already been saved.
*/
closeEditorAndSkipAction() {
this.requiresActionOnRouteLeave = false
this.closeEditor()
},
/**
* Resets the calendar-object back to its original state and closes the editor
*/
async cancel() {
if (this.isLoading) {
return
}
if (!this.calendarObject) {
logger.error('Calendar-object not found')
this.closeEditor()
return
}
this.calendarObjectsStore.resetCalendarObjectToDavMutation({
calendarObject: this.calendarObject,
})
this.requiresActionOnRouteLeave = false
this.closeEditor()
},
keyboardCloseEditor(event) {
if (event.key === 'Escape') {
this.cancel()
}
},
keyboardSaveEvent(event) {
if (event.key === 'Enter' && event.ctrlKey === true && !this.isReadOnly && !this.canCreateRecurrenceException) {
this.saveAndLeave(false)
}
},
keyboardDeleteEvent(event) {
if (event.key === 'Delete' && event.ctrlKey === true && this.canDelete && !this.canCreateRecurrenceException) {
this.deleteAndLeave(false)
}
},
keyboardDuplicateEvent(event) {
if (event.key === 'd' && event.ctrlKey === true) {
event.preventDefault()
if (!this.isNew && !this.isReadOnly && !this.canCreateRecurrenceException) {
this.duplicateEvent()
}
}
},
/**
* Saves a calendar-object
*
* @param {boolean} thisAndAllFuture Whether to modify only this or this and all future occurrences
* @return {Promise<void>}
*/
async save(thisAndAllFuture = false) {
if (!this.calendarObject) {
logger.error('Calendar-object not found')
return
}
if (this.isReadOnly) {
return
}
if (this.forceThisAndAllFuture) {
thisAndAllFuture = true
}
this.isLoading = true
this.isSaving = true
try {
await this.calendarObjectInstanceStore.saveCalendarObjectInstance({
thisAndAllFuture,
calendarId: this.calendarId,
})
} catch (error) {
logger.error(`Failed to save event: ${error}`, {
error,
})
showError(t('calendar', 'Failed to save event'))
this.calendarObjectInstance.eventComponent.markDirty()
throw error
} finally {
this.isLoading = false
this.isSaving = false
}
},
/**
* Saves a calendar-object and closes the editor
*
* @param {boolean} thisAndAllFuture Whether to modify only this or this and all future occurrences
* @return {Promise<void>}
*/
async saveAndLeave(thisAndAllFuture = false) {
await this.save(thisAndAllFuture)
this.requiresActionOnRouteLeave = false
this.closeEditor()
},
/**
* Duplicates a calendar-object and saves it
*
* @return {Promise<void>}
*/
async duplicateEvent() {
await this.calendarObjectInstanceStore.duplicateCalendarObjectInstance()
},
/**
* Deletes a calendar-object
*
* @param {boolean} thisAndAllFuture Whether to delete only this or this and all future occurrences
* @return {Promise<void>}
*/
async delete(thisAndAllFuture = false) {
if (!this.calendarObject) {
logger.error('Calendar-object not found')
return
}
if (this.isReadOnly) {
return
}
this.isLoading = true
await this.calendarObjectInstanceStore.deleteCalendarObjectInstance({ thisAndAllFuture })
this.isLoading = false
},
/**
* Deletes a calendar-object and closes the editor
*
* @param {boolean} thisAndAllFuture Whether to delete only this or this and all future occurrences
* @return {Promise<void>}
*/
async deleteAndLeave(thisAndAllFuture = false) {
await this.delete(thisAndAllFuture)
this.requiresActionOnRouteLeave = false
this.closeEditor()
},
/**
* Updates the title of this event
*
* @param {string} title New title
*/
updateTitle(title) {
if (title.trim() === '') {
title = null
}
this.calendarObjectInstanceStore.changeTitle({
calendarObjectInstance: this.calendarObjectInstance,
title,
})
},
/**
* Updates the description of this event
*
* @param {string} description New description
*/
updateDescription(description) {
this.calendarObjectInstanceStore.changeDescription({
calendarObjectInstance: this.calendarObjectInstance,
description,
})
},
/**
* Updates the location of this event
*
* @param {string} location New location
*/
updateLocation(location) {
this.calendarObjectInstanceStore.changeLocation({
calendarObjectInstance: this.calendarObjectInstance,
location,
})
},
/**
* Updates the start date of this event
*
* @param {Date} startDate New start date
*/
updateStartDate(startDate) {
this.calendarObjectInstanceStore.changeStartDate({
calendarObjectInstance: this.calendarObjectInstance,
startDate,
onlyTime: false,
changeEndDate: false,
})
},
/**
* Updates the start time of this event
*
* @param {Date} startDate New start time
*/
updateStartTime(startDate) {
this.calendarObjectInstanceStore.changeStartDate({
calendarObjectInstance: this.calendarObjectInstance,
startDate,
onlyTime: true,
})
},
/**
* Updates the timezone of this event's start date
*
* @param {string} startTimezone New start timezone
*/
updateStartTimezone(startTimezone) {
if (!startTimezone) {
return
}
this.calendarObjectInstanceStore.changeStartTimezone({
calendarObjectInstance: this.calendarObjectInstance,
startTimezone,
})
},
/**
* Updates the end date of this event
*
* @param {Date} endDate New end date
*/
updateEndDate(endDate) {
this.calendarObjectInstanceStore.changeEndDate({
calendarObjectInstance: this.calendarObjectInstance,
endDate,
})
},
/**
* Updates the end time of this event
*
* @param {Date} endDate New end date
*/
updateEndTime(endDate) {
this.calendarObjectInstanceStore.changeEndDate({
calendarObjectInstance: this.calendarObjectInstance,
endDate,
onlyTime: true,
})
},
/**
* Updates the timezone of this event's end date
*
* @param {string} endTimezone New end timezone
*/
updateEndTimezone(endTimezone) {
if (!endTimezone) {
return
}
this.calendarObjectInstanceStore.changeEndTimezone({
calendarObjectInstance: this.calendarObjectInstance,
endTimezone,
})
},
/**
* Toggles the event between all-day and timed
*/
toggleAllDay() {
this.calendarObjectInstanceStore.toggleAllDay({
calendarObjectInstance: this.calendarObjectInstance,
})
},
/**
* Resets the internal state after changing the viewed calendar-object
*/
resetState() {
this.isLoading = true
this.isSaving = false
this.isError = false
this.error = null
this.calendarId = null
this.requiresActionOnRouteLeave = true
this.forceThisAndAllFuture = false
this.isEditingMasterItem = false
this.isRecurrenceException = false
},
/**
* This function returns a promise that resolves
* once the calendars were fetched from the server
*
* @return {Promise<void>}
*/
loadingCalendars() {
if (this.initialCalendarsLoaded) {
return Promise.resolve()
}
return new Promise((resolve) => {
const watcher = this.$watch('initialCalendarsLoaded', () => {
resolve()
watcher()
})
})
},
},
/**
* This is executed before entering the Editor routes
*
* @param {object} to The route to navigate to
* @param {object} from The route coming from
* @param {Function} next Function to be called when ready to load the next view
*/
async beforeRouteEnter(to, from, next) {
if (to.name === 'NewSidebarView' || to.name === 'NewPopoverView') {
next(async vm => {
vm.resetState()
const isAllDay = (to.params.allDay === '1')
const start = parseInt(to.params.dtstart, 10)
const end = parseInt(to.params.dtend, 10)
const timezoneId = vm.settingsStore.getResolvedTimezone
try {
await vm.loadingCalendars()
await vm.calendarObjectInstanceStore.getCalendarObjectInstanceForNewEvent({ isAllDay, start, end, timezoneId })
vm.calendarId = vm.calendarObject.calendarId
} catch (error) {
console.debug(error)
vm.isError = true
vm.error = t('calendar', 'It might have been deleted, or there was a typo in a link')
} finally {
vm.isLoading = false
}
})
} else {
next(async vm => {
vm.resetState()
const objectId = to.params.object
const recurrenceId = to.params.recurrenceId
if (recurrenceId === 'next') {
const closeToDate = dateFactory()
// TODO: can we replace this by simply returning the new route since we are inside next()
// Probably not though, because it's async
try {
await vm.loadingCalendars()
const recurrenceId = await vm.calendarObjectInstanceStore.resolveClosestRecurrenceIdForCalendarObject({
objectId, closeToDate,
})
const params = Object.assign({}, vm.$route.params, { recurrenceId })
vm.$router.replace({ name: vm.$route.name, params })
} catch (error) {
console.debug(error)
vm.isError = true
vm.error = t('calendar', 'It might have been deleted, or there was a typo in a link')
return // if we cannot resolve next to an actual recurrenceId, return here to avoid further processing.
} finally {
vm.isLoading = false
}
}
try {
await vm.loadingCalendars()
await vm.calendarObjectInstanceStore.getCalendarObjectInstanceByObjectIdAndRecurrenceId({ objectId, recurrenceId })
vm.calendarId = vm.calendarObject.calendarId
vm.isEditingMasterItem = vm.eventComponent.isMasterItem()
vm.isRecurrenceException = vm.eventComponent.isRecurrenceException()
} catch (error) {
console.debug(error)
vm.isError = true
vm.error = t('calendar', 'It might have been deleted, or there was a typo in a link')
} finally {
vm.isLoading = false
}
})
}
},
/**
* This function is called when the route changes. This can be caused by various actions:
* - Change of selected time-range when creating new event
* - Navigating through the calendar-view
*
* @param {object} to The route to navigate to
* @param {object} from The route coming from
* @param {Function} next Function to be called when ready to load the next view
*/
async beforeRouteUpdate(to, from, next) {
// If we are in the New Event dialog, we want to update the selected time
if (to.name === 'NewSidebarView' || to.name === 'NewPopoverView') {
// If allDay, dtstart and dtend are the same there is no need to update.
// This is usally the case when navigating through the calendar while the editor is open
if (to.params.allDay === from.params.allDay
&& to.params.dtstart === from.params.dtstart
&& to.params.dtend === from.params.dtend) {
next()
return
}
const isAllDay = (to.params.allDay === '1')
const start = to.params.dtstart
const end = to.params.dtend
const timezoneId = this.settingsStore.getResolvedTimezone
await this.loadingCalendars()
await this.calendarObjectInstanceStore.updateCalendarObjectInstanceForNewEvent({ isAllDay, start, end, timezoneId })
next()
} else {
// If both the objectId and recurrenceId remained the same
// there is no need to update. This is usally the case when navigating
// through the calendar while the editor is open
if (to.params.object === from.params.object
&& to.params.recurrenceId === from.params.recurrenceId) {
next()
return
}
this.isLoading = true
try {
await this.save()
} catch (error) {
console.debug(error)
next(false)
return
}
this.resetState()
const objectId = to.params.object
const recurrenceId = to.params.recurrenceId
if (recurrenceId === 'next') {
const closeToDate = dateFactory()
await this.loadingCalendars()
const recurrenceId = await this.calendarObjectInstanceStore.resolveClosestRecurrenceIdForCalendarObject({
objectId, closeToDate,
})
const params = Object.assign({}, this.$route.params, { recurrenceId })
next({ name: this.$route.name, params })
return
}
try {
await this.loadingCalendars()
await this.calendarObjectInstanceStore.getCalendarObjectInstanceByObjectIdAndRecurrenceId({ objectId, recurrenceId })
this.calendarId = this.calendarObject.calendarId
this.isEditingMasterItem = this.eventComponent.isMasterItem()
this.isRecurrenceException = this.eventComponent.isRecurrenceException()
} catch (error) {
console.debug(error)
this.isError = true
this.error = t('calendar', 'It might have been deleted, or there was a typo in the link')
} finally {
this.isLoading = false
next()
}
}
},
/**
* This route is called when the user leaves the editor
*
* @param {object} to The route to navigate to
* @param {object} from The route coming from
* @param {Function} next Function to be called when ready to load the next view
*/
async beforeRouteLeave(to, from, next) {
// requiresActionOnRouteLeave is false when an action like deleting / saving / cancelling was already taken.
// The responsibility of this method is to automatically save the event when the user clicks outside the editor
if (!this.requiresActionOnRouteLeave) {
next()
return
}
try {
if ((from.name !== 'NewPopoverView' || to.name !== 'EditPopoverView')
&& (from.name !== 'NewPopoverView' || to.name !== 'EditSideBarView')) {
await this.save()
}
next()
} catch (error) {
console.debug(error)
next(false)
}
},
}