Tarea #320 Hacer que el datepicker añada el dia con la hora local

This commit is contained in:
gerard 2018-05-25 08:54:47 +02:00
parent 255a33f104
commit 3b4cde9b46
1 changed files with 18 additions and 16 deletions

View File

@ -10,7 +10,6 @@ class DatePicker extends Component {
this.$translate = $translate;
this.$attrs = $attrs;
this.enabled = true;
this._modelView = null;
this._model = undefined;
this.dateValue = undefined;
this.hasMouseIn = false;
@ -23,15 +22,26 @@ class DatePicker extends Component {
};
this.userOptions = {};
this._iniOptions = this.defaultOptions;
componentHandler.upgradeElement($element[0].firstChild);
this.vp = new Flatpickr(this.input, this._iniOptions);
}
onValueUpdate() {
if (this.vp.selectedDates.length)
this.model = this.vp.selectedDates[0];
else
if (this.vp.selectedDates.length) {
let date = this.vp.selectedDates[0];
if (!this.isLocale && !this._iniOptions.enableTime) {
let now = new Date();
date.setTime(date.getTime()
+ now.getHours() * 60 * 60 * 1000
+ now.getUTCMinutes() * 60 * 1000
+ now.getUTCSeconds() * 1000
+ now.getUTCMilliseconds()
);
}
this._model = date;
} else
this.model = null;
this.$.$apply();
}
@ -40,10 +50,9 @@ class DatePicker extends Component {
this.userOptions = value;
let options = Object.assign({}, this.defaultOptions, value);
this._iniOptions = options;
this.isTimePicker = options.enableTime && options.noCalendar;
// TODO: When some properties change Flatpickr doesn't refresh the view
//for (let option in options)
// for (let option in options)
// this.vp.set(option, options[option]);
if (this.vp) this.vp.destroy();
@ -67,14 +76,6 @@ class DatePicker extends Component {
this.mdlUpdate();
}
get modelView() {
return this._modelView;
}
set modelView(value) {
this._modelView = value;
}
onClear() {
this.model = null;
}
@ -99,7 +100,8 @@ ngModule.component('vnDatePicker', {
name: '@?',
enabled: '<?',
rule: '<?',
iniOptions: '<?'
iniOptions: '<?',
isLocale: '<?'
},
controller: DatePicker
});