42 lines
1.1 KiB
JavaScript
42 lines
1.1 KiB
JavaScript
import ngModule from '../../module';
|
|
import Field from '../field';
|
|
|
|
export default class InputTime extends Field {
|
|
constructor($element, $scope, $compile, $filter) {
|
|
super($element, $scope, $compile);
|
|
this.$filter = $filter;
|
|
|
|
this.input = $compile(`<input type="time"></input>`)($scope)[0];
|
|
this.input.addEventListener('change', () => this.onValueUpdate());
|
|
}
|
|
|
|
get field() {
|
|
return super.field;
|
|
}
|
|
|
|
set field(value) {
|
|
this.input.value = this.$filter('dateTime')(value, 'HH:mm');
|
|
super.field = value;
|
|
}
|
|
|
|
onValueUpdate() {
|
|
let date = null;
|
|
let value = this.input.value;
|
|
|
|
if (value) {
|
|
let split = value.split(':').map(i => parseInt(i) || null);
|
|
date = new Date(this.field || null);
|
|
date.setHours(split[0], split[1], 0, 0);
|
|
}
|
|
|
|
super.field = date;
|
|
this.$.$applyAsync();
|
|
}
|
|
}
|
|
|
|
InputTime.$inject = ['$element', '$scope', '$compile', '$filter'];
|
|
|
|
ngModule.vnComponent('vnInputTime', {
|
|
controller: InputTime
|
|
});
|