78 lines
1.8 KiB
JavaScript
78 lines
1.8 KiB
JavaScript
import ngModule from '../../module';
|
|
import Textfield from '../textfield/textfield';
|
|
import './style.scss';
|
|
|
|
export default class InputTime extends Textfield {
|
|
set offsetedValue(value) {
|
|
this._offsetedValue = value;
|
|
|
|
let date = new Date(value);
|
|
let offset = date.getTimezoneOffset() * 60000;
|
|
date.setTime(date.getTime() - offset);
|
|
this._value = date;
|
|
}
|
|
|
|
get offsetedValue() {
|
|
return this._offsetedValue;
|
|
}
|
|
|
|
get value() {
|
|
return this._value;
|
|
}
|
|
|
|
set value(value) {
|
|
if (!value) return;
|
|
if (!this._offsetedValue) {
|
|
let date = new Date(value);
|
|
date.setSeconds(0);
|
|
date.setMilliseconds(0);
|
|
let offset = date.getTimezoneOffset() * 60000;
|
|
date.setTime(date.getTime() + offset);
|
|
this.offsetedValue = date;
|
|
}
|
|
|
|
this.hasValue = this._offsetedValue !== null;
|
|
|
|
if (this.hasValue) this.element.classList.add('not-empty');
|
|
|
|
this.element.querySelector('.infix').classList.remove('invalid', 'validated');
|
|
}
|
|
|
|
get step() {
|
|
return parseInt(this.input.step);
|
|
}
|
|
|
|
set step(value) {
|
|
this.input.step = value;
|
|
}
|
|
|
|
clear() {
|
|
this.saveOldValue();
|
|
this.offsetedValue = null;
|
|
if (this.onClear) this.onClear();
|
|
this.input.focus();
|
|
}
|
|
}
|
|
|
|
InputTime.$inject = ['$element', '$scope', '$attrs', 'vnTemplate', '$transclude'];
|
|
|
|
ngModule.component('vnInputTime', {
|
|
template: require('./index.html'),
|
|
controller: InputTime,
|
|
transclude: {
|
|
leftIcons: '?tLeftIcons',
|
|
rightIcons: '?tRightIcons'
|
|
},
|
|
bindings: {
|
|
label: '@?',
|
|
disabled: '<?',
|
|
readonly: '<?',
|
|
step: '<?',
|
|
rule: '@?',
|
|
value: '=model',
|
|
vnTabIndex: '@?',
|
|
onChange: '&',
|
|
onClear: '&'
|
|
}
|
|
});
|