-
Notifications
You must be signed in to change notification settings - Fork 24
/
timepicker.controller.js
61 lines (51 loc) · 1.68 KB
/
timepicker.controller.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import { addBooleanParameter, addDefaultParameter } from '@ovh-ux/ui-kit.core/src/js/component-utils';
export default class {
constructor($attrs, $element, $timeout) {
'ngInject';
this.$attrs = $attrs;
this.$element = $element;
this.$timeout = $timeout;
this.options = {
enableTime: true,
enableSeconds: false,
noCalendar: true,
dateFormat: 'H:i',
time_24hr: true,
};
}
setOptionsProperty(property, value) {
if (angular.isDefined(value)) {
this.options[property] = value;
}
}
$onInit() {
addDefaultParameter(this, 'id', `ouiTimepicker${this.$id}`);
addDefaultParameter(this, 'name', `ouiTimepicker${this.$id}`);
addDefaultParameter(this, 'format', this.options.dateFormat);
addDefaultParameter(this, 'altFormat', this.format || this.options.dateFormat);
addBooleanParameter(this, 'appendToBody');
addBooleanParameter(this, 'disabled');
addBooleanParameter(this, 'enableSeconds');
addBooleanParameter(this, 'enableAmPm');
addBooleanParameter(this, 'inline');
addBooleanParameter(this, 'required');
addBooleanParameter(this, 'static');
this.setOptionsProperty('enableSeconds', this.enableSeconds);
this.setOptionsProperty('time_24hr', !this.enableAmPm);
// flatpickr's timepicker need a default value to work in inline mode
if (this.inline) {
this.setOptionsProperty('defaultDate', this.model || 'today');
}
}
$postLink() {
this.$timeout(() => {
this.$element
.addClass('oui-timepicker')
.removeAttr('id')
.removeAttr('name');
if (this.inline) {
this.$element.addClass('oui-timepicker_inline');
}
});
}
}