UNPKG

nakedobjects.spa

Version:

Single Page Application client for a Naked Objects application.

147 lines 5.72 kB
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; }; var __metadata = (this && this.__metadata) || function (k, v) { if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); }; import { Component, ElementRef, Input, Output, EventEmitter, ViewChild, Renderer } from '@angular/core'; import * as moment from 'moment'; import { BehaviorSubject } from 'rxjs'; import { safeUnsubscribe, focus } from '../helpers-components'; import * as Models from '../models'; var TimePickerComponent = (function () { function TimePickerComponent(el, renderer) { this.el = el; this.renderer = renderer; this.validInputFormats = ["HH:mm:ss", "HH:mm", "HHmm"]; this.outputEvents = new EventEmitter(); } Object.defineProperty(TimePickerComponent.prototype, "model", { get: function () { return this.modelValue; }, set: function (s) { this.modelValue = s; if (this.bSubject) { this.bSubject.next(s); } }, enumerable: true, configurable: true }); Object.defineProperty(TimePickerComponent.prototype, "time", { get: function () { return this.timeValue; }, set: function (time) { if (time && time.isValid()) { this.timeValue = time; this.outputEvents.emit({ type: 'timeChanged', data: time.format("HH:mm:ss") }); } }, enumerable: true, configurable: true }); TimePickerComponent.prototype.validateTime = function (newValue) { var dt = moment(); for (var _i = 0, _a = this.validInputFormats; _i < _a.length; _i++) { var f = _a[_i]; dt = moment.utc(newValue, f, true); if (dt.isValid()) { break; } } return dt; }; TimePickerComponent.prototype.setTimeIfChanged = function (newTime) { var _this = this; if (!newTime.isSame(Models.withUndefined(this.time))) { this.time = newTime; setTimeout(function () { return _this.model = newTime.format("HH:mm"); }); } }; TimePickerComponent.prototype.setTime = function (newValue) { if (newValue === "" || newValue == null) { this.timeValue = null; this.outputEvents.emit({ type: 'timeCleared', data: "" }); } else { var dt = this.validateTime(newValue); if (dt.isValid()) { this.setTimeIfChanged(dt); } else { this.timeValue = null; this.outputEvents.emit({ type: 'timeInvalid', data: newValue }); } } }; TimePickerComponent.prototype.inputChanged = function (newValue) { this.setTime(newValue); }; TimePickerComponent.prototype.ngOnInit = function () { var _this = this; if (this.inputEvents) { this.eventsSub = this.inputEvents.subscribe(function (e) { if (e.type === 'setTime') { _this.setTime(e.data); } }); } }; TimePickerComponent.prototype.clear = function () { this.modelValue = ""; this.setTime(""); }; Object.defineProperty(TimePickerComponent.prototype, "subject", { get: function () { var _this = this; if (!this.bSubject) { var initialValue = this.model; this.bSubject = new BehaviorSubject(initialValue); this.sub = this.bSubject.debounceTime(200).subscribe(function (data) { return _this.inputChanged(data); }); } return this.bSubject; }, enumerable: true, configurable: true }); TimePickerComponent.prototype.ngOnDestroy = function () { safeUnsubscribe(this.sub); safeUnsubscribe(this.eventsSub); }; TimePickerComponent.prototype.focus = function () { return focus(this.renderer, this.inputField); }; return TimePickerComponent; }()); __decorate([ Input(), __metadata("design:type", EventEmitter) ], TimePickerComponent.prototype, "inputEvents", void 0); __decorate([ Output(), __metadata("design:type", EventEmitter) ], TimePickerComponent.prototype, "outputEvents", void 0); __decorate([ Input(), __metadata("design:type", String) ], TimePickerComponent.prototype, "id", void 0); __decorate([ ViewChild("focus"), __metadata("design:type", ElementRef) ], TimePickerComponent.prototype, "inputField", void 0); TimePickerComponent = __decorate([ Component({ selector: 'nof-time-picker', template: require('./time-picker.component.html'), styles: [require('./time-picker.component.css')] }), __metadata("design:paramtypes", [ElementRef, Renderer]) ], TimePickerComponent); export { TimePickerComponent }; //# sourceMappingURL=time-picker.component.js.map