devextreme
Version:
JavaScript/TypeScript Component Suite for Responsive Web Development
153 lines (152 loc) • 4.84 kB
JavaScript
/**
* DevExtreme (esm/__internal/ui/date_box/m_date_box.strategy.date_view.js)
* Version: 26.1.3
* Build date: Wed Jun 10 2026
*
* Copyright (c) 2012 - 2026 Developer Express Inc. ALL RIGHTS RESERVED
* Read about DevExtreme licensing here: https://js.devexpress.com/Licensing/
*/
import messageLocalization from "../../../common/core/localization/message";
import $ from "../../../core/renderer";
import {
inputType
} from "../../../core/utils/support";
import {
getWindow
} from "../../../core/utils/window";
import {
getGlobalFormatByDataType
} from "../../core/m_global_format_config";
import dateUtils from "./date_utils";
import DateView from "./date_view";
import DateBoxStrategy from "./m_date_box.strategy";
const window = getWindow();
class DateViewStrategy extends DateBoxStrategy {
constructor(dateBox) {
super(dateBox);
this.NAME = "DateView"
}
getWidget() {
return this._widget
}
getDefaultOptions() {
return Object.assign({}, super.getDefaultOptions(), {
openOnFieldClick: true,
applyButtonText: messageLocalization.format("OK"),
dropDownOptions: {
showTitle: true
}
})
}
getDisplayFormat(displayFormat) {
const {
type: type = "date"
} = this.dateBox.option();
const globalFormat = "date" === type || "datetime" === type ? getGlobalFormatByDataType(type) : void 0;
return displayFormat || globalFormat || dateUtils.FORMATS_MAP[type]
}
popupConfig(config) {
return {
toolbarItems: this.dateBox._popupToolbarItemsConfig(),
onInitialized: config.onInitialized,
defaultOptionsRules: [{
device: {
platform: "android"
},
options: {
width: 333,
height: 331
}
}, {
device(device) {
const {
platform: platform
} = device;
return "generic" === platform || "ios" === platform
},
options: {
width: "auto",
height: "auto"
}
}, {
device(device) {
const {
platform: platform
} = device;
const {
phone: phone
} = device;
return "generic" === platform && Boolean(phone)
},
options: {
width: 333,
maxWidth: "100%",
maxHeight: "100%",
height: "auto",
position: {
collision: "flipfit flip"
}
}
}, {
device: {
platform: "ios",
phone: true
},
options: {
width: "100%",
position: {
my: "bottom",
at: "bottom",
of: window
}
}
}]
}
}
_renderWidget() {
const {
mode: mode,
readOnly: readOnly
} = this.dateBox.option();
if (inputType(mode) && this.dateBox._isNativeType() || readOnly) {
if (this._widget) {
this._widget.$element().remove();
this._widget = null
}
return
}
const $popupContent = this._getPopupContent();
if (this._widget) {
this._widget.option(this._getWidgetOptions())
} else {
const element = $("<div>").appendTo($popupContent);
this._widget = this._createWidget(element)
}
this._widget.$element().appendTo(this._getWidgetContainer())
}
_getWidgetName() {
return DateView
}
renderOpenedState() {
super.renderOpenedState();
const widget = this.getWidget();
if (widget) {
widget.option("value", widget._getCurrentDate())
}
}
_getWidgetOptions() {
const {
type: type = "date"
} = this.dateBox.option();
return {
value: this.dateBoxValue() ?? new Date,
type: type,
minDate: this.dateBox.getDateOption("min") ?? new Date(1900, 0, 1),
maxDate: this.dateBox.getDateOption("max") ?? new Date(Date.now() + 50 * dateUtils.ONE_YEAR),
onDisposing: () => {
this._widget = null
}
}
}
}
export default DateViewStrategy;