UNPKG

ng-pick-datetime

Version:
367 lines (366 loc) 13.9 kB
var __extends = (this && this.__extends) || (function () { var extendStatics = function (d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; return extendStatics(d, b); } return function (d, b) { extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); 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); }; var __param = (this && this.__param) || function (paramIndex, decorator) { return function (target, key) { decorator(target, key, paramIndex); } }; import { ChangeDetectionStrategy, ChangeDetectorRef, Component, EventEmitter, forwardRef, HostBinding, Inject, Input, Optional, Output, ViewChild } from '@angular/core'; import { NG_VALUE_ACCESSOR } from '@angular/forms'; import { coerceBooleanProperty } from '@angular/cdk/coercion'; import { OwlDateTime } from './date-time.class'; import { DateTimeAdapter } from './adapter/date-time-adapter.class'; import { OWL_DATE_TIME_FORMATS } from './adapter/date-time-format.class'; import { OwlDateTimeContainerComponent } from './date-time-picker-container.component'; export var OWL_DATETIME_VALUE_ACCESSOR = { provide: NG_VALUE_ACCESSOR, useExisting: forwardRef(function () { return OwlDateTimeInlineComponent; }), multi: true }; var OwlDateTimeInlineComponent = (function (_super) { __extends(OwlDateTimeInlineComponent, _super); function OwlDateTimeInlineComponent(changeDetector, dateTimeAdapter, dateTimeFormats) { var _this = _super.call(this, dateTimeAdapter, dateTimeFormats) || this; _this.changeDetector = changeDetector; _this.dateTimeAdapter = dateTimeAdapter; _this.dateTimeFormats = dateTimeFormats; _this._pickerType = 'both'; _this._disabled = false; _this._selectMode = 'single'; _this._values = []; _this.yearSelected = new EventEmitter(); _this.monthSelected = new EventEmitter(); _this._selecteds = []; _this.onModelChange = function () { }; _this.onModelTouched = function () { }; return _this; } Object.defineProperty(OwlDateTimeInlineComponent.prototype, "pickerType", { get: function () { return this._pickerType; }, set: function (val) { if (val !== this._pickerType) { this._pickerType = val; } }, enumerable: true, configurable: true }); Object.defineProperty(OwlDateTimeInlineComponent.prototype, "disabled", { get: function () { return !!this._disabled; }, set: function (value) { this._disabled = coerceBooleanProperty(value); }, enumerable: true, configurable: true }); Object.defineProperty(OwlDateTimeInlineComponent.prototype, "selectMode", { get: function () { return this._selectMode; }, set: function (mode) { if (mode !== 'single' && mode !== 'range' && mode !== 'rangeFrom' && mode !== 'rangeTo') { throw Error('OwlDateTime Error: invalid selectMode value!'); } this._selectMode = mode; }, enumerable: true, configurable: true }); Object.defineProperty(OwlDateTimeInlineComponent.prototype, "startAt", { get: function () { if (this._startAt) { return this._startAt; } if (this.selectMode === 'single') { return this.value || null; } else if (this.selectMode === 'range' || this.selectMode === 'rangeFrom') { return this.values[0] || null; } else if (this.selectMode === 'rangeTo') { return this.values[1] || null; } else { return null; } }, set: function (date) { this._startAt = this.getValidDate(this.dateTimeAdapter.deserialize(date)); }, enumerable: true, configurable: true }); Object.defineProperty(OwlDateTimeInlineComponent.prototype, "dateTimeFilter", { get: function () { return this._dateTimeFilter; }, set: function (filter) { this._dateTimeFilter = filter; }, enumerable: true, configurable: true }); Object.defineProperty(OwlDateTimeInlineComponent.prototype, "minDateTime", { get: function () { return this._min || null; }, set: function (value) { this._min = this.getValidDate(this.dateTimeAdapter.deserialize(value)); this.changeDetector.markForCheck(); }, enumerable: true, configurable: true }); Object.defineProperty(OwlDateTimeInlineComponent.prototype, "maxDateTime", { get: function () { return this._max || null; }, set: function (value) { this._max = this.getValidDate(this.dateTimeAdapter.deserialize(value)); this.changeDetector.markForCheck(); }, enumerable: true, configurable: true }); Object.defineProperty(OwlDateTimeInlineComponent.prototype, "value", { get: function () { return this._value; }, set: function (value) { value = this.dateTimeAdapter.deserialize(value); value = this.getValidDate(value); this._value = value; this.selected = value; }, enumerable: true, configurable: true }); Object.defineProperty(OwlDateTimeInlineComponent.prototype, "values", { get: function () { return this._values; }, set: function (values) { var _this = this; if (values && values.length > 0) { values = values.map(function (v) { v = _this.dateTimeAdapter.deserialize(v); v = _this.getValidDate(v); return v ? _this.dateTimeAdapter.clone(v) : null; }); this._values = values.slice(); this.selecteds = values.slice(); } else { this._values = []; this.selecteds = []; } }, enumerable: true, configurable: true }); Object.defineProperty(OwlDateTimeInlineComponent.prototype, "selected", { get: function () { return this._selected; }, set: function (value) { this._selected = value; this.changeDetector.markForCheck(); }, enumerable: true, configurable: true }); Object.defineProperty(OwlDateTimeInlineComponent.prototype, "selecteds", { get: function () { return this._selecteds; }, set: function (values) { this._selecteds = values; this.changeDetector.markForCheck(); }, enumerable: true, configurable: true }); Object.defineProperty(OwlDateTimeInlineComponent.prototype, "opened", { get: function () { return true; }, enumerable: true, configurable: true }); Object.defineProperty(OwlDateTimeInlineComponent.prototype, "pickerMode", { get: function () { return 'inline'; }, enumerable: true, configurable: true }); Object.defineProperty(OwlDateTimeInlineComponent.prototype, "isInSingleMode", { get: function () { return this._selectMode === 'single'; }, enumerable: true, configurable: true }); Object.defineProperty(OwlDateTimeInlineComponent.prototype, "isInRangeMode", { get: function () { return this._selectMode === 'range' || this._selectMode === 'rangeFrom' || this._selectMode === 'rangeTo'; }, enumerable: true, configurable: true }); Object.defineProperty(OwlDateTimeInlineComponent.prototype, "owlDTInlineClass", { get: function () { return true; }, enumerable: true, configurable: true }); OwlDateTimeInlineComponent.prototype.ngOnInit = function () { this.container.picker = this; }; OwlDateTimeInlineComponent.prototype.writeValue = function (value) { if (this.isInSingleMode) { this.value = value; this.container.pickerMoment = value; } else { this.values = value; this.container.pickerMoment = this._values[this.container.activeSelectedIndex]; } }; OwlDateTimeInlineComponent.prototype.registerOnChange = function (fn) { this.onModelChange = fn; }; OwlDateTimeInlineComponent.prototype.registerOnTouched = function (fn) { this.onModelTouched = fn; }; OwlDateTimeInlineComponent.prototype.setDisabledState = function (isDisabled) { this.disabled = isDisabled; }; OwlDateTimeInlineComponent.prototype.select = function (date) { if (this.disabled) { return; } if (Array.isArray(date)) { this.values = date.slice(); } else { this.value = date; } this.onModelChange(date); this.onModelTouched(); }; OwlDateTimeInlineComponent.prototype.selectYear = function (normalizedYear) { this.yearSelected.emit(normalizedYear); }; OwlDateTimeInlineComponent.prototype.selectMonth = function (normalizedMonth) { this.monthSelected.emit(normalizedMonth); }; __decorate([ ViewChild(OwlDateTimeContainerComponent), __metadata("design:type", OwlDateTimeContainerComponent) ], OwlDateTimeInlineComponent.prototype, "container", void 0); __decorate([ Input(), __metadata("design:type", String), __metadata("design:paramtypes", [String]) ], OwlDateTimeInlineComponent.prototype, "pickerType", null); __decorate([ Input(), __metadata("design:type", Boolean), __metadata("design:paramtypes", [Boolean]) ], OwlDateTimeInlineComponent.prototype, "disabled", null); __decorate([ Input(), __metadata("design:type", String), __metadata("design:paramtypes", [String]) ], OwlDateTimeInlineComponent.prototype, "selectMode", null); __decorate([ Input(), __metadata("design:type", Object), __metadata("design:paramtypes", [Object]) ], OwlDateTimeInlineComponent.prototype, "startAt", null); __decorate([ Input('owlDateTimeFilter'), __metadata("design:type", Function), __metadata("design:paramtypes", [Function]) ], OwlDateTimeInlineComponent.prototype, "dateTimeFilter", null); __decorate([ Input('min'), __metadata("design:type", Object), __metadata("design:paramtypes", [Object]) ], OwlDateTimeInlineComponent.prototype, "minDateTime", null); __decorate([ Input('max'), __metadata("design:type", Object), __metadata("design:paramtypes", [Object]) ], OwlDateTimeInlineComponent.prototype, "maxDateTime", null); __decorate([ Input(), __metadata("design:type", Object), __metadata("design:paramtypes", [Object]) ], OwlDateTimeInlineComponent.prototype, "value", null); __decorate([ Input(), __metadata("design:type", Array), __metadata("design:paramtypes", [Array]) ], OwlDateTimeInlineComponent.prototype, "values", null); __decorate([ Output(), __metadata("design:type", Object) ], OwlDateTimeInlineComponent.prototype, "yearSelected", void 0); __decorate([ Output(), __metadata("design:type", Object) ], OwlDateTimeInlineComponent.prototype, "monthSelected", void 0); __decorate([ HostBinding('class.owl-dt-inline'), __metadata("design:type", Boolean), __metadata("design:paramtypes", []) ], OwlDateTimeInlineComponent.prototype, "owlDTInlineClass", null); OwlDateTimeInlineComponent = __decorate([ Component({ selector: 'owl-date-time-inline', template: "<owl-date-time-container></owl-date-time-container>", styles: [""], changeDetection: ChangeDetectionStrategy.OnPush, preserveWhitespaces: false, providers: [ OWL_DATETIME_VALUE_ACCESSOR, ], }), __param(1, Optional()), __param(2, Optional()), __param(2, Inject(OWL_DATE_TIME_FORMATS)), __metadata("design:paramtypes", [ChangeDetectorRef, DateTimeAdapter, Object]) ], OwlDateTimeInlineComponent); return OwlDateTimeInlineComponent; }(OwlDateTime)); export { OwlDateTimeInlineComponent };