ui.scheduler.appointment_form.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  1. /**
  2. * DevExtreme (ui/scheduler/ui.scheduler.appointment_form.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 _form = require("../form");
  13. var _form2 = _interopRequireDefault(_form);
  14. var _date_serialization = require("../../core/utils/date_serialization");
  15. var _date_serialization2 = _interopRequireDefault(_date_serialization);
  16. var _message = require("../../localization/message");
  17. var _message2 = _interopRequireDefault(_message);
  18. var _click = require("../../events/click");
  19. var _click2 = _interopRequireDefault(_click);
  20. var _type = require("../../core/utils/type");
  21. var _type2 = _interopRequireDefault(_type);
  22. var _events_engine = require("../../events/core/events_engine");
  23. var _events_engine2 = _interopRequireDefault(_events_engine);
  24. require("./ui.scheduler.recurrence_editor");
  25. require("./timezones/ui.scheduler.timezone_editor");
  26. require("../text_area");
  27. require("../tag_box");
  28. require("../switch");
  29. function _interopRequireDefault(obj) {
  30. return obj && obj.__esModule ? obj : {
  31. "default": obj
  32. }
  33. }
  34. var RECURRENCE_EDITOR_ITEM_CLASS = "dx-scheduler-recurrence-rule-item";
  35. var SCREEN_SIZE_OF_TOP_LABEL_LOCATION = 608;
  36. var SCREEN_SIZE_OF_SINGLE_COLUMN = 460;
  37. var SchedulerAppointmentForm = {
  38. _appointmentForm: {},
  39. _lockDateShiftFlag: false,
  40. _validateAppointmentFormDate: function(editor, value, previousValue) {
  41. var isCurrentDateCorrect = null === value || !!value;
  42. var isPreviousDateCorrect = null === previousValue || !!previousValue;
  43. if (!isCurrentDateCorrect && isPreviousDateCorrect) {
  44. editor.option("value", previousValue)
  45. }
  46. },
  47. _getAllDayStartDate: function(startDate) {
  48. return startDate.setHours(0, 0, 0, 0)
  49. },
  50. _getAllDayEndDate: function(startDate) {
  51. var endDate = new Date(startDate);
  52. endDate.setDate(startDate.getDate() + 1);
  53. return endDate
  54. },
  55. _updateLabelLocation: function(formWidth) {
  56. if (formWidth > 0 && this._appointmentForm._initialized && this._appointmentForm.isReady()) {
  57. this._appointmentForm.option("labelLocation", formWidth < SCREEN_SIZE_OF_TOP_LABEL_LOCATION ? "top" : "left")
  58. }
  59. },
  60. create: function(componentCreator, $container, isReadOnly, formData) {
  61. var _this = this;
  62. this._appointmentForm = componentCreator($container, _form2.default, {
  63. items: this._editors,
  64. readOnly: isReadOnly,
  65. showValidationSummary: true,
  66. scrollingEnabled: true,
  67. formData: formData,
  68. colCount: 2,
  69. showColonAfterLabel: false,
  70. onContentReady: function() {
  71. var formWidth = $container.parent().outerWidth();
  72. _this._updateLabelLocation(formWidth)
  73. },
  74. screenByWidth: function() {
  75. var formWidth = $container.parent().outerWidth();
  76. _this._updateLabelLocation(formWidth);
  77. return formWidth < SCREEN_SIZE_OF_SINGLE_COLUMN ? "xs" : "lg"
  78. }
  79. });
  80. return this._appointmentForm
  81. },
  82. prepareAppointmentFormEditors: function(allDay, dataExprs, schedulerInst) {
  83. var that = this;
  84. this._editors = [{
  85. dataField: dataExprs.textExpr,
  86. editorType: "dxTextBox",
  87. colSpan: 2,
  88. label: {
  89. text: _message2.default.format("dxScheduler-editorLabelTitle")
  90. }
  91. }, {
  92. dataField: dataExprs.startDateExpr,
  93. editorType: "dxDateBox",
  94. label: {
  95. text: _message2.default.format("dxScheduler-editorLabelStartDate")
  96. },
  97. validationRules: [{
  98. type: "required"
  99. }],
  100. editorOptions: {
  101. type: allDay ? "date" : "datetime",
  102. width: "100%",
  103. calendarOptions: {
  104. firstDayOfWeek: schedulerInst.option("firstDayOfWeek")
  105. },
  106. onValueChanged: function(args) {
  107. that._validateAppointmentFormDate(args.component, args.value, args.previousValue);
  108. var value = _date_serialization2.default.deserializeDate(args.value);
  109. var previousValue = _date_serialization2.default.deserializeDate(args.previousValue);
  110. var endDateEditor = that._appointmentForm.getEditor(dataExprs.endDateExpr);
  111. var endValue = _date_serialization2.default.deserializeDate(endDateEditor.option("value"));
  112. if (!that._appointmentForm._lockDateShiftFlag && _type2.default.isDefined(endValue) && _type2.default.isDefined(value) && !!endValue && endValue < value) {
  113. var duration = endValue.getTime() - previousValue.getTime();
  114. endDateEditor.option("value", new Date(value.getTime() + duration))
  115. }
  116. }
  117. }
  118. }, {
  119. dataField: dataExprs.startDateTimeZoneExpr,
  120. editorType: "dxSchedulerTimezoneEditor",
  121. colSpan: 2,
  122. label: {
  123. text: " ",
  124. showColon: false
  125. },
  126. editorOptions: {
  127. observer: schedulerInst
  128. },
  129. visible: false
  130. }, {
  131. dataField: dataExprs.endDateExpr,
  132. editorType: "dxDateBox",
  133. label: {
  134. text: _message2.default.format("dxScheduler-editorLabelEndDate")
  135. },
  136. validationRules: [{
  137. type: "required"
  138. }],
  139. editorOptions: {
  140. type: allDay ? "date" : "datetime",
  141. width: "100%",
  142. calendarOptions: {
  143. firstDayOfWeek: schedulerInst.option("firstDayOfWeek")
  144. },
  145. onValueChanged: function(args) {
  146. that._validateAppointmentFormDate(args.component, args.value, args.previousValue);
  147. var value = _date_serialization2.default.deserializeDate(args.value);
  148. var previousValue = _date_serialization2.default.deserializeDate(args.previousValue);
  149. var startDateEditor = that._appointmentForm.getEditor(dataExprs.startDateExpr);
  150. var startValue = _date_serialization2.default.deserializeDate(startDateEditor.option("value"));
  151. if (!that._appointmentForm._lockDateShiftFlag && !!value && startValue > value) {
  152. var duration = previousValue ? previousValue.getTime() - startValue.getTime() : 0;
  153. startDateEditor.option("value", new Date(value.getTime() - duration))
  154. }
  155. }
  156. }
  157. }, {
  158. dataField: dataExprs.endDateTimeZoneExpr,
  159. editorType: "dxSchedulerTimezoneEditor",
  160. colSpan: 2,
  161. label: {
  162. text: " ",
  163. showColon: false
  164. },
  165. editorOptions: {
  166. observer: schedulerInst
  167. },
  168. visible: false
  169. }, {
  170. dataField: dataExprs.allDayExpr,
  171. editorType: "dxSwitch",
  172. colSpan: 2,
  173. label: {
  174. text: _message2.default.format("dxScheduler-allDay")
  175. },
  176. editorOptions: {
  177. onValueChanged: function(args) {
  178. var value = args.value;
  179. var startDateEditor = that._appointmentForm.getEditor(dataExprs.startDateExpr);
  180. var endDateEditor = that._appointmentForm.getEditor(dataExprs.endDateExpr);
  181. if (startDateEditor && endDateEditor) {
  182. startDateEditor.option("type", value ? "date" : "datetime");
  183. endDateEditor.option("type", value ? "date" : "datetime");
  184. if (!startDateEditor.option("value")) {
  185. return
  186. }
  187. var startDate = _date_serialization2.default.deserializeDate(startDateEditor.option("value"));
  188. if (value) {
  189. startDateEditor.option("value", that._getAllDayStartDate(startDate));
  190. endDateEditor.option("value", that._getAllDayEndDate(startDate))
  191. } else {
  192. startDate.setHours(schedulerInst.option("startDayHour"));
  193. startDateEditor.option("value", startDate);
  194. endDateEditor.option("value", schedulerInst._workSpace.calculateEndDate(_date_serialization2.default.deserializeDate(startDateEditor.option("value"))))
  195. }
  196. }
  197. }
  198. }
  199. }, {
  200. itemType: "empty",
  201. colSpan: 2
  202. }, {
  203. dataField: dataExprs.descriptionExpr,
  204. editorType: "dxTextArea",
  205. colSpan: 2,
  206. label: {
  207. text: _message2.default.format("dxScheduler-editorLabelDescription")
  208. }
  209. }, {
  210. itemType: "empty",
  211. colSpan: 2
  212. }, {
  213. dataField: dataExprs.recurrenceRuleExpr,
  214. editorType: "dxRecurrenceEditor",
  215. colSpan: 2,
  216. editorOptions: {
  217. observer: schedulerInst,
  218. firstDayOfWeek: schedulerInst.option("firstDayOfWeek"),
  219. onValueChanged: function(args) {
  220. var value = that._getRecurrenceRule(schedulerInst, that._appointmentForm);
  221. schedulerInst.fire("recurrenceEditorVisibilityChanged", value)
  222. },
  223. onContentReady: function(args) {
  224. var $editorField = (0, _renderer2.default)(args.element).closest(".dx-field-item");
  225. var $editorLabel = $editorField.find(".dx-field-item-label");
  226. _events_engine2.default.off($editorLabel, _click2.default.name);
  227. _events_engine2.default.on($editorLabel, _click2.default.name, function() {
  228. args.component.toggle()
  229. })
  230. }
  231. },
  232. cssClass: RECURRENCE_EDITOR_ITEM_CLASS,
  233. label: {
  234. text: _message2.default.format("dxScheduler-editorLabelRecurrence")
  235. }
  236. }];
  237. if (!dataExprs.recurrenceRuleExpr) {
  238. this._editors.splice(9, 2)
  239. }
  240. return this._editors
  241. },
  242. _getRecurrenceRule: function(schedulerInstance, appointmentForm) {
  243. return !_type2.default.isEmptyObject(appointmentForm) ? !!schedulerInstance.fire("getField", "recurrenceRule", appointmentForm.option("formData")) : false
  244. },
  245. concatResources: function(resources) {
  246. this._editors = this._editors.concat(resources)
  247. },
  248. checkEditorsType: function(form, startDateExpr, endDateExpr, allDay) {
  249. var startDateFormItem = form.itemOption(startDateExpr);
  250. var endDateFormItem = form.itemOption(endDateExpr);
  251. if (startDateFormItem && endDateFormItem) {
  252. var startDateEditorOptions = startDateFormItem.editorOptions;
  253. var endDateEditorOptions = endDateFormItem.editorOptions;
  254. if (allDay) {
  255. startDateEditorOptions.type = endDateEditorOptions.type = "date"
  256. } else {
  257. startDateEditorOptions.type = endDateEditorOptions.type = "datetime"
  258. }
  259. form.itemOption(startDateExpr, "editorOptions", startDateEditorOptions);
  260. form.itemOption(endDateExpr, "editorOptions", endDateEditorOptions)
  261. }
  262. },
  263. updateFormData: function(appointmentForm, formData) {
  264. appointmentForm._lockDateShiftFlag = true;
  265. appointmentForm.option("formData", formData);
  266. appointmentForm._lockDateShiftFlag = false
  267. }
  268. };
  269. module.exports = SchedulerAppointmentForm;