ui.scheduler.recurrence_editor.js 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761
  1. /**
  2. * DevExtreme (ui/scheduler/ui.scheduler.recurrence_editor.js)
  3. * Version: 19.1.16
  4. * Build date: Tue Oct 18 2022
  5. *
  6. * Copyright (c) 2012 - 2022 Developer Express Inc. ALL RIGHTS RESERVED
  7. * Read about DevExtreme licensing here: https://js.devexpress.com/Licensing/
  8. */
  9. "use strict";
  10. var _renderer = require("../../core/renderer");
  11. var _renderer2 = _interopRequireDefault(_renderer);
  12. var _guid = require("../../core/guid");
  13. var _guid2 = _interopRequireDefault(_guid);
  14. var _component_registrator = require("../../core/component_registrator");
  15. var _component_registrator2 = _interopRequireDefault(_component_registrator);
  16. var _utils = require("./utils.recurrence");
  17. var _utils2 = _interopRequireDefault(_utils);
  18. var _dom = require("../../core/utils/dom");
  19. var _dom2 = _interopRequireDefault(_dom);
  20. var _type = require("../../core/utils/type");
  21. var _extend = require("../../core/utils/extend");
  22. var _array = require("../../core/utils/array");
  23. var _iterator = require("../../core/utils/iterator");
  24. var _editor = require("../editor/editor");
  25. var _editor2 = _interopRequireDefault(_editor);
  26. var _check_box = require("../check_box");
  27. var _check_box2 = _interopRequireDefault(_check_box);
  28. var _radio_group = require("../radio_group");
  29. var _radio_group2 = _interopRequireDefault(_radio_group);
  30. var _number_box = require("../number_box");
  31. var _number_box2 = _interopRequireDefault(_number_box);
  32. var _select_box = require("../select_box");
  33. var _select_box2 = _interopRequireDefault(_select_box);
  34. var _date_box = require("../date_box");
  35. var _date_box2 = _interopRequireDefault(_date_box);
  36. var _message = require("../../localization/message");
  37. var _message2 = _interopRequireDefault(_message);
  38. var _date = require("../../localization/date");
  39. var _date2 = _interopRequireDefault(_date);
  40. var _date3 = require("../../core/utils/date");
  41. var _date4 = _interopRequireDefault(_date3);
  42. var _uiScheduler = require("./ui.scheduler.publisher_mixin");
  43. var _uiScheduler2 = _interopRequireDefault(_uiScheduler);
  44. function _interopRequireDefault(obj) {
  45. return obj && obj.__esModule ? obj : {
  46. "default": obj
  47. }
  48. }
  49. function _classCallCheck(instance, Constructor) {
  50. if (!(instance instanceof Constructor)) {
  51. throw new TypeError("Cannot call a class as a function")
  52. }
  53. }
  54. function _defineProperties(target, props) {
  55. for (var i = 0; i < props.length; i++) {
  56. var descriptor = props[i];
  57. descriptor.enumerable = descriptor.enumerable || false;
  58. descriptor.configurable = true;
  59. if ("value" in descriptor) {
  60. descriptor.writable = true
  61. }
  62. Object.defineProperty(target, descriptor.key, descriptor)
  63. }
  64. }
  65. function _createClass(Constructor, protoProps, staticProps) {
  66. if (protoProps) {
  67. _defineProperties(Constructor.prototype, protoProps)
  68. }
  69. if (staticProps) {
  70. _defineProperties(Constructor, staticProps)
  71. }
  72. Object.defineProperty(Constructor, "prototype", {
  73. writable: false
  74. });
  75. return Constructor
  76. }
  77. var RECURRENCE_EDITOR = "dx-recurrence-editor";
  78. var LABEL_POSTFIX = "-label";
  79. var WRAPPER_POSTFIX = "-wrapper";
  80. var RECURRENCE_EDITOR_CONTAINER = "dx-recurrence-editor-container";
  81. var FREQUENCY_EDITOR = "dx-recurrence-selectbox-freq";
  82. var INTERVAL_EDITOR = "dx-recurrence-numberbox-interval";
  83. var INTERVAL_EDITOR_FIELD = "dx-recurrence-interval-field";
  84. var REPEAT_END_EDITOR = "dx-recurrence-repeat-end";
  85. var REPEAT_END_EDITOR_CONTAINER = "dx-recurrence-repeat-end-container";
  86. var REPEAT_TYPE_EDITOR = "dx-recurrence-radiogroup-repeat-type";
  87. var REPEAT_COUNT_EDITOR = "dx-recurrence-numberbox-repeat-count";
  88. var REPEAT_UNTIL_DATE_EDITOR = "dx-recurrence-datebox-until-date";
  89. var REPEAT_ON_EDITOR = "dx-recurrence-repeat-on";
  90. var REPEAT_ON_WEEK_EDITOR = "dx-recurrence-repeat-on-week";
  91. var DAY_OF_WEEK = "dx-recurrence-checkbox-day-of-week";
  92. var REPEAT_ON_MONTH_EDITOR = "dx-recurrence-repeat-on-month";
  93. var DAY_OF_MONTH = "dx-recurrence-numberbox-day-of-month";
  94. var REPEAT_ON_YEAR_EDITOR = "dx-recurrence-repeat-on-year";
  95. var MONTH_OF_YEAR = "dx-recurrence-selectbox-month-of-year";
  96. var FIELD_CLASS = "dx-field";
  97. var RECURRENCE_FREQ_FIELD = "dx-recurrence-freq-field";
  98. var FIELD_LABEL_CLASS = "dx-field-label";
  99. var FIELD_VALUE_CLASS = "dx-field-value";
  100. var frequencies = [{
  101. text: function() {
  102. return _message2.default.format("dxScheduler-recurrenceNever")
  103. },
  104. value: "never"
  105. }, {
  106. text: function() {
  107. return _message2.default.format("dxScheduler-recurrenceDaily")
  108. },
  109. value: "daily"
  110. }, {
  111. text: function() {
  112. return _message2.default.format("dxScheduler-recurrenceWeekly")
  113. },
  114. value: "weekly"
  115. }, {
  116. text: function() {
  117. return _message2.default.format("dxScheduler-recurrenceMonthly")
  118. },
  119. value: "monthly"
  120. }, {
  121. text: function() {
  122. return _message2.default.format("dxScheduler-recurrenceYearly")
  123. },
  124. value: "yearly"
  125. }];
  126. var repeatEndTypes = [{
  127. text: function() {
  128. return _message2.default.format("dxScheduler-recurrenceNever")
  129. },
  130. value: "never"
  131. }, {
  132. text: function() {
  133. return _message2.default.format("dxScheduler-recurrenceRepeatOnDate")
  134. },
  135. value: "until"
  136. }, {
  137. text: function() {
  138. return _message2.default.format("dxScheduler-recurrenceRepeatCount")
  139. },
  140. value: "count"
  141. }];
  142. var days = ["SU", "MO", "TU", "WE", "TH", "FR", "SA"];
  143. var RecurrenceRule = function() {
  144. function RecurrenceRule(recurrence) {
  145. _classCallCheck(this, RecurrenceRule);
  146. this._recurrenceRule = _utils2.default.getRecurrenceRule(recurrence).rule
  147. }
  148. _createClass(RecurrenceRule, [{
  149. key: "makeRules",
  150. value: function(string) {
  151. this._recurrenceRule = _utils2.default.getRecurrenceRule(string).rule
  152. }
  153. }, {
  154. key: "makeRule",
  155. value: function(field, value) {
  156. if (!value) {
  157. delete this._recurrenceRule[field];
  158. return
  159. }
  160. if ((0, _type.isDefined)(field)) {
  161. if ("until" === field) {
  162. delete this._recurrenceRule.count
  163. }
  164. if ("count" === field) {
  165. delete this._recurrenceRule.until
  166. }
  167. this._recurrenceRule[field] = value
  168. }
  169. }
  170. }, {
  171. key: "repeatableRule",
  172. value: function() {
  173. var rules = this._recurrenceRule;
  174. if ("count" in rules) {
  175. return "count"
  176. }
  177. if ("until" in rules) {
  178. return "until"
  179. }
  180. return null
  181. }
  182. }, {
  183. key: "recurrenceString",
  184. value: function() {
  185. return _utils2.default.getRecurrenceString(this._recurrenceRule)
  186. }
  187. }, {
  188. key: "rules",
  189. value: function() {
  190. return this._recurrenceRule
  191. }
  192. }, {
  193. key: "daysFromByDayRule",
  194. value: function() {
  195. return _utils2.default.daysFromByDayRule(this._recurrenceRule)
  196. }
  197. }]);
  198. return RecurrenceRule
  199. }();
  200. var RecurrenceEditor = _editor2.default.inherit({
  201. _getDefaultOptions: function() {
  202. return (0, _extend.extend)(this.callBase(), {
  203. value: null,
  204. startDate: new Date,
  205. firstDayOfWeek: void 0
  206. })
  207. },
  208. _getFirstDayOfWeek: function() {
  209. return (0, _type.isDefined)(this.option("firstDayOfWeek")) ? this.option("firstDayOfWeek") : _date2.default.firstDayOfWeekIndex()
  210. },
  211. _createComponent: function(element, name) {
  212. var config = arguments.length > 2 && void 0 !== arguments[2] ? arguments[2] : {};
  213. this._extendConfig(config, {
  214. readOnly: this.option("readOnly")
  215. });
  216. return this.callBase(element, name, config)
  217. },
  218. _init: function() {
  219. this.callBase();
  220. this._recurrenceRule = new RecurrenceRule(this.option("value"))
  221. },
  222. _render: function() {
  223. this.callBase();
  224. this.$element().addClass(RECURRENCE_EDITOR);
  225. this._$container = (0, _renderer2.default)("<div>").addClass(RECURRENCE_EDITOR_CONTAINER).appendTo(this.$element());
  226. this._renderEditors();
  227. this._renderContainerVisibility(this.option("value"))
  228. },
  229. _renderContainerVisibility: function(value) {
  230. if (value) {
  231. this._$container.show();
  232. _dom2.default.triggerShownEvent(this._$container)
  233. } else {
  234. this._$container.hide()
  235. }
  236. },
  237. _changeValueByVisibility: function(value) {
  238. this._renderContainerVisibility(value);
  239. if (value) {
  240. if (!this.option("value")) {
  241. this._handleDefaults()
  242. }
  243. } else {
  244. this._recurrenceRule.makeRules("");
  245. this.option("value", "")
  246. }
  247. },
  248. _handleDefaults: function() {
  249. this._recurrenceRule.makeRule("freq", "daily");
  250. this._changeEditorValue()
  251. },
  252. _changeEditorValue: function() {
  253. this.option("value", this._recurrenceRule.recurrenceString() || "")
  254. },
  255. _renderEditors: function() {
  256. this._renderFreqEditor();
  257. this._renderIntervalEditor();
  258. this._renderRepeatOnEditor();
  259. this._renderRepeatEndEditor()
  260. },
  261. _renderFreqEditor: function() {
  262. var _this = this;
  263. var freq = (this._recurrenceRule.rules().freq || "never").toLowerCase();
  264. var $freqEditor = (0, _renderer2.default)("<div>").addClass(FREQUENCY_EDITOR).addClass(FIELD_VALUE_CLASS);
  265. this._freqEditor = this._createComponent($freqEditor, _select_box2.default, {
  266. field: "freq",
  267. items: frequencies,
  268. value: freq,
  269. valueExpr: "value",
  270. displayExpr: "text",
  271. layout: "horizontal",
  272. onValueChanged: function(args) {
  273. _this._valueChangedHandler(args);
  274. _this.invoke("resizePopup")
  275. }
  276. });
  277. var $field = (0, _renderer2.default)("<div>").addClass(FIELD_CLASS).addClass(RECURRENCE_FREQ_FIELD).append($freqEditor);
  278. this.$element().prepend($field)
  279. },
  280. _renderIntervalEditor: function() {
  281. var freq = this._recurrenceRule.rules().freq || "daily";
  282. var $intervalEditor = (0, _renderer2.default)("<div>").addClass(INTERVAL_EDITOR).addClass(FIELD_VALUE_CLASS);
  283. var $intervalEditorLabel = (0, _renderer2.default)("<div>").text(_message2.default.format("dxScheduler-recurrenceRepeatEvery")).addClass(INTERVAL_EDITOR + LABEL_POSTFIX).addClass(FIELD_LABEL_CLASS);
  284. this._$intervalTypeLabel = (0, _renderer2.default)("<div>").text(_message2.default.format("dxScheduler-recurrenceRepeat".concat(freq.charAt(0).toUpperCase()).concat(freq.substr(1).toLowerCase()))).addClass(REPEAT_TYPE_EDITOR + LABEL_POSTFIX);
  285. var interval = this._recurrenceRule.rules().interval || 1;
  286. this._intervalEditor = this._createComponent($intervalEditor, _number_box2.default, {
  287. field: "interval",
  288. min: 1,
  289. value: interval,
  290. showSpinButtons: true,
  291. useLargeSpinButtons: false,
  292. onValueChanged: this._valueChangedHandler.bind(this)
  293. });
  294. var $field = (0, _renderer2.default)("<div>").addClass(FIELD_CLASS).addClass(INTERVAL_EDITOR_FIELD).append($intervalEditorLabel, $intervalEditor, this._$intervalTypeLabel);
  295. this._$container.append($field);
  296. this._setAriaDescribedBy(this._intervalEditor, $intervalEditorLabel)
  297. },
  298. _renderRepeatOnEditor: function() {
  299. var freq = (this._recurrenceRule.rules().freq || "").toLowerCase();
  300. if (!(0, _type.isDefined)(this._$repeatOnEditor)) {
  301. this._$repeatOnEditor = (0, _renderer2.default)("<div>").addClass(REPEAT_ON_EDITOR).addClass(FIELD_CLASS).appendTo(this._$container)
  302. }
  303. if (!freq || "daily" === freq) {
  304. this._clearRepeatOnEditor();
  305. this._clearRepeatOnLabel();
  306. return
  307. }
  308. if (!(0, _type.isDefined)(this._$repeatOnLabel)) {
  309. this._renderRepeatOnLabel(this._$repeatOnEditor)
  310. }
  311. if ("weekly" === freq && !this._$repeatOnWeek) {
  312. this._renderRepeatOnWeekEditor();
  313. return
  314. }
  315. if ("monthly" === freq && !this._$repeatOnMonth) {
  316. this._renderRepeatOnMonthEditor();
  317. return
  318. }
  319. if ("yearly" === freq && !this._$repeatOnYear) {
  320. this._renderRepeatOnYearEditor();
  321. return
  322. }
  323. },
  324. _renderRepeatOnLabel: function($element) {
  325. this._$repeatOnLabel = (0, _renderer2.default)("<div>").text(_message2.default.format("dxScheduler-recurrenceRepeatOn")).addClass(REPEAT_ON_EDITOR + LABEL_POSTFIX).addClass(FIELD_LABEL_CLASS);
  326. $element.append(this._$repeatOnLabel)
  327. },
  328. _clearRepeatOnEditor: function() {
  329. if ((0, _type.isDefined)(this._$repeatOnWeek)) {
  330. this._$repeatOnWeek.detach();
  331. this._$repeatOnWeek.remove();
  332. delete this._$repeatOnWeek
  333. }
  334. if ((0, _type.isDefined)(this._$repeatOnMonth)) {
  335. this._$repeatOnMonth.detach();
  336. this._$repeatOnMonth.remove();
  337. delete this._$repeatOnMonth
  338. }
  339. if ((0, _type.isDefined)(this._$repeatOnYear)) {
  340. this._$repeatOnYear.detach();
  341. this._$repeatOnYear.remove();
  342. delete this._$repeatOnYear
  343. }
  344. },
  345. _clearRepeatOnLabel: function() {
  346. if ((0, _type.isDefined)(this._$repeatOnLabel)) {
  347. this._$repeatOnLabel.detach();
  348. this._$repeatOnLabel.remove();
  349. delete this._$repeatOnLabel
  350. }
  351. },
  352. _renderRepeatOnWeekEditor: function() {
  353. this._clearRepeatOnEditor();
  354. this._$repeatOnWeek = (0, _renderer2.default)("<div>").addClass(REPEAT_ON_WEEK_EDITOR).addClass(FIELD_VALUE_CLASS).appendTo(this._$repeatOnEditor);
  355. var localDaysNames = _date2.default.getDayNames("short");
  356. var daysFromRules = this._daysOfWeekByRules();
  357. this._daysOfWeek = [];
  358. for (var i = 0; i < 7; i++) {
  359. var daysOffset = this._getFirstDayOfWeek() + i;
  360. var dayIndex = daysOffset % 7;
  361. var checkBoxText = localDaysNames[dayIndex].toUpperCase();
  362. var dayName = days[dayIndex];
  363. var $day = (0, _renderer2.default)("<div>").addClass(DAY_OF_WEEK);
  364. var day = this._createComponent($day, _check_box2.default, {
  365. text: checkBoxText,
  366. value: (0, _array.inArray)(dayName, daysFromRules) > -1 ? true : false,
  367. onValueChanged: this._repeatByDayValueChangeHandler.bind(this)
  368. });
  369. this._daysOfWeek[dayIndex] = day;
  370. this._$repeatOnWeek.append($day)
  371. }
  372. },
  373. _daysOfWeekByRules: function() {
  374. var daysByRule = this._recurrenceRule.daysFromByDayRule();
  375. if (!daysByRule.length) {
  376. daysByRule = [days[this.option("startDate").getDay()]]
  377. }
  378. return daysByRule
  379. },
  380. _repeatByDayValueChangeHandler: function() {
  381. var byDayRule = "";
  382. (0, _iterator.each)(this._daysOfWeek, function(index, day) {
  383. if (day.option("value")) {
  384. var dayName = days[index];
  385. if (!byDayRule) {
  386. byDayRule = dayName
  387. } else {
  388. byDayRule = "".concat(byDayRule, ",").concat(dayName)
  389. }
  390. }
  391. });
  392. this._recurrenceRule.makeRule("byday", byDayRule);
  393. this._changeEditorValue()
  394. },
  395. _renderRepeatOnMonthEditor: function() {
  396. this._clearRepeatOnEditor();
  397. this._$repeatOnMonth = (0, _renderer2.default)("<div>").addClass(REPEAT_ON_MONTH_EDITOR).addClass(FIELD_VALUE_CLASS).appendTo(this._$repeatOnEditor);
  398. this._renderDayOfMonthEditor(this._$repeatOnMonth)
  399. },
  400. _renderRepeatOnYearEditor: function() {
  401. this._clearRepeatOnEditor();
  402. this._$repeatOnYear = (0, _renderer2.default)("<div>").addClass(REPEAT_ON_YEAR_EDITOR).addClass(FIELD_VALUE_CLASS).appendTo(this._$repeatOnEditor);
  403. var months = [];
  404. var monthsNames = _date2.default.getMonthNames("wide");
  405. for (var i = 0; i < 12; i++) {
  406. months[i] = {
  407. value: String(i + 1),
  408. text: monthsNames[i]
  409. }
  410. }
  411. var byMonth = this._monthOfYearByRules();
  412. var $monthOfYear = (0, _renderer2.default)("<div>").addClass(MONTH_OF_YEAR).appendTo(this._$repeatOnYear);
  413. var monthChanged = function(args) {
  414. this._valueChangedHandler.call(this, args);
  415. var monthValue = parseInt(args.component.option("value"));
  416. if (this._dayEditor && monthValue) {
  417. var maxAllowedDay = new Date((new Date).getFullYear(), parseInt(monthValue), 0).getDate();
  418. if (2 === monthValue) {
  419. maxAllowedDay = 29
  420. }
  421. this._dayEditor.option("max", maxAllowedDay)
  422. }
  423. };
  424. this._monthEditor = this._createComponent($monthOfYear, _select_box2.default, {
  425. field: "bymonth",
  426. items: months,
  427. value: byMonth,
  428. displayExpr: "text",
  429. valueExpr: "value",
  430. onValueChanged: monthChanged.bind(this)
  431. });
  432. this._renderDayOfMonthEditor(this._$repeatOnYear)
  433. },
  434. _monthOfYearByRules: function() {
  435. var monthByRule = this._recurrenceRule.rules().bymonth;
  436. if (!monthByRule) {
  437. monthByRule = this.option("startDate").getMonth() + 1
  438. }
  439. return monthByRule
  440. },
  441. _renderDayOfMonthEditor: function($element) {
  442. var byMonthDay = this._dayOfMonthByRules();
  443. var $dayEditor = (0, _renderer2.default)("<div>").addClass(DAY_OF_MONTH);
  444. this._dayEditor = this._createComponent($dayEditor, _number_box2.default, {
  445. field: "bymonthday",
  446. min: 1,
  447. max: 31,
  448. showSpinButtons: true,
  449. useLargeSpinButtons: false,
  450. value: byMonthDay,
  451. onValueChanged: this._valueChangedHandler.bind(this)
  452. });
  453. $element.append($dayEditor)
  454. },
  455. _dayOfMonthByRules: function() {
  456. var dayByRule = this._recurrenceRule.rules().bymonthday;
  457. if (!dayByRule) {
  458. dayByRule = this.option("startDate").getDate()
  459. }
  460. return dayByRule
  461. },
  462. _setAriaDescribedBy: function(editor, $label) {
  463. var labelId = "label-".concat(new _guid2.default);
  464. editor.setAria("describedby", labelId);
  465. editor.setAria("id", labelId, $label)
  466. },
  467. _repeatEndSwitchValueChangeHandler: function(args) {
  468. var value = args.value;
  469. this._renderRepeatEndVisibility(value);
  470. if (!this._recurrenceRule.rules().count && !this._recurrenceRule.rules().until && value) {
  471. this._handleRepeatEndDefaults()
  472. } else {
  473. if (!value) {
  474. this._recurrenceRule.makeRule("count", "");
  475. this._recurrenceRule.makeRule("until", "");
  476. this._changeEditorValue()
  477. }
  478. }
  479. },
  480. _renderRepeatEndVisibility: function(value) {
  481. if (!value) {
  482. this._$repeatEndEditor.hide()
  483. } else {
  484. this._$repeatEndEditor.show()
  485. }
  486. },
  487. _handleRepeatEndDefaults: function() {
  488. this._recurrenceRule.makeRule("count", 1);
  489. this._changeEditorValue()
  490. },
  491. _renderRepeatEndEditor: function(rule) {
  492. rule = (0, _type.isDefined)(rule) ? rule : this._recurrenceRule.repeatableRule();
  493. if (!rule) {
  494. rule = "count"
  495. }
  496. if (!(0, _type.isDefined)(this._$repeatEndEditor)) {
  497. (0, _renderer2.default)("<div>").text(_message2.default.format("dxScheduler-recurrenceEnd")).addClass(REPEAT_END_EDITOR_CONTAINER + LABEL_POSTFIX).addClass(FIELD_LABEL_CLASS).appendTo(this._$container);
  498. this._$repeatEndEditor = (0, _renderer2.default)("<div>").addClass(REPEAT_END_EDITOR_CONTAINER).addClass(FIELD_CLASS).appendTo(this._$container);
  499. this._renderRepeatEndTypeEditor()
  500. }
  501. },
  502. _renderRepeatEndTypeEditor: function() {
  503. var _this2 = this;
  504. var repeatType = this._recurrenceRule.repeatableRule() || "never";
  505. this._$repeatTypeEditor = (0, _renderer2.default)("<div>").addClass(REPEAT_TYPE_EDITOR).addClass(FIELD_VALUE_CLASS).appendTo(this._$repeatEndEditor);
  506. this._repeatTypeEditor = this._createComponent(this._$repeatTypeEditor, _radio_group2.default, {
  507. items: repeatEndTypes,
  508. value: repeatType,
  509. displayExpr: "text",
  510. valueExpr: "value",
  511. itemTemplate: function(itemData) {
  512. if ("count" === itemData.value) {
  513. return _this2._renderRepeatCountEditor()
  514. }
  515. if ("until" === itemData.value) {
  516. return _this2._renderRepeatUntilEditor()
  517. }
  518. return _this2._renderDefaultRepeatEnd()
  519. },
  520. layout: "vertical",
  521. onValueChanged: this._repeatTypeValueChangedHandler.bind(this)
  522. });
  523. this._disableRepeatEndParts(repeatType)
  524. },
  525. _renderDefaultRepeatEnd: function() {
  526. var $editorTemplate = (0, _renderer2.default)("<div>").addClass(REPEAT_END_EDITOR + WRAPPER_POSTFIX);
  527. (0, _renderer2.default)("<div>").text(_message2.default.format("dxScheduler-recurrenceNever")).addClass(REPEAT_END_EDITOR + LABEL_POSTFIX).appendTo($editorTemplate);
  528. return $editorTemplate
  529. },
  530. _repeatTypeValueChangedHandler: function(args) {
  531. var value = args.value;
  532. this._disableRepeatEndParts(value);
  533. if ("until" === value) {
  534. this._recurrenceRule.makeRule(value, this._getUntilValue())
  535. }
  536. if ("count" === value) {
  537. this._recurrenceRule.makeRule(value, this._repeatCountEditor.option("value"))
  538. }
  539. if ("never" === value) {
  540. this._recurrenceRule.makeRule("count", "");
  541. this._recurrenceRule.makeRule("until", "")
  542. }
  543. this._changeEditorValue()
  544. },
  545. _disableRepeatEndParts: function(value) {
  546. if ("until" === value) {
  547. this._repeatCountEditor.option("disabled", true);
  548. this._repeatUntilDate.option("disabled", false)
  549. }
  550. if ("count" === value) {
  551. this._repeatCountEditor.option("disabled", false);
  552. this._repeatUntilDate.option("disabled", true)
  553. }
  554. if ("never" === value) {
  555. this._repeatCountEditor.option("disabled", true);
  556. this._repeatUntilDate.option("disabled", true)
  557. }
  558. },
  559. _renderRepeatCountEditor: function() {
  560. var repeatCount = this._recurrenceRule.rules().count || 1;
  561. var $editorTemplate = (0, _renderer2.default)("<div>").addClass(REPEAT_END_EDITOR + WRAPPER_POSTFIX);
  562. (0, _renderer2.default)("<div>").text(_message2.default.format("dxScheduler-recurrenceAfter")).addClass(REPEAT_END_EDITOR + LABEL_POSTFIX).appendTo($editorTemplate);
  563. this._$repeatCountEditor = (0, _renderer2.default)("<div>").addClass(REPEAT_COUNT_EDITOR).addClass(FIELD_VALUE_CLASS).appendTo($editorTemplate);
  564. (0, _renderer2.default)("<div>").text(_message2.default.format("dxScheduler-recurrenceRepeatCount")).addClass(REPEAT_END_EDITOR + LABEL_POSTFIX).appendTo($editorTemplate);
  565. this._repeatCountEditor = this._createComponent(this._$repeatCountEditor, _number_box2.default, {
  566. field: "count",
  567. min: 1,
  568. showSpinButtons: true,
  569. useLargeSpinButtons: false,
  570. value: repeatCount,
  571. onValueChanged: this._repeatCountValueChangeHandler.bind(this)
  572. });
  573. return $editorTemplate
  574. },
  575. _repeatCountValueChangeHandler: function(args) {
  576. if ("count" !== this._recurrenceRule.repeatableRule()) {
  577. return
  578. }
  579. var value = args.value;
  580. this._recurrenceRule.makeRule("count", value);
  581. this._changeEditorValue()
  582. },
  583. _formatUntilDate: function(date) {
  584. if (this._recurrenceRule.rules().until && _date4.default.sameDate(this._recurrenceRule.rules().until, date)) {
  585. return date
  586. }
  587. return _date4.default.setToDayEnd(date)
  588. },
  589. _renderRepeatUntilEditor: function() {
  590. var repeatUntil = this._recurrenceRule.rules().until || this._formatUntilDate(new Date);
  591. var $editorTemplate = (0, _renderer2.default)("<div>").addClass(REPEAT_END_EDITOR + WRAPPER_POSTFIX);
  592. (0, _renderer2.default)("<div>").text(_message2.default.format("dxScheduler-recurrenceOn")).addClass(REPEAT_END_EDITOR + LABEL_POSTFIX).appendTo($editorTemplate);
  593. this._$repeatDateEditor = (0, _renderer2.default)("<div>").addClass(REPEAT_UNTIL_DATE_EDITOR).addClass(FIELD_VALUE_CLASS).appendTo($editorTemplate);
  594. this._repeatUntilDate = this._createComponent(this._$repeatDateEditor, _date_box2.default, {
  595. field: "until",
  596. value: repeatUntil,
  597. type: "date",
  598. onValueChanged: this._repeatUntilValueChangeHandler.bind(this),
  599. calendarOptions: {
  600. firstDayOfWeek: this._getFirstDayOfWeek()
  601. }
  602. });
  603. return $editorTemplate
  604. },
  605. _repeatUntilValueChangeHandler: function(args) {
  606. if ("until" !== this._recurrenceRule.repeatableRule()) {
  607. return
  608. }
  609. var untilDate = this._formatUntilDate(new Date(args.value));
  610. this._repeatUntilDate.option("value", untilDate);
  611. this._recurrenceRule.makeRule("until", untilDate);
  612. this._changeEditorValue()
  613. },
  614. _valueChangedHandler: function(args) {
  615. var value = args.component.option("value");
  616. var field = args.component.option("field");
  617. var freqEditorValue = this._freqEditor && this._freqEditor.option("value");
  618. var visible = true;
  619. if ("freq" === field && "never" === value || "freq" !== field && "never" === freqEditorValue) {
  620. visible = false;
  621. this.option("value", "")
  622. } else {
  623. this._recurrenceRule.makeRule(field, value);
  624. this._makeRepeatOnRule(field, value);
  625. this._changeEditorValue()
  626. }
  627. this._renderContainerVisibility(visible)
  628. },
  629. _makeRepeatOnRule: function(field, value) {
  630. if ("freq" !== field) {
  631. return
  632. }
  633. if ("daily" === value) {
  634. this._recurrenceRule.makeRule("byday", "");
  635. this._recurrenceRule.makeRule("bymonth", "");
  636. this._recurrenceRule.makeRule("bymonthday", "")
  637. }
  638. if ("weekly" === value) {
  639. this._recurrenceRule.makeRule("byday", this._daysOfWeekByRules());
  640. this._recurrenceRule.makeRule("bymonth", "");
  641. this._recurrenceRule.makeRule("bymonthday", "")
  642. }
  643. if ("monthly" === value) {
  644. this._recurrenceRule.makeRule("bymonthday", this._dayOfMonthByRules());
  645. this._recurrenceRule.makeRule("bymonth", "");
  646. this._recurrenceRule.makeRule("byday", "")
  647. }
  648. if ("yearly" === value) {
  649. this._recurrenceRule.makeRule("bymonthday", this._dayOfMonthByRules());
  650. this._recurrenceRule.makeRule("bymonth", this._monthOfYearByRules());
  651. this._recurrenceRule.makeRule("byday", "")
  652. }
  653. },
  654. _optionChanged: function(args) {
  655. switch (args.name) {
  656. case "value":
  657. this._recurrenceRule.makeRules(args.value);
  658. this._repeatTypeEditor.option("value", this._recurrenceRule.repeatableRule() || "never");
  659. this._renderRepeatEndEditor();
  660. this._renderRepeatOnEditor();
  661. this._changeEditorsValues(this._recurrenceRule.rules());
  662. this.callBase(args);
  663. break;
  664. case "startDate":
  665. this._clearRepeatOnEditor();
  666. this._renderRepeatOnEditor();
  667. this._makeRepeatOnRule("freq", this._recurrenceRule.rules().freq);
  668. if ((0, _type.isDefined)(this._recurrenceRule.recurrenceString())) {
  669. this._changeEditorValue()
  670. }
  671. break;
  672. case "firstDayOfWeek":
  673. this._clearRepeatOnEditor();
  674. this._renderRepeatOnEditor();
  675. if (this._$repeatDateEditor) {
  676. this._repeatUntilDate.option("calendarOptions.firstDayOfWeek", this._getFirstDayOfWeek())
  677. }
  678. break;
  679. case "visible":
  680. this._changeValueByVisibility(args.value);
  681. this.callBase(args);
  682. break;
  683. default:
  684. this.callBase(args)
  685. }
  686. },
  687. _changeEditorsValues: function(rules) {
  688. this._changeCheckBoxesValue(!!rules.byday);
  689. this._freqEditor.option("value", (rules.freq || "never").toLowerCase());
  690. this._changeRepeatTypeLabel();
  691. this._intervalEditor.option("value", rules.interval);
  692. this._changeRepeatCountValue();
  693. this._changeRepeatUntilValue();
  694. this._changeDayOfMonthValue();
  695. this._changeMonthOfYearValue()
  696. },
  697. _changeRepeatTypeLabel: function() {
  698. var $labels = this.$element().find(".".concat(REPEAT_TYPE_EDITOR).concat(LABEL_POSTFIX));
  699. if (!$labels.length) {
  700. return
  701. }
  702. var freq = this._recurrenceRule.rules().freq || "daily";
  703. (0, _iterator.each)($labels, function(_, $label) {
  704. (0, _renderer2.default)($label).text(_message2.default.format("dxScheduler-recurrenceRepeat".concat(freq.charAt(0).toUpperCase()).concat(freq.substr(1).toLowerCase())))
  705. })
  706. },
  707. _changeRepeatCountValue: function() {
  708. if (!this._$repeatCountEditor) {
  709. return
  710. }
  711. var count = this._recurrenceRule.rules().count || 1;
  712. this._repeatCountEditor.option("value", count)
  713. },
  714. _changeRepeatUntilValue: function() {
  715. if (!this._$repeatDateEditor) {
  716. return
  717. }
  718. this._repeatUntilDate.option("value", this._getUntilValue())
  719. },
  720. _getUntilValue: function() {
  721. return this._recurrenceRule.rules().until || this._formatUntilDate(new Date)
  722. },
  723. _changeCheckBoxesValue: function(byDayChanged) {
  724. if (!this._$repeatOnWeek || !byDayChanged) {
  725. return
  726. }
  727. var daysByRule = this._daysOfWeekByRules();
  728. (0, _iterator.each)(this._daysOfWeek, function(index, day) {
  729. var dayName = days[index];
  730. day.option("value", (0, _array.inArray)(dayName, daysByRule) > -1)
  731. })
  732. },
  733. _changeDayOfMonthValue: function() {
  734. if (!this._$repeatOnMonth && !this._$repeatOnYear) {
  735. return
  736. }
  737. var day = this._dayOfMonthByRules() || 1;
  738. this._dayEditor.option("value", day)
  739. },
  740. _changeMonthOfYearValue: function() {
  741. if (!this._$repeatOnYear) {
  742. return
  743. }
  744. var month = this._monthOfYearByRules() || 1;
  745. this._monthEditor.option("value", month)
  746. },
  747. toggle: function() {
  748. this._freqEditor.focus()
  749. },
  750. setAria: function() {
  751. if (this._switchEditor) {
  752. this._switchEditor.setAria(arguments.length <= 0 ? void 0 : arguments[0], arguments.length <= 1 ? void 0 : arguments[1])
  753. }
  754. }
  755. }).include(_uiScheduler2.default);
  756. (0, _component_registrator2.default)("dxRecurrenceEditor", RecurrenceEditor);
  757. module.exports = RecurrenceEditor;