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 | 1×
1×
1×
1×
1000×
1000×
1×
299×
299×
299×
1×
299×
11×
11×
288×
1×
2177×
2177×
2177×
1×
1×
1×
1×
2176×
2176×
2176×
2176×
1×
2149×
2149×
494×
1655×
1655×
1655×
545379×
545379×
1655×
1655×
1655×
1639×
1607×
1×
51×
51×
32×
19×
1×
1727×
1727×
1717×
1717×
1727×
49×
49×
1×
1×
1×
1×
49×
49×
1727×
7×
7×
1720×
1720×
1720×
1720×
1×
299×
299×
299×
299×
299×
55×
42×
42×
42×
42×
62×
62×
62×
50×
42×
42×
62×
62×
42×
299×
298×
298×
298×
1×
1×
1×
1×
1×
1×
128×
128×
126×
12×
12×
114×
114×
1×
113×
113×
113×
111×
111×
111×
111×
111×
166×
166×
166×
166×
111×
111×
111×
1×
162×
162×
160×
14×
14×
14×
146×
146×
1×
145×
145×
75×
3×
3×
38×
38×
12×
12×
22×
22×
70×
70×
70×
67×
67×
67×
67×
67×
67×
67×
67×
67×
67×
67×
67×
67×
67×
1×
56×
56×
55×
55×
55×
9×
25×
46×
55×
1×
54×
43×
16×
16×
9×
9×
4×
4×
14×
14×
11×
11×
11×
8×
8×
8×
8×
2×
2×
6×
6×
8×
8×
8×
1×
47×
47×
47×
47×
9×
9×
9×
38×
47×
47×
47×
47×
47×
44×
44×
44×
44×
44×
44×
44×
44×
44×
44×
326×
36×
36×
34×
34×
34×
34×
34×
34×
2×
36×
8×
7×
7×
8×
1×
1×
8×
44×
44×
44×
44×
44×
44×
44×
1×
16×
16×
16×
4×
4×
4×
12×
16×
16×
16×
16×
16×
16×
16×
16×
16×
16×
16×
16×
16×
16×
12×
12×
12×
12×
12×
12×
12×
11×
11×
4×
4×
2×
11×
1×
1×
11×
1×
1×
11×
12×
4×
4×
4×
4×
16×
16×
16×
16×
16×
16×
16×
1×
36×
36×
36×
36×
14×
16×
16×
22×
36×
36×
36×
36×
22×
14×
36×
16×
16×
16×
16×
16×
16×
36×
36×
34×
34×
34×
34×
34×
36×
36×
36×
36×
36×
21×
21×
21×
21×
5×
13×
5×
5×
16×
16×
21×
21×
21×
15×
15×
15×
34×
36×
34×
34×
34×
34×
34×
1×
16×
16×
16×
21×
21×
2×
19×
16×
16×
16×
16×
16×
16×
16×
21×
21×
2×
2×
1×
2×
2×
1×
1×
1×
2×
1×
2×
21×
19×
16×
21×
16×
16×
16×
16×
1×
3×
3×
3×
3×
3×
3×
1×
2×
3×
3×
3×
3×
3×
3×
3×
3×
3×
1×
1×
1×
1×
1×
1×
1×
2×
3×
3×
3×
3×
3×
1×
105×
105×
105×
4×
105×
1×
45×
45×
45×
45×
45×
18×
15×
27×
45×
1×
16×
16×
16×
16×
4×
12×
12×
12×
12×
12×
12×
12×
12×
12×
12×
16×
1×
28×
28×
28×
110×
110×
85×
85×
85×
29×
29×
85×
28×
28×
1×
274×
274×
274×
327×
327×
274×
1×
975×
975×
1×
1×
| define(["require", "exports", "@syncfusion/ej2-base", "../../recurrence-editor/date-generator", "../base/constant", "../base/util"], function (require, exports, ej2_base_1, date_generator_1, events, util) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var Crud = (function () {
function Crud(parent) {
this.parent = parent;
this.crudObj = { sourceEvent: null, targetEvent: null, isCrudAction: false };
}
Crud.prototype.getQuery = function () {
var start = this.parent.activeView.startDate();
var end = this.parent.activeView.endDate();
return this.parent.dataModule.generateQuery(start, end);
};
Crud.prototype.getTable = function () {
if (this.parent.eventSettings.query) {
var query = this.parent.eventSettings.query.clone();
return query.fromTable;
}
return null;
};
Crud.prototype.refreshDataManager = function () {
var _this = this;
Iif (!this.parent.activeView) {
return;
}
if (this.parent.uiStateValues && this.parent.uiStateValues.isPreventEventRefresh) {
this.parent.uiStateValues.isPreventEventRefresh = false;
this.parent.refreshEvents(false);
this.parent.hideSpinner();
return;
}
var start = this.parent.activeView.startDate();
var end = this.parent.activeView.endDate();
var dataManager = this.parent.dataModule.getData(this.parent.dataModule.generateQuery(start, end));
dataManager.then(function (e) { return _this.dataManagerSuccess(e); }).catch(function (e) { return _this.dataManagerFailure(e); });
};
Crud.prototype.dataManagerSuccess = function (e) {
var _this = this;
if (!this.parent || this.parent && this.parent.isDestroyed) {
return;
}
this.parent.trigger(events.dataBinding, e, function (args) {
Iif (args.cancel) {
return;
}
var resultData = ej2_base_1.extend([], args.result, null, true);
_this.parent.eventsData = resultData.filter(function (data) { return !data[_this.parent.eventFields.isBlock]; });
_this.parent.blockData = resultData.filter(function (data) { return data[_this.parent.eventFields.isBlock]; });
_this.refreshProcessedData();
Iif (_this.parent.dragAndDropModule && _this.parent.dragAndDropModule.actionObj.action === 'drag') {
_this.parent.dragAndDropModule.navigationWrapper();
}
_this.parent.trigger(events.dataBound, null, function () {
_this.parent.hideSpinner();
Iif (_this.parent.isPrinting) {
setTimeout(function () {
_this.parent.notify(events.print, {});
}, 100);
}
});
});
};
Crud.prototype.dataManagerFailure = function (e) {
var _this = this;
if (!this.parent || this.parent && this.parent.isDestroyed) {
return;
}
this.parent.trigger(events.actionFailure, { error: e }, function () { return _this.parent.hideSpinner(); });
};
Crud.prototype.refreshProcessedData = function (isVirtualScrollAction, dynamicEvents) {
if (isVirtualScrollAction === void 0) { isVirtualScrollAction = false; }
if (this.parent.dragAndDropModule) {
this.parent.dragAndDropModule.actionObj.action = '';
ej2_base_1.removeClass([this.parent.element], 'e-event-action');
}
if (this.parent.activeViewOptions && this.parent.activeViewOptions.eventTemplate) {
var templateNames = ['eventTemplate'];
if (this.crudObj.isCrudAction &&
['Agenda', 'MonthAgenda', 'Year', 'TimelineYear'].indexOf(this.parent.currentView) === -1) {
templateNames = [];
for (var i = 0, len = this.crudObj.sourceEvent.length; i < len; i++) {
templateNames.push('eventTemplate_' + this.crudObj.sourceEvent[parseInt(i.toString(), 10)].groupIndex);
Iif (this.crudObj.targetEvent[parseInt(i.toString(), 10)] && this.crudObj.sourceEvent[parseInt(i.toString(), 10)].groupIndex !==
this.crudObj.targetEvent[parseInt(i.toString(), 10)].groupIndex) {
templateNames.push('eventTemplate_' + this.crudObj.targetEvent[parseInt(i.toString(), 10)].groupIndex);
}
}
}
Eif (templateNames.length > 0) {
this.parent.resetTemplates(templateNames);
}
}
if (isVirtualScrollAction) {
this.parent.notify(events.dataReady, { processedData: dynamicEvents ? this.parent.eventBase.processData(dynamicEvents) : this.parent.eventsProcessed });
return;
}
var eventsData = this.parent.eventsData || [];
var blockData = this.parent.blockData || [];
var data = eventsData.concat(blockData);
this.parent.notify(events.dataReady, { processedData: this.parent.eventBase ? this.parent.eventBase.processData(data) : [] });
};
Crud.prototype.refreshData = function (args) {
var _this = this;
var actionArgs = {
requestType: args.requestType, cancel: false, data: args.data,
addedRecords: args.editParams.addedRecords, changedRecords: args.editParams.changedRecords,
deletedRecords: args.editParams.deletedRecords
};
Iif (this.parent.dragAndDropModule && this.parent.dragAndDropModule.actionObj && this.parent.dragAndDropModule.actionObj.element && this.parent.dragAndDropModule.actionObj.action) {
this.parent.dragAndDropModule.actionObj.element.style.display = 'none';
}
Iif (this.parent.resizeModule && this.parent.resizeModule.actionObj && this.parent.resizeModule.actionObj.element && this.parent.resizeModule.actionObj.action) {
this.parent.resizeModule.actionObj.element.style.display = 'none';
}
if (this.parent.isSpecificResourceEvents()) {
if (args.requestType === 'eventCreated' || args.requestType === 'eventRemoved') {
this.crudObj.isCrudAction = true;
this.crudObj.sourceEvent = [];
var crudData = args.data instanceof Array ? (args.data.length === 0 &&
args.requestType === 'eventRemoved' ? args.editParams.deletedRecords : args.data) :
((typeof args.data === 'string' || typeof args.data === 'number') && args.requestType === 'eventRemoved') ?
args.editParams.deletedRecords : [args.data];
var _loop_1 = function (data) {
this_1.crudObj.isCrudAction = !(args.requestType === 'eventRemoved' && !ej2_base_1.isNullOrUndefined(data.parent));
var groupIndex = this_1.parent.eventBase.getGroupIndexFromEvent(data);
if (groupIndex > -1 && this_1.parent.crudModule.crudObj.sourceEvent.filter(function (tdData) { return tdData.groupIndex === groupIndex; }).length === 0
&& this_1.crudObj.isCrudAction) {
this_1.crudObj.sourceEvent.push(this_1.parent.resourceBase.lastResourceLevel[parseInt(groupIndex.toString(), 10)]);
}
};
var this_1 = this;
for (var _i = 0, crudData_1 = crudData; _i < crudData_1.length; _i++) {
var data = crudData_1[_i];
_loop_1(data);
}
this.crudObj.targetEvent = this.crudObj.sourceEvent;
}
}
if (this.parent.dataModule.dataManager.dataSource.offline) {
this.parent.trigger(events.actionComplete, actionArgs, function (offlineArgs) {
Eif (!offlineArgs.cancel) {
_this.refreshDataManager();
}
});
}
else {
args.promise.then(function () {
Iif (!_this.parent || _this.parent && _this.parent.isDestroyed) {
return;
}
_this.parent.trigger(events.actionComplete, actionArgs, function (onlineArgs) {
Eif (!onlineArgs.cancel) {
_this.refreshDataManager();
}
});
}).catch(function (e) {
if (!_this.parent || _this.parent && _this.parent.isDestroyed) {
return;
}
_this.parent.trigger(events.actionFailure, { error: e });
});
}
};
Crud.prototype.addEvent = function (eventData) {
var _this = this;
if (this.parent.eventSettings.allowAdding && !this.parent.activeViewOptions.readonly) {
if (!this.isBlockEvent(eventData) && this.parent.eventBase.isBlockRange(eventData)) {
this.parent.quickPopup.openValidationError('blockAlert', eventData);
return;
}
var addEvents = (eventData instanceof Array) ? eventData : [eventData];
if (addEvents.length === 0) {
return;
}
var args = {
requestType: 'eventCreate', cancel: false, data: addEvents,
addedRecords: addEvents, changedRecords: [], deletedRecords: []
};
this.parent.trigger(events.actionBegin, args, function (addArgs) {
if (!addArgs.cancel) {
var fields = _this.parent.eventFields;
var editParams = { addedRecords: [], changedRecords: [], deletedRecords: [] };
var promise = void 0;
Eif (addArgs.addedRecords instanceof Array) {
for (var _i = 0, _a = addArgs.addedRecords; _i < _a.length; _i++) {
var event_1 = _a[_i];
event_1 = _this.parent.eventBase.updateEventDateTime(event_1);
var eventData_1 = ej2_base_1.extend({}, _this.parent.eventBase.processTimezone(event_1, true), null, true);
editParams.addedRecords.push(eventData_1);
}
promise = _this.parent.dataModule.dataManager.saveChanges(editParams, fields.id, _this.getTable(), _this.getQuery());
}
else {
var event_2 = _this.parent.eventBase.processTimezone(addArgs.addedRecords, true);
editParams.addedRecords.push(event_2);
promise = _this.parent.dataModule.dataManager.insert(event_2, _this.getTable(), _this.getQuery());
}
var crudArgs = {
requestType: 'eventCreated', cancel: false, data: addArgs.addedRecords, promise: promise, editParams: editParams
};
_this.refreshData(crudArgs);
}
});
}
};
Crud.prototype.saveEvent = function (eventData, action) {
var _this = this;
if (this.parent.eventSettings.allowEditing && !this.parent.activeViewOptions.readonly) {
if (this.parent.currentAction !== 'EditFollowingEvents' && !this.isBlockEvent(eventData)
&& this.parent.eventBase.isBlockRange(eventData)) {
this.parent.quickPopup.openValidationError('blockAlert', eventData);
this.parent.crudModule.crudObj.isCrudAction = false;
return;
}
var updateEvents = (eventData instanceof Array) ? eventData : [eventData];
if (updateEvents.length === 0) {
return;
}
this.parent.currentAction = action;
if (action) {
switch (action) {
case 'Save':
this.processSave(eventData);
break;
case 'EditOccurrence':
this.processOccurrences(eventData, action);
break;
case 'EditFollowingEvents':
this.processFollowSeries(eventData, action);
break;
case 'EditSeries':
this.processEntireSeries(eventData, action);
break;
}
}
else {
var args = {
requestType: 'eventChange', cancel: false, data: eventData,
addedRecords: [], changedRecords: updateEvents, deletedRecords: []
};
this.parent.trigger(events.actionBegin, args, function (saveArgs) {
if (!saveArgs.cancel) {
var promise = void 0;
var fields = _this.parent.eventFields;
var editParams = { addedRecords: [], changedRecords: [], deletedRecords: [] };
Eif (saveArgs.changedRecords instanceof Array) {
for (var _i = 0, _a = saveArgs.changedRecords; _i < _a.length; _i++) {
var event_3 = _a[_i];
event_3 = _this.parent.eventBase.updateEventDateTime(event_3);
var eventData_2 = ej2_base_1.extend({}, _this.parent.eventBase.processTimezone(event_3, true), null, true);
editParams.changedRecords.push(eventData_2);
}
promise = _this.parent.dataModule.dataManager.saveChanges(editParams, fields.id, _this.getTable(), _this.getQuery());
}
else {
var event_4 = _this.parent.eventBase.processTimezone(saveArgs.changedRecords, true);
editParams.changedRecords.push(event_4);
promise = _this.parent.dataModule.dataManager.update(fields.id, event_4, _this.getTable(), _this.getQuery());
}
var cloneEvent = ej2_base_1.extend({}, saveArgs.changedRecords[saveArgs.changedRecords.length - 1], null, true);
_this.parent.eventBase.selectWorkCellByTime([_this.parent.eventBase.processTimezone(cloneEvent)]);
var crudArgs = {
requestType: 'eventChanged', cancel: false,
data: saveArgs.changedRecords, promise: promise, editParams: editParams
};
_this.refreshData(crudArgs);
}
});
}
}
};
Crud.prototype.deleteEvent = function (eventData, action) {
var _this = this;
if (this.parent.eventSettings.allowDeleting && !this.parent.activeViewOptions.readonly) {
this.parent.currentAction = action;
var deleteEvents = [];
if (typeof eventData === 'string' || typeof eventData === 'number') {
deleteEvents = this.parent.eventsData.filter(function (eventObj) {
return eventObj[_this.parent.eventFields.id] === eventData;
});
}
else {
deleteEvents = (eventData instanceof Array ? eventData : [eventData]);
}
if (deleteEvents.length === 0) {
return;
}
if (action) {
switch (action) {
case 'Delete':
this.processDelete(deleteEvents);
break;
case 'DeleteOccurrence':
this.processOccurrences(deleteEvents, action);
break;
case 'DeleteFollowingEvents':
this.processFollowSeries(deleteEvents, action);
break;
case 'DeleteSeries':
this.processEntireSeries(deleteEvents, action);
break;
}
}
else {
var args = {
requestType: 'eventRemove', cancel: false, data: eventData,
addedRecords: [], changedRecords: [], deletedRecords: deleteEvents
};
this.parent.trigger(events.actionBegin, args, function (deleteArgs) {
if (!deleteArgs.cancel) {
var promise = void 0;
var fields = _this.parent.eventFields;
var editParams = { addedRecords: [], changedRecords: [], deletedRecords: [] };
if (deleteArgs.deletedRecords.length > 1) {
editParams.deletedRecords = editParams.deletedRecords.concat(deleteArgs.deletedRecords);
promise = _this.parent.dataModule.dataManager.saveChanges(editParams, fields.id, _this.getTable(), _this.getQuery());
}
else {
editParams.deletedRecords.push(deleteArgs.deletedRecords[0]);
promise = _this.parent.dataModule.dataManager.remove(fields.id, deleteArgs.deletedRecords[0], _this.getTable(), _this.getQuery());
}
_this.parent.eventBase.selectWorkCellByTime(deleteArgs.deletedRecords);
var crudArgs = {
requestType: 'eventRemoved', cancel: false,
data: deleteArgs.deletedRecords, promise: promise, editParams: editParams
};
_this.refreshData(crudArgs);
}
});
}
}
};
Crud.prototype.processOccurrences = function (eventData, action) {
var _this = this;
var occurrenceData = [];
var isDeletedRecords = false;
if (eventData instanceof Array) {
for (var _i = 0, eventData_3 = eventData; _i < eventData_3.length; _i++) {
var event_5 = eventData_3[_i];
occurrenceData.push({ occurrence: event_5, parent: this.getParentEvent(event_5) });
}
}
else {
occurrenceData = { occurrence: eventData, parent: this.getParentEvent(eventData) };
}
var updateEvents = (eventData instanceof Array) ? eventData : [eventData];
var args = {
requestType: action === 'EditOccurrence' ? 'eventChange' : 'eventRemove',
cancel: false,
addedRecords: [], changedRecords: updateEvents, deletedRecords: []
};
args.data = occurrenceData;
this.parent.trigger(events.actionBegin, args, function (occurrenceArgs) {
if (!occurrenceArgs.cancel) {
var fields = _this.parent.eventFields;
var editParams = { addedRecords: [], changedRecords: [], deletedRecords: [] };
var occurrenceEvents = (occurrenceData instanceof Array ? occurrenceData : [occurrenceData]);
var _loop_2 = function (a, count) {
var childEvent = occurrenceArgs.changedRecords[parseInt(a.toString(), 10)];
var parentEvent = occurrenceEvents[parseInt(a.toString(), 10)].parent;
var parentException = parentEvent[fields.recurrenceException];
var editedData = void 0;
var exceptionDate = void 0;
switch (action) {
case 'EditOccurrence':
editedData = _this.parent.eventsProcessed.filter(function (event) { return event.Guid === childEvent.Guid; })[0];
exceptionDate = _this.excludeDateCheck(editedData[fields.startTime], parentException);
if (exceptionDate !== parentEvent[fields.recurrenceException]) {
parentEvent[fields.recurrenceException] = exceptionDate;
childEvent[fields.recurrenceException] = date_generator_1.getRecurrenceStringFromDate(editedData[fields.startTime]);
childEvent[fields.recurrenceID] = parentEvent[fields.id];
childEvent[fields.followingID] = null;
editParams.changedRecords.push(_this.parent.eventBase.processTimezone(parentEvent, true));
editParams.addedRecords.push(_this.parent.eventBase.processTimezone(childEvent, true));
}
else {
editParams.changedRecords.push(_this.parent.eventBase.processTimezone(childEvent, true));
}
break;
case 'DeleteOccurrence':
if (!childEvent[fields.recurrenceException]) {
parentEvent[fields.recurrenceException] =
_this.excludeDateCheck(childEvent[fields.startTime], parentException);
editParams.changedRecords.push(_this.parent.eventBase.processTimezone(parentEvent, true));
}
if (childEvent[fields.id] !== parentEvent[fields.id]) {
editParams.deletedRecords.push(childEvent);
isDeletedRecords = true;
}
break;
}
};
for (var a = 0, count = occurrenceArgs.changedRecords.length; a < count; a++) {
_loop_2(a, count);
}
var promise = _this.parent.dataModule.dataManager.saveChanges(editParams, fields.id, _this.getTable(), _this.getQuery());
var cloneEvent = ej2_base_1.extend({}, occurrenceArgs.changedRecords[occurrenceArgs.changedRecords.length - 1], null, true);
_this.parent.eventBase.selectWorkCellByTime(action === 'EditOccurrence' ? [_this.parent.eventBase.processTimezone(cloneEvent)] : [cloneEvent]);
var crudArgs = {
requestType: action === 'EditOccurrence' ? 'eventChanged' : 'eventRemoved',
cancel: false, data: isDeletedRecords ? occurrenceArgs.deletedRecords : occurrenceArgs.changedRecords,
promise: promise, editParams: editParams
};
_this.refreshData(crudArgs);
}
});
};
Crud.prototype.processFollowSeries = function (eventData, action) {
var _this = this;
var followData = [];
if (eventData instanceof Array) {
for (var _i = 0, eventData_4 = eventData; _i < eventData_4.length; _i++) {
var event_6 = eventData_4[_i];
followData.push({ occurrence: event_6, parent: this.getParentEvent(event_6) });
}
}
else {
followData = { occurrence: eventData, parent: this.getParentEvent(eventData) };
}
var updateFollowEvents = (eventData instanceof Array) ? eventData : [eventData];
var args = {
requestType: action === 'EditFollowingEvents' ? 'eventChange' : 'eventRemove', cancel: false,
addedRecords: [], changedRecords: updateFollowEvents, deletedRecords: []
};
args.data = followData;
this.parent.trigger(events.actionBegin, args, function (followArgs) {
Eif (!followArgs.cancel) {
var fields_1 = _this.parent.eventFields;
var editParams = { addedRecords: [], changedRecords: [], deletedRecords: [] };
var followEvents = followData instanceof Array ? followData : [followData];
var _loop_3 = function (a, count) {
var childEvent = followArgs.changedRecords[parseInt(a.toString(), 10)];
var parentEvent = followEvents[parseInt(a.toString(), 10)].parent;
var followData_1 = _this.parent.eventBase.getEventCollections(parentEvent, childEvent);
var isSpanned = void 0;
switch (action) {
case 'EditFollowingEvents':
_this.processRecurrenceRule(parentEvent, childEvent);
isSpanned = !_this.parent.eventBase.isFollowingEvent(parentEvent, childEvent);
childEvent[fields_1.followingID] = isSpanned ? null : parentEvent[fields_1.id];
childEvent[fields_1.recurrenceID] = null;
editParams.addedRecords.push(_this.parent.eventBase.processTimezone(childEvent, true));
editParams.changedRecords.push(_this.parent.eventBase.processTimezone(parentEvent, true));
if (!_this.parent.uiStateValues.isIgnoreOccurrence) {
childEvent[fields_1.recurrenceException] = null;
if (followData_1.occurrence.length > 0) {
var rule = followData_1.occurrence.slice(-1)[0][fields_1.recurrenceRule];
if (rule.indexOf('COUNT') === -1) {
childEvent[fields_1.recurrenceRule] = rule;
}
}
if (followData_1.follow.length > 0) {
childEvent[fields_1.recurrenceRule] = followData_1.follow.slice(-1)[0][fields_1.recurrenceRule];
editParams.deletedRecords = editParams.deletedRecords.concat(followData_1.follow);
}
if (isSpanned) {
followData_1.occurrence = followData_1.occurrence.filter(function (eventObj) {
return eventObj[fields_1.recurrenceID] === parentEvent[fields_1.id];
});
}
editParams.deletedRecords = editParams.deletedRecords.concat(followData_1.occurrence);
}
break;
case 'DeleteFollowingEvents':
_this.processRecurrenceRule(parentEvent, childEvent[fields_1.startTime]);
editParams.changedRecords.push(_this.parent.eventBase.processTimezone(parentEvent, true));
editParams.deletedRecords = editParams.deletedRecords.concat(followData_1.occurrence).concat(followData_1.follow);
break;
}
};
for (var a = 0, count = followArgs.changedRecords.length; a < count; a++) {
_loop_3(a, count);
}
var promise = _this.parent.dataModule.dataManager.saveChanges(editParams, fields_1.id, _this.getTable(), _this.getQuery());
var cloneEvent = ej2_base_1.extend({}, followArgs.changedRecords[followArgs.changedRecords.length - 1], null, true);
_this.parent.eventBase.selectWorkCellByTime(action === 'EditFollowingEvents' ? [_this.parent.eventBase.processTimezone(cloneEvent)] : [cloneEvent]);
var crudArgs = {
requestType: action === 'EditFollowingEvents' ? 'eventChanged' : 'eventRemoved',
cancel: false, data: followArgs.changedRecords, promise: promise, editParams: editParams
};
_this.refreshData(crudArgs);
}
});
};
Crud.prototype.processEntireSeries = function (eventData, action) {
var _this = this;
var seriesData = [];
var isDeletedRecords = false;
if (eventData instanceof Array) {
for (var _i = 0, eventData_5 = eventData; _i < eventData_5.length; _i++) {
var event_7 = eventData_5[_i];
seriesData.push(this.getParentEvent(event_7, true));
}
}
else {
seriesData = this.getParentEvent(eventData, true);
}
var updateSeriesEvents = (eventData instanceof Array) ? eventData : [eventData];
var args = {
requestType: action === 'EditSeries' ? 'eventChange' : 'eventRemove', cancel: false,
addedRecords: [], changedRecords: [], deletedRecords: []
};
args.data = seriesData;
if (action === 'EditSeries') {
args.changedRecords = updateSeriesEvents;
}
else {
args.deletedRecords = updateSeriesEvents;
}
if (action === 'EditSeries' && !this.parent.uiStateValues.isIgnoreOccurrence) {
var seriesEvents = seriesData instanceof Array ? seriesData : [seriesData];
for (var a = 0, count = args.changedRecords.length; a < count; a++) {
var parentEvent = seriesEvents[parseInt(a.toString(), 10)];
var eventCollections = this.parent.eventBase.getEventCollections(parentEvent);
var deletedEvents = eventCollections.follow.concat(eventCollections.occurrence);
args.deletedRecords = args.deletedRecords.concat(deletedEvents);
}
}
this.parent.trigger(events.actionBegin, args, function (seriesArgs) {
if (!seriesArgs.cancel) {
var fields_2 = _this.parent.eventFields;
var editParams = { addedRecords: [], changedRecords: [], deletedRecords: [] };
var seriesEvents = seriesData instanceof Array ? seriesData : [seriesData];
var records = action === 'EditSeries' ? seriesArgs.changedRecords : seriesArgs.deletedRecords;
var _loop_4 = function (a, count) {
var childEvent = records[parseInt(a.toString(), 10)];
var parentEvent = seriesEvents[parseInt(a.toString(), 10)];
var eventCollections = _this.parent.eventBase.getEventCollections(parentEvent);
var deletedEvents = eventCollections.follow.concat(eventCollections.occurrence);
switch (action) {
case 'EditSeries':
childEvent[fields_2.id] = parentEvent[fields_2.id];
childEvent[fields_2.recurrenceID] = null;
childEvent[fields_2.followingID] = null;
if (_this.parent.uiStateValues.isIgnoreOccurrence && childEvent[fields_2.recurrenceException]) {
var originalParent = _this.parent.eventsData.filter(function (eventObj) {
return eventObj[fields_2.id] === childEvent[fields_2.id];
});
Eif (originalParent.length > 0) {
childEvent[fields_2.recurrenceRule] = originalParent[0][fields_2.recurrenceRule];
}
}
else {
childEvent[fields_2.recurrenceException] = null;
editParams.deletedRecords = editParams.deletedRecords.concat(deletedEvents);
}
editParams.changedRecords.push(_this.parent.eventBase.processTimezone(childEvent, true));
_this.parent.uiStateValues.isIgnoreOccurrence = false;
break;
case 'DeleteSeries':
editParams.deletedRecords = editParams.deletedRecords.concat(deletedEvents.concat(parentEvent));
isDeletedRecords = true;
break;
}
};
for (var a = 0, count = records.length; a < count; a++) {
_loop_4(a, count);
}
var promise = _this.parent.dataModule.dataManager.saveChanges(editParams, fields_2.id, _this.getTable(), _this.getQuery());
var cloneEvent = ej2_base_1.extend({}, records[records.length - 1], null, true);
_this.parent.eventBase.selectWorkCellByTime(action === 'EditSeries' ? [_this.parent.eventBase.processTimezone(cloneEvent)] : [cloneEvent]);
var crudArgs = {
requestType: action === 'EditSeries' ? 'eventChanged' : 'eventRemoved',
cancel: false, data: isDeletedRecords ? seriesArgs.deletedRecords : seriesArgs.changedRecords,
promise: promise, editParams: editParams
};
_this.refreshData(crudArgs);
}
});
};
Crud.prototype.processDelete = function (eventData) {
var _this = this;
var deleteData = [];
for (var _i = 0, eventData_6 = eventData; _i < eventData_6.length; _i++) {
var eventObj = eventData_6[_i];
if (eventObj[this.parent.eventFields.recurrenceRule]) {
deleteData.push({ occurrence: eventObj, parent: this.getParentEvent(eventObj) });
}
else {
deleteData.push(eventObj);
}
}
var args = {
requestType: 'eventRemove', cancel: false,
addedRecords: [], changedRecords: [], deletedRecords: eventData
};
args.data = deleteData;
this.parent.trigger(events.actionBegin, args, function (deleteArgs) {
Eif (!deleteArgs.cancel) {
var fields_3 = _this.parent.eventFields;
var editParams = { addedRecords: [], changedRecords: [], deletedRecords: [] };
var _loop_5 = function (a, count) {
var isDelete = ej2_base_1.isNullOrUndefined(deleteArgs.deletedRecords[parseInt(a.toString(), 10)][_this.parent.eventFields.recurrenceRule]);
if (!isDelete) {
var parentEvent_1 = deleteData[parseInt(a.toString(), 10)].parent;
var isEdited = editParams.changedRecords.filter(function (obj) {
return obj[fields_3.id] === parentEvent_1[fields_3.id];
});
var editedDate = deleteArgs.deletedRecords[parseInt(a.toString(), 10)][fields_3.startTime];
if (isEdited.length > 0) {
var editedData = isEdited[0];
editedData[fields_3.recurrenceException] =
_this.excludeDateCheck(editedDate, editedData[fields_3.recurrenceException]);
}
else {
parentEvent_1[fields_3.recurrenceException] =
_this.excludeDateCheck(editedDate, parentEvent_1[fields_3.recurrenceException]);
}
if (isEdited.length === 0) {
editParams.changedRecords.push(_this.parent.eventBase.processTimezone(parentEvent_1, true));
}
isDelete = deleteArgs.deletedRecords[parseInt(a.toString(), 10)][fields_3.id] !== parentEvent_1[fields_3.id];
}
if (isDelete) {
editParams.deletedRecords.push(deleteArgs.deletedRecords[parseInt(a.toString(), 10)]);
}
};
for (var a = 0, count = deleteArgs.deletedRecords.length; a < count; a++) {
_loop_5(a, count);
}
var promise = _this.parent.dataModule.dataManager.saveChanges(editParams, fields_3.id, _this.getTable(), _this.getQuery());
_this.parent.eventBase.selectWorkCellByTime(deleteArgs.deletedRecords);
var crudArgs = {
requestType: 'eventRemoved', cancel: false, data: deleteArgs.deletedRecords, promise: promise, editParams: editParams
};
_this.refreshData(crudArgs);
}
});
};
Crud.prototype.processSave = function (data) {
var _this = this;
var eventData = (data instanceof Array) ? data : [data];
var editData = [];
for (var _i = 0, eventData_7 = eventData; _i < eventData_7.length; _i++) {
var eventObj = eventData_7[_i];
if (eventObj[this.parent.eventFields.recurrenceRule]) {
editData.push({ occurrence: eventObj, parent: this.getParentEvent(eventObj) });
}
else {
editData.push(eventObj);
}
}
var args = { requestType: 'eventChange', cancel: false, addedRecords: [], changedRecords: eventData, deletedRecords: [] };
args.data = editData;
this.parent.trigger(events.actionBegin, args, function (editArgs) {
Eif (!editArgs.cancel) {
var fields = _this.parent.eventFields;
var editParams = { addedRecords: [], changedRecords: [], deletedRecords: [] };
for (var _i = 0, _a = editArgs.changedRecords; _i < _a.length; _i++) {
var record = _a[_i];
if (!ej2_base_1.isNullOrUndefined(record[fields.recurrenceRule]) && ej2_base_1.isNullOrUndefined(record[fields.recurrenceException])) {
var exceptionString = date_generator_1.getRecurrenceStringFromDate(record[fields.startTime]);
var parentEle = _this.getParentEvent(record);
parentEle[fields.recurrenceException] = ej2_base_1.isNullOrUndefined(parentEle[fields.recurrenceException]) ?
exceptionString : parentEle[fields.recurrenceException].concat(',' + exceptionString);
record[fields.id] = _this.parent.getEventMaxID();
record[fields.recurrenceException] = exceptionString;
editParams.addedRecords.push(_this.parent.eventBase.processTimezone(record, true));
editParams.changedRecords.push(_this.parent.eventBase.processTimezone(parentEle, true));
}
else {
editParams.changedRecords.push(_this.parent.eventBase.processTimezone(record, true));
}
}
var promise = _this.parent.dataModule.dataManager.saveChanges(editParams, fields.id, _this.getTable(), _this.getQuery());
var cloneEvent = ej2_base_1.extend({}, editArgs.changedRecords[editArgs.changedRecords.length - 1], null, true);
_this.parent.eventBase.selectWorkCellByTime([_this.parent.eventBase.processTimezone(cloneEvent)]);
var crudArgs = { requestType: 'eventChanged', cancel: false, data: editArgs.changedRecords, promise: promise, editParams: editParams };
_this.refreshData(crudArgs);
}
});
};
Crud.prototype.getParentEvent = function (event, isParent) {
if (isParent === void 0) { isParent = false; }
var parentEvent = this.parent.eventBase.getParentEvent(event, isParent) || event;
if (parentEvent[this.parent.eventFields.startTimezone] || parentEvent[this.parent.eventFields.endTimezone]) {
this.parent.eventBase.timezoneConvert(parentEvent);
}
return parentEvent;
};
Crud.prototype.excludeDateCheck = function (eventStartTime, exceptionDateList) {
var timezone = this.parent.timezone || this.parent.tzModule.getLocalTimezoneName();
Eif (timezone) {
eventStartTime = this.parent.tzModule.remove(new Date(+eventStartTime.getTime()), timezone);
}
var exDate = date_generator_1.getRecurrenceStringFromDate(eventStartTime);
if (!ej2_base_1.isNullOrUndefined(exceptionDateList)) {
if (exceptionDateList.indexOf(exDate) === -1) {
exceptionDateList = !(ej2_base_1.isNullOrUndefined(exceptionDateList)) ? exceptionDateList + ',' + exDate : exDate;
}
}
else {
exceptionDateList = exDate;
}
return exceptionDateList;
};
Crud.prototype.processRecurrenceRule = function (parentEvent, followEvent) {
var fields = this.parent.eventFields;
var recurrenceRule = parentEvent[fields.recurrenceRule];
var endDate;
if (followEvent instanceof Date) {
endDate = new Date(+followEvent);
}
else {
endDate = new Date(+followEvent[fields.startTime]);
var newRecurrenceRule = followEvent[fields.recurrenceRule];
Eif (newRecurrenceRule) {
var startDate = parentEvent[fields.startTime];
var ruleException = (this.parent.currentAction === 'DeleteFollowingEvents') ? followEvent[fields.recurrenceException] : null;
var dateCollection = date_generator_1.generate(startDate, newRecurrenceRule, ruleException, this.parent.activeViewOptions.firstDayOfWeek);
var untilDate = new Date(dateCollection.slice(-1)[0]);
untilDate.setHours(endDate.getHours(), endDate.getMinutes(), endDate.getSeconds());
endDate.setHours(startDate.getHours(), startDate.getMinutes(), startDate.getSeconds());
followEvent[fields.recurrenceRule] = this.getUpdatedRecurrenceRule(newRecurrenceRule, new Date(+untilDate), false);
}
}
parentEvent[fields.recurrenceRule] = this.getUpdatedRecurrenceRule(recurrenceRule, util.addDays(new Date(endDate.getTime()), -1), true);
};
Crud.prototype.getUpdatedRecurrenceRule = function (recurrenceRule, untilDate, isParent) {
var splitRule = recurrenceRule.split(';');
var updatedRule = '';
for (var _i = 0, splitRule_1 = splitRule; _i < splitRule_1.length; _i++) {
var rule = splitRule_1[_i];
if (rule !== '') {
var ruleKey = rule.split('=')[0];
var ruleValue = rule.split('=')[1];
if (ruleKey === 'COUNT' || ruleKey === 'UNTIL') {
ruleValue = date_generator_1.getRecurrenceStringFromDate(untilDate);
rule = rule.replace(rule, 'UNTIL=' + ruleValue);
}
updatedRule += rule + ';';
}
}
Iif (isParent && updatedRule.indexOf('UNTIL') === -1) {
updatedRule += 'UNTIL=' + date_generator_1.getRecurrenceStringFromDate(untilDate);
}
return updatedRule;
};
Crud.prototype.isBlockEvent = function (eventData) {
var eventCollection = (eventData instanceof Array) ? eventData : [eventData];
var value = false;
for (var _i = 0, eventCollection_1 = eventCollection; _i < eventCollection_1.length; _i++) {
var event_8 = eventCollection_1[_i];
value = event_8[this.parent.eventFields.isBlock] || false;
}
return value;
};
Crud.prototype.destroy = function () {
this.crudObj = null;
this.parent = null;
};
return Crud;
}());
exports.Crud = Crud;
});
|