-
Notifications
You must be signed in to change notification settings - Fork 158
/
Copy pathdatetimepicker.ts
2206 lines (2168 loc) · 90.1 KB
/
datetimepicker.ts
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
// eslint-disable-next-line @typescript-eslint/triple-slash-reference
///<reference path='../datepicker/datepicker-model.d.ts'/>
import { EventHandler, Internationalization, Property, NotifyPropertyChanges, Browser, RippleOptions } from '@syncfusion/ej2-base';
import { Animation, EmitType, Event, AnimationModel, cldrData, getDefaultDateObject, detach } from '@syncfusion/ej2-base';
import { createElement, remove, addClass, L10n, removeClass, closest, append, attributes } from '@syncfusion/ej2-base';
import { KeyboardEvents, KeyboardEventArgs, isNullOrUndefined, formatUnit, getValue, rippleEffect } from '@syncfusion/ej2-base';
import { ModuleDeclaration, extend, Touch, SwipeEventArgs } from '@syncfusion/ej2-base';
import { Popup } from '@syncfusion/ej2-popups';
import { Input } from '@syncfusion/ej2-inputs';
import { BlurEventArgs, ClearedEventArgs, CalendarType, CalendarView, DayHeaderFormats } from '../calendar/calendar';
import { DatePicker, PopupObjectArgs } from '../datepicker/datepicker';
import { TimePickerBase } from '../timepicker/timepicker';
import { DateTimePickerModel } from './datetimepicker-model';
import {MaskPlaceholderModel} from '../common/maskplaceholder-model';
//class constant defination
const DATEWRAPPER: string = 'e-date-wrapper';
const DATEPICKERROOT: string = 'e-datepicker';
const DATETIMEWRAPPER: string = 'e-datetime-wrapper';
const DAY: number = new Date().getDate();
const MONTH: number = new Date().getMonth();
const YEAR: number = new Date().getFullYear();
const HOUR: number = new Date().getHours();
const MINUTE: number = new Date().getMinutes();
const SECOND: number = new Date().getSeconds();
const MILLISECOND: number = new Date().getMilliseconds();
const ROOT: string = 'e-datetimepicker';
const DATETIMEPOPUPWRAPPER: string = 'e-datetimepopup-wrapper';
const INPUTWRAPPER: string = 'e-input-group-icon';
const POPUP: string = 'e-popup';
const TIMEICON: string = 'e-time-icon';
const INPUTFOCUS: string = 'e-input-focus';
const POPUPDIMENSION: string = '250px';
const ICONANIMATION: string = 'e-icon-anim';
const DISABLED: string = 'e-disabled';
const ERROR: string = 'e-error';
const CONTENT: string = 'e-content';
const NAVIGATION: string = 'e-navigation';
const ACTIVE: string = 'e-active';
const HOVER: string = 'e-hover';
const ICONS: string = 'e-icons';
const HALFPOSITION: number = 2;
const LISTCLASS: string = 'e-list-item';
const ANIMATIONDURATION: number = 100;
const OVERFLOW: string = 'e-time-overflow';
/**
* Represents the DateTimePicker component that allows user to select
* or enter a date time value.
* ```html
* <input id="dateTimePicker"/>
* ```
* ```typescript
* <script>
* let dateTimePickerObject:DateTimePicker = new DateTimePicker({ value: new Date() });
* dateTimePickerObject.appendTo("#dateTimePicker");
* </script>
* ```
*/
@NotifyPropertyChanges
export class DateTimePicker extends DatePicker {
private timeIcon: HTMLElement;
private cloneElement: HTMLElement;
private dateTimeWrapper: HTMLElement;
private rippleFn: Function;
private listWrapper: HTMLElement;
private liCollections: HTMLElement[];
private timeCollections: number[];
private listTag: HTMLElement;
private selectedElement: HTMLElement;
private containerStyle: ClientRect;
private popupObject: Popup;
protected timeModal: HTMLElement;
protected modelWrapper: HTMLElement;
private isNavigate: boolean;
protected isPreventBlur: boolean;
private timeValue: string;
protected l10n: L10n;
private keyboardHandler: KeyboardEvents;
protected inputEvent: KeyboardEvents;
private activeIndex: number;
private valueWithMinutes: Date = null;
private initValue: Date;
protected tabIndex: string;
private isValidState: boolean;
protected timekeyConfigure: { [key: string]: string };
protected preventArgs: PopupObjectArgs;
private dateTimeOptions: DateTimePickerModel;
protected scrollInvoked: boolean = false;
protected maskedDateValue: string;
protected moduleName: string = this.getModuleName();
protected touchDTModule: Touch;
protected touchDTStart: boolean;
private formatRegex : RegExp = /dddd|ddd|dd|d|MMMM|MMM|MM|M|yyyy|yyy|yy|y|'[^']*'|'[^']*'/g;
private dateFormatString : string = '';
/**
* Specifies the format of the time value that to be displayed in time popup list.
*
* @default null
*/
@Property(null)
public timeFormat: string;
/**
* Specifies the time interval between the two adjacent time values in the time popup list .
*
* @default 30
*/
@Property(30)
public step: number;
/**
* Specifies the scroll bar position if there is no value is selected in the timepicker popup list or
* the given value is not present in the timepicker popup list.
* {% codeBlock src='datetimepicker/scrollTo/index.md' %}{% endcodeBlock %}
*
* @default null
*/
@Property(null)
public scrollTo: Date;
/**
* specifies the z-index value of the popup element.
*
* @default 1000
* @aspType int
*/
@Property(1000)
public zIndex: number;
/**
* Gets or sets the selected date of the Calendar.
*
* @default null
* @isGenericType true
*/
@Property(null)
public value: Date;
/**
* Customizes the key actions in DateTimePicker.
* For example, when using German keyboard, the key actions can be customized using these shortcuts.
*
*
* Input Navigation
* <table>
* <tr>
* <td colSpan=1 rowSpan=1>
* Key action<br/></td><td colSpan=1 rowSpan=1>
* Key<br/></td></tr>
* <tr>
* <td colSpan=1 rowSpan=1>
* altUpArrow<br/></td><td colSpan=1 rowSpan=1>
* alt+uparrow<br/></td></tr>
* <tr>
* <td colSpan=1 rowSpan=1>
* altDownArrow<br/></td><td colSpan=1 rowSpan=1>
* alt+downarrow<br/></td></tr>
* <tr>
* <td colSpan=1 rowSpan=1>
* escape<br/></td><td colSpan=1 rowSpan=1>
* escape<br/></td></tr>
* </table>
*
* Calendar Navigation (Use the following list of keys to navigate the currently focused Calendar after the popup has opened).
* <table>
* <tr>
* <td colSpan=1 rowSpan=1>
* Key action<br/></td><td colSpan=1 rowSpan=1>
* Key<br/></td></tr>
* <tr>
* <td colSpan=1 rowSpan=1>
* controlUp<br/></td><td colSpan=1 rowSpan=1>
* ctrl+38<br/></td></tr>
* <tr>
* <td colSpan=1 rowSpan=1>
* controlDown<br/></td><td colSpan=1 rowSpan=1>
* ctrl+40<br/></td></tr>
* <tr>
* <td colSpan=1 rowSpan=1>
* moveDown<br/></td><td colSpan=1 rowSpan=1>
* downarrow<br/></td></tr>
* <tr>
* <td colSpan=1 rowSpan=1>
* moveUp<br/></td><td colSpan=1 rowSpan=1>
* uparrow<br/></td></tr>
* <tr>
* <td colSpan=1 rowSpan=1>
* moveLeft<br/></td><td colSpan=1 rowSpan=1>
* leftarrow<br/></td></tr>
* <tr>
* <td colSpan=1 rowSpan=1>
* moveRight<br/></td><td colSpan=1 rowSpan=1>
* rightarrow<br/></td></tr>
* <tr>
* <td colSpan=1 rowSpan=1>
* select<br/></td><td colSpan=1 rowSpan=1>
* enter<br/></td></tr>
* <tr>
* <td colSpan=1 rowSpan=1>
* home<br/></td><td colSpan=1 rowSpan=1>
* home<br/></td></tr>
* <tr>
* <td colSpan=1 rowSpan=1>
* end<br/></td><td colSpan=1 rowSpan=1>
* end<br/></td></tr>
* <tr>
* <td colSpan=1 rowSpan=1>
* pageUp<br/></td><td colSpan=1 rowSpan=1>
* pageup<br/></td></tr>
* <tr>
* <td colSpan=1 rowSpan=1>
* pageDown<br/></td><td colSpan=1 rowSpan=1>
* pagedown<br/></td></tr>
* <tr>
* <td colSpan=1 rowSpan=1>
* shiftPageUp<br/></td><td colSpan=1 rowSpan=1>
* shift+pageup<br/></td></tr>
* <tr>
* <td colSpan=1 rowSpan=1>
* shiftPageDown<br/></td><td colSpan=1 rowSpan=1>
* shift+pagedown<br/></td></tr>
* <tr>
* <td colSpan=1 rowSpan=1>
* controlHome<br/></td><td colSpan=1 rowSpan=1>
* ctrl+home<br/></td></tr>
* <tr>
* <td colSpan=1 rowSpan=1>
* controlEnd<br/></td><td colSpan=1 rowSpan=1>
* ctrl+end<br/></td></tr>
* <tr>
* <td colSpan=1 rowSpan=1>
* altUpArrow<br/></td><td colSpan=1 rowSpan=1>
* alt+uparrow<br/></td></tr>
* <tr>
* <td colSpan=1 rowSpan=1>
* spacebar<br/></td><td colSpan=1 rowSpan=1>
* space<br/></td></tr>
* <tr>
* <td colSpan=1 rowSpan=1>
* altRightArrow<br/></td><td colSpan=1 rowSpan=1>
* alt+rightarrow<br/></td></tr>
* <tr>
* <td colSpan=1 rowSpan=1>
* altLeftArrow<br/></td><td colSpan=1 rowSpan=1>
* alt+leftarrow<br/></td></tr>
* </table>
*
* TimePicker Navigation (Use the below list of shortcut keys to interact with the TimePicker after the TimePicker Popup has opened).
* <table>
* <tr>
* <td colSpan=1 rowSpan=1>
* Key action<br/></td><td colSpan=1 rowSpan=1>
* Key<br/></td></tr>
* <tr>
* <td colSpan=1 rowSpan=1>
* down<br/></td><td colSpan=1 rowSpan=1>
* downarrow<br/></td></tr>
* <tr>
* <td colSpan=1 rowSpan=1>
* up<br/></td><td colSpan=1 rowSpan=1>
* uparrow<br/></td></tr>
* <tr>
* <td colSpan=1 rowSpan=1>
* left<br/></td><td colSpan=1 rowSpan=1>
* leftarrow<br/></td></tr>
* <tr>
* <td colSpan=1 rowSpan=1>
* right<br/></td><td colSpan=1 rowSpan=1>
* rightarrow<br/></td></tr>
* </table>
*
* {% codeBlock src='datetimepicker/keyConfigs/index.md' %}{% endcodeBlock %}
*
* @default null
*/
@Property(null)
public keyConfigs: { [key: string]: string };
/**
* You can add the additional html attributes such as disabled, value etc., to the element.
* If you configured both property and equivalent html attribute then the component considers the property value.
* {% codeBlock src='datetimepicker/htmlAttributes/index.md' %}{% endcodeBlock %}
*
* @default {}
*/
@Property({})
public htmlAttributes: { [key: string]: string };
/**
* Enable or disable persisting component's state between page reloads. If enabled, following list of states will be persisted.
* 1. value
*
* @default false
*/
@Property(false)
public enablePersistence: boolean;
/**
* > Support for `allowEdit` has been provided from
* [`v16.2.46`](https://ej2.syncfusion.com/angular/documentation/release-notes/16.2.46/#datetimepicker).
*
* Specifies whether the input textbox is editable or not. Here the user can select the value from the
* popup and cannot edit in the input textbox.
*
* @default true
*/
@Property(true)
public allowEdit: boolean;
/**
* Specifies the option to enable the multiple dates selection of the calendar.
*
* @default false
* @private
*/
@Property(false)
public isMultiSelection: boolean;
/**
* Gets or sets multiple selected dates of the calendar.
*
* @default null
* @private
*/
@Property(null)
public values: Date[];
/**
* Specifies whether to show or hide the clear icon in textbox.
*
* @default true
*/
@Property(true)
public showClearButton: boolean;
/**
* Specifies the placeholder text that to be is displayed in textbox.
*
* @default null
*/
@Property(null)
public placeholder: string;
/**
* Specifies the component to act as strict. So that, it allows to enter only a valid
* date and time value within a specified range or else it
* will resets to previous value. By default, strictMode is in false.
* it allows invalid or out-of-range value with highlighted error class.
*
* @default false
* > For more details refer to
* [`Strict Mode`](../../datetimepicker/strict-mode/) documentation.
*/
@Property(false)
public strictMode: boolean;
/**
* Specifies the component popup display full screen in mobile devices.
*
* @default false
*/
@Property(false)
public fullScreenMode : boolean;
/**
* By default, the date value will be processed based on system time zone.
* If you want to process the initial date value using server time zone
* then specify the time zone value to `serverTimezoneOffset` property.
*
* @default null
*/
@Property(null)
public serverTimezoneOffset: number;
/**
* Gets or sets the minimum date that can be selected in the DateTimePicker.
*
* @default new Date(1900, 00, 01)
*/
@Property(new Date(1900, 0, 1))
public min: Date;
/**
* Gets or sets the maximum date that can be selected in the DateTimePicker.
*
* @default new Date(2099, 11, 31)
*/
@Property(new Date(2099, 11, 31))
public max: Date;
/**
* Gets or sets the minimum time that can be selected in the time popup of the DateTimePicker.
*
* @default null
*/
@Property(null)
public minTime: Date;
/**
* Gets or sets the maximum time that can be selected in the time popup of the DateTimePicker.
*
* @default null
*/
@Property(null)
public maxTime: Date;
/**
* Gets or sets the Calendar's first day of the week. By default, the first day of the week will be based on the current culture.
*
* @default 0
* @aspType int
* > For more details about firstDayOfWeek refer to
* [`First day of week`](../../calendar/how-to/first-day-of-week#change-the-first-day-of-the-week) documentation.
*/
@Property(null)
public firstDayOfWeek: number;
/**
* Gets or sets the Calendar's Type like gregorian or islamic.
*
* @default Gregorian
*/
@Property('Gregorian')
public calendarMode: CalendarType;
/**
* Specifies the initial view of the Calendar when it is opened.
* With the help of this property, initial view can be changed to year or decade view.
*
* @default Month
*
* <table>
* <tr>
* <td colSpan=1 rowSpan=1>
* View<br/></td><td colSpan=1 rowSpan=1>
* Description<br/></td></tr>
* <tr>
* <td colSpan=1 rowSpan=1>
* Month<br/></td><td colSpan=1 rowSpan=1>
* Calendar view shows the days of the month.<br/></td></tr>
* <tr>
* <td colSpan=1 rowSpan=1>
* Year<br/></td><td colSpan=1 rowSpan=1>
* Calendar view shows the months of the year.<br/></td></tr>
* <tr>
* <td colSpan=1 rowSpan=1>
* Decade<br/></td><td colSpan=1 rowSpan=1>
* Calendar view shows the years of the decade.<br/></td></tr>
* </table>
*
* > For more details about start refer to
* [`calendarView`](../../calendar/calendar-views#view-restriction)documentation.
*/
@Property('Month')
public start: CalendarView;
/**
* Sets the maximum level of view such as month, year, and decade in the Calendar.
* Depth view should be smaller than the start view to restrict its view navigation.
*
* @default Month
*
* <table>
* <tr>
* <td colSpan=1 rowSpan=1>
* view<br/></td><td colSpan=1 rowSpan=1>
* Description<br/></td></tr>
* <tr>
* <td colSpan=1 rowSpan=1>
* Month<br/></td><td colSpan=1 rowSpan=1>
* Calendar view shows up to the days of the month.<br/></td></tr>
* <tr>
* <td colSpan=1 rowSpan=1>
* Year<br/></td><td colSpan=1 rowSpan=1>
* Calendar view shows up to the months of the year.<br/></td></tr>
* <tr>
* <td colSpan=1 rowSpan=1>
* Decade<br/></td><td colSpan=1 rowSpan=1>
* Calendar view shows up to the years of the decade.<br/></td></tr>
* </table>
*
* > For more details about depth refer to
* [`calendarView`](../../calendar/calendar-views#view-restriction)documentation.
*/
@Property('Month')
public depth: CalendarView;
/**
* Determines whether the week number of the year is to be displayed in the calendar or not.
*
* @default false
* > For more details about weekNumber refer to
* [`Calendar with week number`](../../calendar/how-to/render-the-calendar-with-week-numbers)documentation.
*/
@Property(false)
public weekNumber: boolean;
/**
* Specifies whether the today button is to be displayed or not.
*
* @default true
*/
@Property(true)
public showTodayButton: boolean;
/**
* Specifies the format of the day that to be displayed in header. By default, the format is ‘short’.
* Possible formats are:
* * `Short` - Sets the short format of day name (like Su ) in day header.
* * `Narrow` - Sets the single character of day name (like S ) in day header.
* * `Abbreviated` - Sets the min format of day name (like Sun ) in day header.
* * `Wide` - Sets the long format of day name (like Sunday ) in day header.
*
* @default Short
*/
@Property('Short')
public dayHeaderFormat: DayHeaderFormats;
/**
* By default, the popup opens while clicking on the datetimepicker icon.
* If you want to open the popup while focusing the datetime input then specify its value as true.
*
* @default false
*/
@Property(false)
public openOnFocus : boolean;
/**
* Specifies whether it is a masked datetimepicker or not.
* By default the datetimepicker component render without masked input.
* If you need masked datetimepicker input then specify it as true.
*
* @default false
*/
@Property(false)
public enableMask: boolean;
/**
* Specifies the mask placeholder to be displayed on masked datetimepicker.
*
* @default {day:'day' , month:'month', year: 'year', hour:'hour',minute:'minute',second:'second',dayOfTheWeek: 'day of the week'}
*/
@Property({day: 'day' , month: 'month', year: 'year', hour: 'hour', minute: 'minute', second: 'second', dayOfTheWeek: 'day of the week'})
public maskPlaceholder: MaskPlaceholderModel;
/**
* Triggers when popup is opened.
*
* @event open
*/
@Event()
public open: EmitType<Object>;
/**
* Triggers when popup is closed.
*
* @event close
*/
@Event()
public close: EmitType<Object>;
/**
* Triggers when datetimepicker value is cleared using clear button.
*
* @event cleared
*/
@Event()
public cleared: EmitType<ClearedEventArgs>;
/**
* Triggers when input loses the focus.
*
* @event blur
*/
@Event()
public blur: EmitType<Object>;
/**
* Triggers when input gets focus.
*
* @event focus
*/
@Event()
public focus: EmitType<Object>;
/**
* Triggers when DateTimePicker is created.
*
* @event created
*/
@Event()
public created: EmitType<Object>;
/**
* Triggers when DateTimePicker is destroyed.
*
* @event destroyed
*/
@Event()
public destroyed: EmitType<Object>;
/**
* Constructor for creating the widget
*
* @param {DateTimePickerModel} options - Specifies the DateTimePicker model.
* @param {string | HTMLInputElement} element - Specifies the element to render as component.
* @private
*/
public constructor(options?: DateTimePickerModel, element?: string | HTMLInputElement) {
super(options, element);
this.dateTimeOptions = options;
}
private focusHandler(): void {
if (!this.enabled) {
return;
}
addClass([this.inputWrapper.container], INPUTFOCUS);
}
/**
* Sets the focus to widget for interaction.
*
* @returns {void}
*/
public focusIn(): void {
super.focusIn();
}
/**
* Remove the focus from widget, if the widget is in focus state.
*
* @returns {void}
*/
public focusOut(): void {
if (document.activeElement === this.inputElement) {
this.inputElement.blur();
removeClass([this.inputWrapper.container], [INPUTFOCUS]);
}
}
protected blurHandler(e: MouseEvent): void {
if (!this.enabled) {
return;
}
// IE popup closing issue when click over the scrollbar
if (this.isTimePopupOpen() && this.isPreventBlur) {
this.inputElement.focus();
return;
}
removeClass([this.inputWrapper.container], INPUTFOCUS);
const blurArguments: BlurEventArgs = {
model: this
};
if (this.isTimePopupOpen()) {
this.hide(e);
}
this.trigger('blur', blurArguments);
}
/**
* To destroy the widget.
*
* @returns {void}
*/
public destroy(): void {
if (this.showClearButton) {
this.clearButton = document.getElementsByClassName('e-clear-icon')[0] as HTMLElement;
}
if (this.popupObject && this.popupObject.element.classList.contains(POPUP)) {
this.popupObject.destroy();
detach(this.dateTimeWrapper);
this.dateTimeWrapper = undefined;
this.liCollections = this.timeCollections = [];
if (!isNullOrUndefined(this.rippleFn)) {
this.rippleFn();
}
}
const ariaAttribute: object = {
'aria-live': 'assertive', 'aria-atomic': 'true', 'aria-invalid': 'false',
'autocorrect': 'off', 'autocapitalize': 'off', 'spellcheck': 'false',
'aria-expanded': 'false', 'role': 'combobox', 'autocomplete': 'off'
};
if (this.inputElement) {
Input.removeAttributes(<{ [key: string]: string }>ariaAttribute, this.inputElement);
}
if (this.isCalendar()) {
if (this.popupWrapper) {
detach(this.popupWrapper);
}
this.popupObject = this.popupWrapper = null;
this.keyboardHandler.destroy();
}
this.unBindInputEvents();
this.liCollections = null;
this.rippleFn = null;
this.selectedElement = null;
this.listTag = null;
this.timeIcon = null;
this.popupObject = null;
this.preventArgs = null;
this.keyboardModule = null;
Input.destroy({
element: this.inputElement,
floatLabelType: this.floatLabelType,
properties: this.properties
}, this.clearButton);
super.destroy();
}
/**
* To Initialize the control rendering.
*
* @returns {void}
* @private
*/
public render(): void {
this.timekeyConfigure = {
enter: 'enter',
escape: 'escape',
end: 'end',
tab: 'tab',
home: 'home',
down: 'downarrow',
up: 'uparrow',
left: 'leftarrow',
right: 'rightarrow',
open: 'alt+downarrow',
close: 'alt+uparrow'
};
this.valueWithMinutes = null;
this.previousDateTime = null;
this.isPreventBlur = false;
this.cloneElement = <HTMLElement>this.element.cloneNode(true);
this.dateTimeFormat = this.cldrDateTimeFormat();
this.initValue = this.value;
if (typeof (this.min) === 'string')
{
this.min = this.checkDateValue(new Date((this as any).min));
}
if (typeof (this.max) === 'string')
{
this.max = this.checkDateValue(new Date((this as any).max));
}
if (typeof (this.minTime) === 'string')
{
this.minTime = this.checkDateValue(new Date((this as any).minTime));
}
if (typeof (this.maxTime) === 'string')
{
this.maxTime = this.checkDateValue(new Date((this as any).maxTime));
}
if (!isNullOrUndefined(closest(this.element, 'fieldset') as HTMLFieldSetElement) && (closest(this.element, 'fieldset') as HTMLFieldSetElement).disabled) {
this.enabled = false;
}
super.updateHtmlAttributeToElement();
this.checkAttributes(false);
const localeText: { placeholder: string } = { placeholder: this.placeholder };
this.l10n = new L10n('datetimepicker', localeText, this.locale);
this.setProperties({ placeholder: this.placeholder || this.l10n.getConstant('placeholder') }, true);
super.render();
this.createInputElement();
super.updateHtmlAttributeToWrapper();
this.bindInputEvents();
if (this.enableMask) {
this.notify('createMask', {
module: 'MaskedDateTime'
});
}
this.setValue(true);
if (this.enableMask && !this.value && this.maskedDateValue && (this.floatLabelType === 'Always' || !this.floatLabelType || !this.placeholder)){
Input.setValue(this.maskedDateValue, this.inputElement, this.floatLabelType, this.showClearButton);
}
this.setProperties({ scrollTo: this.checkDateValue(new Date(this.checkValue(this.scrollTo))) }, true);
this.previousDateTime = this.value && new Date(+this.value);
if (this.element.tagName === 'EJS-DATETIMEPICKER') {
this.tabIndex = this.element.hasAttribute('tabindex') ? this.element.getAttribute('tabindex') : '0';
this.element.removeAttribute('tabindex');
if (!this.enabled) {
this.inputElement.tabIndex = -1;
}
}
if (this.floatLabelType !== 'Never') {
Input.calculateWidth(this.inputElement, this.inputWrapper.container);
}
if (!isNullOrUndefined(this.inputWrapper.buttons[0]) && !isNullOrUndefined(this.inputWrapper.container.getElementsByClassName('e-float-text-overflow')[0]) && this.floatLabelType !== 'Never') {
this.inputWrapper.container.getElementsByClassName('e-float-text-overflow')[0].classList.add('e-date-time-icon');
}
this.renderComplete();
}
private setValue(isDynamic : boolean = false): void {
this.initValue = this.validateMinMaxRange(this.value);
if (!this.strictMode && this.isDateObject(this.initValue)) {
const value: Date = this.validateMinMaxRange(this.initValue);
Input.setValue(this.getFormattedValue(value), this.inputElement, this.floatLabelType, this.showClearButton);
this.setProperties({ value: value }, true);
} else {
if (isNullOrUndefined(this.value)) {
this.initValue = null;
this.setProperties({ value: null }, true);
}
}
this.valueWithMinutes = this.value;
super.updateInput(isDynamic);
}
private validateMinMaxRange(value: Date): Date {
let result: Date = value;
if (this.isDateObject(value)) {
result = this.validateValue(value);
} else {
if (+this.min > +this.max) {
this.disablePopupButton(true);
}
}
this.checkValidState(result);
return result;
}
private checkValidState(value: Date): void {
this.isValidState = true;
if (!this.strictMode) {
if ((+(value) > +(this.max)) || (+(value) < +(this.min)) || !this.isValidTime(value)) {
this.isValidState = false;
}
}
this.checkErrorState();
}
private checkErrorState(): void {
if (this.isValidState) {
removeClass([this.inputWrapper.container], ERROR);
} else {
addClass([this.inputWrapper.container], ERROR);
}
attributes(this.inputElement, { 'aria-invalid': this.isValidState ? 'false' : 'true' });
}
protected isValidTime(value: Date): boolean {
if (value != null && (this.minTime || this.maxTime)) {
let minTimeValue: number;
let maxTimeValue: number;
let maxValue: number;
let minValue: number;
const valueTime: number = value.getHours() * 3600000 + value.getMinutes() * 60000 +
value.getSeconds() * 1000 + value.getMilliseconds();
if (this.minTime) {
minTimeValue = this.minTime.getHours() * 3600000 + this.minTime.getMinutes() * 60000 +
this.minTime.getSeconds() * 1000 + this.minTime.getMilliseconds();
}
if (this.maxTime) {
maxTimeValue = this.maxTime.getHours() * 3600000 + this.maxTime.getMinutes() * 60000 +
this.maxTime.getSeconds() * 1000 + this.maxTime.getMilliseconds();
}
if (this.min && (+value.getDate() === +this.min.getDate() && +value.getMonth() === +this.min.getMonth() &&
+value.getFullYear() === +this.min.getFullYear())) {
minValue = this.min.getHours() * 3600000 + this.min.getMinutes() * 60000 +
this.min.getSeconds() * 1000 + this.min.getMilliseconds();
minTimeValue = minTimeValue < minValue ? minValue : minTimeValue;
}
if (this.max && (+value.getDate() === +this.max.getDate() && +value.getMonth() === +this.max.getMonth() &&
+this.max.getFullYear() === +this.max.getFullYear())) {
maxValue = this.max.getHours() * 3600000 + this.max.getMinutes() * 60000 +
this.max.getSeconds() * 1000 + this.max.getMilliseconds();
maxTimeValue = maxTimeValue > maxValue ? maxValue : maxTimeValue;
}
if (this.strictMode) {
let newValue: Date;
if (minTimeValue && valueTime < minTimeValue) {
newValue = new Date(
value.getFullYear(),
value.getMonth(),
value.getDate(),
this.minTime.getHours(),
this.minTime.getMinutes(),
this.minTime.getSeconds(),
this.minTime.getMilliseconds()
);
this.setProperties({ value: newValue }, true);
this.changedArgs = { value: this.value };
}
else if (maxTimeValue && valueTime > maxTimeValue) {
newValue = new Date(
value.getFullYear(),
value.getMonth(),
value.getDate(),
this.maxTime.getHours(),
this.maxTime.getMinutes(),
this.maxTime.getSeconds(),
this.maxTime.getMilliseconds()
);
this.setProperties({ value: newValue }, true);
this.changedArgs = { value: this.value };
}
return true;
}
else {
return !((minTimeValue && valueTime < minTimeValue) || (maxTimeValue && valueTime > maxTimeValue));
}
}
return true;
}
private validateValue(value: Date): Date {
let dateVal: Date = value;
if (this.strictMode) {
if (+this.min > +this.max) {
this.disablePopupButton(true);
dateVal = this.max;
} else if (+value < +this.min) {
dateVal = this.min;
} else if (+value > +this.max) {
dateVal = this.max;
}
} else {
if (+this.min > +this.max) {
this.disablePopupButton(true);
dateVal = value;
}
}
return dateVal;
}
private disablePopupButton(isDisable: boolean): void {
if (isDisable) {
addClass([this.inputWrapper.buttons[0], this.timeIcon], DISABLED);
this.hide();
} else {
removeClass([this.inputWrapper.buttons[0], this.timeIcon], DISABLED);
}
}
private getFormattedValue(value: Date): string {
let dateOptions: object;
if (!isNullOrUndefined(value)) {
if (this.calendarMode === 'Gregorian') {
dateOptions = { format: this.cldrDateTimeFormat(), type: 'dateTime', skeleton: 'yMd' };
} else {
dateOptions = { format: this.cldrDateTimeFormat(), type: 'dateTime', skeleton: 'yMd', calendar: 'islamic' };
}
return this.globalize.formatDate(value, dateOptions);
} else {
return null;
}
}
private isDateObject(value: Date): boolean {
return (!isNullOrUndefined(value) && !isNaN(+value)) ? true : false;
}
private createInputElement(): void {
removeClass([this.inputElement], DATEPICKERROOT);
removeClass([this.inputWrapper.container], DATEWRAPPER);
addClass([this.inputWrapper.container], DATETIMEWRAPPER);
addClass([this.inputElement], ROOT);
this.renderTimeIcon();
}
private renderTimeIcon(): void {
this.timeIcon = Input.appendSpan(INPUTWRAPPER + ' ' + TIMEICON + ' ' + ICONS, this.inputWrapper.container);
}
private bindInputEvents(): void {
EventHandler.add(this.timeIcon, 'mousedown', this.timeHandler, this);
EventHandler.add(this.inputWrapper.buttons[0], 'mousedown', this.dateHandler, this);
EventHandler.add(this.inputElement, 'blur', this.blurHandler, this);
EventHandler.add(this.inputElement, 'focus', this.focusHandler, this);
this.defaultKeyConfigs = (extend(this.defaultKeyConfigs, this.keyConfigs) as { [key: string]: string });
this.keyboardHandler = new KeyboardEvents(
<HTMLElement>this.inputElement,
{
eventName: 'keydown',
keyAction: this.inputKeyAction.bind(this),
keyConfigs: this.defaultKeyConfigs
});
}
private unBindInputEvents(): void {
EventHandler.remove(this.timeIcon, 'mousedown touchstart', this.timeHandler);
EventHandler.remove(this.inputWrapper.buttons[0], 'mousedown touchstart', this.dateHandler);
if (this.inputElement) {
EventHandler.remove(this.inputElement, 'blur', this.blurHandler);
EventHandler.remove(this.inputElement, 'focus', this.focusHandler);
}
if (this.keyboardHandler) {
this.keyboardHandler.destroy();
}
}
private cldrTimeFormat(): string {
let cldrTime: string;
if (this.isNullOrEmpty(this.timeFormat)) {
if (this.locale === 'en' || this.locale === 'en-US') {
cldrTime = <string>(getValue('timeFormats.short', getDefaultDateObject()));
} else {
cldrTime = <string>(this.getCultureTimeObject(cldrData, '' + this.locale));
}
} else {
cldrTime = this.timeFormat;
}
return cldrTime;
}
private cldrDateTimeFormat(): string {
let cldrTime: string;
const culture: Internationalization = new Internationalization(this.locale);
const dateFormat: string = culture.getDatePattern({ skeleton: 'yMd' });
if (this.isNullOrEmpty(this.formatString)) {
cldrTime = dateFormat + ' ' + this.getCldrFormat('time');
} else {
cldrTime = this.formatString;
}
return cldrTime;
}
private getCldrFormat(type: string): string {
let cldrDateTime: string;
if (this.locale === 'en' || this.locale === 'en-US') {
cldrDateTime = <string>(getValue('timeFormats.short', getDefaultDateObject()));
} else {
cldrDateTime = <string>(this.getCultureTimeObject(cldrData, '' + this.locale));
}
return cldrDateTime;
}
private isNullOrEmpty(value: Date | string): boolean {
if (isNullOrUndefined(value) || (typeof value === 'string' && value.trim() === '')) {
return true;
} else {
return false;
}
}
protected getCultureTimeObject(ld: Object, c: string): Object {
if (this.calendarMode === 'Gregorian') {
return getValue('main.' + '' + this.locale + '.dates.calendars.gregorian.timeFormats.short', ld);
} else {
return getValue('main.' + '' + this.locale + '.dates.calendars.islamic.timeFormats.short', ld);
}
}
private timeHandler(e?: MouseEvent): void {
if (!this.enabled) {