UNPKG

react-application-core

Version:

A react-based application core for the business applications.

1,023 lines 56.7 kB
"use strict"; 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 (Object.prototype.hasOwnProperty.call(b, 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 __assign = (this && this.__assign) || function () { __assign = Object.assign || function(t) { for (var s, i = 1, n = arguments.length; i < n; i++) { s = arguments[i]; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p]; } return t; }; return __assign.apply(this, arguments); }; var __spreadArrays = (this && this.__spreadArrays) || function () { for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length; for (var r = Array(s), k = 0, i = 0; i < il; i++) for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++) r[k] = a[j]; return r; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.DateField = void 0; var React = require("react"); var R = require("ramda"); var util_1 = require("../../../util"); var definitions_interface_1 = require("../../../definitions.interface"); var definition_1 = require("../../../definition"); var base_text_field_component_1 = require("../text-field/base-text-field.component"); var button_component_1 = require("../../button/button.component"); var calendar_component_1 = require("../../calendar/calendar.component"); var dialog_component_1 = require("../../dialog/dialog.component"); var DateField = /** @class */ (function (_super) { __extends(DateField, _super); /** * @stable [07.12.2020] * @param originalProps */ function DateField(originalProps) { var _this = _super.call(this, originalProps) || this; _this.dialogRef = React.createRef(); _this.fromDateRef = React.createRef(); _this.addPeriod = _this.addPeriod.bind(_this); _this.isDaySelected = _this.isDaySelected.bind(_this); _this.isFirstDaySelected = _this.isFirstDaySelected.bind(_this); _this.isLastDaySelected = _this.isLastDaySelected.bind(_this); _this.isMiddleDaySelected = _this.isMiddleDaySelected.bind(_this); _this.onAccept = _this.onAccept.bind(_this); _this.onDaySelect = _this.onDaySelect.bind(_this); _this.onDialogDeactivate = _this.onDialogDeactivate.bind(_this); _this.onFromDateFieldChange = _this.onFromDateFieldChange.bind(_this); _this.onSetCustom = _this.onSetCustom.bind(_this); _this.onSetLastMonth = _this.onSetLastMonth.bind(_this); _this.onSetLastQuarter = _this.onSetLastQuarter.bind(_this); _this.onSetLastWeek = _this.onSetLastWeek.bind(_this); _this.onSetYesterday = _this.onSetYesterday.bind(_this); _this.onToDateFieldChange = _this.onToDateFieldChange.bind(_this); _this.openDialog = _this.openDialog.bind(_this); _this.setFromDateFocus = _this.setFromDateFocus.bind(_this); _this.setNextMonth = _this.setNextMonth.bind(_this); _this.setPreviousMonth = _this.setPreviousMonth.bind(_this); _this.setQuickValue = _this.setQuickValue.bind(_this); _this.subtractPeriod = _this.subtractPeriod.bind(_this); _this.defaultActions = __spreadArrays((!_this.isInline && originalProps.calendarActionRendered ? [{ type: definition_1.FieldActionTypesEnum.CALENDAR, onClick: _this.openDialog }] : []), _this.defaultActions); return _this; } /** * @stable [07.12.2020] */ DateField.prototype.render = function () { var originalProps = this.originalProps; var baseElement = _super.prototype.render.call(this); if (!this.isPeriodNavigatorUsed) { return baseElement; } var _a = originalProps.backActionConfiguration, backActionConfiguration = _a === void 0 ? {} : _a, _b = originalProps.forwardActionConfiguration, forwardActionConfiguration = _b === void 0 ? {} : _b; return (React.createElement("div", { className: definition_1.DateFieldClassesEnum.DATE_FIELD_NAVIGATOR }, React.createElement(button_component_1.Button, __assign({ icon: definition_1.IconsEnum.ARROW_LEFT, mini: true }, backActionConfiguration, { onClick: this.subtractPeriod })), baseElement, React.createElement(button_component_1.Button, __assign({ icon: definition_1.IconsEnum.ARROW_RIGHT, mini: true }, forwardActionConfiguration, { onClick: this.addPeriod })))); }; /** * @stable [07.03.2020] * @param {IDatesRangeEntity | DateTimeLikeTypeT | AnyT} currentRawValue */ DateField.prototype.onChangeManually = function (currentRawValue) { var rangeEntity = currentRawValue; _super.prototype.onChangeManually.call(this, this.isRangeEnabled ? (this.fromDatesRangeEntity(__assign(__assign({}, rangeEntity), { from: this.serializeValue(rangeEntity.from), to: this.serializeValue(util_1.NvlUtils.nvl(rangeEntity.to, rangeEntity.from)) }))) : this.serializeValue(currentRawValue)); }; Object.defineProperty(DateField.prototype, "attachmentElement", { /** * @stable [09.01.2020] * @returns {JSX.Element} */ get: function () { var _this = this; var dialogOpened = this.state.dialogOpened; var _a = this.originalProps.dialogConfiguration, dialogConfiguration = _a === void 0 ? {} : _a; var className = util_1.ClsUtils.joinClassName(!this.isInline && util_1.CalcUtils.calc(dialogConfiguration.className), definition_1.CalendarDialogClassesEnum.CALENDAR_BASE_DIALOG, this.isInline ? definition_1.CalendarDialogClassesEnum.CALENDAR_INLINE_DIALOG : definition_1.CalendarDialogClassesEnum.CALENDAR_DIALOG, this.isRangeEnabled ? definition_1.DateFieldClassesEnum.DATE_FIELD_CALENDARS_DIALOG : definition_1.DateFieldClassesEnum.DATE_FIELD_CALENDAR_DIALOG); if (this.isInline) { return (React.createElement("div", { className: className }, this.calendarAttachmentElement)); } return util_1.ConditionUtils.orNull(dialogOpened, // To improve a performance function () { return (React.createElement(dialog_component_1.Dialog, __assign({ checkModal: true }, dialogConfiguration, { ref: _this.dialogRef, acceptable: false, closable: false, className: className, onDeactivate: _this.onDialogDeactivate }), _this.calendarAttachmentElement)); }); }, enumerable: false, configurable: true }); Object.defineProperty(DateField.prototype, "originalEmptyValue", { /** * @stable [07.03.2020] * @returns {StringNumberT[] | string} */ get: function () { return this.isRangeEnabled ? [] : definition_1.FieldConstants.DISPLAY_EMPTY_VALUE; }, enumerable: false, configurable: true }); /** * @stable [07.03.2020] * @param {IBaseEvent} event */ DateField.prototype.onClick = function (event) { _super.prototype.onClick.call(this, event); if (!this.isInline && this.isFocusPrevented) { this.openDialog(); } }; /** * @stable [26.03.2020] * @param {DateFieldRangeValueT} value * @returns {string} */ DateField.prototype.decorateDisplayValue = function (value) { if (this.isPeriodNavigatorUsed) { switch (this.props.periodType) { case definition_1.DatePeriodsEnum.MONTH: return this.dc.dateAsString({ date: this.valueAsDate, outputFormat: this.yearMonthFormat }); } } else if (this.isRangeEnabled) { var dateRangeEntity = this.fromDatesRangeValue(value); return R.isNil(dateRangeEntity) ? definition_1.FieldConstants.DISPLAY_EMPTY_VALUE : this.getDecoratedRangeDisplayValue(dateRangeEntity); } return this.serializeValue(value); }; /** * @stable [12.01.2021] * @protected */ DateField.prototype.getFieldClassName = function () { return util_1.ClsUtils.joinClassName(_super.prototype.getFieldClassName.call(this), definition_1.DateFieldClassesEnum.DATE_FIELD); }; /** * @stable [12.01.2020] * @protected */ DateField.prototype.getFieldPattern = function () { var _this = this; return util_1.ConditionUtils.orNull(this.isFieldMaskOrPatternApplicable, function () { return _super.prototype.getFieldPattern.call(_this) || _this.dateTimeSettings.uiDatePattern; }); }; /** * @stable [12.01.2020] * @protected */ DateField.prototype.getFieldMask = function () { var _this = this; return util_1.ConditionUtils.orNull(this.isFieldMaskOrPatternApplicable, function () { return _super.prototype.getFieldMask.call(_this) || _this.dateTimeSettings.uiDateMask; }); }; Object.defineProperty(DateField.prototype, "fieldFormat", { /** * @stable [12.01.2020] * @protected */ get: function () { return util_1.NvlUtils.nvl(this.originalProps.format, this.dateTimeSettings.uiDateFormat); }, enumerable: false, configurable: true }); Object.defineProperty(DateField.prototype, "calendarAttachmentElement", { /** * @stable [25.03.2020] * @returns {JSX.Element} */ get: function () { return (React.createElement(React.Fragment, null, this.isRangeEnabled && (React.createElement(React.Fragment, null, this.quickButtonsElement, this.previousQuickButtonsElement)), React.createElement("div", { className: definition_1.CalendarDialogClassesEnum.CALENDAR_DIALOG_RANGE_EXPLORER }, React.createElement(button_component_1.Button, { icon: definition_1.IconsEnum.ARROW_LEFT, mini: true, onClick: this.setPreviousMonth }), React.createElement("div", { className: definition_1.CalendarDialogClassesEnum.CALENDAR_DIALOG_RANGE_EXPLORER_DATE }, this.rangeExplorerDateElement), React.createElement(button_component_1.Button, { icon: definition_1.IconsEnum.ARROW_RIGHT, mini: true, onClick: this.setNextMonth })), this.calendarElement, React.createElement("div", { className: definition_1.CalendarDialogClassesEnum.CALENDAR_DIALOG_FOOTER }, this.dateFieldsElement, !this.isInline && (React.createElement(button_component_1.Button, { text: this.settings.messages.OK, onClick: this.onAccept }))))); }, enumerable: false, configurable: true }); Object.defineProperty(DateField.prototype, "calendarElement", { /** * @stable [20.01.2020] * @returns {JSX.Element} */ get: function () { var defaultCalendarProps = this.defaultCalendarProps; var _a = defaultCalendarProps.gridConfiguration, gridConfiguration = _a === void 0 ? {} : _a; if (this.isRangeEnabled) { return (React.createElement("div", { className: 'rac-calendar-dialog__calendars-wrapper' }, React.createElement(calendar_component_1.Calendar, __assign({}, defaultCalendarProps, { calendarEntity: this.currentCalendarEntity })), React.createElement(calendar_component_1.Calendar, __assign({}, defaultCalendarProps, { gridConfiguration: __assign(__assign({}, gridConfiguration), { wrapperClassName: util_1.ClsUtils.joinClassName('rac-calendar-dialog__second-calendar', util_1.CalcUtils.calc(gridConfiguration.className)) }), calendarEntity: this.nextCalendarEntity })))); } return (React.createElement(calendar_component_1.Calendar, __assign({}, defaultCalendarProps, { calendarEntity: this.currentCalendarEntity }))); }, enumerable: false, configurable: true }); Object.defineProperty(DateField.prototype, "defaultCalendarProps", { /** * @stable [21.01.2020] * @returns {ICalendarProps} */ get: function () { return __assign(__assign({ gridConfiguration: { headerRendered: true }, showOnlyCurrentDays: true }, this.props.calendarConfiguration), { isSelected: this.isDaySelected, isMiddleSelected: this.isMiddleDaySelected, isFirstSelected: this.isFirstDaySelected, isLastSelected: this.isLastDaySelected, onSelect: this.onDaySelect }); }, enumerable: false, configurable: true }); Object.defineProperty(DateField.prototype, "rangeExplorerDateElement", { /** * @stable [20.01.2020] * @returns {React.ReactNode} */ get: function () { if (this.isRangeEnabled) { return (React.createElement(React.Fragment, null, React.createElement("div", { className: 'rac-calendar-dialog__range-explorer-date-content' }, this.currentDateAsDisplayValue), React.createElement("div", { className: 'rac-calendar-dialog__range-explorer-date-content rac-calendar-dialog__range-explorer-date-content-next' }, this.nextDateAsDisplayValue))); } return this.currentDateAsDisplayValue; }, enumerable: false, configurable: true }); Object.defineProperty(DateField.prototype, "dateFieldsElement", { /** * @stable [20.01.2020] * @returns {JSX.Element} */ get: function () { return (React.createElement(React.Fragment, null, React.createElement(DateField, __assign({ ref: this.fromDateRef }, this.rangeFieldProps, { autoFocus: true, value: this.fromDateFieldValue, onChange: this.onFromDateFieldChange })), this.isRangeEnabled && R.isEmpty(R.intersection([this.selectedPeriodMode, this.aheadEntityPeriodMode], definition_1.DAYS_PERIODS)) && (React.createElement(React.Fragment, null, React.createElement("span", { className: definition_1.ComponentClassesEnum.CALENDAR_DIALOG_RANGE_INPUT_SEPARATOR }, "\u2014"), React.createElement(DateField, __assign({}, this.rangeFieldProps, { value: this.toDateFieldValue, onChange: this.onToDateFieldChange })))))); }, enumerable: false, configurable: true }); Object.defineProperty(DateField.prototype, "toDateFieldValue", { /** * @stable [12.01.2020] * @private */ get: function () { var _a = this.state, toDate = _a.toDate, to = _a.to; return to === DateField.INITIAL_PERIOD_DATE_VALUE ? to : util_1.NvlUtils.coalesce(toDate, to, this.valueAsDateTo); }, enumerable: false, configurable: true }); Object.defineProperty(DateField.prototype, "fromDateFieldValue", { /** * @stable [25.03.2020] * @returns {DateTimeLikeTypeT} */ get: function () { var _a = this.state, fromDate = _a.fromDate, from = _a.from; return from === DateField.INITIAL_PERIOD_DATE_VALUE ? from : util_1.NvlUtils.coalesce(fromDate, from, this.isRangeEnabled ? this.valueAsDateFrom : this.valueAsDate); }, enumerable: false, configurable: true }); Object.defineProperty(DateField.prototype, "previousQuickButtonsElement", { /** * @stable [25.03.2020] * @returns {JSX.Element} */ get: function () { var isPreviousPeriodModeEnabled = this.isPreviousPeriodModeEnabled; return (React.createElement("div", { className: definition_1.CalendarDialogClassesEnum.CALENDAR_DIALOG_QUICK_ACTIONS }, React.createElement(button_component_1.Button, { full: true, className: this.getQuickActionClassName(definition_1.DatePeriodsEnum.PREVIOUS_DAY), disabled: isPreviousPeriodModeEnabled, text: this.settings.messages.YESTERDAY, onClick: this.onSetYesterday }), React.createElement(button_component_1.Button, { full: true, className: this.getQuickActionClassName(definition_1.DatePeriodsEnum.PREVIOUS_WEEK), disabled: isPreviousPeriodModeEnabled, text: this.settings.messages.LAST_WEEK, onClick: this.onSetLastWeek }), React.createElement(button_component_1.Button, { full: true, className: this.getQuickActionClassName(definition_1.DatePeriodsEnum.PREVIOUS_MONTH), disabled: isPreviousPeriodModeEnabled, text: this.settings.messages.LAST_MONTH, onClick: this.onSetLastMonth }), React.createElement(button_component_1.Button, { key: 'quick-action-previous-quarter', full: true, className: this.getQuickActionClassName(definition_1.DatePeriodsEnum.PREVIOUS_QUARTER), disabled: isPreviousPeriodModeEnabled, text: this.settings.messages.LAST_QUARTER, onClick: this.onSetLastQuarter }))); }, enumerable: false, configurable: true }); Object.defineProperty(DateField.prototype, "quickButtonsElement", { /** * @stable [07.03.2020] * @returns {JSX.Element} */ get: function () { var _this = this; var previousPeriodModeEnabled = this.isPreviousPeriodModeEnabled; var aheadEntityPeriodMode = this.aheadEntityPeriodMode; var buttonsElement = util_1.FilterUtils.objectValuesArrayFilter((!previousPeriodModeEnabled || definition_1.DAYS_PERIODS.includes(aheadEntityPeriodMode)) && (React.createElement(button_component_1.Button, { key: 'quick-action-day', full: true, className: this.getQuickActionClassName(definition_1.DatePeriodsEnum.DAY, false), text: previousPeriodModeEnabled ? this.previousPeriodQuickActionText : this.settings.messages.TODAY, onClick: function () { return _this.onSetDay(); } })), (!previousPeriodModeEnabled || definition_1.WEEKS_PERIODS.includes(aheadEntityPeriodMode)) && (React.createElement(button_component_1.Button, { key: 'quick-action-week', full: true, className: this.getQuickActionClassName(definition_1.DatePeriodsEnum.WEEK, false), text: previousPeriodModeEnabled ? this.previousPeriodQuickActionText : this.settings.messages.THIS_WEEK, onClick: function () { return _this.onSetWeek(); } })), (!previousPeriodModeEnabled || definition_1.MONTHS_PERIODS.includes(aheadEntityPeriodMode)) && (React.createElement(button_component_1.Button, { key: 'quick-action-month', full: true, className: this.getQuickActionClassName(definition_1.DatePeriodsEnum.MONTH, false), text: previousPeriodModeEnabled ? this.previousPeriodQuickActionText : this.settings.messages.THIS_MONTH, onClick: function () { return _this.onSetMonth(); } })), (!previousPeriodModeEnabled || definition_1.QUARTERS_PERIODS.includes(aheadEntityPeriodMode)) && (React.createElement(button_component_1.Button, { key: 'quick-action-quarter', full: true, className: this.getQuickActionClassName(definition_1.DatePeriodsEnum.QUARTER, false), text: previousPeriodModeEnabled ? this.previousPeriodQuickActionText : this.settings.messages.THIS_QUARTER, onClick: function () { return _this.onSetQuarter(); } })), (!previousPeriodModeEnabled || aheadEntityPeriodMode === definition_1.DatePeriodsEnum.CUSTOM) && (React.createElement(button_component_1.Button, { key: 'quick-action-custom', full: true, disabled: previousPeriodModeEnabled, className: this.getQuickActionClassName(definition_1.DatePeriodsEnum.CUSTOM, false), text: this.settings.messages.CUSTOM, onClick: this.onSetCustom }))); return (React.createElement("div", { className: definition_1.CalendarDialogClassesEnum.CALENDAR_DIALOG_QUICK_ACTIONS }, buttonsElement)); }, enumerable: false, configurable: true }); /** * @stable [25.03.2020] */ DateField.prototype.subtractPeriod = function () { this.doChangePeriod(-this.props.periodStep); }; /** * @stable [25.03.2020] */ DateField.prototype.addPeriod = function () { this.doChangePeriod(this.props.periodStep); }; /** * @stable [26.03.2020] * @param {number} duration */ DateField.prototype.doChangePeriod = function (duration) { var _this = this; var nextValue; var cfg = { date: this.valueAsDate, duration: duration }; switch (this.props.periodType) { case definition_1.DatePeriodsEnum.DAY: nextValue = this.dc.addDaysAsDate(cfg); break; case definition_1.DatePeriodsEnum.WEEK: nextValue = this.dc.addWeeksAsDate(cfg); break; case definition_1.DatePeriodsEnum.MONTH: nextValue = this.dc.addMonthsAsDate(cfg); break; } util_1.ConditionUtils.ifNotNilThanValue(nextValue, function () { return _this.onChangeManually(nextValue); }); }; /** * @stable [25.03.2020] * @param {DatePeriodsEnum} period * @param {boolean} isPreviousPeriodModeEnabled * @returns {string} */ DateField.prototype.getQuickActionClassName = function (period, isPreviousPeriodModeEnabled) { if (isPreviousPeriodModeEnabled === void 0) { isPreviousPeriodModeEnabled = this.isPreviousPeriodModeEnabled; } return util_1.ClsUtils.joinClassName(!isPreviousPeriodModeEnabled && this.selectedPeriodMode === period && definition_1.CalendarDialogClassesEnum.CALENDAR_DIALOG_SELECTED_QUICK_ACTION); }; /** * @stable [07.03.2020] */ DateField.prototype.onSetDay = function (setQuickValue) { if (setQuickValue === void 0) { setQuickValue = this.setQuickValue; } var currentDate = this.dc.getCurrentDate(); if (this.isPreviousPeriodModeEnabled) { var previousDay = this.dc.addDaysAsDate({ date: this.aheadEntity.from, duration: -1 }); setQuickValue(previousDay, previousDay, definition_1.DatePeriodsEnum.DAY); } else { setQuickValue(currentDate, currentDate, definition_1.DatePeriodsEnum.DAY); } }; /** * @stable [25.03.2020] */ DateField.prototype.onSetYesterday = function () { var date = this.dc.addDaysAsDate({ date: this.dc.getCurrentDate(), duration: -1 }); this.setQuickValue(date, date, definition_1.DatePeriodsEnum.PREVIOUS_DAY); }; /** * @stable [07.03.2020] */ DateField.prototype.onSetWeek = function (setQuickValue) { if (setQuickValue === void 0) { setQuickValue = this.setQuickValue; } if (this.isPreviousPeriodModeEnabled) { var aheadEntity = this.aheadEntity; var firstDayOfWeekAsDate = this.dc.asFirstDayOfWeekAsDate({ date: aheadEntity.from, inputFormat: this.fieldFormat }); var firstDayOfPreviousWeek = this.dc.addWeeksAsDate({ date: firstDayOfWeekAsDate, duration: -1 }); setQuickValue(firstDayOfPreviousWeek, this.dc.asLastDayOfWeekAsDate({ date: firstDayOfPreviousWeek }), definition_1.DatePeriodsEnum.WEEK); } else { setQuickValue(this.dc.asFirstDayOfWeekAsDate(), this.dc.asLastDayOfWeekAsDate(), definition_1.DatePeriodsEnum.WEEK); } }; /** * @stable [25.03.2020] */ DateField.prototype.onSetLastWeek = function () { var date = this.dc.addWeeksAsDate({ date: this.dc.getCurrentDate(), duration: -1 }); this.setQuickValue(this.dc.asFirstDayOfWeekAsDate({ date: date }), this.dc.asLastDayOfWeekAsDate({ date: date }), definition_1.DatePeriodsEnum.PREVIOUS_WEEK); }; /** * @stable [07.03.2020] */ DateField.prototype.onSetMonth = function (setQuickValue) { if (setQuickValue === void 0) { setQuickValue = this.setQuickValue; } if (this.isPreviousPeriodModeEnabled) { var aheadEntity = this.aheadEntity; var firstDayOfMonthAsDate = this.dc.asFirstDayOfMonthAsDate({ date: aheadEntity.from, inputFormat: this.fieldFormat }); var firstDayOfPreviousMonth = this.dc.addMonthsAsDate({ date: firstDayOfMonthAsDate, duration: -1 }); setQuickValue(firstDayOfPreviousMonth, this.dc.asLastDayOfMonthAsDate({ date: firstDayOfPreviousMonth }), definition_1.DatePeriodsEnum.MONTH); } else { setQuickValue(this.dc.asFirstDayOfMonthAsDate(), this.dc.asLastDayOfMonthAsDate(), definition_1.DatePeriodsEnum.MONTH); } }; /** * @stable [25.03.2020] */ DateField.prototype.onSetLastMonth = function () { var date = this.dc.addMonthsAsDate({ date: this.dc.getCurrentDate(), duration: -1 }); this.setQuickValue(this.dc.asFirstDayOfMonthAsDate({ date: date }), this.dc.asLastDayOfMonthAsDate({ date: date }), definition_1.DatePeriodsEnum.PREVIOUS_MONTH); }; /** * @stable [08.03.2020] */ DateField.prototype.onSetQuarter = function (setQuickValue) { if (setQuickValue === void 0) { setQuickValue = this.setQuickValue; } if (this.isPreviousPeriodModeEnabled) { var aheadEntity = this.aheadEntity; var firstDayOfQuarterAsDate = this.dc.asFirstDayOfQuarterAsDate({ date: aheadEntity.from, inputFormat: this.fieldFormat }); var firstDayOfPreviousQuarter = this.dc.addQuartersAsDate({ date: firstDayOfQuarterAsDate, duration: -1 }); setQuickValue(firstDayOfPreviousQuarter, this.dc.asLastDayOfQuarterAsDate({ date: firstDayOfPreviousQuarter }), definition_1.DatePeriodsEnum.QUARTER); } else { setQuickValue(this.dc.asFirstDayOfQuarterAsDate(), this.dc.asLastDayOfQuarterAsDate(), definition_1.DatePeriodsEnum.QUARTER); } }; /** * @stable [25.03.2020] */ DateField.prototype.onSetLastQuarter = function () { var date = this.dc.addQuartersAsDate({ date: this.dc.getCurrentDate(), duration: -1 }); this.setQuickValue(this.dc.asFirstDayOfQuarterAsDate({ date: date }), this.dc.asLastDayOfQuarterAsDate({ date: date }), definition_1.DatePeriodsEnum.PREVIOUS_QUARTER); }; /** * @stable [08.03.2020] */ DateField.prototype.onSetCustom = function () { this.setState(__assign(__assign({}, DateField.INITIAL_RANGE_PERIOD_STATE), { periodMode: definition_1.DatePeriodsEnum.CUSTOM })); }; /** * @stable [06.03.2020] * @param {Date} from * @param {Date} to * @param {DatePeriodsEnum} periodMode */ DateField.prototype.setQuickValue = function (from, to, periodMode) { this.setState({ cursor: from, from: from, fromDate: definitions_interface_1.UNDEF, periodMode: periodMode, to: to, toDate: definitions_interface_1.UNDEF, }, this.setFromDateFocus); }; /** * @stable [11.03.2020] */ DateField.prototype.setFromDateFocus = function () { util_1.ConditionUtils.ifNotNilThanValue(this.fromDateRef.current, function (field) { return field.setFocus(); }); }; /** * @stable [07.03.2020] */ DateField.prototype.setPreviousMonth = function () { this.doChangeMonth(-1); }; /** * @stable [07.03.2020] */ DateField.prototype.setNextMonth = function () { this.doChangeMonth(1); }; /** * @stable [07.03.2020] * @param {number} duration */ DateField.prototype.doChangeMonth = function (duration) { this.setState({ cursor: this.dc.addMonthsAsDate({ date: this.currentCalendarDate, duration: duration }) }); }; /** * @stable [12.01.2021] * @param value * @private */ DateField.prototype.onToDateFieldChange = function (value) { var to = this.getValueAsDate(value); this.setState(__assign({ toDate: value }, (R.isNil(to) ? {} : (util_1.TypeUtils.asType({ cursor: this.dc.addMonthsAsDate({ date: this.dc.asFirstDayOfMonth({ date: to }), duration: -1 }), periodMode: definition_1.DatePeriodsEnum.CUSTOM, to: to, }))))); }; /** * @stable [25.03.2020] * @param {string} value */ DateField.prototype.onFromDateFieldChange = function (value) { var from = this.getValueAsDate(value); this.setState(__assign({ fromDate: value }, (R.isNil(from) ? {} : (__assign({ periodMode: definition_1.DatePeriodsEnum.CUSTOM, cursor: from, from: from }, (definition_1.DAYS_PERIODS.includes(this.selectedPeriodMode) ? DateField.INITIAL_RANGE_TO_DATE_STATE : {})))))); }; /** * @stable [10.03.2020] */ DateField.prototype.onAccept = function () { var _this = this; var acceptedValue = this.isRangeEnabled ? this.acceptedDatesRangeEntity : this.acceptedDateValue; var acceptedValueAsRangeEntity = acceptedValue; this.onDialogClose(function () { util_1.ConditionUtils.ifNotEmptyThanValue(acceptedValue, function () { if (!_this.isRangeEnabled || util_1.ObjectUtils.isObjectNotEmpty(acceptedValueAsRangeEntity.from)) { _this.onChangeManually(acceptedValue); } }); _this.setFocus(); }); }; /** * @stable [25.03.2020] * @param {ICalendarDayEntity} calendarDayEntity */ DateField.prototype.onDaySelect = function (calendarDayEntity) { var _this = this; var updatedState; if (this.isRangeEnabled) { var daysOfYearRange = this.dc.selectDaysOfYearRange(this.currentFromToDayOfYearEntity, calendarDayEntity); updatedState = __assign(__assign(__assign(__assign({}, DateField.INITIAL_RANGE_PERIOD_STATE), util_1.ConditionUtils.ifNotEmptyThanValue(daysOfYearRange.from, function (from) { return ({ from: _this.dc.fromDayOfYearEntityAsDate(from) }); })), util_1.ConditionUtils.ifNotEmptyThanValue(daysOfYearRange.to, function (to) { return ({ to: _this.dc.fromDayOfYearEntityAsDate(to) }); })), { periodMode: definition_1.DatePeriodsEnum.CUSTOM }); util_1.ConditionUtils.ifNotEmptyThanValue(updatedState.from, function () { return (updatedState.fromDate = _this.serializeValue(updatedState.from)); }); util_1.ConditionUtils.ifNotEmptyThanValue(updatedState.to, function () { return (updatedState.toDate = _this.serializeValue(updatedState.to)); }); } else { updatedState = __assign(__assign({}, DateField.INITIAL_PERIOD_STATE), { from: calendarDayEntity.date }); util_1.ConditionUtils.ifNotEmptyThanValue(updatedState.from, function () { return (updatedState.fromDate = _this.serializeValue(calendarDayEntity.date)); }); } this.setState(function (prevState) { return (__assign(__assign({}, updatedState), { cursor: prevState.cursor })); }, this.setFromDateFocus); }; /** * @stable [08.03.2020] */ DateField.prototype.onDialogDeactivate = function () { this.onDialogClose(); }; /** * @stable [08.03.2020] * @param {() => void} callback */ DateField.prototype.onDialogClose = function (callback) { this.setState(__assign(__assign({}, DateField.DEFAULT_RANGE_PERIOD_STATE), { dialogOpened: definitions_interface_1.UNDEF, periodMode: definitions_interface_1.UNDEF }), callback); }; /** * @stable [08.03.2020] */ DateField.prototype.openDialog = function () { var _this = this; this.setState({ dialogOpened: true }, function () { return _this.dialog.activate(); }); }; /** * @stable [09.03.2020] * @param {IDatesRangeEntity} dateRangeEntity * @returns {string} */ DateField.prototype.getDecoratedRangeDisplayValue = function (dateRangeEntity) { var dateFromAsString = this.serializeValue(dateRangeEntity.from); var dateToAsString = this.serializeValue(dateRangeEntity.to); var messages = this.settings.messages; if (this.checkRange(dateFromAsString, dateToAsString, this.dc.addDaysAsDate({ date: this.dc.getCurrentDate(), duration: -1 }), this.dc.addDaysAsDate({ date: this.dc.getCurrentDate(), duration: -1 }))) { return messages.YESTERDAY + ": " + this.dc.dateAsPstDateString({ date: dateRangeEntity.from }); } else if (this.checkRange(dateFromAsString, dateToAsString, this.dc.addWeeksAsDate({ date: this.dc.asFirstDayOfWeekAsDate(), duration: -1 }), this.dc.addWeeksAsDate({ date: this.dc.asLastDayOfWeekAsDate(), duration: -1 }))) { return this.getDecoratedRangeSpecificValue(dateRangeEntity.from, dateRangeEntity.to, messages.LAST_WEEK); } else if (this.checkRange(dateFromAsString, dateToAsString, this.dc.addMonthsAsDate({ date: this.dc.asFirstDayOfMonthAsDate(), duration: -1 }), this.dc.addMonthsAsDate({ date: this.dc.asLastDayOfMonthAsDate(), duration: -1 }))) { return this.getDecoratedRangeSpecificValue(dateRangeEntity.from, dateRangeEntity.to, messages.LAST_MONTH); } else if (this.checkRange(dateFromAsString, dateToAsString, this.dc.addQuartersAsDate({ date: this.dc.asFirstDayOfQuarterAsDate(), duration: -1 }), this.dc.addQuartersAsDate({ date: this.dc.asLastDayOfQuarterAsDate(), duration: -1 }))) { return this.getDecoratedRangeSpecificValue(dateRangeEntity.from, dateRangeEntity.to, messages.LAST_QUARTER); } else if (this.checkRange(dateFromAsString, dateToAsString, this.dc.getCurrentDate(), this.dc.getCurrentDate())) { return messages.TODAY + ": " + this.dc.dateAsPstDateString({ date: dateRangeEntity.from }); } else if (this.checkRange(dateFromAsString, dateToAsString, this.dc.asFirstDayOfWeekAsDate(), this.dc.asLastDayOfWeekAsDate())) { return this.getDecoratedRangeSpecificValue(dateRangeEntity.from, dateRangeEntity.to, messages.THIS_WEEK); } else if (this.checkRange(dateFromAsString, dateToAsString, this.dc.asFirstDayOfMonthAsDate(), this.dc.asLastDayOfMonthAsDate())) { return this.getDecoratedRangeSpecificValue(dateRangeEntity.from, dateRangeEntity.to, messages.THIS_MONTH); } else if (this.checkRange(dateFromAsString, dateToAsString, this.dc.asFirstDayOfQuarterAsDate(), this.dc.asLastDayOfQuarterAsDate())) { return this.getDecoratedRangeSpecificValue(dateRangeEntity.from, dateRangeEntity.to, messages.THIS_QUARTER); } if (R.equals(dateToAsString, dateFromAsString)) { return messages.DATE + ": " + dateFromAsString; } return dateFromAsString + " " + definitions_interface_1.UniCodesEnum.N_DASH + " " + dateToAsString; }; /** * @stable [09.03.2020] * @param {DateTimeLikeTypeT} from * @param {DateTimeLikeTypeT} to * @param {string} label * @returns {string} */ DateField.prototype.getDecoratedRangeSpecificValue = function (from, to, label) { var dateFrom = this.getValueAsDate(from); var dateTo = this.getValueAsDate(to); return label + ": " + this.dc.dateAsPstDateString({ date: dateFrom }) + " " + definitions_interface_1.UniCodesEnum.N_DASH + " " + this.dc.dateAsPstDateString({ date: dateTo }); }; Object.defineProperty(DateField.prototype, "previousPeriodQuickActionText", { /** * @stable [24.03.2020] * @returns {string} */ get: function () { var _this = this; var from; var to; var onSetValue = function (fromDate, toDate) { from = _this.serializeValue(fromDate); to = _this.serializeValue(toDate); }; var messages = this.settings.messages; switch (this.aheadEntityPeriodMode) { case definition_1.DatePeriodsEnum.PREVIOUS_DAY: this.onSetDay(onSetValue); break; case definition_1.DatePeriodsEnum.DAY: from = to = messages.YESTERDAY; break; case definition_1.DatePeriodsEnum.PREVIOUS_WEEK: this.onSetWeek(onSetValue); break; case definition_1.DatePeriodsEnum.WEEK: from = to = messages.LAST_WEEK; break; case definition_1.DatePeriodsEnum.PREVIOUS_MONTH: this.onSetMonth(onSetValue); break; case definition_1.DatePeriodsEnum.MONTH: from = to = messages.LAST_MONTH; break; case definition_1.DatePeriodsEnum.PREVIOUS_QUARTER: this.onSetQuarter(onSetValue); break; case definition_1.DatePeriodsEnum.QUARTER: from = to = messages.LAST_QUARTER; break; } var separator = "" + definitions_interface_1.UniCodesEnum.NO_BREAK_SPACE + definitions_interface_1.UniCodesEnum.NO_BREAK_SPACE; if (R.equals(from, to)) { return messages.COMPARE_TO + ":" + separator + from; } return messages.COMPARE_TO + ":" + separator + from + separator + definitions_interface_1.UniCodesEnum.N_DASH + separator + to; }, enumerable: false, configurable: true }); /** * @stable [09.03.2020] * @param {string} dateFromAsString * @param {string} dateToAsString * @param {Date} dateFrom * @param {Date} dateTo * @returns {boolean} */ DateField.prototype.checkRange = function (dateFromAsString, dateToAsString, dateFrom, dateTo) { return this.serializeValue(dateFrom) === dateFromAsString && this.serializeValue(dateTo) === dateToAsString; }; /** * @stable [08.03.2020] * @param {DateTimeLikeTypeT} value * @returns {string} */ DateField.prototype.serializeValue = function (value) { return this.dc.dateAsString({ date: value, inputFormat: this.fieldFormat, outputFormat: this.fieldFormat }); }; Object.defineProperty(DateField.prototype, "currentDateAsDisplayValue", { /** * @stable [08.03.2020] * @returns {string} */ get: function () { return this.dc.dateAsString({ date: this.currentCalendarDate, outputFormat: this.yearMonthFormat }); }, enumerable: false, configurable: true }); Object.defineProperty(DateField.prototype, "nextDateAsDisplayValue", { /** * @stable [08.03.2020] * @returns {string} */ get: function () { return this.dc.dateAsString({ date: this.nextCalendarDate, outputFormat: this.yearMonthFormat }); }, enumerable: false, configurable: true }); Object.defineProperty(DateField.prototype, "currentCalendarEntity", { /** * @stable [08.03.2020] * @returns {ICalendarEntity} */ get: function () { return this.getCalendarEntity(this.currentCalendarDate); }, enumerable: false, configurable: true }); Object.defineProperty(DateField.prototype, "nextCalendarEntity", { /** * @stable [08.03.2020] * @returns {ICalendarEntity} */ get: function () { return this.getCalendarEntity(this.nextCalendarDate); }, enumerable: false, configurable: true }); /** * @stable [08.03.2020] * @param {Date} date * @returns {ICalendarEntity} */ DateField.prototype.getCalendarEntity = function (date) { return this.dc.asCalendar(__assign(__assign({}, this.props.calendarEntityConfiguration), { date: date })); }; Object.defineProperty(DateField.prototype, "currentCalendarDate", { /** * @stable [25.03.2020] * @returns {Date} */ get: function () { var cursor = this.state.cursor; return cursor || (this.isRangeEnabled ? this.getValueAsDate(this.valueAsDateFrom) : this.acceptedDateValue) || this.dc.getCurrentDate(); }, enumerable: false, configurable: true }); Object.defineProperty(DateField.prototype, "nextCalendarDate", { /** * @stable [08.03.2020] * @returns {Date} */ get: function () { return this.dc.addMonthsAsDate({ date: this.currentCalendarDate, duration: 1 }); }, enumerable: false, configurable: true }); Object.defineProperty(DateField.prototype, "currentFromToDayOfYearEntity", { /** * @stable [25.03.2020] * @returns {IFromToDayOfYearEntity} */ get: function () { var _this = this; return __assign(__assign({}, util_1.ConditionUtils.ifNotEmptyThanValue(this.fromDateFieldValue, function (fromValue) { return ({ from: _this.dc.asDayOfYearEntity({ date: fromValue, inputFormat: _this.fieldFormat }) }); })), util_1.ConditionUtils.ifNotEmptyThanValue(this.toDateFieldValue, function (toValue) { return ({ to: _this.dc.asDayOfYearEntity({ date: toValue, inputFormat: _this.fieldFormat }) }); })); }, enumerable: false, configurable: true }); /** * @stable [07.03.2020] * @param {IDatesRangeEntity} entity * @returns {DatesRangeValueT} */ DateField.prototype.fromDatesRangeEntity = function (entity) { return this.fieldConverter.convert({ from: definition_1.FieldConverterTypesEnum.DATES_RANGE_ENTITY, to: definition_1.FieldConverterTypesEnum.DATES_RANGE_VALUE, value: entity, }); }; /** * @stable [07.03.2020] * @param {DatesRangeValueT} value * @returns {IDatesRangeEntity} */ DateField.prototype.fromDatesRangeValue = function (value) { return this.fieldConverter.convert({ from: definition_1.FieldConverterTypesEnum.DATES_RANGE_VALUE, to: definition_1.FieldConverterTypesEnum.DATES_RANGE_ENTITY, value: value, }); }; Object.defineProperty(DateField.prototype, "datesRangeEntity", { /** * @stable [07.03.2020] * @returns {IDatesRangeEntity} */ get: function () { return this.fromDatesRangeValue(this.value); }, enumerable: false, configurable: true }); /** * @stable [06.03.2020] * @param {DateTimeLikeTypeT} date * @returns {Date} */ DateField.prototype.getValueAsDate = function (date) { return this.dc.asDate({ date: date, inputFormat: this.fieldFormat }); }; Object.defineProperty(DateField.prototype, "acceptedDatesRangeEntity", { /** * @stable [12.01.2021] * @private */ get: function () { var _a = this.state, from = _a.from, periodMode = _a.periodMode, to = _a.to; var selectedPeriodMode = this.selectedPeriodMode; var defaultResult = util_1.FilterUtils.defValuesFilter({ from: from, periodMode: periodMode, to: to, }); var isFromNotEmpty = util_1.ObjectUtils.isObjectNotEmpty(from); if (!definition_1.DAYS_PERIODS.includes(selectedPeriodMode) && (isFromNotEmpty || util_1.ObjectUtils.isObjectNotEmpty(to))) { var actualFrom = from || this.valueAsDateFrom; var actualTo = to || this.valueAsDateTo; if (selectedPeriodMode === definition_1.DatePeriodsEnum.CUSTOM && to === null && isFromNotEmpty) { // Single day selected return defaultResult; } return util_1.FilterUtils.defValuesFilter({ from: actualFrom, periodMode: periodMode, to: actualTo, }); } return defaultResult; }, enumerable: false, configurable: true }); Object.defineProperty(DateField.prototype, "acceptedDateValue", { /** * @stable [06.03.2020] * @returns {Date} */ get: function () { return this.state.from || this.valueAsDate; }, enumerable: false, configurable: true }); Object.defineProperty(DateField.prototype, "valueAsDate", { /** * @stable [06.03.2020] * @returns {Date} */ get: function () { return this.getValueAsDate(this.value); }, enumerable: false, configurable: true }); Object.defineProperty(DateField.prototype, "valueAsPeriodMode", { /** * @stable [06.03.2020] * @returns {DatePeriodsEnum} */ get: function () { return util_1.ConditionUtils.ifNotNilThanValue(this.datesRangeEntity, function (rangeEntity) { return rangeEntity.periodMode; }); }, enumerable: false, configurable: true }); Object.defineProperty(DateField.prototype, "valueAsDateFrom", { /** * @stable [12.01.2021] * @private */ get: function () { return util_1.ConditionUtils.ifNotNilThanValue(this.datesRangeEntity, function (rangeEntity) { return rangeEntity.from; }); }, enumerable: false, configurable: true }); Object.defineProperty(DateField.prototype, "valueAsDateTo", { /** * @stable [12.01.2021] * @private */ get: function () { return util_1.ConditionUtils.ifNotNilThanValue(this.datesRangeEntity, function (rangeEntity) { return rangeEntity.to; }); }, enumerable: false, configurable: true }); Object.defineProperty(DateField.prototype, "aheadValue", { /** * @stable [06.03.2020] * @returns {DateFieldRangeValueT} */ get: function () { return this.props.aheadValue; }, enumerable: false, configurable: true }); Object.defineProperty(DateField.prototype, "aheadEntity", { /** * @stable [07.03.2020] * @returns {IDatesRangeEntity} */ get: function () { return this.fromDatesRangeValue(this.aheadValue); }, enumerable: false, configurable: true }); Object.defineProperty(DateField.prototype, "aheadEntityPeriodMode", { /** * @stable [07.03.2020] * @returns {DatePeriodsEnum} */ get: function () { return util_1.ConditionUtils.ifNotNilThanValue(this.aheadEntity, function (aheadEntity) { return aheadEntity.periodMode; }); }, enumerable: false, configurable: true }); Object.defineProperty(DateField.prototype, "selectedPeriodMode", { /** * @stable [12.01.2020] * @private */ get: function () { var periodMode = this.state.periodMode; return util_1.TypeUtils.isDef(periodMode) ? periodMode : util_1.NvlUtils.nvl(this.valueAsPeriodMode, definition_1.DatePeriodsEnum.CUSTOM); }, enumerable: false, configurable: true }); /** * @stable [07.03.2020] * @param {ICalendarDayEntity} entity * @returns {boolean} */ DateField.prototype.isDaySelected = function (entity) { return this.isRangeEnabled ? this.isRangeSelected(entity) : this.dc.compare(entity.date, this.acceptedDateValue) === 0; }; /** * @stable [08.03.2020] * @param {ICalendarDayEntity} entity * @returns {boolean} */ DateField.prototype.isRangeSelected = function (entity) { re