devextreme
Version:
HTML5 JavaScript Component Suite for Responsive Web Development
1,088 lines (1,087 loc) • 84.5 kB
JavaScript
/**
* DevExtreme (ui/scheduler/ui.scheduler.js)
* Version: 19.2.6
* Build date: Thu Jan 30 2020
*
* Copyright (c) 2012 - 2020 Developer Express Inc. ALL RIGHTS RESERVED
* Read about DevExtreme licensing here: https://js.devexpress.com/Licensing/
*/
"use strict";
var _renderer = require("../../core/renderer");
var _renderer2 = _interopRequireDefault(_renderer);
var _callbacks = require("../../core/utils/callbacks");
var _callbacks2 = _interopRequireDefault(_callbacks);
var _translator = require("../../animation/translator");
var _translator2 = _interopRequireDefault(_translator);
var _ui = require("../widget/ui.errors");
var _ui2 = _interopRequireDefault(_ui);
var _window = require("../../core/utils/window");
var _window2 = _interopRequireDefault(_window);
var _dialog = require("../dialog");
var _dialog2 = _interopRequireDefault(_dialog);
var _utils = require("./utils.recurrence");
var _utils2 = _interopRequireDefault(_utils);
var _dom = require("../../core/utils/dom");
var _dom2 = _interopRequireDefault(_dom);
var _date = require("../../core/utils/date");
var _date2 = _interopRequireDefault(_date);
var _iterator = require("../../core/utils/iterator");
var _extend = require("../../core/utils/extend");
var _array = require("../../core/utils/array");
var _common = require("../../core/utils/common");
var _type = require("../../core/utils/type");
var _type2 = _interopRequireDefault(_type);
var _devices = require("../../core/devices");
var _devices2 = _interopRequireDefault(_devices);
var _config = require("../../core/config");
var _config2 = _interopRequireDefault(_config);
var _data = require("../../core/utils/data");
var _data2 = _interopRequireDefault(_data);
var _component_registrator = require("../../core/component_registrator");
var _component_registrator2 = _interopRequireDefault(_component_registrator);
var _message = require("../../localization/message");
var _message2 = _interopRequireDefault(_message);
var _date_serialization = require("../../core/utils/date_serialization");
var _date_serialization2 = _interopRequireDefault(_date_serialization);
var _date3 = require("../../localization/date");
var _date4 = _interopRequireDefault(_date3);
var _ui3 = require("../widget/ui.widget");
var _ui4 = _interopRequireDefault(_ui3);
var _uiScheduler = require("./ui.scheduler.subscribes");
var _uiScheduler2 = _interopRequireDefault(_uiScheduler);
var _desktopTooltipStrategy = require("./tooltip_strategies/desktopTooltipStrategy");
var _mobileTooltipStrategy = require("./tooltip_strategies/mobileTooltipStrategy");
var _appointmentPopup = require("./appointmentPopup");
var _appointmentPopup2 = _interopRequireDefault(_appointmentPopup);
var _uiScheduler3 = require("./ui.scheduler.header");
var _uiScheduler4 = _interopRequireDefault(_uiScheduler3);
var _uiScheduler5 = require("./workspaces/ui.scheduler.work_space_day");
var _uiScheduler6 = _interopRequireDefault(_uiScheduler5);
var _uiScheduler7 = require("./workspaces/ui.scheduler.work_space_week");
var _uiScheduler8 = _interopRequireDefault(_uiScheduler7);
var _uiScheduler9 = require("./workspaces/ui.scheduler.work_space_work_week");
var _uiScheduler10 = _interopRequireDefault(_uiScheduler9);
var _uiScheduler11 = require("./workspaces/ui.scheduler.work_space_month");
var _uiScheduler12 = _interopRequireDefault(_uiScheduler11);
var _uiScheduler13 = require("./workspaces/ui.scheduler.timeline_day");
var _uiScheduler14 = _interopRequireDefault(_uiScheduler13);
var _uiScheduler15 = require("./workspaces/ui.scheduler.timeline_week");
var _uiScheduler16 = _interopRequireDefault(_uiScheduler15);
var _uiScheduler17 = require("./workspaces/ui.scheduler.timeline_work_week");
var _uiScheduler18 = _interopRequireDefault(_uiScheduler17);
var _uiScheduler19 = require("./workspaces/ui.scheduler.timeline_month");
var _uiScheduler20 = _interopRequireDefault(_uiScheduler19);
var _uiScheduler21 = require("./workspaces/ui.scheduler.agenda");
var _uiScheduler22 = _interopRequireDefault(_uiScheduler21);
var _uiScheduler23 = require("./ui.scheduler.resource_manager");
var _uiScheduler24 = _interopRequireDefault(_uiScheduler23);
var _uiScheduler25 = require("./ui.scheduler.appointment_model");
var _uiScheduler26 = _interopRequireDefault(_uiScheduler25);
var _uiScheduler27 = require("./ui.scheduler.appointments");
var _uiScheduler28 = _interopRequireDefault(_uiScheduler27);
var _uiSchedulerAppointments = require("./ui.scheduler.appointments.layout_manager");
var _uiSchedulerAppointments2 = _interopRequireDefault(_uiSchedulerAppointments);
var _compactAppointmentsHelper = require("./compactAppointmentsHelper");
var _uiScheduler29 = require("./timezones/ui.scheduler.timezones");
var _uiScheduler30 = _interopRequireDefault(_uiScheduler29);
var _async_template_mixin = require("../shared/async_template_mixin");
var _async_template_mixin2 = _interopRequireDefault(_async_template_mixin);
var _data_helper = require("../../data_helper");
var _data_helper2 = _interopRequireDefault(_data_helper);
var _ui5 = require("./ui.loading");
var _ui6 = _interopRequireDefault(_ui5);
var _deferred = require("../../core/utils/deferred");
var _deferred2 = _interopRequireDefault(_deferred);
var _empty_template = require("../../core/templates/empty_template");
var _bindable_template = require("../../core/templates/bindable_template");
var _themes = require("../themes");
var _themes2 = _interopRequireDefault(_themes);
var _browser = require("../../core/utils/browser");
var _browser2 = _interopRequireDefault(_browser);
var _support = require("../../core/utils/support");
var _utils3 = require("./utils");
var _utils4 = _interopRequireDefault(_utils3);
var _constants = require("./constants");
function _interopRequireDefault(obj) {
return obj && obj.__esModule ? obj : {
"default": obj
}
}
var when = _deferred2.default.when;
var Deferred = _deferred2.default.Deferred;
var toMs = _date2.default.dateToMilliseconds;
var WIDGET_CLASS = "dx-scheduler";
var WIDGET_SMALL_CLASS = "".concat(WIDGET_CLASS, "-small");
var WIDGET_ADAPTIVE_CLASS = "".concat(WIDGET_CLASS, "-adaptive");
var WIDGET_WIN_NO_TOUCH_CLASS = "".concat(WIDGET_CLASS, "-win-no-touch");
var WIDGET_READONLY_CLASS = "".concat(WIDGET_CLASS, "-readonly");
var RECURRENCE_EDITOR_ITEM_CLASS = "".concat(WIDGET_CLASS, "-recurrence-rule-item");
var RECURRENCE_EDITOR_OPENED_ITEM_CLASS = "".concat(WIDGET_CLASS, "-recurrence-rule-item-opened");
var WIDGET_SMALL_WIDTH = 400;
var FULL_DATE_FORMAT = "yyyyMMddTHHmmss";
var UTC_FULL_DATE_FORMAT = FULL_DATE_FORMAT + "Z";
var VIEWS_CONFIG = {
day: {
workSpace: _uiScheduler6.default,
renderingStrategy: "vertical"
},
week: {
workSpace: _uiScheduler8.default,
renderingStrategy: "vertical"
},
workWeek: {
workSpace: _uiScheduler10.default,
renderingStrategy: "vertical"
},
month: {
workSpace: _uiScheduler12.default,
renderingStrategy: "horizontalMonth"
},
timelineDay: {
workSpace: _uiScheduler14.default,
renderingStrategy: "horizontal"
},
timelineWeek: {
workSpace: _uiScheduler16.default,
renderingStrategy: "horizontal"
},
timelineWorkWeek: {
workSpace: _uiScheduler18.default,
renderingStrategy: "horizontal"
},
timelineMonth: {
workSpace: _uiScheduler20.default,
renderingStrategy: "horizontalMonthLine"
},
agenda: {
workSpace: _uiScheduler22.default,
renderingStrategy: "agenda"
}
};
var Scheduler = _ui4.default.inherit({
_getDefaultOptions: function() {
return (0, _extend.extend)(this.callBase(), {
views: ["day", "week"],
currentView: "day",
currentDate: _date2.default.trimTime(new Date),
min: void 0,
max: void 0,
dateSerializationFormat: void 0,
firstDayOfWeek: void 0,
groups: [],
resources: [],
dataSource: null,
customizeDateNavigatorText: void 0,
appointmentTemplate: "item",
dropDownAppointmentTemplate: "dropDownAppointment",
appointmentCollectorTemplate: "appointmentCollector",
dataCellTemplate: null,
timeCellTemplate: null,
resourceCellTemplate: null,
dateCellTemplate: null,
startDayHour: 0,
endDayHour: 24,
editing: {
allowAdding: true,
allowDeleting: true,
allowDragging: true,
allowResizing: true,
allowUpdating: true
},
showAllDayPanel: true,
showCurrentTimeIndicator: true,
shadeUntilCurrentTime: false,
indicatorUpdateInterval: 3e5,
indicatorTime: void 0,
recurrenceEditMode: "dialog",
cellDuration: 30,
maxAppointmentsPerCell: "auto",
selectedCellData: [],
groupByDate: false,
onAppointmentRendered: null,
onAppointmentClick: null,
onAppointmentDblClick: null,
onAppointmentContextMenu: null,
onCellClick: null,
onCellContextMenu: null,
onAppointmentAdding: null,
onAppointmentAdded: null,
onAppointmentUpdating: null,
onAppointmentUpdated: null,
onAppointmentDeleting: null,
onAppointmentDeleted: null,
onAppointmentFormOpening: null,
appointmentTooltipTemplate: "appointmentTooltip",
appointmentPopupTemplate: "appointmentPopup",
crossScrollingEnabled: false,
useDropDownViewSwitcher: false,
startDateExpr: "startDate",
endDateExpr: "endDate",
textExpr: "text",
descriptionExpr: "description",
allDayExpr: "allDay",
recurrenceRuleExpr: "recurrenceRule",
recurrenceExceptionExpr: "recurrenceException",
remoteFiltering: false,
timeZone: "",
startDateTimeZoneExpr: "startDateTimeZone",
endDateTimeZoneExpr: "endDateTimeZone",
noDataText: _message2.default.format("dxCollectionWidget-noDataText"),
adaptivityEnabled: false,
allowMultipleCellSelection: true,
_appointmentTooltipOffset: {
x: 0,
y: 0
},
_appointmentTooltipButtonsPosition: "bottom",
_appointmentTooltipOpenButtonText: _message2.default.format("dxScheduler-openAppointment"),
_dropDownButtonIcon: "overflow",
_appointmentCountPerCell: 2,
_collectorOffset: 0,
_appointmentOffset: 26
})
},
_defaultOptionsRules: function() {
return this.callBase().concat([{
device: function() {
return "desktop" === _devices2.default.real().deviceType && !_devices2.default.isSimulator()
},
options: {
focusStateEnabled: true
}
}, {
device: function() {
return !_devices2.default.current().generic
},
options: {
useDropDownViewSwitcher: true,
editing: {
allowDragging: false,
allowResizing: false
}
}
}, {
device: function() {
return _themes2.default.isMaterial()
},
options: {
useDropDownViewSwitcher: true,
dateCellTemplate: function(data, index, element) {
var text = data.text;
text.split(" ").forEach(function(text, index) {
var span = (0, _renderer2.default)("<span>").text(text).addClass("dx-scheduler-header-panel-cell-date");
(0, _renderer2.default)(element).append(span);
if (!index) {
(0, _renderer2.default)(element).append(" ")
}
})
},
_appointmentTooltipOffset: {
x: 0,
y: 11
},
_appointmentTooltipButtonsPosition: "top",
_appointmentTooltipOpenButtonText: null,
_dropDownButtonIcon: "chevrondown",
_appointmentCountPerCell: 1,
_collectorOffset: 20,
_appointmentOffset: 30
}
}])
},
_setDeprecatedOptions: function() {
this.callBase();
(0, _extend.extend)(this._deprecatedOptions, {
onAppointmentFormCreated: {
since: "18.2",
alias: "onAppointmentFormOpening"
},
dropDownAppointmentTemplate: {
since: "19.2",
message: "appointmentTooltipTemplate"
}
})
},
_postponeDataSourceLoading: function(promise) {
this.postponedOperations.add("_reloadDataSource", this._reloadDataSource.bind(this), promise)
},
_postponeResourceLoading: function() {
var _this = this;
var whenLoaded = this.postponedOperations.add("_loadResources", function() {
return _this._loadResources()
});
var resolveCallbacks = new Deferred;
whenLoaded.done(function(resources) {
resolveCallbacks.resolve(resources)
});
this._postponeDataSourceLoading(whenLoaded);
return resolveCallbacks.promise()
},
_optionChanged: function(args) {
var _this2 = this;
var value = args.value;
var name = args.name;
switch (args.name) {
case "customizeDateNavigatorText":
this._updateOption("header", name, value);
break;
case "firstDayOfWeek":
this._updateOption("workSpace", name, value);
this._updateOption("header", name, value);
break;
case "currentDate":
value = this._dateOption(name);
value = _date2.default.trimTime(new Date(value));
this.option("selectedCellData", []);
this._workSpace.option(name, new Date(value));
this._header.option(name, new Date(value));
this._header.option("displayedDate", this._workSpace._getViewStartByOptions());
this._appointments.option("items", []);
this._filterAppointmentsByDate();
this._postponeDataSourceLoading();
break;
case "dataSource":
this._initDataSource();
this._customizeStoreLoadOptions();
this._appointmentModel.setDataSource(this._dataSource);
this._postponeResourceLoading().done(function(resources) {
_this2._filterAppointmentsByDate();
_this2._updateOption("workSpace", "showAllDayPanel", _this2.option("showAllDayPanel"))
});
break;
case "min":
case "max":
value = this._dateOption(name);
this._updateOption("header", name, new Date(value));
this._updateOption("workSpace", name, new Date(value));
break;
case "views":
this._processCurrentView();
if (this._getCurrentViewOptions()) {
this.repaint()
} else {
this._header.option(name, value)
}
break;
case "useDropDownViewSwitcher":
this._header.option(name, value);
break;
case "currentView":
this._processCurrentView();
this.getLayoutManager().initRenderingStrategy(this._getAppointmentsRenderingStrategy());
this._appointments.option({
items: [],
allowDrag: this._allowDragging(),
allowResize: this._allowResizing(),
itemTemplate: this._getAppointmentTemplate("appointmentTemplate")
});
this._postponeResourceLoading().done(function(resources) {
_this2._refreshWorkSpace(resources);
_this2._updateHeader();
_this2._filterAppointmentsByDate();
_this2._appointments.option("allowAllDayResize", "day" !== value)
});
break;
case "appointmentTemplate":
this._appointments.option("itemTemplate", value);
break;
case "dateCellTemplate":
case "resourceCellTemplate":
case "dataCellTemplate":
case "timeCellTemplate":
this._updateOption("workSpace", name, value);
this.repaint();
break;
case "groups":
this._postponeResourceLoading().done(function(resources) {
_this2._refreshWorkSpace(resources);
_this2._filterAppointmentsByDate()
});
break;
case "resources":
this._resourcesManager.setResources(this.option("resources"));
this._appointmentModel.setDataAccessors(this._combineDataAccessors());
this._postponeResourceLoading().done(function(resources) {
_this2._appointments.option("items", []);
_this2._refreshWorkSpace(resources);
_this2._filterAppointmentsByDate()
});
break;
case "startDayHour":
case "endDayHour":
this._appointments.option("items", []);
this._updateOption("workSpace", name, value);
this._appointments.repaint();
this._filterAppointmentsByDate();
this._postponeDataSourceLoading();
break;
case "onAppointmentAdding":
case "onAppointmentAdded":
case "onAppointmentUpdating":
case "onAppointmentUpdated":
case "onAppointmentDeleting":
case "onAppointmentDeleted":
case "onAppointmentFormOpening":
this._actions[name] = this._createActionByOption(name);
break;
case "onAppointmentRendered":
this._appointments.option("onItemRendered", this._getAppointmentRenderedAction());
break;
case "onAppointmentClick":
this._appointments.option("onItemClick", this._createActionByOption(name));
break;
case "onAppointmentDblClick":
this._appointments.option(name, this._createActionByOption(name));
break;
case "onAppointmentContextMenu":
this._appointments.option("onItemContextMenu", this._createActionByOption(name));
break;
case "noDataText":
case "allowMultipleCellSelection":
case "selectedCellData":
case "accessKey":
case "onCellClick":
this._workSpace.option(name, value);
break;
case "onCellContextMenu":
this._workSpace.option(name, value);
break;
case "crossScrollingEnabled":
this._postponeResourceLoading().done(function(resources) {
_this2._appointments.option("items", []);
_this2._refreshWorkSpace(resources);
if (_this2._readyToRenderAppointments) {
_this2._appointments.option("items", _this2._getAppointmentsToRepaint())
}
});
break;
case "cellDuration":
this._appointments.option("items", []);
if (this._readyToRenderAppointments) {
this._updateOption("workSpace", "hoursInterval", value / 60);
this._appointments.option("items", this._getAppointmentsToRepaint())
}
break;
case "tabIndex":
case "focusStateEnabled":
this._updateOption("header", name, value);
this._updateOption("workSpace", name, value);
this._appointments.option(name, value);
this.callBase(args);
break;
case "width":
this._updateOption("header", name, value);
if (this.option("crossScrollingEnabled")) {
this._updateOption("workSpace", "width", value)
}
this.callBase(args);
this._dimensionChanged();
break;
case "height":
this.callBase(args);
this._dimensionChanged();
break;
case "editing":
this._initEditing();
var editing = this._editing;
this._bringEditingModeToAppointments(editing);
this.hideAppointmentTooltip();
this._cleanPopup();
break;
case "showAllDayPanel":
this._postponeResourceLoading().done(function(resources) {
_this2._filterAppointmentsByDate();
_this2._updateOption("workSpace", "allDayExpanded", value);
_this2._updateOption("workSpace", name, value)
});
break;
case "showCurrentTimeIndicator":
case "indicatorTime":
case "indicatorUpdateInterval":
case "shadeUntilCurrentTime":
case "groupByDate":
this._updateOption("workSpace", name, value);
this.repaint();
break;
case "appointmentDragging":
case "appointmentTooltipTemplate":
case "appointmentPopupTemplate":
case "recurrenceEditMode":
case "remoteFiltering":
case "timeZone":
case "dropDownAppointmentTemplate":
case "appointmentCollectorTemplate":
case "_appointmentTooltipOffset":
case "_appointmentTooltipButtonsPosition":
case "_appointmentTooltipOpenButtonText":
case "_dropDownButtonIcon":
case "_appointmentCountPerCell":
case "_collectorOffset":
case "_appointmentOffset":
this.repaint();
break;
case "dateSerializationFormat":
break;
case "maxAppointmentsPerCell":
break;
case "startDateExpr":
case "endDateExpr":
case "startDateTimeZoneExpr":
case "endDateTimeZoneExpr":
case "textExpr":
case "descriptionExpr":
case "allDayExpr":
case "recurrenceRuleExpr":
case "recurrenceExceptionExpr":
this._updateExpression(name, value);
this._appointmentModel.setDataAccessors(this._combineDataAccessors());
this._initAppointmentTemplate();
this.repaint();
break;
case "adaptivityEnabled":
this._toggleAdaptiveClass();
this.repaint();
break;
default:
this.callBase(args)
}
},
_updateHeader: function() {
var viewCountConfig = this._getViewCountConfig();
this._header.option("intervalCount", viewCountConfig.intervalCount);
this._header.option("displayedDate", this._workSpace._getViewStartByOptions());
this._header.option("min", this._dateOption("min"));
this._header.option("max", this._dateOption("max"));
this._header.option("currentDate", this._dateOption("currentDate"));
this._header.option("firstDayOfWeek", this._getCurrentViewOption("firstDayOfWeek"));
this._header.option("currentView", this._currentView)
},
_dateOption: function(optionName) {
var optionValue = this._getCurrentViewOption(optionName);
return _date_serialization2.default.deserializeDate(optionValue)
},
_getSerializationFormat: function(optionName) {
var value = this._getCurrentViewOption(optionName);
if ("number" === typeof value) {
return "number"
}
if (!_type2.default.isString(value)) {
return
}
return _date_serialization2.default.getDateSerializationFormat(value)
},
_bringEditingModeToAppointments: function(editing) {
var editingConfig = {
allowDelete: editing.allowUpdating && editing.allowDeleting
};
if (!this._isAgenda()) {
editingConfig.allowDrag = editing.allowDragging;
editingConfig.allowResize = editing.allowResizing;
editingConfig.allowAllDayResize = editing.allowResizing && this._supportAllDayResizing()
}
this._appointments.option(editingConfig);
this.repaint()
},
_isAgenda: function() {
return "agenda" === this._getAppointmentsRenderingStrategy()
},
_allowDragging: function() {
return this._editing.allowDragging && !this._isAgenda()
},
_allowResizing: function() {
return this._editing.allowResizing && !this._isAgenda()
},
_allowAllDayResizing: function() {
return this._editing.allowResizing && this._supportAllDayResizing()
},
_supportAllDayResizing: function() {
return "day" !== this._getCurrentViewType() || this._currentView.intervalCount > 1
},
_isAllDayExpanded: function(items) {
return this.option("showAllDayPanel") && this._appointmentModel.hasAllDayAppointments(items, this._getCurrentViewOption("startDayHour"), this._getCurrentViewOption("endDayHour"))
},
_getTimezoneOffsetByOption: function(date) {
return this._calculateTimezoneByValue(this.option("timeZone"), date)
},
_calculateTimezoneByValue: function(timezone, date) {
var result = timezone;
if ("string" === typeof timezone) {
date = date || new Date;
var dateUtc = Date.UTC(date.getUTCFullYear(), date.getUTCMonth(), date.getUTCDate(), date.getUTCHours(), date.getUTCMinutes());
result = _uiScheduler30.default.getTimezoneOffsetById(timezone, dateUtc)
}
return result
},
_filterAppointmentsByDate: function() {
var dateRange = this._workSpace.getDateRange();
this._appointmentModel.filterByDate(dateRange[0], dateRange[1], this.option("remoteFiltering"), this.option("dateSerializationFormat"))
},
_loadResources: function() {
var groups = this._getCurrentViewOption("groups");
var result = new Deferred;
this._resourcesManager.loadResources(groups).done(function(resources) {
this._loadedResources = resources;
result.resolve(resources)
}.bind(this));
return result.promise()
},
_dataSourceLoadedCallback: (0, _callbacks2.default)(),
_reloadDataSource: function() {
var result = new Deferred;
if (this._dataSource) {
this._dataSource.load().done(function() {
_ui6.default.hide();
this._fireContentReadyAction(result)
}.bind(this)).fail(function() {
_ui6.default.hide();
result.reject()
});
this._dataSource.isLoading() && _ui6.default.show({
container: this.$element(),
position: {
of: this.$element()
}
})
} else {
this._fireContentReadyAction(result)
}
return result.promise()
},
_fireContentReadyAction: function(result) {
this.callBase();
result && result.resolve()
},
_dimensionChanged: function() {
var filteredItems = this.getFilteredItems();
this._toggleSmallClass();
if (!this._isAgenda() && filteredItems && this._isVisible()) {
this._workSpace._cleanAllowedPositions();
this._workSpace.option("allDayExpanded", this._isAllDayExpanded(filteredItems));
this._workSpace._dimensionChanged();
var appointments = this._layoutManager.createAppointmentsMap(filteredItems);
this._appointments.option("items", appointments)
}
this.hideAppointmentTooltip();
this.resizePopup();
this._appointmentPopup.updatePopupFullScreenMode()
},
_clean: function() {
this._cleanPopup();
this.callBase()
},
_toggleSmallClass: function() {
var width = this.$element().get(0).getBoundingClientRect().width;
this.$element().toggleClass(WIDGET_SMALL_CLASS, width < WIDGET_SMALL_WIDTH)
},
_toggleAdaptiveClass: function() {
this.$element().toggleClass(WIDGET_ADAPTIVE_CLASS, this.option("adaptivityEnabled"))
},
_visibilityChanged: function(visible) {
visible && this._dimensionChanged()
},
_dataSourceOptions: function() {
return {
paginate: false
}
},
_init: function() {
this._initExpressions({
startDate: this.option("startDateExpr"),
endDate: this.option("endDateExpr"),
startDateTimeZone: this.option("startDateTimeZoneExpr"),
endDateTimeZone: this.option("endDateTimeZoneExpr"),
allDay: this.option("allDayExpr"),
text: this.option("textExpr"),
description: this.option("descriptionExpr"),
recurrenceRule: this.option("recurrenceRuleExpr"),
recurrenceException: this.option("recurrenceExceptionExpr")
});
this.callBase();
this._initDataSource();
this._loadedResources = [];
this._proxiedCustomizeStoreLoadOptionsHandler = this._customizeStoreLoadOptionsHandler.bind(this);
this._customizeStoreLoadOptions();
this.$element().addClass(WIDGET_CLASS).toggleClass(WIDGET_WIN_NO_TOUCH_CLASS, !!(_browser2.default.msie && _support.touch));
this._initEditing();
this._resourcesManager = new _uiScheduler24.default(this.option("resources"));
var combinedDataAccessors = this._combineDataAccessors();
this._appointmentModel = new _uiScheduler26.default(this._dataSource, combinedDataAccessors, this.getAppointmentDurationInMinutes());
this._initActions();
this._compactAppointmentsHelper = new _compactAppointmentsHelper.CompactAppointmentsHelper(this);
this._subscribes = _uiScheduler2.default
},
_initTemplates: function() {
this.callBase();
this._initAppointmentTemplate();
this._defaultTemplates.appointmentTooltip = new _empty_template.EmptyTemplate;
this._defaultTemplates.dropDownAppointment = new _empty_template.EmptyTemplate
},
setDefaultTemplate: function(templateName, template) {
this._defaultTemplates[templateName] = template
},
_initAppointmentTemplate: function() {
var _this3 = this;
var expr = this._dataAccessors.expr;
var createGetter = function(property) {
return _data2.default.compileGetter("appointmentData.".concat(property))
};
this._defaultTemplates.item = new _bindable_template.BindableTemplate(function($container, data, model) {
_this3.getAppointmentsInstance()._renderAppointmentTemplate($container, data, model)
}, ["html", "text", "startDate", "endDate", "allDay", "description", "recurrenceRule", "recurrenceException", "startDateTimeZone", "endDateTimeZone"], this.option("integrationOptions.watchMethod"), {
text: createGetter(expr.textExpr),
startDate: createGetter(expr.startDateExpr),
endDate: createGetter(expr.endDateExpr),
startDateTimeZone: createGetter(expr.startDateTimeZoneExpr),
endDateTimeZone: createGetter(expr.endDateTimeZoneExpr),
allDay: createGetter(expr.allDayExpr),
recurrenceRule: createGetter(expr.recurrenceRuleExpr)
})
},
_combineDataAccessors: function() {
var resourcesDataAccessors = this._resourcesManager._dataAccessors;
var result = (0, _extend.extend)(true, {}, this._dataAccessors);
(0, _iterator.each)(resourcesDataAccessors, function(type, accessor) {
result[type].resources = accessor
}.bind(this));
return result
},
_renderContent: function() {
this._renderContentImpl()
},
_dataSourceChangedHandler: function(result) {
if (this._readyToRenderAppointments) {
this._workSpaceRecalculation.done(function() {
this._filteredItems = this.fire("prerenderFilter");
this._workSpace.option("allDayExpanded", this._isAllDayExpanded(this._filteredItems));
if (this._isAgenda()) {
this.getRenderingStrategyInstance().calculateRows(this._filteredItems, 7, this.option("currentDate"), true)
}
if (this._filteredItems.length && this._isVisible()) {
this._appointments.option("items", this._getAppointmentsToRepaint());
this._appointmentModel.cleanModelState()
} else {
this._appointments.option("items", [])
}
if (this._isAgenda()) {
this._workSpace._renderView();
this._dataSourceLoadedCallback.fireWith(this, [result])
}
}.bind(this))
}
},
_getAppointmentsToRepaint: function() {
var appointments = this._layoutManager.createAppointmentsMap(this._filteredItems);
return this._layoutManager.getRepaintedAppointments(appointments, this.getAppointmentsInstance().option("items"))
},
_initExpressions: function(fields) {
var isDateField = function(field) {
return "startDate" === field || "endDate" === field
};
if (!this._dataAccessors) {
this._dataAccessors = {
getter: {},
setter: {},
expr: {}
}
}(0, _iterator.each)(fields, function(name, expr) {
if (expr) {
var getter = _data2.default.compileGetter(expr);
var setter = _data2.default.compileSetter(expr);
var dateGetter;
var dateSetter;
if (isDateField(name)) {
var that = this;
dateGetter = function() {
var value = getter.apply(this, arguments);
if ((0, _config2.default)().forceIsoDateParsing) {
if (!that.option("dateSerializationFormat")) {
var format = _date_serialization2.default.getDateSerializationFormat(value);
if (format) {
that.option("dateSerializationFormat", format)
}
}
value = _date_serialization2.default.deserializeDate(value)
}
return value
};
dateSetter = function(object, value) {
if ((0, _config2.default)().forceIsoDateParsing || that.option("dateSerializationFormat")) {
value = _date_serialization2.default.serializeDate(value, that.option("dateSerializationFormat"))
}
setter.call(this, object, value)
}
}
this._dataAccessors.getter[name] = dateGetter || getter;
this._dataAccessors.setter[name] = dateSetter || setter;
this._dataAccessors.expr[name + "Expr"] = expr
} else {
delete this._dataAccessors.getter[name];
delete this._dataAccessors.setter[name];
delete this._dataAccessors.expr[name + "Expr"]
}
}.bind(this))
},
_updateExpression: function(name, value) {
var exprObj = {};
exprObj[name.replace("Expr", "")] = value;
this._initExpressions(exprObj)
},
_initEditing: function() {
var editing = this.option("editing");
this._editing = {
allowAdding: !!editing,
allowUpdating: !!editing,
allowDeleting: !!editing,
allowResizing: !!editing,
allowDragging: !!editing
};
if (_type2.default.isObject(editing)) {
this._editing = (0, _extend.extend)(this._editing, editing)
}
this._editing.allowDragging = this._editing.allowDragging && this._editing.allowUpdating;
this._editing.allowResizing = this._editing.allowResizing && this._editing.allowUpdating;
this.$element().toggleClass(WIDGET_READONLY_CLASS, this._isReadOnly())
},
_isReadOnly: function() {
var result = true;
var editing = this._editing;
for (var prop in editing) {
if (Object.prototype.hasOwnProperty.call(editing, prop)) {
result = result && !editing[prop]
}
}
return result
},
_customizeStoreLoadOptions: function() {
this._dataSource && this._dataSource.on("customizeStoreLoadOptions", this._proxiedCustomizeStoreLoadOptionsHandler)
},
_dispose: function() {
this._appointmentTooltip && this._appointmentTooltip.dispose();
this.hideAppointmentPopup();
this.hideAppointmentTooltip();
this._cleanAsyncTemplatesTimer();
this._dataSource && this._dataSource.off("customizeStoreLoadOptions", this._proxiedCustomizeStoreLoadOptionsHandler);
this.callBase()
},
_customizeStoreLoadOptionsHandler: function(options) {
options.storeLoadOptions.dxScheduler = {
startDate: this.getStartViewDate(),
endDate: this.getEndViewDate(),
resources: this.option("resources")
}
},
_initActions: function() {
this._actions = {
onAppointmentAdding: this._createActionByOption("onAppointmentAdding"),
onAppointmentAdded: this._createActionByOption("onAppointmentAdded"),
onAppointmentUpdating: this._createActionByOption("onAppointmentUpdating"),
onAppointmentUpdated: this._createActionByOption("onAppointmentUpdated"),
onAppointmentDeleting: this._createActionByOption("onAppointmentDeleting"),
onAppointmentDeleted: this._createActionByOption("onAppointmentDeleted"),
onAppointmentFormOpening: this._createActionByOption("onAppointmentFormOpening")
}
},
_getAppointmentRenderedAction: function() {
return this._createActionByOption("onAppointmentRendered", {
excludeValidators: ["disabled", "readOnly"]
})
},
_renderFocusTarget: _common.noop,
_initMarkup: function() {
this.callBase();
this._processCurrentView();
this._renderHeader();
this._layoutManager = new _uiSchedulerAppointments2.default(this, this._getAppointmentsRenderingStrategy());
this._appointments = this._createComponent("<div>", _uiScheduler28.default, this._appointmentsConfig());
this._appointments.option("itemTemplate", this._getAppointmentTemplate("appointmentTemplate"));
this._appointmentTooltip = new(this.option("adaptivityEnabled") ? _mobileTooltipStrategy.MobileTooltipStrategy : _desktopTooltipStrategy.DesktopTooltipStrategy)(this._getAppointmentTooltipOptions());
this._appointmentPopup = new _appointmentPopup2.default(this);
if (this._isLoaded()) {
this._initMarkupCore(this._loadedResources);
this._dataSourceChangedHandler(this._dataSource.items());
this._fireContentReadyAction()
} else {
this._loadResources().done(function(resources) {
this._initMarkupCore(resources);
this._reloadDataSource()
}.bind(this))
}
},
_getAppointmentTooltipOptions: function() {
var _this4 = this;
var that = this;
return {
createComponent: that._createComponent.bind(that),
container: that.$element(),
getScrollableContainer: that.getWorkSpaceScrollableContainer.bind(that),
setDefaultTemplate: that.setDefaultTemplate.bind(that),
getAppointmentTemplate: that._getAppointmentTemplate.bind(that),
showAppointmentPopup: that.showAppointmentPopup.bind(that),
getTextAndFormatDate: function(data, currentData, format) {
return that.fire("getTextAndFormatDate", data, currentData, format)
},
checkAndDeleteAppointment: that.checkAndDeleteAppointment.bind(that),
isAppointmentInAllDayPanel: that.isAppointmentInAllDayPanel.bind(that),
getSingleAppointmentData: function(appointmentData, targetElement) {
var $appointment = (0, _renderer2.default)(targetElement);
return _this4._getSingleAppointmentData(appointmentData, {
data: appointmentData,
target: $appointment.get(0),
$appointment: $appointment
})
}
}
},
checkAndDeleteAppointment: function(data, appointmentData) {
var that = this;
var startDate = that.fire("getField", "startDate", appointmentData);
that._checkRecurringAppointment(data, appointmentData, startDate, function() {
that.deleteAppointment(data)
}, true)
},
_getExtraAppointmentTooltipOptions: function() {
return {
rtlEnabled: this.option("rtlEnabled"),
focusStateEnabled: this.option("focusStateEnabled"),
editing: this.option("editing"),
offset: this.option("_appointmentTooltipOffset")
}
},
isAppointmentInAllDayPanel: function(appointmentData) {
var workSpace = this._workSpace;
var itTakesAllDay = this.appointmentTakesAllDay(appointmentData);
return itTakesAllDay && workSpace.supportAllDayRow() && workSpace.option("showAllDayPanel")
},
_initMarkupCore: function(resources) {
var _this5 = this;
this._readyToRenderAppointments = _window2.default.hasWindow();
this._workSpace && this._cleanWorkspace();
this._renderWorkSpace(resources);
this._appointments.option({
fixedContainer: this._workSpace.getFixedContainer(),
allDayContainer: this._workSpace.getAllDayContainer()
});
this._waitAsyncTemplates(function() {
_this5._workSpaceRecalculation && _this5._workSpaceRecalculation.resolve()
});
this._filterAppointmentsByDate()
},
_isLoaded: function() {
return this._isResourcesLoaded() && this._isDataSourceLoaded()
},
_isResourcesLoaded: function() {
return _type2.default.isDefined(this._loadedResources)
},
_isDataSourceLoaded: function() {
return this._dataSource && this._dataSource.isLoaded()
},
_render: function() {
this._toggleSmallClass();
this._toggleAdaptiveClass();
this.callBase()
},
_renderHeader: function() {
var $header = (0, _renderer2.default)("<div>").appendTo(this.$element());
this._header = this._createComponent($header, _uiScheduler4.default, this._headerConfig())
},
_headerConfig: function() {
var result;
var currentViewOptions = this._getCurrentViewOptions();
var countConfig = this._getViewCountConfig();
result = (0, _extend.extend)({
firstDayOfWeek: this.option("firstDayOfWeek"),
currentView: this._currentView,
tabIndex: this.option("tabIndex"),
focusStateEnabled: this.option("focusStateEnabled"),
width: this.option("width"),
rtlEnabled: this.option("rtlEnabled"),
useDropDownViewSwitcher: this.option("useDropDownViewSwitcher"),
_dropDownButtonIcon: this.option("_dropDownButtonIcon"),
customizeDateNavigatorText: this.option("customizeDateNavigatorText")
}, currentViewOptions);
result.observer = this;
result.intervalCount = countConfig.intervalCount;
result.views = this.option("views");
result.min = new Date(this._dateOption("min"));
result.max = new Date(this._dateOption("max"));
result.currentDate = _date2.default.trimTime(new Date(this._dateOption("currentDate")));
return result
},
_appointmentsConfig: function() {
var that = this;
var config = {
observer: this,
onItemRendered: this._getAppointmentRenderedAction(),
onItemClick: this._createActionByOption("onAppointmentClick"),
onItemContextMenu: this._createActionByOption("onAppointmentContextMenu"),
onAppointmentDblClick: this._createActionByOption("onAppointmentDblClick"),
tabIndex: this.option("tabIndex"),
focusStateEnabled: this.option("focusStateEnabled"),
allowDrag: this._allowDragging(),
allowDelete: this._editing.allowUpdating && this._editing.allowDeleting,
allowResize: this._allowResizing(),
allowAllDayResize: this._allowAllDayResizing(),
rtlEnabled: this.option("rtlEnabled"),
currentView: this.option("currentView"),
onContentReady: function() {
that._workSpace && that._workSpace.option("allDayExpanded", that._isAllDayExpanded(that.getFilteredItems()))
}
};
return config
},
getCollectorOffset: function() {
if (this._workSpace.needApplyCollectorOffset() && !this.option("adaptivityEnabled")) {
return this.option("_collectorOffset")
} else {
return 0
}
},
getAppointmentDurationInMinutes: function() {
return this._getCurrentViewOption("cellDuration")
},
_processCurrentView: function() {
var views = this.option("views");
var currentView = this.option("currentView");
var that = this;
this._currentView = currentView;
(0, _iterator.each)(views, function(_, view) {
var isViewIsObject = _type2.default.isObject(view);
var viewName = isViewIsObject ? view.name : view;
var viewType = view.type;
if (currentView === viewName || currentView === viewType) {
that._currentView = view;
return false
}
})
},
_getCurrentViewType: function() {
return this._currentView.type || this._currentView
},
_getAppointmentsRenderingStrategy: function() {
return VIEWS_CONFIG[this._getCurrentViewType()].renderingStrategy
},
_renderWorkSpace: function(groups) {
this._readyToRenderAppointments && this._toggleSmallClass();
var $workSpace = (0, _renderer2.default)("<div>").appendTo(this.$element());
var countConfig = this._getViewCountConfig();
this._workSpace = this._createComponent($workSpace, VIEWS_CONFIG[this._getCurrentViewType()].workSpace, this._workSpaceConfig(groups, countConfig));
this._allowDragging() && this._workSpace.initDragBehavior(this);
this._workSpace.getWorkArea().append(this._appointments.$element());
this._recalculateWorkspace();
countConfig.startDate && this._header && this._header.option("currentDate", this._workSpace._getHeaderDate());
this._appointments.option("_collectorOffset", this.getCollectorOffset())
},
_getViewCountConfig: function() {
var currentView = this.option("currentView");
var view = this._getViewByName(currentView);
var viewCount = view && view.intervalCount || 1;
var startDate = view && view.startDate || null;
return {
intervalCount: viewCount,
startDate: startDate
}
},
_getViewByName: function(name) {
var views = this.option("views");
for (var i = 0; i < views.length; i++) {
if (views[i].name === name || views[i].type