-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlibrary.js
More file actions
2498 lines (2149 loc) · 116 KB
/
library.js
File metadata and controls
2498 lines (2149 loc) · 116 KB
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
const tasksDefinition = [
{
targets: 0,
visible: false,
title: builder.Locale.get('ID'),
name: 'id',
data: 'id',
},
{
targets: 1,
visible: false,
title: builder.Locale.get('Category'),
className: 'min-md',
name: 'category',
data: 'category',
defaultContent: '',
responsivePriority: 100,
},
{
targets: 2,
visible: true,
title: builder.Locale.get('Label'),
className: 'all',
name: 'label',
data: 'label',
width: '50%',
defaultContent: '',
responsivePriority: 1,
render: function(data, type, row, meta) {
return builder.Render('task.label', data, row, type);
},
},
{
targets: 3,
visible: false,
title: builder.Locale.get('Name'),
className: 'min-md',
name: 'name',
data: 'root.target.vcard.name',
defaultContent: '',
responsivePriority: 110,
},
{
targets: 4,
visible: false,
title: builder.Locale.get('Contact'),
className: 'min-md',
name: 'name',
data: 'target.vcard.name',
defaultContent: '',
responsivePriority: 115,
},
{
targets: 5,
visible: false,
title: builder.Locale.get('Address'),
className: 'min-md',
name: 'address',
data: 'root.target.vcard.address',
defaultContent: '',
responsivePriority: 120,
},
{
targets: 6,
visible: false,
title: builder.Locale.get('City'),
className: 'min-md',
name: 'city',
data: 'root.target.vcard.city',
defaultContent: '',
responsivePriority: 130,
},
{
targets: 7,
visible: false,
title: builder.Locale.get('State'),
className: 'min-md',
name: 'state',
data: 'root.target.vcard.state',
defaultContent: '',
responsivePriority: 140,
},
{
targets: 8,
visible: false,
title: builder.Locale.get('Country'),
className: 'min-md',
name: 'country',
data: 'root.target.vcard.country',
defaultContent: '',
responsivePriority: 150,
},
{
targets: 9,
visible: false,
title: builder.Locale.get('Phone'),
className: 'min-md',
name: 'phone',
data: 'target.vcard.phone',
defaultContent: '',
responsivePriority: 160,
},
{
targets: 10,
visible: false,
title: builder.Locale.get('Mobile'),
className: 'min-md',
name: 'mobile',
data: 'target.vcard.mobile',
defaultContent: '',
responsivePriority: 170,
},
{
targets: 11,
visible: false,
title: builder.Locale.get('Tollfree'),
className: 'min-md',
name: 'tollfree',
data: 'target.vcard.tollfree',
defaultContent: '',
responsivePriority: 180,
},
{
targets: 12,
visible: false,
title: builder.Locale.get('Status'),
className: 'min-md',
name: 'status',
data: 'progress',
defaultContent: '',
responsivePriority: 200,
render: function(data, type, row, meta) {
return builder.Render('task.progress', data, row, type);
},
},
{
targets: 13,
visible: true,
title: builder.Locale.get('Task'),
className: 'min-md',
name: 'task',
data: 'process',
defaultContent: '',
responsivePriority: 10,
render: function(data, type, row, meta) {
return builder.Render('task.process', data, row, type);
},
},
{
targets: 14,
visible: true,
title: builder.Locale.get('Priority'),
className: 'min-md',
name: 'priority',
data: 'priority',
defaultContent: 0,
responsivePriority: 20,
render: function(data, type, row, meta) {
return builder.Render('task.priority', data, row, type);
},
},
{
targets: 15,
visible: true,
title: builder.Locale.get('Assigned To'),
className: 'min-md',
name: 'assignedTo',
data: 'assignedTo.username',
defaultContent: '',
responsivePriority: 30,
render: function(data, type, row, meta) {
return builder.Render('task.assignedTo.username', data, row, type);
},
},
{
targets: 16,
visible: true,
title: builder.Locale.get('Due'),
className: 'min-md',
name: 'due',
data: 'due',
defaultContent: '',
responsivePriority: 40,
render: function(data, type, row, meta) {
return builder.Render('task.due', data, row, type);
},
},
];
builder.add('renderers', 'task.label', function(value, data, type){
if(typeof data.task !== 'undefined' || typeof data.label !== 'undefined'){
return '<div>' + builder.Parser.parse(value) + '</div>';
}
return '<div>' + value + '</div>';
})
builder.add('renderers', 'task.progress', function(value, data, type){
if(typeof data.task !== 'undefined' || typeof data.progress !== 'undefined'){
var process = (typeof data.task !== 'undefined') ? data.task.process : data.process;
var color = (process === null || typeof process[value] === "undefined") ? 'success' : process[value].color;
var icon = (process === null || typeof process[value] === "undefined") ? 'asterisk' : process[value].icon;
var name = (process === null || typeof process[value] === "undefined") ? builder.Locale.get('New') : process[value].name;
return '<div><h5><span class="badge text-bg-'+color+'"><i class="me-1 bi bi-'+icon+'"></i>'+name+'</span></h5></div>';
}
return '<div>' + value + '</div>';
})
builder.add('renderers', 'task.process', function(value, data, type){
var current = {};
var last = {};
if(typeof data.task !== 'undefined' || typeof data.process !== 'undefined'){
for(const [progress, step] of Object.entries(value)){
for(const [order, task] of Object.entries(step.tasks)){
last.step = step;
last.task = task;
if(!task.isCompleted){
if(typeof current.step === 'undefined' || typeof current.task === 'undefined'){
current.step = step;
current.task = task;
}
}
}
}
}
if(typeof current.step !== 'undefined' && typeof current.task !== 'undefined'){
return '<div><h5><span class="badge text-bg-'+current.step.color+'"><i class="me-1 bi bi-'+current.step.icon+'"></i>'+current.task.name+'</span></h5></div>';
}
if(typeof last.step !== 'undefined' && typeof last.task !== 'undefined'){
return '<div><h5><span class="badge text-bg-'+last.step.color+'"><i class="me-1 bi bi-'+last.step.icon+'"></i>'+last.task.name+'</span></h5></div>';
}
return '<div>' + value + '</div>';
})
builder.add('renderers', 'task.priority', function(value, data, type){
if(typeof data.task !== 'undefined' || typeof data.priority !== 'undefined'){
let color = ['secondary','primary','warning','orange','danger'];
let name = ['Low','Normal','High','Urgent','Critical'];
let icon = ['exclamation-triangle','info-circle','exclamation-circle','exclamation-diamond','exclamation-square'];
return '<div><h5><span class="badge text-bg-'+color[value]+'"><i class="me-1 bi bi-'+icon[value]+'"></i>'+builder.Locale.get(name[value])+'</span></h5></div>';
}
return '<div>' + value + '</div>';
})
builder.add('renderers', 'task.assignedTo.username', function(value, data, type){
if(typeof data.task !== 'undefined' || typeof data.assignedTo !== 'undefined'){
return '<div><img class="avatar" alt="'+value+'" src="/avatar?username='+value+'"><span>'+(value ?? builder.Locale.get('Unassigned'))+'</span></div>';
}
return '<div>' + value + '</div>';
})
builder.add('renderers', 'task.due', function(value, data, type){
// Handle sorting
if (type === 'sort') {
return value ? Date.parse(value) : Number.MAX_SAFE_INTEGER;
}
// Check if value is null
if(value === null || value === ''){
return '';
}
// Check for required data
if(typeof data.task !== 'undefined' || typeof data.due !== 'undefined'){
// Compare date to now and set background color
var bg = 'rounded px-2 py-1';
if(moment(value).isBefore(moment())){
bg += ' text-bg-danger';
} else if(moment(value).format('YYYY-MM-DD') == moment().format('YYYY-MM-DD')){
bg += ' text-bg-warning';
}
// Setup tooltip and timeago
setInterval(function(){
$('[data-type="due"]:not(.rendered)').each(function(){
const tooltip = new Date($(this).find('time').attr('datetime') ?? new Date().toISOString());
$(this).attr({
'data-bs-toggle': 'tooltip',
'data-bs-title': tooltip.toLocaleString(),
}).addClass('rendered');
new bootstrap.Tooltip($(this));
$(this).find('time').timeago();
});
},100);
// Return the formatted due date
return '<div data-type="due" class="'+bg+'"><i class="bi bi-clock me-1"></i><time datetime="'+value+'"></time></div>';
}
return '<div>' + value + '</div>';
})
builder.add('widgets','task', class extends builder.ComponentClass {
_init(){
this._properties = {
class: {
component: null,
},
data: null,
unassign: true,
callback: {},
};
}
_create(){
// Set Self
const self = this;
// Create Component
this._component = $(document.createElement('div')).attr({
'id': 'task' + this._id,
'class': '',
});
this._component.id = this._component.attr('id');
}
view(){
// Set Self
const self = this;
// Create the Modal
this._builder.Component(
"modal",
{
class: {
component: 'task-modal',
},
icon: "card-checklist",
title: this._builder.Locale.get("Task"),
color: 'primary',
cancel: false,
submit: false,
size: "xl",
callback: {
load: function(component, modal){
// Set the component
const parent = component;
// Promise to fetch data
return new Promise((resolve, reject) => {
try {
API.endpoint('/tasks/fetch?id='+self._properties.data).execute(function(response){
// Styling
component.body.addClass('p-0');
const priorities = {
color: ['secondary','primary','warning','orange','danger'],
name: ['Low','Normal','High','Urgent','Critical'],
icon: ['exclamation-triangle','info-circle','exclamation-circle','exclamation-diamond','exclamation-square'],
}
// Set Properties
self._properties.extensions = response.extensions || [];
// Create the details component
component.details = $(document.createElement('div')).attr({
'class': 'd-flex justify-content-between align-items-center p-3 py-2',
}).appendTo(component.body);
// Create the information section
component.details.info = $(document.createElement('div')).attr({
'class': 'd-flex align-items-start',
}).appendTo(component.details);
// Create the icon
component.details.info.icon = $(document.createElement('div')).attr({
'class': 'task-icon d-none d-lg-flex justify-content-center align-items-center rounded-4 me-3 text-bg-'+priorities.color[response.record.priority],
'style': 'width: 64px; height: 64px;',
'data-task-id': response.record.id,
}).appendTo(component.details.info);
component.details.info.icon.i = $(document.createElement('i')).attr({
'class': 'bi bi-check2-circle fs-3',
}).appendTo(component.details.info.icon);
// Check if the task is completed
if(response.record.isCompleted){
component.details.info.icon.addClass('text-bg-success');
component.details.info.icon.i.attr('class','bi bi-check2-circle fs-3');
}
// Check if the task is archived
if(response.record.isArchived){
component.details.info.icon.addClass('text-bg-dark');
component.details.info.icon.i.attr('class','bi bi-archive fs-3');
}
// Create the meta section
component.details.info.meta = $(document.createElement('div')).appendTo(component.details.info);
// Insert the title
component.details.info.meta.title = $(document.createElement('h4')).attr({
'class': 'fw-light my-1',
}).html(self._builder.Locale.get(response.record.category)).appendTo(component.details.info.meta);
if(typeof response.record.target.vcard !== 'undefined' && response.record.target.vcard !== null){
component.details.info.meta.title.vcard = $(document.createElement('span')).addClass('d-none d-lg-inline-block ms-2').appendTo(component.details.info.meta.title);
component.details.info.meta.title.vcard.append('- ' + response.record.target.vcard.name);
if(typeof response.record.target.vcard.title !== 'undefined' && response.record.target.vcard.title !== null){
component.details.info.meta.title.vcard.append(' - ' + response.record.target.vcard.title);
}
}
// Insert the priority
component.details.info.meta.title.priority = $(document.createElement('span')).attr({
'class': 'badge rounded-pill text-bg-'+priorities.color[response.record.priority]+' ms-2 cursor-pointer',
'style': 'font-size: var(--bs-body-font-size); font-weight: var(--bs-body-font-weight);',
'data-type': 'priority',
'data-task-id': response.record.id,
}).html(self._builder.Locale.get(priorities.name[response.record.priority])).appendTo(component.details.info.meta.title);
component.details.info.meta.title.priority.icon = $(document.createElement('i')).attr({
'class': 'bi bi-'+priorities.icon[response.record.priority]+' me-1',
}).prependTo(component.details.info.meta.title.priority);
component.details.info.meta.title.priority.click(function(e){
// Check if the task is archived or completed
if(!response.record.isArchived && !response.record.isCompleted){
self.priority();
}
});
// Insert the due date
component.details.info.meta.title.due = $(document.createElement('span')).attr({
'class': 'badge rounded-pill text-bg-light ms-2 cursor-pointer',
'style': 'font-size: var(--bs-body-font-size); font-weight: var(--bs-body-font-weight);',
'title': response.record.due ?? new Date().toISOString(),
'data-bs-title': response.record.due ?? new Date().toISOString(),
'data-bs-toggle': 'tooltip',
'data-bs-placement': 'bottom',
'data-type': 'due',
'data-task-id': response.record.id,
}).appendTo(component.details.info.meta.title);
new bootstrap.Tooltip(component.details.info.meta.title.due);
component.details.info.meta.title.due.icon = $(document.createElement('i')).attr({
'class': 'bi bi-clock me-1',
}).prependTo(component.details.info.meta.title.due);
component.details.info.meta.title.due.timeago = $(document.createElement('time')).attr({
'class': 'timeago',
'datetime': response.record.due ?? new Date().toISOString(),
}).appendTo(component.details.info.meta.title.due).timeago();
component.details.info.meta.title.due.click(function(e){
// Check if the task is archived or completed
if(!response.record.isArchived && !response.record.isCompleted){
self.schedule();
}
});
// Insert the subtitle
component.details.info.meta.subtitle = $(document.createElement('div')).attr({
'class': 'd-flex flex-column flex-lg-row align-items-center justify-content-center justify-content-lg-start my-1',
}).appendTo(component.details.info.meta);
// Insert the Assigned to
component.details.info.meta.subtitle.assigned = $(document.createElement('div')).attr({
'class': 'd-flex align-items-center cursor-pointer',
'data-type': 'assigned',
'data-task-id': response.record.id,
}).appendTo(component.details.info.meta.subtitle);
component.details.info.meta.subtitle.assigned.img = $(document.createElement('img')).attr({
'class': 'rounded-circle',
'alt': response.record.assignedTo.username || '',
'src': '/avatar?username=' + ((response.record.assignedTo.username !== null) ? response.record.assignedTo.username : 'Unassigned'),
'style': 'width: 32px; height: 32px;',
}).appendTo(component.details.info.meta.subtitle.assigned);
component.details.info.meta.subtitle.assigned.username = $(document.createElement('span')).attr({
'class': 'ms-2',
}).html(response.record.assignedTo.username || self._builder.Locale.get('Unassigned')).appendTo(component.details.info.meta.subtitle.assigned);
component.details.info.meta.subtitle.assigned.click(function(e){
// Check if the task is archived or completed
if(!response.record.isArchived && !response.record.isCompleted){
self.assign();
}
});
// Insert the Root Target
if(typeof response.record.root.target.vcard !== 'undefined' && response.record.root.target.vcard !== null){
component.details.info.meta.subtitle.root = $(document.createElement('button')).attr({
'class': 'btn btn-link link-dark text-decoration-none',
'type': 'button',
}).text(response.record.root.target.vcard.name).appendTo(component.details.info.meta.subtitle);
component.details.info.meta.subtitle.root.click(function(e){
self._builder.Widget('vcard',{data: response.record.root.target.vcard.id});
});
component.details.info.meta.subtitle.root.icon = $(document.createElement('i')).attr({
'class': 'bi bi-diagram-3 me-1',
}).prependTo(component.details.info.meta.subtitle.root);
}
// Create the controls section
component.details.controls = $(document.createElement('div')).addClass('controls btn-group').appendTo(component.details);
// Insert the target link
component.details.controls.link = $(document.createElement('a')).attr({
'class': 'btn btn-light',
'href': response.record.link || '#',
}).html('<span class="me-2 d-none d-lg-inline-block">'+self._builder.Locale.get('Open target')+'</span><i class="bi bi-chevron-right"></i>').appendTo(component.details.controls);
// Insert the Archive button
component.details.controls.archive = $(document.createElement('button')).attr({
'class': 'btn btn-dark',
'type': 'button',
'data-action': 'archive',
'data-task-id': response.record.id,
}).html('<i class="bi bi-archive"></i>').prependTo(component.details.controls);
component.details.controls.archive.click(function(e){
self.archive();
});
// Create the steps section
component.steps = $(document.createElement('div')).addClass('p-3 py-2 border-bottom').appendTo(component.body);
// Create the tabs section
builder.Component(
"tabs",
component.body,
{
class: {
navbar: 'nav-pills',
},
},
function(tabs,card){
// Styling
card._component.tools.remove();
card._component.header.heading.addClass('m-0');
card._component.card.addClass('border-0 rounded-top-0');
card._component.body.removeClass('card-body').addClass('row m-0');
tabs._content.addClass('col-12 col-lg-8 p-0 order-2 order-lg-1');
tabs._content.details = $(document.createElement('div')).addClass('col-12 col-lg-4 p-0 order-1 order-lg-2 border-start').appendTo(card._component.body);
// Check if the task is attached to a vcard
if(typeof response.record.target.vcard !== 'undefined' && response.record.target.vcard !== null){
// Create the vCard section
card._component.vcard = $(document.createElement('div')).addClass('card vcard border-0 rounded-0').appendTo(tabs._content.details);
card._component.vcard.body = $(document.createElement('div')).addClass('card-body cursor-pointer').appendTo(card._component.vcard);
card._component.vcard.footer = $(document.createElement('div')).addClass('card-footer rounded-0 border-bottom d-flex gap-2').appendTo(card._component.vcard);
// Add vCard information
card._component.vcard.body.info = $(document.createElement('div')).addClass('d-flex align-items-center gap-3').appendTo(card._component.vcard.body);
card._component.vcard.body.info.avatar = $(document.createElement('img')).attr({
'class':'avatar rounded-circle border border-3',
'src': '/avatar?id=' + response.record.target.vcard.id,
'alt': (response.record.target.vcard.name ?? 'Unknown').substring(0,2).toUpperCase(),
'style': 'width: 64px; height: 64px;',
}).appendTo(card._component.vcard.body.info);
card._component.vcard.body.info.container = $(document.createElement('div')).addClass('flex-grow-1').appendTo(card._component.vcard.body.info);
card._component.vcard.body.info.container.name = $(document.createElement('div')).addClass('d-flex align-items-center gap-2 flex-wrap').text(response.record.target.vcard.name).appendTo(card._component.vcard.body.info.container);
card._component.vcard.body.info.container.title = $(document.createElement('div')).addClass('small text-secondary').text(response.record.target.vcard.title ?? '').appendTo(card._component.vcard.body.info.container);
card._component.vcard.body.info.container.dba = $(document.createElement('div')).addClass('small text-secondary').text(response.record.target.vcard.dba ?? '').appendTo(card._component.vcard.body.info.container);
card._component.vcard.body.info.container.phone = $(document.createElement('div')).addClass('badge text-bg-success mt-1').html((response.record.target.vcard.phone !== null) ? '<i class="bi bi-telephone-fill me-2"></i>'+response.record.target.vcard.phone : '').appendTo(card._component.vcard.body.info.container);
card._component.vcard.body.badges = $(document.createElement('div')).addClass('mt-2 d-flex flex-wrap gap-2').appendTo(card._component.vcard.body);
for(const [key, role] of Object.entries(JSON.parse(response.record.target.vcard.role || '[]'))){
$(document.createElement('span')).addClass('badge text-bg-light border').text(role).appendTo(card._component.vcard.body.badges);
}
// Add click event to the card
card._component.vcard.body.click(function(e){
if ($(e.target).closest('.controls').length) return;
self._builder.Widget('vcard',{data: response.record.target.vcard.id});
});
// Add Footer Controls
card._component.vcard.footer.controls = $(document.createElement('div')).addClass('controls btn-group flex-fill').appendTo(card._component.vcard.footer);
card._component.vcard.footer.controls.call = $(document.createElement('a')).attr({
'class':'btn btn-success btn-sm flex-fill',
'type': 'button',
'href':'tel:' + (response.record.target.vcard.phone ?? ''),
}).html('<i class="bi-telephone"></i>').appendTo(card._component.vcard.footer.controls);
card._component.vcard.footer.controls.email = $(document.createElement('a')).attr({
'class':'btn btn-primary btn-sm flex-fill',
'href':'mailto:' + (response.record.target.vcard.email ?? ''),
}).html('<i class="bi-envelope"></i>').appendTo(card._component.vcard.footer.controls);
card._component.vcard.footer.controls.edit = $(document.createElement('button')).attr({
'class':'btn btn-warning btn-sm flex-fill',
'type': 'button',
'data-action': 'edit',
}).html('<i class="bi-pencil"></i>').appendTo(card._component.vcard.footer.controls);
card._component.vcard.footer.controls.edit.click(function(){
self._builder.Widget('vcard',{mode: 'edit', data: response.record.target.vcard.id});
});
}
// Initialize the tabs
card.tabs = {};
// Notes
if(self._properties.extensions.includes('notes')){
tabs.add(
'notes',
{
icon: "stickies",
label: builder.Locale.get("Notes"),
},
function(tab,nav){
card.tabs.notes = tab;
self._builder.Widget('notes',tab,{data: response.dependencies.notes ?? {},targetTable: response.record.root.targetTable,targetId: response.record.root.targetId,autoStart: true})
},
);
}
// Event
if(self._properties.extensions.includes('event')){
// Add the Event tab
tabs.add(
'event',
{
icon: "activity",
label: builder.Locale.get("Activity"),
},
function(tab,nav){
card.tabs.event = tab;
self._builder.Widget("events",tab,{data: response.dependencies.event ?? {},targetTable: 'tasks',targetId: response.record.id});
},
);
}
// Task - Process
if(self._properties.extensions.includes('process')){
builder.Widget(
"processTree",
tabs._content.details,
{
class: {
steps: 'border-bottom p-3 py-2',
pagination: 'p-3 py-2 btn-group w-100',
},
data: response.record.id,
},
function(widget){
widget.controls().appendTo(component.steps)
}
);
}
// Relationship
if(self._properties.extensions.includes('relationship')){
// Create the Relationship widget
self._builder.Widget("related",tabs._content.details,{data: response.dependencies.relationship ?? {},targetTable: 'tasks',targetId: response.record.id});
}
},
);
// Resolve the promise
resolve();
},function(xhr, status, error){
modal.hide();
reject(error);
});
} catch(e) { reject(e); }
});
},
},
},
function(modal,component){
// Show the modal
modal.show();
},
);
}
assign(callback = null){
// Set Self
const self = this;
// Create the Modal
this._builder.Component(
"modal",
{
icon: "person-plus",
title: this._builder.Locale.get("Assign/unassign user"),
color: 'warning',
callback: {
load: function(component, modal){
// Set the component
const parent = component;
// Promise to fetch data
return new Promise((resolve, reject) => {
try {
// Retrieve members
API.endpoint('/auth/users').execute(function(response){
const members = response.records;
const options = [];
for(const [id, member] of Object.entries(members)){
options.push({id: id, text: member.username});
}
// Retrieve task data
API.endpoint('/tasks/fetch?id='+self._properties.data).execute(function(response){
// Check if the task is archived or completed
if(response.record.isArchived || response.record.isCompleted){
// Log the error and reject the promise
console.error('Task is archived('+response.record.isArchived+') or completed('+response.record.isCompleted+').');
modal.hide();
reject('Task is archived('+response.record.isArchived+') or completed('+response.record.isCompleted+').');
}
// Create the Form
self._builder.Utility(
'form',
component.body,
{
callback: {
val: function(values){
if(response.record.assignedTo.username){
values = {assignedTo: null}
}
return values;
},
submit: function(form){
// Show the modal spinner
modal.spinner(true);
// AJAX Request
API.endpoint('/tasks/update?id='+self._properties.data).data(form.val()).execute(function(response){
// Update the task assigned
$('[data-type="assigned"][data-task-id="'+self._properties.data+'"]').each(function(){
// Update the assigned username
$(this).find('span').text(response.record.assignedTo.username || self._builder.Locale.get('Unassigned'));
// Update the assigned image
$(this).find('img').attr({
'alt': response.record.assignedTo.username || '',
'src': '/avatar?username=' + ((response.record.assignedTo.username !== null) ? response.record.assignedTo.username : 'Unassigned'),
});
});
// Check if a callback is provided
if (typeof callback === 'function') {
callback(response);
}
// Close the modal
modal.hide();
},function(xhr, status, error){
modal.hide();
});
},
}
},
function(form,component){
// Add event listener on the modal submit button
parent.dialog.content.footer.submit.click(function(e){
e.preventDefault();
e.stopPropagation();
form.submit();
});
// Check if the task is assigned
if(response.record.assignedTo.username){
// Check if unassign is allowed
if(self._properties.unassign){
// Insert a warning message
$(document.createElement('div')).addClass('p-3').text('You are about to unassign the user from this task. Are you sure you want to proceed?').appendTo(parent.dialog.content.body);
} else {
// Check if a callback is provided
if (typeof callback === 'function') {
callback(response);
}
// Close the modal
modal.hide();
}
} else {
// assignedTo
form.add(
'select2',
{
name: 'assignedTo',
label: self._builder.Locale.get('User'),
placeholder: self._builder.Locale.get('Select a user'),
class: {
component: 'bg-gray-200 p-3 py-2 rounded-0',
},
options: options,
}
);
}
// Resolve the promise
resolve();
},
);
},function(xhr, status, error){
modal.hide();
reject(error);
});
},function(xhr, status, error){
modal.hide();
reject(error);
});
} catch(e) {
// Log the error and reject the promise
modal.hide();
reject(e);
}
});
},
},
},
function(modal,component){
// Styling
component.body.addClass('p-0');
// Show the modal
modal.show();
},
);
}
priority(callback = null){
// Set Self
const self = this;
// Create the Modal
this._builder.Component(
"modal",
{
icon: "exclamation-triangle",
title: this._builder.Locale.get("Change priority"),
color: 'warning',
callback: {
load: function(component, modal){
// Set the component
const parent = component;
// Set Priorities
const priorities = {
color: ['secondary','primary','warning','orange','danger'],
name: ['Low','Normal','High','Urgent','Critical'],
icon: ['exclamation-triangle','info-circle','exclamation-circle','exclamation-diamond','exclamation-square'],
}
// Promise to fetch data
return new Promise((resolve, reject) => {
try {
API.endpoint('/tasks/fetch?id='+self._properties.data).execute(function(response){
// Check if the task is archived or completed
if(response.record.isArchived || response.record.isCompleted){
// Log the error and reject the promise
console.error('Task is archived('+response.record.isArchived+') or completed('+response.record.isCompleted+').');
modal.hide();
reject('Task is archived('+response.record.isArchived+') or completed('+response.record.isCompleted+').');
}
// Create the Form
self._builder.Utility(
'form',
component.body,
{
callback: {
submit: function(form){
// Show the modal spinner
modal.spinner(true);
// AJAX Request
API.endpoint('/tasks/update?id='+self._properties.data).data(form.val()).execute(function(response){
// Update the task priority
$('[data-type="priority"][data-task-id="'+self._properties.data+'"]').each(function(){
// Remove all classes text-bg-*
$(this).removeClass(function (index, className) {
return (className.match(/(^|\s)text-bg-\S+/g) || []).join(' ');
});
// Add the new class
$(this).addClass('text-bg-'+priorities.color[response.record.priority]);
$(this).text(self._builder.Locale.get(priorities.name[response.record.priority]));
$(this).prepend('<i class="bi bi-'+priorities.icon[response.record.priority]+' me-1"></i>');
});
// Check if a callback is provided
if (typeof callback === 'function') {
callback(response);
}
// Close the modal
modal.hide();
},function(xhr, status, error){
modal.hide();
});
},
}
},
function(form,component){
// Add event listener on the modal submit button
parent.dialog.content.footer.submit.click(function(e){
e.preventDefault();
e.stopPropagation();
form.submit();
});
// priority
form.add(
'select',
{
name: 'priority',
label: self._builder.Locale.get('Level'),
placeholder: self._builder.Locale.get('Select a level'),
class: {
component: 'bg-gray-200 p-3 py-2 rounded-0',
},
options: [
{id: 0, text: self._builder.Locale.get(priorities.name[0])},
{id: 1, text: self._builder.Locale.get(priorities.name[1])},
{id: 2, text: self._builder.Locale.get(priorities.name[2])},
{id: 3, text: self._builder.Locale.get(priorities.name[3])},
{id: 4, text: self._builder.Locale.get(priorities.name[4])},
],
value: response.record.priority,
}
);
// Resolve the promise
resolve();
},
);
},function(xhr, status, error){
modal.hide();
reject(error);
});
} catch(e) {
// Log the error and reject the promise
console.error('Error in priority modal:', e);
modal.hide();
reject(e);
}
});
},
},
},
function(modal,component){
// Styling
component.body.addClass('p-0');
// Show the modal
modal.show();
},
);
}
schedule(callback = null){
// Set Self
const self = this;
// Create the Modal
this._builder.Component(
"modal",
{
icon: "calendar",
title: this._builder.Locale.get("Reschedule task"),
color: 'teal',
callback: {
load: function(component, modal){
// Set the component
const parent = component;
// Promise to fetch data
return new Promise((resolve, reject) => {
try {
API.endpoint('/tasks/fetch?id='+self._properties.data).execute(function(response){
// Check if the task is archived or completed
if(response.record.isArchived || response.record.isCompleted){
// Log the error and reject the promise
console.error('Task is archived('+response.record.isArchived+') or completed('+response.record.isCompleted+').');
modal.hide();
reject('Task is archived('+response.record.isArchived+') or completed('+response.record.isCompleted+').');
}
// Create the Form
self._builder.Utility(