Welcome to mirror list, hosted at ThFree Co, Russian Federation.

TheDetails.vue « components « src - github.com/nextcloud/tasks.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 413ea1fd7d91402cbe5aa3c1508aa24224922e8b (plain)
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
<!--
Nextcloud - Tasks

@author Raimund Schlüßler
@copyright 2018 Raimund Schlüßler <raimund.schluessler@mailbox.org>

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
License as published by the Free Software Foundation; either
version 3 of the License, or any later version.

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU AFFERO GENERAL PUBLIC LICENSE for more details.

You should have received a copy of the GNU Affero General Public
License along with this library.  If not, see <http://www.gnu.org/licenses/>.

-->

<template>
	<div class="content-wrapper">
		<div v-if="task"
			:class="{'disabled': readOnly}"
			class="flex-container">
			<div :class="{'editing': edit=='summary'}" class="title">
				<span class="detail-checkbox">
					<input :id="'detailsToggleCompleted_' + task.uid"
						type="checkbox"
						class="checkbox"
						name="detailsToggleCompleted"
						:class="{'disabled': readOnly}"
						:checked="task.completed"
						:aria-checked="task.completed"
						:disabled="readOnly"
						:aria-label="$t('tasks', 'Task is completed')"
						@click="toggleCompleted(task)">
					<label :for="'detailsToggleCompleted_' + task.uid" />
				</span>
				<div v-click-outside="() => finishEditing('summary')" class="title-wrapper">
					<div v-linkify="task.summary"
						:class="{'strike-through': task.completed}"
						class="title-text"
						@click="editProperty('summary', $event)" />
					<div class="expandable-container">
						<div class="expandingArea active">
							<pre><span>{{ tmpTask.summary }}</span><br></pre>
							<textarea id="summaryInput"
								v-model="tmpTask.summary"
								maxlength="200"
								@keyup.27="cancelEditing('summary')"
								@keydown.enter.prevent="finishEditing('summary')" />
						</div>
					</div>
				</div>
				<TaskStatusDisplay :task="task" />
				<button class="reactive inline" @click="togglePinned(task)">
					<span :class="[{'disabled': readOnly}, iconPinned]" class="icon" />
				</button>
				<button class="reactive inline" @click="toggleStarred(task)">
					<span :class="[{'disabled': readOnly}, iconStar]"
						class="icon" />
				</button>
			</div>
			<div class="body">
				<ul class="sections">
					<li v-show="!readOnly || task.start"
						:class="{'date': task.startMoment.isValid(), 'editing': edit=='start', 'high': overdue(task.startMoment)}"
						class="section detail-start">
						<div v-click-outside="($event) => finishEditing('start', $event)"
							class="section-content"
							@click="editProperty('start', $event)">
							<span class="section-icon">
								<span :class="[startDateIcon(task.startMoment)]"
									class="icon" />
							</span>
							<span class="section-title">
								{{ startDateString }}
							</span>
							<div v-if="edit=='start'" class="section-edit">
								<DatetimePicker :value="tmpTask.start.toDate()"
									:lang="lang"
									:format="dateFormat"
									:clearable="false"
									type="date"
									:placeholder="$t('tasks', 'Set start date')"
									class="date"
									@change="setStartDate" />
								<DatetimePicker v-if="!allDay"
									:value="tmpTask.start.toDate()"
									:lang="lang"
									:format="timeFormat"
									:clearable="false"
									:time-picker-options="timePickerOptions"
									type="time"
									:placeholder="$t('tasks', 'Set start time')"
									class="time"
									@change="setStartTime" />
							</div>
						</div>
						<div class="section-utils">
							<button class="inline reactive">
								<span class="icon sprt-color sprt-checkmark-color" />
							</button>
							<button class="delete inline reactive" @click="setProperty('start', null)">
								<span class="icon icon-sprt-bw sprt-trash" />
							</button>
						</div>
					</li>
					<li v-show="!readOnly || task.due"
						:class="{'date': task.dueMoment.isValid(), 'editing': edit=='due', 'high': overdue(task.dueMoment)}"
						class="section detail-date">
						<div v-click-outside="($event) => finishEditing('due', $event)"
							class="section-content"
							@click="editProperty('due', $event)">
							<span class="section-icon">
								<span :class="[dueDateIcon(task.dueMoment)]"
									class="icon" />
							</span>
							<span class="section-title">
								{{ dueDateString }}
							</span>
							<div v-if="edit=='due'" class="section-edit">
								<DatetimePicker :value="tmpTask.due.toDate()"
									:lang="lang"
									:format="dateFormat"
									:clearable="false"
									type="date"
									:placeholder="$t('tasks', 'Set due date')"
									class="date"
									@change="setDueDate" />
								<DatetimePicker v-if="!allDay"
									:value="tmpTask.due.toDate()"
									:lang="lang"
									:format="timeFormat"
									:clearable="false"
									:time-picker-options="timePickerOptions"
									type="time"
									:placeholder="$t('tasks', 'Set due time')"
									class="time"
									@change="setDueTime" />
							</div>
						</div>
						<div class="section-utils">
							<button class="inline reactive">
								<span class="icon sprt-color sprt-checkmark-color" />
							</button>
							<button class="delete inline reactive" @click="setProperty('due', null)">
								<span class="icon icon-sprt-bw sprt-trash" />
							</button>
						</div>
					</li>
					<li v-show="isAllDayPossible"
						class="section detail-all-day reactive">
						<div class="section-content">
							<input id="isAllDayPossible"
								type="checkbox"
								class="checkbox"
								name="isAllDayPossible"
								:class="{'disabled': readOnly}"
								:aria-checked="allDay"
								:checked="allDay"
								:disabled="readOnly"
								@click="toggleAllDay(task)">
							<label for="isAllDayPossible">
								<span>{{ $t('tasks', 'All day') }}</span>
							</label>
						</div>
					</li>
					<li class="section detail-calendar reactive">
						<div v-click-outside="() => finishEditing('calendar')"
							class="section-content"
							@click="editProperty('calendar')">
							<span class="section-icon">
								<span :style="{'background-color': task.calendar.color}" class="calendar-indicator" />
							</span>
							<div class="detail-multiselect-container blue">
								<Multiselect
									:value="task.calendar"
									:multiple="false"
									:allow-empty="false"
									:disabled="readOnly"
									track-by="id"
									:placeholder="$t('tasks', 'Select a calendar')"
									label="displayName"
									:options="targetCalendars"
									:close-on-select="true"
									class="multiselect-vue"
									@input="changeCalendar"
									@tag="changeCalendar" />
							</div>
						</div>
					</li>
					<li class="section detail-class reactive">
						<div v-click-outside="() => finishEditing('class')"
							class="section-content"
							@click="editProperty('class')">
							<span class="section-icon">
								<span class="icon sprt-color sprt-privacy" />
							</span>
							<div class="detail-multiselect-container blue">
								<Multiselect
									:value="classSelect.find( _ => _.type === task.class )"
									:multiple="false"
									:allow-empty="false"
									:disabled="readOnly || task.calendar.isSharedWithMe"
									track-by="type"
									:placeholder="$t('tasks', 'Select a classification')"
									label="displayName"
									:options="classSelect"
									:close-on-select="true"
									class="multiselect-vue"
									@input="changeClass"
									@tag="changeClass" />
							</div>
						</div>
					</li>
					<li v-show="!readOnly || task.status"
						class="section detail-class reactive">
						<div v-click-outside="() => finishEditing('status')"
							class="section-content"
							@click="editProperty('status')">
							<span class="section-icon">
								<span :class="[iconStatus]" class="icon" />
							</span>
							<div class="detail-multiselect-container blue">
								<Multiselect
									:value="statusSelect.find( _ => _.type === task.status )"
									:multiple="false"
									:allow-empty="false"
									:disabled="readOnly"
									track-by="type"
									:placeholder="$t('tasks', 'Select a status')"
									label="displayName"
									:options="statusSelect"
									:close-on-select="true"
									class="multiselect-vue"
									@input="changeStatus"
									@tag="changeStatus" />
							</div>
						</div>
					</li>
					<li v-show="!readOnly || task.priority"
						:class="[{'editing': edit=='priority', 'date': task.priority>0}, priorityClass]"
						class="section detail-priority">
						<div v-click-outside="() => finishEditing('priority')"
							class="section-content"
							@click="editProperty('priority')">
							<span class="section-icon">
								<span :class="[iconStar]" class="icon" />
							</span>
							<span class="section-title">
								{{ priorityString }}
							</span>
							<div class="section-edit">
								<input v-model="tmpTask.priority"
									class="priority-input"
									type="number"
									min="0"
									max="9"
									@keyup.27="cancelEditing('priority')"
									@keydown.enter.prevent="finishEditing('priority')">
								<input v-model="tmpTask.priority"
									type="range"
									min="0"
									max="9"
									step="1">
							</div>
						</div>
						<div class="section-utils">
							<button class="inline reactive">
								<span class="icon sprt-color sprt-checkmark-color" />
							</button>
							<button class="delete inline reactive" @click="setProperty('priority', 0)">
								<span class="icon icon-sprt-bw sprt-trash" />
							</button>
						</div>
					</li>
					<li v-show="!readOnly || task.complete"
						:class="{'editing': edit=='complete', 'date': task.complete>0}"
						class="section detail-complete">
						<div v-click-outside="() => finishEditing('complete')"
							class="section-content"
							@click="editProperty('complete')">
							<span class="section-icon">
								<span :class="[iconPercent]" class="icon" />
							</span>
							<span class="section-title">
								{{ completeString }}
							</span>
							<div class="section-edit">
								<input v-model="tmpTask.complete"
									class="percent-input"
									type="number"
									min="0"
									max="100"
									@keyup.27="cancelEditing('complete')"
									@keydown.enter.prevent="finishEditing('complete')">
								<input v-model="tmpTask.complete"
									type="range"
									min="0"
									max="100"
									step="1">
							</div>
						</div>
						<div class="section-utils">
							<button class="inline reactive">
								<span class="icon sprt-color sprt-checkmark-color" />
							</button>
							<button class="delete inline reactive" @click="setProperty('complete', 0)">
								<span class="icon icon-sprt-bw sprt-trash" />
							</button>
						</div>
					</li>
					<li v-show="!readOnly || task.categories.length>0" :class="{'active': task.categories.length>0}" class="section detail-categories">
						<div class="section-content">
							<span class="section-icon">
								<span :class="[iconCategories]" class="icon detail-categories" />
							</span>
							<div class="detail-multiselect-container">
								<Multiselect v-if="task.categories"
									v-model="task.categories"
									:multiple="true"
									:searchable="true"
									:disabled="readOnly"
									:options="task.categories"
									:placeholder="$t('tasks', 'Select categories')"
									:taggable="true"
									:tag-placeholder="$t('tasks', 'Add this as a new category')"
									:close-on-select="false"
									class="multiselect-vue"
									@input="updateCategories"
									@tag="updateCategory" />
							</div>
						</div>
					</li>
					<li v-show="!readOnly || task.note" class="section detail-note">
						<div class="section-content note">
							<div v-click-outside="() => finishEditing('note')"
								class="note-body selectable"
								@click="editProperty('note', $event)">
								<div :class="{'editing': edit=='note'}" class="content-fakeable">
									<Markdown id="markdown"
										:source="task.note"
										class="display-view" />
									<div class="edit-view">
										<div class="expandingArea active">
											<pre><span>{{ tmpTask.note }}</span><br><br></pre>
											<textarea id="noteInput" v-model="tmpTask.note" @change="setProperty('note', tmpTask.note)" />
										</div>
									</div>
								</div>
							</div>
						</div>
					</li>
				</ul>
			</div>
			<div class="footer">
				<button :style="{visibility: readOnly ? 'hidden' : 'visible'}"
					class="close-all reactive inline"
					@click="removeTask">
					<span class="icon icon-sprt-bw sprt-trash" />
				</button>
				<span v-tooltip="{
						content: taskInfo,
						html: true,
					}"
					class="info">
					<span class="icon icon-info" />
				</span>
				<button class="close-all reactive inline" @click="closeDetails">
					<span class="icon icon-sprt-bw sprt-hide" />
				</button>
			</div>
		</div>
		<div v-else class="notice">
			<span v-if="loading">{{ $t('tasks', 'Loading task from server.') }}</span>
			<span v-else>{{ $t('tasks', 'Task not found!') }}</span>
		</div>
	</div>
