From 1e06a198844f5cd31c2dd30787a100ae3d9de8da Mon Sep 17 00:00:00 2001 From: Joan Sanchez Date: Thu, 11 Apr 2019 07:29:41 +0200 Subject: [PATCH] input time refactor #1292 --- front/core/components/input-number/index.js | 5 +- front/core/components/input-time/index.html | 8 -- front/core/components/input-time/index.js | 109 +++++++++++++++++--- front/core/filters/dateTime.js | 11 +- modules/agency/front/basic-data/index.html | 3 +- modules/agency/front/create/index.html | 31 +++--- 6 files changed, 116 insertions(+), 51 deletions(-) diff --git a/front/core/components/input-number/index.js b/front/core/components/input-number/index.js index efae9c74a..2e4e73c29 100644 --- a/front/core/components/input-number/index.js +++ b/front/core/components/input-number/index.js @@ -87,8 +87,7 @@ export default class InputNumber extends Input { * @param {Number} value - Value */ set min(value) { - if (!value) value = 0; - this.input.min = value; + if (value) this.input.min = value; } /** @@ -104,7 +103,7 @@ export default class InputNumber extends Input { * @param {Number} value - Value */ set step(value) { - this.input.step = value; + if (value) this.input.step = value; } get validationError() { diff --git a/front/core/components/input-time/index.html b/front/core/components/input-time/index.html index c189168d3..8d885ba47 100644 --- a/front/core/components/input-time/index.html +++ b/front/core/components/input-time/index.html @@ -18,14 +18,6 @@
- - clear - diff --git a/front/core/components/input-time/index.js b/front/core/components/input-time/index.js index 535d6004f..00e7c9118 100644 --- a/front/core/components/input-time/index.js +++ b/front/core/components/input-time/index.js @@ -3,32 +3,113 @@ import Input from '../../lib/input'; import './style.scss'; export default class InputTime extends Input { + constructor($element, $scope) { + super($element, $scope); + + this.registerEvents(); + } + + /** + * Registers all event emitters + */ + registerEvents() { + this.input.addEventListener('change', event => { + this.emit('change', {event}); + }); + + this.input.addEventListener('focus', event => { + this.emit('focus', {event}); + }); + } + + /** + * Gets current value + */ get value() { return this._value; } + /** + * Sets input value + * + * @param {Number} value - Value + */ set value(value) { - if (!value) return; + if (this._value === undefined && value || typeof value === 'string') + value = this.formatTime(value); - let newDate = new Date(value); - newDate.setSeconds(0); - newDate.setMilliseconds(0); + this._value = value; + this.hasValue = !(value === null || value === undefined); - this._value = newDate; - this.hasValue = this._value !== null; - this.input.value = this._value; - - if (this.hasValue) this.element.classList.add('not-empty'); - - this.element.querySelector('.infix').classList.remove('invalid', 'validated'); + if (this.hasValue) + this.element.classList.add('not-empty'); + else + this.element.classList.remove('not-empty'); } + /** + * Gets max value + */ + get max() { + return this.input.max; + } + + /** + * Sets max allowed value + * + * @param {Number} value - Value + */ + set max(value) { + if (value) this.input.max = value; + } + + /** + * Gets min value + */ + get min() { + return this.input.min; + } + + /** + * Sets min allowed value + * + * @param {Number} value - Value + */ + set min(value) { + if (value) this.input.min = value; + } + + /** + * Gets min step value + */ get step() { - return parseInt(this.input.step); + return this.input.step; } + /** + * Sets min step value + * + * @param {Number} value - Value + */ set step(value) { - this.input.step = value; + if (value) this.input.step = value; + } + + /** + * Returns a formatted hour + * @param {Date} date -a + * @return {String} Formatted hour + */ + formatTime(date) { + if (typeof date === 'string') { + date = new Date(date); + date.setTime(date.getTime() + (date.getTimezoneOffset() * 60000)); + } + + date.setSeconds(null); + date.setMilliseconds(null); + + return date; } } @@ -46,6 +127,8 @@ ngModule.component('vnInputTime', { disabled: ' - diff --git a/modules/agency/front/create/index.html b/modules/agency/front/create/index.html index eef4be8ba..d25c91219 100644 --- a/modules/agency/front/create/index.html +++ b/modules/agency/front/create/index.html @@ -15,16 +15,14 @@ - - - + model="$ctrl.zone.travelingDays" + min="0" step="1"> - + model="$ctrl.zone.hour" + rule="zone.hour"> + model="$ctrl.zone.price" + min="0" step="0.01"> + model="$ctrl.zone.bonus" + min="0" step="0.01">