2019-10-08 21:57:02 +00:00
|
|
|
import ngModule from '../../module';
|
|
|
|
import Field from '../field';
|
|
|
|
|
|
|
|
class DatePicker extends Field {
|
2019-10-28 16:31:33 +00:00
|
|
|
constructor($element, $scope, $compile) {
|
2019-10-08 21:57:02 +00:00
|
|
|
super($element, $scope, $compile);
|
|
|
|
|
2019-10-15 14:19:35 +00:00
|
|
|
this.input = $compile(`<input type="date"></input>`)($scope)[0];
|
|
|
|
this.input.addEventListener('change', () => this.onValueUpdate());
|
2019-10-08 21:57:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
onValueUpdate() {
|
|
|
|
let date = null;
|
2019-10-15 14:19:35 +00:00
|
|
|
let value = this.input.value;
|
|
|
|
|
|
|
|
if (value) {
|
|
|
|
date = new Date(value);
|
|
|
|
|
|
|
|
if (this.field) {
|
|
|
|
let orgDate = this.field instanceof Date
|
|
|
|
? this.field
|
|
|
|
: new Date(this.field);
|
|
|
|
|
|
|
|
date.setHours(
|
|
|
|
orgDate.getHours(),
|
|
|
|
orgDate.getMinutes(),
|
|
|
|
orgDate.getSeconds(),
|
|
|
|
orgDate.getMilliseconds()
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2019-10-08 21:57:02 +00:00
|
|
|
|
2019-10-15 14:19:35 +00:00
|
|
|
super.field = date;
|
2019-10-08 21:57:02 +00:00
|
|
|
this.$.$applyAsync();
|
|
|
|
}
|
|
|
|
|
2019-10-15 14:19:35 +00:00
|
|
|
get field() {
|
|
|
|
return super.field;
|
|
|
|
}
|
|
|
|
|
|
|
|
set field(value) {
|
|
|
|
super.field = value;
|
2019-10-18 23:18:25 +00:00
|
|
|
this.input.value = this.$filter('date')(value, 'yyyy-MM-dd');
|
2019-10-08 21:57:02 +00:00
|
|
|
}
|
|
|
|
}
|
2019-10-28 16:31:33 +00:00
|
|
|
DatePicker.$inject = ['$element', '$scope', '$compile'];
|
2019-10-08 21:57:02 +00:00
|
|
|
|
|
|
|
ngModule.vnComponent('vnDatePicker', {
|
|
|
|
controller: DatePicker,
|
|
|
|
bindings: {
|
|
|
|
options: '<?'
|
|
|
|
}
|
|
|
|
});
|