UNPKG

devextreme

Version:

HTML5 JavaScript Component Suite for Responsive Web Development

160 lines (134 loc) 5.25 kB
"use strict"; var Calendar = require("../calendar"), DateBoxStrategy = require("./ui.date_box.strategy"), dateUtils = require("../../core/utils/date"), commonUtils = require("../../core/utils/common"), isFunction = require("../../core/utils/type").isFunction, extend = require("../../core/utils/extend").extend, messageLocalization = require("../../localization/message"); var CalendarStrategy = DateBoxStrategy.inherit({ NAME: "Calendar", supportedKeys: function supportedKeys() { return { rightArrow: function rightArrow() { if (this.option("opened")) { return true; } }, leftArrow: function leftArrow() { if (this.option("opened")) { return true; } }, enter: function (e) { if (this.dateBox.option("opened")) { e.preventDefault(); if (this._widget.option("zoomLevel") === this._widget.option("maxZoomLevel")) { var contouredDate = this._widget._view.option("contouredDate"); contouredDate && this.dateBoxValue(contouredDate, e); this.dateBox.close(); this.dateBox._valueChangeEventHandler(e); } else { return true; } } else { this.dateBox._valueChangeEventHandler(e); } }.bind(this) }; }, getDisplayFormat: function getDisplayFormat(displayFormat) { return displayFormat || "shortdate"; }, _getWidgetName: function _getWidgetName() { return Calendar; }, _getWidgetOptions: function _getWidgetOptions() { var disabledDates = this.dateBox.option("disabledDates"); return extend(this.dateBox.option("calendarOptions"), { value: this.dateBoxValue() || null, dateSerializationFormat: null, _keyboardProcessor: this._widgetKeyboardProcessor, min: this.dateBox.dateOption("min"), max: this.dateBox.dateOption("max"), onValueChanged: this._valueChangedHandler.bind(this), onCellClick: this._cellClickHandler.bind(this), tabIndex: null, disabledDates: isFunction(disabledDates) ? this._injectComponent(disabledDates.bind(this.dateBox)) : disabledDates, onContouredChanged: this._refreshActiveDescendant.bind(this), hasFocus: function hasFocus() { return true; } }); }, _injectComponent: function _injectComponent(func) { var that = this; return function (params) { extend(params, { component: that.dateBox }); return func(params); }; }, _refreshActiveDescendant: function _refreshActiveDescendant(e) { this.dateBox.setAria("activedescendant", e.actionValue); }, popupConfig: function popupConfig(_popupConfig) { var toolbarItems = _popupConfig.toolbarItems, buttonsLocation = this.dateBox.option("buttonsLocation"); var position = []; if (buttonsLocation !== "default") { position = commonUtils.splitPair(buttonsLocation); } else { position = ["bottom", "center"]; } if (this.dateBox.option("applyValueMode") === "useButtons") { toolbarItems.unshift({ widget: "dxButton", toolbar: position[0], location: position[1] === "after" ? "before" : position[1], options: { onClick: function () { this._widget._toTodayView(); }.bind(this), text: messageLocalization.format("dxCalendar-todayButtonText"), type: "today" } }); } return extend(true, _popupConfig, { toolbarItems: toolbarItems, position: { collision: "flipfit flip" } }); }, _valueChangedHandler: function _valueChangedHandler(e) { var dateBox = this.dateBox, value = e.value, prevValue = e.previousValue; if (dateUtils.sameDate(value, prevValue)) { return; } if (dateBox.option("applyValueMode") === "instantly") { this.dateBoxValue(this.getValue(), e.event); } }, _updateValue: function _updateValue() { if (!this._widget) { return; } this._widget.option("value", this.dateBoxValue()); }, textChangedHandler: function textChangedHandler() { if (this.dateBox.option("opened") && this._widget) { this._updateValue(true); } }, _cellClickHandler: function _cellClickHandler(e) { var dateBox = this.dateBox; if (dateBox.option("applyValueMode") === "instantly") { dateBox.option("opened", false); this.dateBoxValue(this.getValue(), e.event); } } }); module.exports = CalendarStrategy;