/*! * devextreme-angular-test * Version: 17.2.8 * Build date: Mon Feb 05 2018 * * Copyright (c) 2012 - 2018 Developer Express Inc. ALL RIGHTS RESERVED * * This software may be modified and distributed under the terms * of the MIT license. See the LICENSE file in the root of the project for details. * * https://github.com/DevExpress/devextreme-angular */ import { Component, NgModule, ElementRef, NgZone, Input, Output, OnDestroy, Injector, EventEmitter, OnInit, AfterViewInit, ContentChild, forwardRef, HostListener, OnChanges, DoCheck, SimpleChanges } from '@angular/core'; import DevExpress from 'devextreme/bundles/dx.all'; import DxDateBox from 'devextreme/ui/date_box'; import { DxValidatorComponent } from './validator'; import { ControlValueAccessor, NG_VALUE_ACCESSOR } from '@angular/forms'; import { DxComponent } from '../core/component'; import { DxTemplateHost } from '../core/template-host'; import { DxTemplateModule } from '../core/template'; import { EventsRegistrator } from '../core/events-strategy'; import { NestedOptionHost } from '../core/nested-option'; import { WatcherHelper } from '../core/watcher-helper'; import { IterableDifferHelper } from '../core/iterable-differ-helper'; import { DxoDisplayFormatModule } from './nested/display-format'; const CUSTOM_VALUE_ACCESSOR_PROVIDER = { provide: NG_VALUE_ACCESSOR, useExisting: forwardRef(() => DxDateBoxComponent), multi: true }; /** * The DateBox is a widget that displays date and time in a specified format, and enables a user to pick or type in the required date/time value. */ @Component({ selector: 'dx-date-box', template: '', providers: [ DxTemplateHost, WatcherHelper, CUSTOM_VALUE_ACCESSOR_PROVIDER, NestedOptionHost, IterableDifferHelper ] }) export class DxDateBoxComponent extends DxComponent implements OnDestroy, OnInit, AfterViewInit, ControlValueAccessor, OnChanges, DoCheck { instance: DxDateBox; @ContentChild(DxValidatorComponent) validator: DxValidatorComponent; /** * Specifies whether or not the widget allows an end-user to enter a custom value. */ @Input() get acceptCustomValue(): boolean { return this._getOption('acceptCustomValue'); } set acceptCustomValue(value: boolean) { this._setOption('acceptCustomValue', value); } /** * Specifies the shortcut key that sets focus on the widget. */ @Input() get accessKey(): string { return this._getOption('accessKey'); } set accessKey(value: string) { this._setOption('accessKey', value); } /** * Specifies whether or not the widget changes its state when interacting with a user. */ @Input() get activeStateEnabled(): boolean { return this._getOption('activeStateEnabled'); } set activeStateEnabled(value: boolean) { this._setOption('activeStateEnabled', value); } /** * Specifies whether or not adaptive widget rendering is enabled on a small screen. */ @Input() get adaptivityEnabled(): boolean { return this._getOption('adaptivityEnabled'); } set adaptivityEnabled(value: boolean) { this._setOption('adaptivityEnabled', value); } /** * The text displayed on the Apply button. */ @Input() get applyButtonText(): string { return this._getOption('applyButtonText'); } set applyButtonText(value: string) { this._setOption('applyButtonText', value); } /** * Specifies the way an end-user applies the selected value. */ @Input() get applyValueMode(): string { return this._getOption('applyValueMode'); } set applyValueMode(value: string) { this._setOption('applyValueMode', value); } @Input() get attr(): any { return this._getOption('attr'); } set attr(value: any) { this._setOption('attr', value); } /** * The text displayed on the Cancel button. */ @Input() get cancelButtonText(): string { return this._getOption('cancelButtonText'); } set cancelButtonText(value: string) { this._setOption('cancelButtonText', value); } /** * Specifies the message displayed if the specified date is later than the max value or earlier than the min value. */ @Input() get dateOutOfRangeMessage(): string { return this._getOption('dateOutOfRangeMessage'); } set dateOutOfRangeMessage(value: string) { this._setOption('dateOutOfRangeMessage', value); } /** * Specifies the date-time value serialization format. Use it only if you do not specify the value at design time. */ @Input() get dateSerializationFormat(): string { return this._getOption('dateSerializationFormat'); } set dateSerializationFormat(value: string) { this._setOption('dateSerializationFormat', value); } /** * Specifies whether widget content is rendered when the widget is shown or when rendering the widget. */ @Input() get deferRendering(): boolean { return this._getOption('deferRendering'); } set deferRendering(value: boolean) { this._setOption('deferRendering', value); } /** * Specifies whether the widget responds to user interaction. */ @Input() get disabled(): boolean { return this._getOption('disabled'); } set disabled(value: boolean) { this._setOption('disabled', value); } /** * Specifies dates to be disabled. Applies only if pickerType is "calendar". */ @Input() get disabledDates(): Function| Array { return this._getOption('disabledDates'); } set disabledDates(value: Function| Array) { this._setOption('disabledDates', value); } /** * Specifies the date display format. Ignored if the pickerType option is 'native' */ @Input() get displayFormat(): DevExpress.ui.format| string { return this._getOption('displayFormat'); } set displayFormat(value: DevExpress.ui.format| string) { this._setOption('displayFormat', value); } /** * Specifies a custom template for the drop-down button. */ @Input() get dropDownButtonTemplate(): any { return this._getOption('dropDownButtonTemplate'); } set dropDownButtonTemplate(value: any) { this._setOption('dropDownButtonTemplate', value); } /** * Specifies the attributes to be attached to the widget's root element. */ @Input() get elementAttr(): any { return this._getOption('elementAttr'); } set elementAttr(value: any) { this._setOption('elementAttr', value); } @Input() get fieldEditEnabled(): any { return this._getOption('fieldEditEnabled'); } set fieldEditEnabled(value: any) { this._setOption('fieldEditEnabled', value); } /** * Specifies whether the widget can be focused using keyboard navigation. */ @Input() get focusStateEnabled(): boolean { return this._getOption('focusStateEnabled'); } set focusStateEnabled(value: boolean) { this._setOption('focusStateEnabled', value); } @Input() get format(): any { return this._getOption('format'); } set format(value: any) { this._setOption('format', value); } @Input() get formatString(): any { return this._getOption('formatString'); } set formatString(value: any) { this._setOption('formatString', value); } /** * Specifies the widget's height. */ @Input() get height(): number| Function| string { return this._getOption('height'); } set height(value: number| Function| string) { this._setOption('height', value); } /** * Specifies text for a hint that appears when a user pauses on the widget. */ @Input() get hint(): string { return this._getOption('hint'); } set hint(value: string) { this._setOption('hint', value); } /** * Specifies whether the widget changes its state when a user pauses on it. */ @Input() get hoverStateEnabled(): boolean { return this._getOption('hoverStateEnabled'); } set hoverStateEnabled(value: boolean) { this._setOption('hoverStateEnabled', value); } /** * Specifies the attributes to be passed on to the underlying HTML element. */ @Input() get inputAttr(): any { return this._getOption('inputAttr'); } set inputAttr(value: any) { this._setOption('inputAttr', value); } /** * Specifies the interval between neighboring values in the popup list in minutes. */ @Input() get interval(): number { return this._getOption('interval'); } set interval(value: number) { this._setOption('interval', value); } /** * Specifies the message displayed if the typed value is not a valid date or time. */ @Input() get invalidDateMessage(): string { return this._getOption('invalidDateMessage'); } set invalidDateMessage(value: string) { this._setOption('invalidDateMessage', value); } /** * Specifies whether the editor's value is valid. */ @Input() get isValid(): boolean { return this._getOption('isValid'); } set isValid(value: boolean) { this._setOption('isValid', value); } /** * The last date that can be selected within the widget. */ @Input() get max(): Date| number| string { return this._getOption('max'); } set max(value: Date| number| string) { this._setOption('max', value); } /** * Specifies the maximum number of characters you can enter into the textbox. */ @Input() get maxLength(): number| string { return this._getOption('maxLength'); } set maxLength(value: number| string) { this._setOption('maxLength', value); } /** * Specifies the maximum zoom level of a calendar, which is used to pick the date. */ @Input() get maxZoomLevel(): string { return this._getOption('maxZoomLevel'); } set maxZoomLevel(value: string) { this._setOption('maxZoomLevel', value); } /** * The minimum date that can be selected within the widget. */ @Input() get min(): Date| number| string { return this._getOption('min'); } set min(value: Date| number| string) { this._setOption('min', value); } /** * Specifies the minimal zoom level of a calendar, which is used to pick the date. */ @Input() get minZoomLevel(): string { return this._getOption('minZoomLevel'); } set minZoomLevel(value: string) { this._setOption('minZoomLevel', value); } /** * The value to be assigned to the `name` attribute of the underlying HTML element. */ @Input() get name(): string { return this._getOption('name'); } set name(value: string) { this._setOption('name', value); } /** * Specifies whether or not the drop-down editor is displayed. */ @Input() get opened(): boolean { return this._getOption('opened'); } set opened(value: boolean) { this._setOption('opened', value); } /** * Specifies the type of the date/time picker. */ @Input() get pickerType(): string { return this._getOption('pickerType'); } set pickerType(value: string) { this._setOption('pickerType', value); } /** * Specifies a placeholder for the input field. */ @Input() get placeholder(): string { return this._getOption('placeholder'); } set placeholder(value: string) { this._setOption('placeholder', value); } /** * A Boolean value specifying whether or not the widget is read-only. */ @Input() get readOnly(): boolean { return this._getOption('readOnly'); } set readOnly(value: boolean) { this._setOption('readOnly', value); } /** * Switches the widget to a right-to-left representation. */ @Input() get rtlEnabled(): boolean { return this._getOption('rtlEnabled'); } set rtlEnabled(value: boolean) { this._setOption('rtlEnabled', value); } /** * Specifies whether to display the Clear button in the widget. */ @Input() get showClearButton(): boolean { return this._getOption('showClearButton'); } set showClearButton(value: boolean) { this._setOption('showClearButton', value); } /** * Specifies whether or not the widget checks the inner text for spelling mistakes. */ @Input() get spellcheck(): boolean { return this._getOption('spellcheck'); } set spellcheck(value: boolean) { this._setOption('spellcheck', value); } /** * Specifies the number of the element when the Tab key is used for navigating. */ @Input() get tabIndex(): number { return this._getOption('tabIndex'); } set tabIndex(value: number) { this._setOption('tabIndex', value); } /** * The read-only option that holds the text displayed by the widget input element. */ @Input() get text(): string { return this._getOption('text'); } set text(value: string) { this._setOption('text', value); } /** * A format used to display date/time information. */ @Input() get type(): string { return this._getOption('type'); } set type(value: string) { this._setOption('type', value); } /** * Use the pickerType option instead. */ @Input() get useCalendar(): boolean { return this._getOption('useCalendar'); } set useCalendar(value: boolean) { this._setOption('useCalendar', value); } /** * Use the pickerType option instead. */ @Input() get useNative(): boolean { return this._getOption('useNative'); } set useNative(value: boolean) { this._setOption('useNative', value); } /** * Specifies information on the validation error when using a custom validation engine. Should be changed at runtime along with the isValid option. */ @Input() get validationError(): any { return this._getOption('validationError'); } set validationError(value: any) { this._setOption('validationError', value); } /** * Specifies how the message about the validation rules that are not satisfied by this editor's value is displayed. */ @Input() get validationMessageMode(): string { return this._getOption('validationMessageMode'); } set validationMessageMode(value: string) { this._setOption('validationMessageMode', value); } /** * An object or a value specifying the date and time currently selected using the date box. */ @Input() get value(): Date| number| string { return this._getOption('value'); } set value(value: Date| number| string) { this._setOption('value', value); } /** * Specifies DOM event names that update a widget's value. */ @Input() get valueChangeEvent(): string { return this._getOption('valueChangeEvent'); } set valueChangeEvent(value: string) { this._setOption('valueChangeEvent', value); } /** * Specifies whether the widget is visible. */ @Input() get visible(): boolean { return this._getOption('visible'); } set visible(value: boolean) { this._setOption('visible', value); } /** * Specifies the widget's width. */ @Input() get width(): number| Function| string { return this._getOption('width'); } set width(value: number| Function| string) { this._setOption('width', value); } /** * A handler for the change event. */ @Output() onChange: EventEmitter; /** * A handler for the closed event. */ @Output() onClosed: EventEmitter; /** * A handler for the contentReady event. Executed when the widget's content is ready. This handler may be executed multiple times during the widget's lifetime depending on the number of times its content changes. */ @Output() onContentReady: EventEmitter; /** * A handler for the copy event. */ @Output() onCopy: EventEmitter; /** * A handler for the cut event. */ @Output() onCut: EventEmitter; /** * A handler for the disposing event. Executed when the widget is removed from the DOM using the remove(), empty(), or html() jQuery methods only. */ @Output() onDisposing: EventEmitter; /** * A handler for the enterKey event. */ @Output() onEnterKey: EventEmitter; /** * A handler for the focusIn event. */ @Output() onFocusIn: EventEmitter; /** * A handler for the focusOut event. */ @Output() onFocusOut: EventEmitter; /** * A handler for the initialized event. Executed only once, after the widget is initialized. */ @Output() onInitialized: EventEmitter; /** * A handler for the input event. */ @Output() onInput: EventEmitter; /** * A handler for the keyDown event. */ @Output() onKeyDown: EventEmitter; /** * A handler for the keyPress event. */ @Output() onKeyPress: EventEmitter; /** * A handler for the keyUp event. */ @Output() onKeyUp: EventEmitter; /** * A handler for the opened event. */ @Output() onOpened: EventEmitter; /** * A handler for the optionChanged event. Executed after an option of the widget is changed. */ @Output() onOptionChanged: EventEmitter; /** * A handler for the paste event. */ @Output() onPaste: EventEmitter; /** * A handler for the valueChanged event. */ @Output() onValueChanged: EventEmitter; /** * A handler for the acceptCustomValueChange event. */ @Output() acceptCustomValueChange: EventEmitter; /** * A handler for the accessKeyChange event. */ @Output() accessKeyChange: EventEmitter; /** * A handler for the activeStateEnabledChange event. */ @Output() activeStateEnabledChange: EventEmitter; /** * A handler for the adaptivityEnabledChange event. */ @Output() adaptivityEnabledChange: EventEmitter; /** * A handler for the applyButtonTextChange event. */ @Output() applyButtonTextChange: EventEmitter; /** * A handler for the applyValueModeChange event. */ @Output() applyValueModeChange: EventEmitter; /** * A handler for the attrChange event. */ @Output() attrChange: EventEmitter; /** * A handler for the cancelButtonTextChange event. */ @Output() cancelButtonTextChange: EventEmitter; /** * A handler for the dateOutOfRangeMessageChange event. */ @Output() dateOutOfRangeMessageChange: EventEmitter; /** * A handler for the dateSerializationFormatChange event. */ @Output() dateSerializationFormatChange: EventEmitter; /** * A handler for the deferRenderingChange event. */ @Output() deferRenderingChange: EventEmitter; /** * A handler for the disabledChange event. */ @Output() disabledChange: EventEmitter; /** * A handler for the disabledDatesChange event. */ @Output() disabledDatesChange: EventEmitter>; /** * A handler for the displayFormatChange event. */ @Output() displayFormatChange: EventEmitter; /** * A handler for the dropDownButtonTemplateChange event. */ @Output() dropDownButtonTemplateChange: EventEmitter; /** * A handler for the elementAttrChange event. */ @Output() elementAttrChange: EventEmitter; /** * A handler for the fieldEditEnabledChange event. */ @Output() fieldEditEnabledChange: EventEmitter; /** * A handler for the focusStateEnabledChange event. */ @Output() focusStateEnabledChange: EventEmitter; /** * A handler for the formatChange event. */ @Output() formatChange: EventEmitter; /** * A handler for the formatStringChange event. */ @Output() formatStringChange: EventEmitter; /** * A handler for the heightChange event. */ @Output() heightChange: EventEmitter; /** * A handler for the hintChange event. */ @Output() hintChange: EventEmitter; /** * A handler for the hoverStateEnabledChange event. */ @Output() hoverStateEnabledChange: EventEmitter; /** * A handler for the inputAttrChange event. */ @Output() inputAttrChange: EventEmitter; /** * A handler for the intervalChange event. */ @Output() intervalChange: EventEmitter; /** * A handler for the invalidDateMessageChange event. */ @Output() invalidDateMessageChange: EventEmitter; /** * A handler for the isValidChange event. */ @Output() isValidChange: EventEmitter; /** * A handler for the maxChange event. */ @Output() maxChange: EventEmitter; /** * A handler for the maxLengthChange event. */ @Output() maxLengthChange: EventEmitter; /** * A handler for the maxZoomLevelChange event. */ @Output() maxZoomLevelChange: EventEmitter; /** * A handler for the minChange event. */ @Output() minChange: EventEmitter; /** * A handler for the minZoomLevelChange event. */ @Output() minZoomLevelChange: EventEmitter; /** * A handler for the nameChange event. */ @Output() nameChange: EventEmitter; /** * A handler for the openedChange event. */ @Output() openedChange: EventEmitter; /** * A handler for the pickerTypeChange event. */ @Output() pickerTypeChange: EventEmitter; /** * A handler for the placeholderChange event. */ @Output() placeholderChange: EventEmitter; /** * A handler for the readOnlyChange event. */ @Output() readOnlyChange: EventEmitter; /** * A handler for the rtlEnabledChange event. */ @Output() rtlEnabledChange: EventEmitter; /** * A handler for the showClearButtonChange event. */ @Output() showClearButtonChange: EventEmitter; /** * A handler for the spellcheckChange event. */ @Output() spellcheckChange: EventEmitter; /** * A handler for the tabIndexChange event. */ @Output() tabIndexChange: EventEmitter; /** * A handler for the textChange event. */ @Output() textChange: EventEmitter; /** * A handler for the typeChange event. */ @Output() typeChange: EventEmitter; /** * A handler for the useCalendarChange event. */ @Output() useCalendarChange: EventEmitter; /** * A handler for the useNativeChange event. */ @Output() useNativeChange: EventEmitter; /** * A handler for the validationErrorChange event. */ @Output() validationErrorChange: EventEmitter; /** * A handler for the validationMessageModeChange event. */ @Output() validationMessageModeChange: EventEmitter; /** * A handler for the valueChange event. */ @Output() valueChange: EventEmitter; /** * A handler for the valueChangeEventChange event. */ @Output() valueChangeEventChange: EventEmitter; /** * A handler for the visibleChange event. */ @Output() visibleChange: EventEmitter; /** * A handler for the widthChange event. */ @Output() widthChange: EventEmitter; @Output() onBlur: EventEmitter; @HostListener('valueChange', ['$event']) change(_) { } @HostListener('onBlur', ['$event']) touched = () => {}; constructor(elementRef: ElementRef, ngZone: NgZone, templateHost: DxTemplateHost, injector: Injector, private _watcherHelper: WatcherHelper, private _idh: IterableDifferHelper, optionHost: NestedOptionHost) { super(elementRef, ngZone, templateHost, _watcherHelper); injector.get(EventsRegistrator); this._createEventEmitters([ { subscribe: 'change', emit: 'onChange' }, { subscribe: 'closed', emit: 'onClosed' }, { subscribe: 'contentReady', emit: 'onContentReady' }, { subscribe: 'copy', emit: 'onCopy' }, { subscribe: 'cut', emit: 'onCut' }, { subscribe: 'disposing', emit: 'onDisposing' }, { subscribe: 'enterKey', emit: 'onEnterKey' }, { subscribe: 'focusIn', emit: 'onFocusIn' }, { subscribe: 'focusOut', emit: 'onFocusOut' }, { subscribe: 'initialized', emit: 'onInitialized' }, { subscribe: 'input', emit: 'onInput' }, { subscribe: 'keyDown', emit: 'onKeyDown' }, { subscribe: 'keyPress', emit: 'onKeyPress' }, { subscribe: 'keyUp', emit: 'onKeyUp' }, { subscribe: 'opened', emit: 'onOpened' }, { subscribe: 'optionChanged', emit: 'onOptionChanged' }, { subscribe: 'paste', emit: 'onPaste' }, { subscribe: 'valueChanged', emit: 'onValueChanged' }, { emit: 'acceptCustomValueChange' }, { emit: 'accessKeyChange' }, { emit: 'activeStateEnabledChange' }, { emit: 'adaptivityEnabledChange' }, { emit: 'applyButtonTextChange' }, { emit: 'applyValueModeChange' }, { emit: 'attrChange' }, { emit: 'cancelButtonTextChange' }, { emit: 'dateOutOfRangeMessageChange' }, { emit: 'dateSerializationFormatChange' }, { emit: 'deferRenderingChange' }, { emit: 'disabledChange' }, { emit: 'disabledDatesChange' }, { emit: 'displayFormatChange' }, { emit: 'dropDownButtonTemplateChange' }, { emit: 'elementAttrChange' }, { emit: 'fieldEditEnabledChange' }, { emit: 'focusStateEnabledChange' }, { emit: 'formatChange' }, { emit: 'formatStringChange' }, { emit: 'heightChange' }, { emit: 'hintChange' }, { emit: 'hoverStateEnabledChange' }, { emit: 'inputAttrChange' }, { emit: 'intervalChange' }, { emit: 'invalidDateMessageChange' }, { emit: 'isValidChange' }, { emit: 'maxChange' }, { emit: 'maxLengthChange' }, { emit: 'maxZoomLevelChange' }, { emit: 'minChange' }, { emit: 'minZoomLevelChange' }, { emit: 'nameChange' }, { emit: 'openedChange' }, { emit: 'pickerTypeChange' }, { emit: 'placeholderChange' }, { emit: 'readOnlyChange' }, { emit: 'rtlEnabledChange' }, { emit: 'showClearButtonChange' }, { emit: 'spellcheckChange' }, { emit: 'tabIndexChange' }, { emit: 'textChange' }, { emit: 'typeChange' }, { emit: 'useCalendarChange' }, { emit: 'useNativeChange' }, { emit: 'validationErrorChange' }, { emit: 'validationMessageModeChange' }, { emit: 'valueChange' }, { emit: 'valueChangeEventChange' }, { emit: 'visibleChange' }, { emit: 'widthChange' }, { emit: 'onBlur' } ]); this._idh.setHost(this); optionHost.setHost(this); } protected _createInstance(element, options) { return new DxDateBox(element, options); } writeValue(value: any): void { this.value = value; } setDisabledState(isDisabled: boolean): void { this.disabled = isDisabled; } registerOnChange(fn: (_: any) => void): void { this.change = fn; } registerOnTouched(fn: () => void): void { this.touched = fn; } _createWidget(element: any) { super._createWidget(element); this.instance.on('focusOut', (e) => { this.eventHelper.fireNgEvent('onBlur', [e]); }); } ngOnDestroy() { this._destroyWidget(); } ngOnChanges(changes: SimpleChanges) { super.ngOnChanges(changes); this.setupChanges('disabledDates', changes); } setupChanges(prop: string, changes: SimpleChanges) { if (!(prop in this._optionsToUpdate)) { this._idh.setup(prop, changes); } } ngDoCheck() { this._idh.doCheck('disabledDates'); this._watcherHelper.checkWatchers(); super.ngDoCheck(); } _setOption(name: string, value: any) { let isSetup = this._idh.setupSingle(name, value); let isChanged = this._idh.getChanges(name, value) !== null; if (isSetup || isChanged) { super._setOption(name, value); } } ngOnInit() { super.ngOnInit(); if (this.validator) { this.validator.createInstanceOnInit = false; } } ngAfterViewInit() { super.ngAfterViewInit(); if (this.validator) { this.validator.createInstance(this.element.nativeElement); } } } @NgModule({ imports: [ DxoDisplayFormatModule, DxTemplateModule ], declarations: [ DxDateBoxComponent ], exports: [ DxDateBoxComponent, DxoDisplayFormatModule, DxTemplateModule ], providers: [EventsRegistrator] }) export class DxDateBoxModule { }