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