UNPKG

devextreme

Version:

JavaScript/TypeScript Component Suite for Responsive Web Development

94 lines (93 loc) 3.56 kB
/** * DevExtreme (esm/__internal/scheduler/appointment_popup/utils.js) * Version: 25.2.7 * Build date: Tue May 05 2026 * * Copyright (c) 2012 - 2026 Developer Express Inc. ALL RIGHTS RESERVED * Read about DevExtreme licensing here: https://js.devexpress.com/Licensing/ */ import $ from "../../../core/renderer"; import dateUtils from "../../../core/utils/date"; import { isDefined } from "../../../core/utils/type"; import { getImageContainer } from "../../core/utils/m_icon"; import { getRecurrenceString, parseRecurrenceRule } from "../recurrence/base"; import { daysFromByDayRule } from "../recurrence/days_from_by_day_rule"; export const createFormIconTemplate = iconName => () => getImageContainer(iconName) ?? $("<div>").addClass("dx-scheduler-form-icon-sized-gap"); export const getStartDateCommonConfig = firstDayOfWeek => ({ colSpan: 1, itemType: "simple", editorType: "dxDateBox", validationRules: [{ type: "required" }], editorOptions: { type: "date", useMaskBehavior: true, calendarOptions: { firstDayOfWeek: firstDayOfWeek, showTodayButton: true } } }); export class RecurrenceRule { constructor(rule, startDate) { var _recurrenceRule$freq, _this$startDate; this.startDate = null; this.frequency = null; const recurrenceRule = parseRecurrenceRule(rule); const todayEnd = dateUtils.setToDayEnd(new Date); this.startDate = startDate; this.frequency = (null === (_recurrenceRule$freq = recurrenceRule.freq) || void 0 === _recurrenceRule$freq ? void 0 : _recurrenceRule$freq.toLowerCase()) ?? null; this.interval = recurrenceRule.interval ?? 1; this.until = recurrenceRule.until ?? todayEnd; this.count = recurrenceRule.count ?? 1; this.byDay = daysFromByDayRule(recurrenceRule); this.byMonthDay = recurrenceRule.bymonthday ? Number(recurrenceRule.bymonthday) : (null === startDate || void 0 === startDate ? void 0 : startDate.getDate()) ?? 1; this.byMonth = recurrenceRule.bymonth ? Number(recurrenceRule.bymonth) : ((null === (_this$startDate = this.startDate) || void 0 === _this$startDate ? void 0 : _this$startDate.getMonth()) ?? 0) + 1; this.repeatEnd = "never"; if (isDefined(recurrenceRule.count)) { this.repeatEnd = "count" } else if (isDefined(recurrenceRule.until)) { this.repeatEnd = "until" } } toString() { if (!this.frequency) { return } const rule = { freq: this.frequency, interval: this.interval }; if ("until" === this.repeatEnd && this.until) { rule.until = this.until } else if ("count" === this.repeatEnd && this.count) { rule.count = this.count } switch (this.frequency) { case "weekly": rule.byday = this.byDay.join(","); break; case "monthly": if (this.byMonthDay) { rule.bymonthday = String(this.byMonthDay) } break; case "yearly": if (this.byMonthDay && this.byMonth) { rule.bymonthday = String(this.byMonthDay); rule.bymonth = String(this.byMonth) } } return getRecurrenceString(rule) } }