</template>

<script>
import { mapGetters, mapActions } from 'vuex'
import { overdue } from '../store/storeHelper'
import moment from '@nextcloud/moment'
import DatetimePicker from '@nextcloud/vue/dist/Components/DatetimePicker'
import Multiselect from '@nextcloud/vue/dist/Components/Multiselect'
import Markdown from './Markdown'
import TaskStatusDisplay from './TaskStatusDisplay'

import ClickOutside from 'vue-click-outside'
import { linkify } from '../directives/linkify.js'

export default {
	components: {
		DatetimePicker,
		Multiselect,
		Markdown,
		TaskStatusDisplay,
	},
	directives: {
		ClickOutside,
		linkify,
	},
	filters: {
	},
	data: function() {
		return {
			loading: false,
			edit: '',
			tmpTask: {
				summary: '',
				start: '',
				due: '',
				priority: '',
				complete: '',
				note: '',
			},
			lang: {
				formatLocale: {
					firstDayOfWeek: window.firstDay,
				},
				days: window.dayNamesShort, // provided by nextcloud
				months: window.monthNamesShort, // provided by nextcloud
			},
			dateFormat: moment.localeData().longDateFormat('L'),
			timeFormat: moment.localeData().longDateFormat('LT'),
			timePickerOptions: {
				start: '00:00',
				step: '00:30',
				end: '23:30',
			},
			categories: [],
			classSelect: [
				{ displayName: this.$t('tasks', 'When shared show full event'), type: 'PUBLIC' },
				{ displayName: this.$t('tasks', 'When shared show only busy'), type: 'CONFIDENTIAL' },
				{ displayName: this.$t('tasks', 'When shared hide this event'), type: 'PRIVATE' },
			],
			statusSelect: [
				{ displayName: this.$t('tasks', 'Needs action'), type: 'NEEDS-ACTION' },
				{ displayName: this.$t('tasks', 'Completed'), type: 'COMPLETED' },
				{ displayName: this.$t('tasks', 'In process'), type: 'IN-PROCESS' },
				{ displayName: this.$t('tasks', 'Canceled'), type: 'CANCELLED' },
			],
		}
	},
	computed: {
		/**
		 * Whether we treat the task as read-only.
		 * We also treat tasks in shared calendars with an access class other than 'PUBLIC'
		 * as read-only.
		 *
		 * @returns {Boolean} Is the task read-only
		 */
		readOnly() {
			return this.task.calendar.readOnly || (this.task.calendar.isSharedWithMe && this.task.class !== 'PUBLIC')
		},
		/**
		 * Whether the dates of a task are all-day
		 * When no dates are set, we consider the last used value.
		 *
		 * @returns {Boolean} Are the dates all-day
		 */
		allDay: function() {
			if (this.task.startMoment.isValid() || this.task.dueMoment.isValid()) {
				return this.task.allDay
			} else {
				return this.$store.state.settings.settings.allDay
			}
		},
		startDateString: function() {
			const $t = this.$t
			if (this.task.startMoment.isValid()) {
				if (this.allDay) {
					return this.task.startMoment.calendar(null, {
						// TRANSLATORS This is a string for moment.js. The square brackets escape the string from moment.js. Please translate the string and keep the brackets.
						sameDay: this.$t('tasks', '[Starts today]'),
						// TRANSLATORS This is a string for moment.js. The square brackets escape the string from moment.js. Please translate the string and keep the brackets.
						nextDay: this.$t('tasks', '[Starts tomorrow]'),
						// TRANSLATORS This is a string for moment.js. The square brackets escape the string from moment.js. "LL" will be replaced with a date, e.g. 'September 4 1986'. Please translate the string, and keep the brackets and the "LL".
						nextWeek: this.$t('tasks', '[Starts on] LL'),
						// TRANSLATORS This is a string for moment.js. The square brackets escape the string from moment.js. Please translate the string and keep the brackets.
						lastDay: this.$t('tasks', '[Started yesterday]'),
						// TRANSLATORS This is a string for moment.js. The square brackets escape the string from moment.js. "LL" will be replaced with a date, e.g. 'September 4 1986'. Please translate the string, and keep the brackets and the "LL".
						lastWeek: this.$t('tasks', '[Started on] LL'),
						sameElse: function(now) {
							if (this.isBefore(now)) {
								// TRANSLATORS This is a string for moment.js. The square brackets escape the string from moment.js. "LL" will be replaced with a date, e.g. 'September 4 1986'. Please translate the string, and keep the brackets and the "LL".
								return $t('tasks', '[Started on] LL')
							} else {
								// TRANSLATORS This is a string for moment.js. The square brackets escape the string from moment.js. "LL" will be replaced with a date, e.g. 'September 4 1986'. Please translate the string, and keep the brackets and the "LL".
								return $t('tasks', '[Starts on] LL')
							}
						},
					})
				} else {
					return this.task.startMoment.calendar(null, {
						sameDay: function(now) {
							if (this.isBefore(now)) {
								// TRANSLATORS This is a string for moment.js. The square brackets escape the string from moment.js. "LT" will be replaced with a time, e.g. '08:30 PM'. Please translate the string and keep the brackets and the "LT".
								return $t('tasks', '[Started today at] LT')
							} else {
								// TRANSLATORS This is a string for moment.js. The square brackets escape the string from moment.js. "LT" will be replaced with a time, e.g. '08:30 PM'. Please translate the string and keep the brackets and the "LT".
								return $t('tasks', '[Starts today at] LT')
							}
						},
						// TRANSLATORS This is a string for moment.js. The square brackets escape the string from moment.js. "LT" will be replaced with a time, e.g. '08:30 PM'. Please translate the string and keep the brackets and the "LT".
						nextDay: this.$t('tasks', '[Starts tomorrow at] LT'),
						// TRANSLATORS This is a string for moment.js. The square brackets escape the string from moment.js. "LL" will be replaced with a date, e.g. 'September 4 1986' and "LT" will be replaced with a time, e.g. '08:30 PM'. Please translate the string and keep the brackets the "LL" and the "LT".
						nextWeek: this.$t('tasks', '[Starts on] LL [at] LT'),
						// TRANSLATORS This is a string for moment.js. The square brackets escape the string from moment.js. "LT" will be replaced with a time, e.g. '08:30 PM'. Please translate the string and keep the brackets and the "LT".
						lastDay: this.$t('tasks', '[Started yesterday at] LT'),
						// TRANSLATORS This is a string for moment.js. The square brackets escape the string from moment.js. "LL" will be replaced with a date, e.g. 'September 4 1986' and "LT" will be replaced with a time, e.g. '08:30 PM'. Please translate the string and keep the brackets the "LL" and the "LT".
						lastWeek: this.$t('tasks', '[Started on] LL [at] LT'),
						sameElse: function(now) {
							if (this.isBefore(now)) {
								// TRANSLATORS This is a string for moment.js. The square brackets escape the string from moment.js. "LL" will be replaced with a date, e.g. 'September 4 1986' and "LT" will be replaced with a time, e.g. '08:30 PM'. Please translate the string and keep the brackets the "LL" and the "LT".
								return $t('tasks', '[Started on] LL [at] LT')
							} else {
								// TRANSLATORS This is a string for moment.js. The square brackets escape the string from moment.js. "LL" will be replaced with a date, e.g. 'September 4 1986' and "LT" will be replaced with a time, e.g. '08:30 PM'. Please translate the string and keep the brackets the "LL" and the "LT".
								return $t('tasks', '[Starts on] LL [at] LT')
							}
						},
					})
				}
			} else {
				return this.$t('tasks', 'Set start date')
			}
		},
		dueDateString: function() {
			const $t = this.$t
			if (this.task.dueMoment.isValid()) {
				if (this.allDay) {
					return this.task.dueMoment.calendar(null, {
						// TRANSLATORS This is a string for moment.js. The square brackets escape the string from moment.js. Please translate the string and keep the brackets.
						sameDay: this.$t('tasks', '[Due today]'),
						// TRANSLATORS This is a string for moment.js. The square brackets escape the string from moment.js. Please translate the string and keep the brackets.
						nextDay: this.$t('tasks', '[Due tomorrow]'),
						// TRANSLATORS This is a string for moment.js. The square brackets escape the string from moment.js. "LL" will be replaced with a date, e.g. 'September 4 1986'. Please translate the string and keep the brackets and the "LL".
						nextWeek: this.$t('tasks', '[Due on] LL'),
						// TRANSLATORS This is a string for moment.js. The square brackets escape the string from moment.js. Please translate the string, but keep the brackets.
						lastDay: this.$t('tasks', '[Was due yesterday]'),
						// TRANSLATORS This is a string for moment.js. The square brackets escape the string from moment.js. "LL" will be replaced with a date, e.g. 'September 4 1986'. Please translate the string, but keep the brackets and the "LL".
						lastWeek: this.$t('tasks', '[Was due on] LL'),
						sameElse: function(now) {
							if (this.isBefore(now)) {
								// TRANSLATORS This is a string for moment.js. The square brackets escape the string from moment.js. Please translate the string, but keep the brackets and the "LL".
								return $t('tasks', '[Was due on] LL')
							} else {
								// TRANSLATORS This is a string for moment.js. The square brackets escape the string from moment.js. Please translate the string, but keep the brackets and the "LL".
								return $t('tasks', '[Due on] LL')
							}
						},
					})
				} else {
					return this.task.dueMoment.calendar(null, {
						sameDay: function(now) {
							if (this.isBefore(now)) {
								// TRANSLATORS This is a string for moment.js. The square brackets escape the string from moment.js. "LT" will be replaced with a time, e.g. '08:30 PM'. Please translate the string and keep the brackets and the "LT".
								return $t('tasks', '[Was due today at] LT')
							} else {
								// TRANSLATORS This is a string for moment.js. The square brackets escape the string from moment.js. "LT" will be replaced with a time, e.g. '08:30 PM'. Please translate the string and keep the brackets and the "LT".
								return $t('tasks', '[Due today at] LT')
							}
						},
						// TRANSLATORS This is a string for moment.js. The square brackets escape the string from moment.js. "LT" will be replaced with a time, e.g. '08:30 PM'. Please translate the string and keep the brackets and the "LT".
						nextDay: this.$t('tasks', '[Due tomorrow at] LT'),
						// TRANSLATORS This is a string for moment.js. The square brackets escape the string from moment.js. "LT" will be replaced with a time, e.g. '08:30 PM'. Please translate the string and keep the brackets and the "LT".
						nextWeek: this.$t('tasks', '[Due on] LL [at] LT'),
						// TRANSLATORS This is a string for moment.js. The square brackets escape the string from moment.js. "LT" will be replaced with a time, e.g. '08:30 PM'. Please translate the string and keep the brackets and the "LT".
						lastDay: this.$t('tasks', '[Was due yesterday at] LT'),
						// TRANSLATORS This is a string for moment.js. The square brackets escape the string from moment.js. "LL" will be replaced with a date, e.g. 'September 4 1986' and "LT" will be replaced with a time, e.g. '08:30 PM'. Please translate the string and keep the brackets the "LL" and the "LT".
						lastWeek: this.$t('tasks', '[Was due on] LL [at] LT'),
						sameElse: function(now) {
							if (this.isBefore(now)) {
								// TRANSLATORS This is a string for moment.js. The square brackets escape the string from moment.js. "LL" will be replaced with a date, e.g. 'September 4 1986' and "LT" will be replaced with a time, e.g. '08:30 PM'. Please translate the string and keep the brackets the "LL" and the "LT".
								return $t('tasks', '[Was due on] LL [at] LT')
							} else {
								// TRANSLATORS This is a string for moment.js. The square brackets escape the string from moment.js. "LL" will be replaced with a date, e.g. 'September 4 1986' and "LT" will be replaced with a time, e.g. '08:30 PM'. Please translate the string and keep the brackets the "LL" and the "LT".
								return $t('tasks', '[Due on] LL [at] LT')
							}
						},
					})
				}
			} else {
				return this.$t('tasks', 'Set due date')
			}
		},
		taskInfo: function() {
			return this.$t('tasks', 'Last modified {date}', { date: this.task.modifiedMoment.calendar() })
				+ '<br />' + this.$t('tasks', 'Created {date}', { date: this.task.createdMoment.calendar() })
				+ (this.task.completed ? ('<br />' + this.$t('tasks', 'Completed {date}', { date: this.task.completedDateMoment.calendar() })) : '')
		},
		isAllDayPossible: function() {
			return !this.readOnly && (this.task.due || this.task.start || ['start', 'due'].includes(this.edit))
		},
		priorityClass: function() {
			if (+this.task.priority > 5) {
				return 'low'
			} else if (+this.task.priority === 5) {
				return 'medium'
			} else if (+this.task.priority > 0 && +this.task.priority < 5) {
				return 'high'
			} else {
				return ''
			}
		},
		priorityString: function() {
			if (+this.task.priority === 0) {
				return this.$t('tasks', 'No priority assigned')
			} else if (+this.task.priority > 0 && +this.task.priority < 5) {
				return this.$t('tasks', 'Priority {priority}: high', { priority: this.task.priority })
			} else if (+this.task.priority === 5) {
				return this.$t('tasks', 'Priority {priority}: medium', { priority: this.task.priority })
			} else if (+this.task.priority > 5 && +this.task.priority < 10) {
				return this.$t('tasks', 'Priority {priority}: low', { priority: this.task.priority })
			}
			return ''
		},
		completeString: function() {
			return this.$t('tasks', '{percent} % completed', { percent: this.task.complete })
		},
		iconStar: function() {
			if (+this.task.priority) {
				return 'sprt-color sprt-task-star-' + this.priorityClass
			} else {
				return 'icon-sprt-bw sprt-task-star'
			}
		},
		iconPinned: function() {
			if (this.task.pinned) {
				return 'icon-sprt-bw sprt-pinned'
			} else {
				return 'icon-sprt-bw sprt-pinned-off'
			}
		},
		iconPercent: function() {
			if (this.task.complete > 0) {
				return 'sprt-color sprt-percent-active'
			} else {
				return 'icon-sprt-bw sprt-percent'
			}
		},
		iconCategories: function() {
			if (this.task.categories.length > 0) {
				return 'sprt-color sprt-tag-active'
			} else {
				return 'icon-sprt-bw sprt-tag'
			}
		},
		iconStatus: function() {
			if (this.task.status) {
				return 'sprt-color sprt-status'
			} else {
				return 'icon-sprt-bw sprt-current'
			}
		},
		targetCalendars() {
			let calendars = this.writableCalendars
			// Tasks with an access class other than PUBLIC cannot be moved
			// into calendars shared with me
			if (this.task.class !== 'PUBLIC') {
				calendars = calendars.filter(calendar => !calendar.isSharedWithMe)
			}
			return calendars
		},
		...mapGetters({
			writableCalendars: 'getSortedWritableCalendars',
			task: 'getTaskByRoute',
			calendar: 'getCalendarByRoute',
			calendars: 'getSortedCalendars',
		}),
	},

	watch: {
		$route: 'loadTask',
		calendars: 'loadTask',
	},

	created() {
		this.loadTask()
	},

	/**
	 * Before we close the details view, we save possible edits.
	 *
	 * @param {Route} to The target Route Object being navigated to.
	 * @param {Route} from The current route being navigated away from.
	 * @param {Function} next This function must be called to resolve the hook.
	 */
	beforeRouteLeave: function(to, from, next) {
		this.finishEditing(this.edit)
		next()
	},

	/**
	 * Before we navigate to a new task, we save possible edits.
	 *
	 * @param {Route} to The target Route Object being navigated to.
	 * @param {Route} from The current route being navigated away from.
	 * @param {Function} next This function must be called to resolve the hook.
	 */
	beforeRouteUpdate: function(to, from, next) {
		this.finishEditing(this.edit)
		next()
	},
	methods: {
		...mapActions([
			'deleteTask',
			'toggleCompleted',
			'toggleStarred',
			'setSummary',
			'setNote',
			'setPriority',
			'setPercentComplete',
			'setCategories',
			'addCategory',
			'setDue',
			'setStart',
			'toggleAllDay',
			'moveTask',
			'setClassification',
			'setStatus',
			'getTaskByUri',
			'togglePinned',
		]),

		async loadTask() {
			if (this.task === undefined || this.task === null) {
				const calendars = this.calendar ? [this.calendar] : this.calendars
				for (const calendar of calendars) {
					this.loading = true
					try {
						const task = await this.getTaskByUri({ calendar, taskUri: this.$route.params.taskId })
						// If we found the task, we don't need to query the other calendars.
						if (task) {
							break
						}
					} catch {
						console.debug('Task ' + this.$route.params.taskId + ' not found in calendar ' + calendar.displayName + '.')
					}
				}
				this.loading = false
			}
		},

		removeTask: function() {
			this.deleteTask({ task: this.task, dav: true })
			this.closeDetails()
		},

		closeDetails: function() {
			if (this.$route.params.calendarId) {
				this.$router.push({ name: 'calendars', params: { calendarId: this.$route.params.calendarId } })
			} else {
				this.$router.push({ name: 'collections', params: { collectionId: this.$route.params.collectionId } })
			}
		},

		startDateIcon: function(date) {
			if (date.isValid()) {
				return `sprt-color sprt-startdate-${overdue(date) ? 'overdue' : 'due'}`
			} else {
				return 'icon-sprt-bw sprt-startdate'
			}
		},

		dueDateIcon: function(date) {
			if (date.isValid()) {
				return `sprt-color sprt-duedate-${overdue(date) ? 'overdue' : 'due'}`
			} else {
				return 'icon-sprt-bw sprt-duedate'
			}
		},

		/**
		 * Checks if a date is overdue
		 */
		overdue: overdue,

		editProperty: function(type, event) {
			// don't start to edit the property again
			// if the confirm button of the datepicker was clicked
			// don't start to edit if a linkified link was clicked
			if (event && (event.target.classList.contains('mx-datepicker-btn-confirm') || event.target.tagName === 'A')) {
				return
			}
			// Don't allow to change the access class in calendars shared with me.
			if (this.task.calendar.isSharedWithMe && type === 'class') {
				return
			}
			// Save possible edits before starting to edit another property.
			if (this.edit !== type) {
				this.finishEditing(this.edit)
			}
			if (!this.readOnly && this.edit !== type) {
				this.edit = type
				this.tmpTask[type] = this.task[type]
				// If we edit the due or the start date, inintialize it.
				if (type === 'due') {
					this.tmpTask.due = this.initDueDate()
					this.tmpTask.start = this.task.startMoment.toDate()
				}
				if (type === 'start') {
					this.tmpTask.start = this.initStartDate()
					this.tmpTask.due = this.task.dueMoment.toDate()
				}
			}
			if (type === 'summary' || type === 'note') {
				this.$nextTick(
					() => document.getElementById(type + 'Input').focus()
				)
			}
		},

		finishEditing: function(type, $event) {
			// For some reason the click-outside handlers fire for the datepicker month and year buttons!?
			if ($event && $event.target.classList.contains('mx-btn')) {
				return
			}
			if (this.edit === type) {
				this.setProperty(type, this.tmpTask[type])
			}
		},

		cancelEditing: function(type) {
			this.edit = ''
			this.tmpTask[type] = this.task[type]
		},

		setProperty: function(type, value) {
			switch (type) {
			case 'summary':
				this.setSummary({ task: this.task, summary: value })
				break
			case 'note':
				this.setNote({ task: this.task, note: value })
				break
			case 'priority':
				this.setPriority({ task: this.task, priority: value })
				break
			case 'complete':
				this.setPercentComplete({ task: this.task, complete: value })
				break
			case 'start':
				this.setStart({ task: this.task, start: value, allDay: this.allDay })
				break
			case 'due':
				this.setDue({ task: this.task, due: value, allDay: this.allDay })
				break
			}
			this.edit = ''
		},

		/**
		 * Initializes the start date of a task
		 *
		 * @returns {Date} The start date moment
		 */
		initStartDate: function() {
			const start = this.task.startMoment
			if (!start.isValid()) {
				const due = this.task.dueMoment
				let reference = moment().add(1, 'h')
				if (due.isBefore(reference)) {
					reference = due.subtract(1, 'm')
				}
				reference.startOf(this.allDay ? 'day' : 'hour')
				return reference
			}
			return start
		},

		/**
		 * Initializes the due date of a task
		 *
		 * @returns {Date} The due date moment
		 */
		initDueDate: function() {
			const due = this.task.dueMoment
			if (!due.isValid()) {
				const start = this.task.startMoment
				const reference = start.isAfter() ? start : moment()
				if (this.allDay) {
					reference.startOf('day').add(1, 'd')
				} else {
					reference.startOf('hour').add(1, 'h')
				}
				return reference
			}
			return due
		},

		setStartDate: function(date) {
			this.setStartDateTime(moment(date), 'day')
		},

		setStartTime: function(time) {
			this.setStartDateTime(moment(time), 'time')
		},

		setStartDateTime: function(datetime, type = null) {
			this.tmpTask.start = this.setDatePartial(this.tmpTask.start.clone(), moment(datetime), type)
		},

		setDueDate: function(date) {
			this.setDueDateTime(moment(date), 'day')
		},

		setDueTime: function(time) {
			this.setDueDateTime(moment(time), 'time')
		},

		setDueDateTime: function(datetime, type = 'day') {
			this.tmpTask.due = this.setDatePartial(this.tmpTask.due.clone(), moment(datetime), type)
		},

		changeClass: function(classification) {
			this.setClassification({ task: this.task, classification: classification.type })
		},

		changeStatus: function(status) {
			this.setStatus({ task: this.task, status: status.type })
		},

		/**
		 * Sets partial values of a moment to the values of an other moment.
		 *
		 * @param {Moment} date The moment to alter
		 * @param {Moment} part The moment to take the new values from
		 * @param {String} type Value indicating what values to set
		 * @returns {Moment} The altered moment
		 */
		setDatePartial: function(date, part, type = null) {
			// Set only year, month and day
			if (type === 'day') {
				if (date.isValid()) {
					return date.year(part.year()).month(part.month()).date(part.date())
				} else {
					return part.add(12, 'h')
				}
			// Set only hour and minute
			} else if (type === 'time') {
				if (date.isValid()) {
					return date.hour(part.hour()).minute(part.minute())
				} else {
					return part
				}
			// Set all values
			} else {
				return part
			}
		},

		/**
		 * Sets the categories of a task
		 *
		 * @param {Array} categories The new categories
		 */
		updateCategories: function(categories) {
			this.setCategories({ task: this.task, categories: categories })
		},

		/**
		 * Adds a category to the list of categories
		 *
		 * @param {String} category The name of the category to add
		 */
		updateCategory: function(category) {
			this.addCategory({ task: this.task, category: category })
		},

		async changeCalendar(calendar) {
			const task = await this.moveTask({ task: this.task, calendar: calendar })
			// If we are in a calendar view, we have to navigate to the new calendar.
			if (this.$route.params.calendarId) {
				this.$router.push({ name: 'calendarsTask', params: { calendarId: task.calendar.id, taskId: task.uri } })
			}
		},
	},
}
</script>