ui.scheduler.appointment_model.js 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572
  1. /**
  2. * DevExtreme (ui/scheduler/ui.scheduler.appointment_model.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 _config = require("../../core/config");
  11. var _config2 = _interopRequireDefault(_config);
  12. var _iterator = require("../../core/utils/iterator");
  13. var _iterator2 = _interopRequireDefault(_iterator);
  14. var _date_serialization = require("../../core/utils/date_serialization");
  15. var _date_serialization2 = _interopRequireDefault(_date_serialization);
  16. var _utils = require("./utils.recurrence");
  17. var _utils2 = _interopRequireDefault(_utils);
  18. var _date = require("../../core/utils/date");
  19. var _date2 = _interopRequireDefault(_date);
  20. var _common = require("../../core/utils/common");
  21. var _common2 = _interopRequireDefault(_common);
  22. var _type = require("../../core/utils/type");
  23. var _type2 = _interopRequireDefault(_type);
  24. var _array = require("../../core/utils/array");
  25. var _array2 = _interopRequireDefault(_array);
  26. var _extend = require("../../core/utils/extend");
  27. var _query = require("../../data/query");
  28. var _query2 = _interopRequireDefault(_query);
  29. function _interopRequireDefault(obj) {
  30. return obj && obj.__esModule ? obj : {
  31. "default": obj
  32. }
  33. }
  34. function _classCallCheck(instance, Constructor) {
  35. if (!(instance instanceof Constructor)) {
  36. throw new TypeError("Cannot call a class as a function")
  37. }
  38. }
  39. function _defineProperties(target, props) {
  40. for (var i = 0; i < props.length; i++) {
  41. var descriptor = props[i];
  42. descriptor.enumerable = descriptor.enumerable || false;
  43. descriptor.configurable = true;
  44. if ("value" in descriptor) {
  45. descriptor.writable = true
  46. }
  47. Object.defineProperty(target, descriptor.key, descriptor)
  48. }
  49. }
  50. function _createClass(Constructor, protoProps, staticProps) {
  51. if (protoProps) {
  52. _defineProperties(Constructor.prototype, protoProps)
  53. }
  54. if (staticProps) {
  55. _defineProperties(Constructor, staticProps)
  56. }
  57. Object.defineProperty(Constructor, "prototype", {
  58. writable: false
  59. });
  60. return Constructor
  61. }
  62. var toMs = _date2.default.dateToMilliseconds;
  63. var DATE_FILTER_POSITION = 0;
  64. var USER_FILTER_POSITION = 1;
  65. var FilterMaker = function() {
  66. function FilterMaker(dataAccessors) {
  67. _classCallCheck(this, FilterMaker);
  68. this._filterRegistry = null;
  69. this._dataAccessors = dataAccessors
  70. }
  71. _createClass(FilterMaker, [{
  72. key: "isRegistered",
  73. value: function() {
  74. return !!this._filterRegistry
  75. }
  76. }, {
  77. key: "clearRegistry",
  78. value: function() {
  79. delete this._filterRegistry
  80. }
  81. }, {
  82. key: "make",
  83. value: function(type, args) {
  84. if (!this._filterRegistry) {
  85. this._filterRegistry = {}
  86. }
  87. this._make(type).apply(this, args)
  88. }
  89. }, {
  90. key: "_make",
  91. value: function(type) {
  92. var _this = this;
  93. switch (type) {
  94. case "date":
  95. return function(min, max, useAccessors) {
  96. var startDate = useAccessors ? _this._dataAccessors.getter.startDate : _this._dataAccessors.expr.startDateExpr;
  97. var endDate = useAccessors ? _this._dataAccessors.getter.endDate : _this._dataAccessors.expr.endDateExpr;
  98. var recurrenceRule = _this._dataAccessors.expr.recurrenceRuleExpr;
  99. _this._filterRegistry.date = [
  100. [
  101. [endDate, ">", min],
  102. [startDate, "<", max]
  103. ], "or", [recurrenceRule, "startswith", "freq"], "or", [
  104. [endDate, min],
  105. [startDate, min]
  106. ]
  107. ];
  108. if (!recurrenceRule) {
  109. _this._filterRegistry.date.splice(1, 2)
  110. }
  111. };
  112. case "user":
  113. return function(userFilter) {
  114. _this._filterRegistry.user = userFilter
  115. }
  116. }
  117. }
  118. }, {
  119. key: "combine",
  120. value: function() {
  121. var filter = [];
  122. this._filterRegistry.date && filter.push(this._filterRegistry.date);
  123. this._filterRegistry.user && filter.push(this._filterRegistry.user);
  124. return filter
  125. }
  126. }, {
  127. key: "dateFilter",
  128. value: function() {
  129. return this._filterRegistry.date
  130. }
  131. }]);
  132. return FilterMaker
  133. }();
  134. var compareDateWithStartDayHour = function(startDate, endDate, startDayHour, allDay, severalDays) {
  135. var startTime = _date2.default.dateTimeFromDecimal(startDayHour);
  136. var result = startDate.getHours() >= startTime.hours && startDate.getMinutes() >= startTime.minutes || endDate.getHours() === startTime.hours && endDate.getMinutes() > startTime.minutes || endDate.getHours() > startTime.hours || severalDays || allDay;
  137. return result
  138. };
  139. var compareDateWithEndDayHour = function(startDate, endDate, startDayHour, endDayHour, allDay, severalDays, max, min) {
  140. var hiddenInterval = (24 - endDayHour + startDayHour) * toMs("hour");
  141. var apptDuration = endDate.getTime() - startDate.getTime();
  142. var delta = (hiddenInterval - apptDuration) / toMs("hour");
  143. var apptStartHour = startDate.getHours();
  144. var apptStartMinutes = startDate.getMinutes();
  145. var result;
  146. var endTime = _date2.default.dateTimeFromDecimal(endDayHour);
  147. var startTime = _date2.default.dateTimeFromDecimal(startDayHour);
  148. result = apptStartHour < endTime.hours || apptStartHour === endTime.hours && apptStartMinutes < endTime.minutes || allDay && startDate <= max || severalDays && startDate < max && endDate > min && (apptStartHour < endTime.hours || 60 * endDate.getHours() + endDate.getMinutes() > 60 * startTime.hours);
  149. if (apptDuration < hiddenInterval) {
  150. if (apptStartHour > endTime.hours && apptStartMinutes > endTime.minutes && delta <= apptStartHour - endDayHour) {
  151. result = false
  152. }
  153. }
  154. return result
  155. };
  156. var AppointmentModel = function() {
  157. function AppointmentModel(dataSource, dataAccessors, baseAppointmentDuration) {
  158. _classCallCheck(this, AppointmentModel);
  159. this.setDataAccessors(dataAccessors);
  160. this.setDataSource(dataSource);
  161. this._updatedAppointmentKeys = [];
  162. this._filterMaker = new FilterMaker(dataAccessors);
  163. this._baseAppointmentDuration = baseAppointmentDuration
  164. }
  165. _createClass(AppointmentModel, [{
  166. key: "_createFilter",
  167. value: function(min, max, remoteFiltering, dateSerializationFormat) {
  168. this._filterMaker.make("date", [min, max]);
  169. var userFilterPosition = this._excessFiltering() ? this._dataSource.filter()[USER_FILTER_POSITION] : this._dataSource.filter();
  170. this._filterMaker.make("user", [userFilterPosition]);
  171. if (remoteFiltering) {
  172. this._dataSource.filter(this._combineRemoteFilter(dateSerializationFormat))
  173. }
  174. }
  175. }, {
  176. key: "_excessFiltering",
  177. value: function() {
  178. var dateFilter = this._filterMaker.dateFilter();
  179. var dataSourceFilter = this._dataSource.filter();
  180. return dataSourceFilter && (_common2.default.equalByValue(dataSourceFilter, dateFilter) || dataSourceFilter.length && _common2.default.equalByValue(dataSourceFilter[DATE_FILTER_POSITION], dateFilter))
  181. }
  182. }, {
  183. key: "_combineFilter",
  184. value: function() {
  185. return this._filterMaker.combine()
  186. }
  187. }, {
  188. key: "_getStoreKey",
  189. value: function(target) {
  190. var store = this._dataSource.store();
  191. return store.keyOf(target)
  192. }
  193. }, {
  194. key: "_filterAppointmentByResources",
  195. value: function(appointment, resources) {
  196. var _this2 = this;
  197. var result = false;
  198. var checkAppointmentResourceValues = function() {
  199. var resourceGetter = _this2._dataAccessors.getter.resources[resourceName];
  200. var resource;
  201. if (_type2.default.isFunction(resourceGetter)) {
  202. resource = resourceGetter(appointment)
  203. }
  204. var appointmentResourceValues = _array2.default.wrapToArray(resource);
  205. var resourceData = _iterator2.default.map(resources[i].items, function(item) {
  206. return item.id
  207. });
  208. for (var j = 0, itemDataCount = appointmentResourceValues.length; j < itemDataCount; j++) {
  209. if ((0, _array.inArray)(appointmentResourceValues[j], resourceData) > -1) {
  210. return true
  211. }
  212. }
  213. return false
  214. };
  215. for (var i = 0, len = resources.length; i < len; i++) {
  216. var resourceName = resources[i].name;
  217. result = checkAppointmentResourceValues.call(this);
  218. if (!result) {
  219. return false
  220. }
  221. }
  222. return result
  223. }
  224. }, {
  225. key: "_filterAppointmentByRRule",
  226. value: function(appointment, min, max, startDayHour, endDayHour, firstDayOfWeek) {
  227. var recurrenceRule = appointment.recurrenceRule;
  228. var recurrenceException = appointment.recurrenceException;
  229. var allDay = appointment.allDay;
  230. var result = true;
  231. var appointmentStartDate = appointment.startDate;
  232. var appointmentEndDate = appointment.endDate;
  233. if (allDay || this._appointmentPartInInterval(appointmentStartDate, appointmentEndDate, startDayHour, endDayHour)) {
  234. var trimmedDates = this._trimDates(min, max);
  235. min = trimmedDates.min;
  236. max = new Date(trimmedDates.max.getTime() - toMs("minute"))
  237. }
  238. if (recurrenceRule && !_utils2.default.getRecurrenceRule(recurrenceRule).isValid) {
  239. result = appointmentEndDate > min && appointmentStartDate <= max
  240. }
  241. if (result && _utils2.default.getRecurrenceRule(recurrenceRule).isValid) {
  242. result = _utils2.default.dateInRecurrenceRange({
  243. rule: recurrenceRule,
  244. exception: recurrenceException,
  245. start: appointmentStartDate,
  246. end: appointmentEndDate,
  247. min: min,
  248. max: max,
  249. firstDayOfWeek: firstDayOfWeek
  250. })
  251. }
  252. return result
  253. }
  254. }, {
  255. key: "_appointmentPartInInterval",
  256. value: function(startDate, endDate, startDayHour, endDayHour) {
  257. var apptStartDayHour = startDate.getHours();
  258. var apptEndDayHour = endDate.getHours();
  259. return apptStartDayHour <= startDayHour && apptEndDayHour <= endDayHour && apptEndDayHour >= startDayHour || apptEndDayHour >= endDayHour && apptStartDayHour <= endDayHour && apptStartDayHour >= startDayHour
  260. }
  261. }, {
  262. key: "_createCombinedFilter",
  263. value: function(filterOptions, timeZoneProcessor) {
  264. var dataAccessors = this._dataAccessors;
  265. var startDayHour = filterOptions.startDayHour;
  266. var endDayHour = filterOptions.endDayHour;
  267. var min = new Date(filterOptions.min);
  268. var max = new Date(filterOptions.max);
  269. var resources = filterOptions.resources;
  270. var firstDayOfWeek = filterOptions.firstDayOfWeek;
  271. var getRecurrenceException = filterOptions.recurrenceException;
  272. var that = this;
  273. return [
  274. [function(appointment) {
  275. var result = true;
  276. var startDate = new Date(dataAccessors.getter.startDate(appointment));
  277. var endDate = new Date(dataAccessors.getter.endDate(appointment));
  278. var appointmentTakesAllDay = that.appointmentTakesAllDay(appointment, startDayHour, endDayHour);
  279. var appointmentTakesSeveralDays = that.appointmentTakesSeveralDays(appointment);
  280. var isAllDay = dataAccessors.getter.allDay(appointment);
  281. var appointmentIsLong = appointmentTakesSeveralDays || appointmentTakesAllDay;
  282. var useRecurrence = _type2.default.isDefined(dataAccessors.getter.recurrenceRule);
  283. var recurrenceRule;
  284. if (useRecurrence) {
  285. recurrenceRule = dataAccessors.getter.recurrenceRule(appointment)
  286. }
  287. if (resources && resources.length) {
  288. result = that._filterAppointmentByResources(appointment, resources)
  289. }
  290. if (appointmentTakesAllDay && false === filterOptions.allDay) {
  291. result = false
  292. }
  293. var startDateTimeZone = dataAccessors.getter.startDateTimeZone(appointment);
  294. var endDateTimeZone = dataAccessors.getter.endDateTimeZone(appointment);
  295. var comparableStartDate = timeZoneProcessor(startDate, startDateTimeZone);
  296. var comparableEndDate = timeZoneProcessor(endDate, endDateTimeZone);
  297. if (result && useRecurrence) {
  298. var recurrenceException = getRecurrenceException ? getRecurrenceException(appointment) : dataAccessors.getter.recurrenceException(appointment);
  299. result = that._filterAppointmentByRRule({
  300. startDate: comparableStartDate,
  301. endDate: comparableEndDate,
  302. recurrenceRule: recurrenceRule,
  303. recurrenceException: recurrenceException,
  304. allDay: appointmentTakesAllDay
  305. }, min, max, startDayHour, endDayHour, firstDayOfWeek)
  306. }
  307. if (result && comparableEndDate < min && appointmentIsLong && !isAllDay && (!useRecurrence || useRecurrence && !recurrenceRule)) {
  308. result = false
  309. }
  310. if (result && void 0 !== startDayHour) {
  311. result = compareDateWithStartDayHour(comparableStartDate, comparableEndDate, startDayHour, appointmentTakesAllDay, appointmentTakesSeveralDays)
  312. }
  313. if (result && void 0 !== endDayHour) {
  314. result = compareDateWithEndDayHour(comparableStartDate, comparableEndDate, startDayHour, endDayHour, appointmentTakesAllDay, appointmentTakesSeveralDays, max, min)
  315. }
  316. if (result && useRecurrence && !recurrenceRule) {
  317. if (comparableEndDate < min && !isAllDay) {
  318. result = false
  319. }
  320. }
  321. return result
  322. }]
  323. ]
  324. }
  325. }, {
  326. key: "setDataSource",
  327. value: function(dataSource) {
  328. this._dataSource = dataSource;
  329. this.cleanModelState();
  330. this._initStoreChangeHandlers();
  331. this._filterMaker && this._filterMaker.clearRegistry()
  332. }
  333. }, {
  334. key: "_initStoreChangeHandlers",
  335. value: function() {
  336. var _this3 = this;
  337. this._dataSource && this._dataSource.store().on("updating", function(newItem) {
  338. _this3._updatedAppointment = newItem
  339. }.bind(this));
  340. this._dataSource && this._dataSource.store().on("push", function(items) {
  341. items.forEach(function(item) {
  342. _this3._updatedAppointmentKeys.push({
  343. key: _this3._dataSource.store().key(),
  344. value: item.key
  345. })
  346. }.bind(_this3))
  347. }.bind(this))
  348. }
  349. }, {
  350. key: "getUpdatedAppointment",
  351. value: function() {
  352. return this._updatedAppointment
  353. }
  354. }, {
  355. key: "getUpdatedAppointmentKeys",
  356. value: function() {
  357. return this._updatedAppointmentKeys
  358. }
  359. }, {
  360. key: "cleanModelState",
  361. value: function() {
  362. this._updatedAppointment = null;
  363. this._updatedAppointmentKeys = []
  364. }
  365. }, {
  366. key: "setDataAccessors",
  367. value: function(dataAccessors) {
  368. this._dataAccessors = dataAccessors;
  369. this._filterMaker = new FilterMaker(dataAccessors)
  370. }
  371. }, {
  372. key: "filterByDate",
  373. value: function(min, max, remoteFiltering, dateSerializationFormat) {
  374. if (!this._dataSource) {
  375. return
  376. }
  377. var trimmedDates = this._trimDates(min, max);
  378. if (!this._filterMaker.isRegistered()) {
  379. this._createFilter(trimmedDates.min, trimmedDates.max, remoteFiltering, dateSerializationFormat)
  380. } else {
  381. this._filterMaker.make("date", [trimmedDates.min, trimmedDates.max]);
  382. if (this._dataSource.filter() && this._dataSource.filter().length > 1) {
  383. var userFilter = this._serializeRemoteFilter([this._dataSource.filter()[1]], dateSerializationFormat);
  384. this._filterMaker.make("user", userFilter)
  385. }
  386. if (remoteFiltering) {
  387. this._dataSource.filter(this._combineRemoteFilter(dateSerializationFormat))
  388. }
  389. }
  390. }
  391. }, {
  392. key: "_combineRemoteFilter",
  393. value: function(dateSerializationFormat) {
  394. var combinedFilter = this._filterMaker.combine();
  395. return this._serializeRemoteFilter(combinedFilter, dateSerializationFormat)
  396. }
  397. }, {
  398. key: "_serializeRemoteFilter",
  399. value: function(filter, dateSerializationFormat) {
  400. if (!Array.isArray(filter)) {
  401. return filter
  402. }
  403. filter = (0, _extend.extend)([], filter);
  404. var startDate = this._dataAccessors.expr.startDateExpr;
  405. var endDate = this._dataAccessors.expr.endDateExpr;
  406. if (_type2.default.isString(filter[0])) {
  407. if ((0, _config2.default)().forceIsoDateParsing && filter.length > 1) {
  408. if (filter[0] === startDate || filter[0] === endDate) {
  409. filter[filter.length - 1] = _date_serialization2.default.serializeDate(new Date(filter[filter.length - 1]), dateSerializationFormat)
  410. }
  411. }
  412. }
  413. for (var i = 0; i < filter.length; i++) {
  414. filter[i] = this._serializeRemoteFilter(filter[i], dateSerializationFormat)
  415. }
  416. return filter
  417. }
  418. }, {
  419. key: "filterLoadedAppointments",
  420. value: function(filterOptions, timeZoneProcessor) {
  421. if (!_type2.default.isFunction(timeZoneProcessor)) {
  422. timeZoneProcessor = function(date) {
  423. return date
  424. }
  425. }
  426. var combinedFilter = this._createCombinedFilter(filterOptions, timeZoneProcessor);
  427. if (this._filterMaker.isRegistered()) {
  428. var trimmedDates = this._trimDates(filterOptions.min, filterOptions.max);
  429. this._filterMaker.make("date", [trimmedDates.min, trimmedDates.max, true]);
  430. var dateFilter = this.customizeDateFilter(this._filterMaker.combine(), timeZoneProcessor);
  431. combinedFilter.push([dateFilter])
  432. }
  433. return (0, _query2.default)(this._dataSource.items()).filter(combinedFilter).toArray()
  434. }
  435. }, {
  436. key: "_trimDates",
  437. value: function(min, max) {
  438. var minCopy = _date2.default.trimTime(new Date(min));
  439. var maxCopy = _date2.default.trimTime(new Date(max));
  440. maxCopy.setDate(maxCopy.getDate() + 1);
  441. return {
  442. min: minCopy,
  443. max: maxCopy
  444. }
  445. }
  446. }, {
  447. key: "hasAllDayAppointments",
  448. value: function(items, startDayHour, endDayHour) {
  449. if (!items) {
  450. return false
  451. }
  452. var that = this;
  453. var result = false;
  454. _iterator2.default.each(items, function(index, item) {
  455. if (that.appointmentTakesAllDay(item, startDayHour, endDayHour)) {
  456. result = true;
  457. return false
  458. }
  459. });
  460. return result
  461. }
  462. }, {
  463. key: "appointmentTakesAllDay",
  464. value: function(appointment, startDayHour, endDayHour) {
  465. var dataAccessors = this._dataAccessors;
  466. var startDate = dataAccessors.getter.startDate(appointment);
  467. var endDate = dataAccessors.getter.endDate(appointment);
  468. var allDay = dataAccessors.getter.allDay(appointment);
  469. return allDay || this._appointmentHasAllDayDuration(startDate, endDate, startDayHour, endDayHour)
  470. }
  471. }, {
  472. key: "_appointmentHasAllDayDuration",
  473. value: function(startDate, endDate, startDayHour, endDayHour) {
  474. startDate = new Date(startDate);
  475. endDate = new Date(endDate);
  476. var dayDuration = 24;
  477. var appointmentDurationInHours = this._getAppointmentDurationInHours(startDate, endDate);
  478. return appointmentDurationInHours >= dayDuration || this._appointmentHasShortDayDuration(startDate, endDate, startDayHour, endDayHour)
  479. }
  480. }, {
  481. key: "_appointmentHasShortDayDuration",
  482. value: function(startDate, endDate, startDayHour, endDayHour) {
  483. var appointmentDurationInHours = this._getAppointmentDurationInHours(startDate, endDate);
  484. var shortDayDurationInHours = endDayHour - startDayHour;
  485. return appointmentDurationInHours >= shortDayDurationInHours && startDate.getHours() === startDayHour && endDate.getHours() === endDayHour
  486. }
  487. }, {
  488. key: "_getAppointmentDurationInHours",
  489. value: function(startDate, endDate) {
  490. return (endDate.getTime() - startDate.getTime()) / toMs("hour")
  491. }
  492. }, {
  493. key: "appointmentTakesSeveralDays",
  494. value: function(appointment) {
  495. var dataAccessors = this._dataAccessors;
  496. var startDate = dataAccessors.getter.startDate(appointment);
  497. var endDate = dataAccessors.getter.endDate(appointment);
  498. var startDateCopy = _date2.default.trimTime(new Date(startDate));
  499. var endDateCopy = _date2.default.trimTime(new Date(endDate));
  500. return startDateCopy.getTime() !== endDateCopy.getTime()
  501. }
  502. }, {
  503. key: "customizeDateFilter",
  504. value: function(dateFilter, timeZoneProcessor) {
  505. var _this4 = this;
  506. var currentFilter = (0, _extend.extend)(true, [], dateFilter);
  507. return function(appointment) {
  508. var startDate = new Date(_this4._dataAccessors.getter.startDate(appointment));
  509. var endDate = new Date(_this4._dataAccessors.getter.endDate(appointment));
  510. endDate = _this4.fixWrongEndDate(appointment, startDate, endDate);
  511. appointment = (0, _extend.extend)(true, {}, appointment);
  512. var startDateTimeZone = _this4._dataAccessors.getter.startDateTimeZone(appointment);
  513. var endDateTimeZone = _this4._dataAccessors.getter.endDateTimeZone(appointment);
  514. var comparableStartDate = timeZoneProcessor(startDate, startDateTimeZone);
  515. var comparableEndDate = timeZoneProcessor(endDate, endDateTimeZone);
  516. _this4._dataAccessors.setter.startDate(appointment, comparableStartDate);
  517. _this4._dataAccessors.setter.endDate(appointment, comparableEndDate);
  518. return (0, _query2.default)([appointment]).filter(currentFilter).toArray().length > 0
  519. }.bind(this)
  520. }
  521. }, {
  522. key: "fixWrongEndDate",
  523. value: function(appointment, startDate, endDate) {
  524. if (this._isEndDateWrong(appointment, startDate, endDate)) {
  525. if (this._dataAccessors.getter.allDay(appointment)) {
  526. endDate = _date2.default.setToDayEnd(new Date(startDate))
  527. } else {
  528. endDate = new Date(startDate.getTime() + this._baseAppointmentDuration * toMs("minute"))
  529. }
  530. this._dataAccessors.setter.endDate(appointment, endDate)
  531. }
  532. return endDate
  533. }
  534. }, {
  535. key: "_isEndDateWrong",
  536. value: function(appointment, startDate, endDate) {
  537. return !endDate || isNaN(endDate.getTime()) || startDate.getTime() > endDate.getTime()
  538. }
  539. }, {
  540. key: "add",
  541. value: function(data, tz) {
  542. var _this5 = this;
  543. return this._dataSource.store().insert(data).done(function() {
  544. _this5._dataSource.load()
  545. }.bind(this))
  546. }
  547. }, {
  548. key: "update",
  549. value: function(target, data) {
  550. var _this6 = this;
  551. var key = this._getStoreKey(target);
  552. return this._dataSource.store().update(key, data).done(function() {
  553. _this6._dataSource.load()
  554. }.bind(this))
  555. }
  556. }, {
  557. key: "remove",
  558. value: function(target) {
  559. var _this7 = this;
  560. var key = this._getStoreKey(target);
  561. return this._dataSource.store().remove(key).done(function() {
  562. _this7._dataSource.load()
  563. }.bind(this))
  564. }
  565. }]);
  566. return AppointmentModel
  567. }();
  568. module.exports = AppointmentModel;