2018-09-19 13:05:07 +00:00
|
|
|
import ngModule from '../../module';
|
2019-10-08 21:57:02 +00:00
|
|
|
import Field from '../field';
|
2018-09-19 13:05:07 +00:00
|
|
|
|
2019-10-08 21:57:02 +00:00
|
|
|
export default class InputTime extends Field {
|
|
|
|
constructor($element, $scope, $compile, $filter) {
|
|
|
|
super($element, $scope, $compile);
|
2019-09-30 09:30:54 +00:00
|
|
|
this.$filter = $filter;
|
2019-04-11 05:29:41 +00:00
|
|
|
|
2019-10-08 21:57:02 +00:00
|
|
|
this.input = $compile(`<input type="time"></input>`)($scope)[0];
|
|
|
|
this.input.addEventListener('change', () => this.onValueUpdate());
|
2019-04-11 05:29:41 +00:00
|
|
|
}
|
|
|
|
|
2019-10-08 21:57:02 +00:00
|
|
|
get field() {
|
|
|
|
return super.field;
|
2019-03-15 06:40:45 +00:00
|
|
|
}
|
|
|
|
|
2019-10-08 21:57:02 +00:00
|
|
|
set field(value) {
|
2019-10-18 23:18:25 +00:00
|
|
|
this.input.value = this.$filter('date')(value, 'HH:mm');
|
2019-10-08 21:57:02 +00:00
|
|
|
super.field = value;
|
2019-09-30 09:30:54 +00:00
|
|
|
}
|
2019-04-11 05:29:41 +00:00
|
|
|
|
2019-10-08 21:57:02 +00:00
|
|
|
onValueUpdate() {
|
2019-09-30 09:30:54 +00:00
|
|
|
let date = null;
|
|
|
|
let value = this.input.value;
|
2019-04-11 05:29:41 +00:00
|
|
|
|
2022-07-26 09:45:12 +00:00
|
|
|
if (this.field && !this.modelDate)
|
|
|
|
this.modelDate = this.field;
|
|
|
|
|
2019-09-30 09:30:54 +00:00
|
|
|
if (value) {
|
|
|
|
let split = value.split(':').map(i => parseInt(i) || null);
|
2019-10-15 14:19:35 +00:00
|
|
|
|
2022-07-26 09:45:12 +00:00
|
|
|
date = this.modelDate
|
|
|
|
? new Date(this.modelDate)
|
|
|
|
: new Date();
|
2019-09-30 09:30:54 +00:00
|
|
|
date.setHours(split[0], split[1], 0, 0);
|
2019-04-11 05:29:41 +00:00
|
|
|
}
|
|
|
|
|
2019-10-08 21:57:02 +00:00
|
|
|
super.field = date;
|
|
|
|
this.$.$applyAsync();
|
2019-09-09 08:57:10 +00:00
|
|
|
}
|
2018-09-19 13:05:07 +00:00
|
|
|
}
|
|
|
|
|
2019-10-08 21:57:02 +00:00
|
|
|
InputTime.$inject = ['$element', '$scope', '$compile', '$filter'];
|
2018-09-19 13:05:07 +00:00
|
|
|
|
2019-10-08 21:57:02 +00:00
|
|
|
ngModule.vnComponent('vnInputTime', {
|
|
|
|
controller: InputTime
|
2018-09-19 13:05:07 +00:00
|
|
|
});
|