").addClass(APPOINTMENT_DATE_CLASS).text(_date4.default.format(endDate, "shorttime")).appendTo($contentDetails);
$contentDetails.appendTo($container);
if (recurrenceRule) {
(0, _renderer2.default)("
").addClass(RECURRING_ICON_CLASS + " dx-icon-repeat").appendTo($container)
}
if (allDay) {
(0, _renderer2.default)("").text(" " + _message2.default.format("dxScheduler-allDay") + ": ").addClass(ALL_DAY_CONTENT_CLASS).prependTo($contentDetails)
}
},
_createAppointmentTitle: function(data) {
if (_type2.default.isPlainObject(data)) {
return data.text
}
return String(data)
},
_executeItemRenderAction: function(index, itemData, itemElement) {
var action = this._getItemRenderAction();
if (action) {
action({
appointmentElement: itemElement,
appointmentData: itemData,
targetedAppointmentData: this.invoke("getTargetedAppointmentData", itemData, itemElement, index)
})
}
delete this._currentAppointmentSettings
},
_itemClickHandler: function(e) {
this.callBase(e, {}, {
afterExecute: function(e) {
this._processItemClick(e.args[0].event)
}.bind(this)
})
},
_processItemClick: function(e) {
var $target = (0, _renderer2.default)(e.currentTarget);
var data = this._getItemData($target);
if (this._targetIsDisabled(e)) {
e.stopPropagation();
return
}
if ("keydown" === e.type || _utils4.default.isFakeClickEvent(e)) {
this.notifyObserver("showEditAppointmentPopup", {
data: data,
target: $target
});
return
}
this._appointmentClickTimeout = setTimeout(function() {
if (!this._preventSingleAppointmentClick && _dom_adapter2.default.getBody().contains($target[0])) {
this.notifyObserver("showAppointmentTooltip", {
data: data,
target: $target
})
}
this._preventSingleAppointmentClick = false
}.bind(this), 300)
},
_extendActionArgs: function() {
var args = this.callBase.apply(this, arguments);
return this.invoke("mapAppointmentFields", args)
},
_render: function() {
this.callBase.apply(this, arguments);
this._attachAppointmentDblClick()
},
_attachAppointmentDblClick: function() {
var that = this;
var itemSelector = that._itemSelector();
var itemContainer = this._itemContainer();
_events_engine2.default.off(itemContainer, DBLCLICK_EVENT_NAME, itemSelector);
_events_engine2.default.on(itemContainer, DBLCLICK_EVENT_NAME, itemSelector, function(e) {
that._itemDXEventHandler(e, "onAppointmentDblClick", {}, {
afterExecute: function(e) {
that._dblClickHandler(e.args[0].event)
}
})
})
},
_dblClickHandler: function(e) {
var $targetAppointment = (0, _renderer2.default)(e.currentTarget);
var appointmentData = this._getItemData($targetAppointment);
clearTimeout(this._appointmentClickTimeout);
this._preventSingleAppointmentClick = true;
this.notifyObserver("showEditAppointmentPopup", {
data: appointmentData,
target: $targetAppointment
})
},
_renderItem: function(index, item, container) {
var itemData = item.itemData;
for (var i = 0; i < item.settings.length; i++) {
var setting = item.settings[i];
this._currentAppointmentSettings = setting;
var $item = this.callBase(index, itemData, container);
$item.data(APPOINTMENT_SETTINGS_NAME, setting)
}
},
_getItemContent: function($itemFrame) {
$itemFrame.data(APPOINTMENT_SETTINGS_NAME, this._currentAppointmentSettings);
var $itemContent = this.callBase($itemFrame);
return $itemContent
},
_createItemByTemplate: function(itemTemplate, renderArgs) {
return itemTemplate.render({
model: renderArgs.itemData,
container: renderArgs.container,
index: renderArgs.index
})
},
_getAppointmentContainer: function(allDay) {
var $allDayContainer = this.option("allDayContainer");
var $container = this.itemsContainer().not($allDayContainer);
if (allDay && $allDayContainer) {
$container = $allDayContainer
}
return $container
},
_postprocessRenderItem: function(args) {
this._renderAppointment(args.itemElement, this._currentAppointmentSettings)
},
_renderAppointment: function($appointment, settings) {
$appointment.data(APPOINTMENT_SETTINGS_NAME, settings);
this._applyResourceDataAttr($appointment);
var data = this._getItemData($appointment);
var geometry = this.invoke("getAppointmentGeometry", settings);
var allowResize = !settings.isCompact && this.option("allowResize") && (!_type2.default.isDefined(settings.skipResizing) || _type2.default.isString(settings.skipResizing));
var allowDrag = this.option("allowDrag");
var allDay = settings.allDay;
this.invoke("setCellDataCacheAlias", this._currentAppointmentSettings, geometry);
var deferredColor = this._getAppointmentColor($appointment, settings.groupIndex);
if (settings.virtual) {
this._processVirtualAppointment(settings, $appointment, data, deferredColor)
} else {
this._createComponent($appointment, _uiScheduler4.default, {
observer: this.option("observer"),
data: data,
geometry: geometry,
direction: settings.direction || "vertical",
allowResize: allowResize,
allowDrag: allowDrag,
allDay: allDay,
reduced: settings.appointmentReduced,
isCompact: settings.isCompact,
startDate: new Date(settings.startDate),
cellWidth: this.invoke("getCellWidth"),
cellHeight: this.invoke("getCellHeight"),
resizableConfig: this._resizableConfig(data, settings)
});
deferredColor.done(function(color) {
if (color) {
$appointment.css("backgroundColor", color)
}
});
this._renderDraggable($appointment, allDay)
}
},
_applyResourceDataAttr: function($appointment) {
this.notifyObserver("getResourcesFromItem", {
itemData: this._getItemData($appointment),
callback: function(resources) {
if (resources) {
(0, _iterator.each)(resources, function(name, values) {
var attr = "data-" + _common2.default.normalizeKey(name.toLowerCase()) + "-";
for (var i = 0; i < values.length; i++) {
$appointment.attr(attr + _common2.default.normalizeKey(values[i]), true)
}
})
}
}
})
},
_resizableConfig: function(appointmentData, itemSetting) {
return {
area: this._calculateResizableArea(itemSetting, appointmentData),
onResizeStart: function(e) {
this._$currentAppointment = (0, _renderer2.default)(e.element);
if (this.invoke("needRecalculateResizableArea")) {
var updatedArea = this._calculateResizableArea(this._$currentAppointment.data("dxAppointmentSettings"), this._$currentAppointment.data("dxItemData"));
e.component.option("area", updatedArea);
e.component._renderDragOffsets(e.event)
}
this._initialSize = {
width: e.width,
height: e.height
};
this._initialCoordinates = _translator2.default.locate(this._$currentAppointment)
}.bind(this),
onResizeEnd: function(e) {
if (this._escPressed) {
e.event.cancel = true;
return
}
this._resizeEndHandler(e)
}.bind(this)
}
},
_calculateResizableArea: function(itemSetting, appointmentData) {
var area = this.$element().closest(".dx-scrollable-content");
this.notifyObserver("getResizableAppointmentArea", {
coordinates: {
left: itemSetting.left,
top: 0,
groupIndex: itemSetting.groupIndex
},
allDay: itemSetting.allDay,
callback: function(result) {
if (result) {
area = result
}
}
});
return area
},
_resizeEndHandler: function(e) {
var $element = (0, _renderer2.default)(e.element);
var itemData = this._getItemData($element);
var startDate = this.invoke("getStartDate", itemData, true);
var endDate = this.invoke("getEndDate", itemData, true);
var dateRange = this._getDateRange(e, startDate, endDate);
var updatedDates = {};
this.invoke("setField", "startDate", updatedDates, new Date(dateRange[0]));
this.invoke("setField", "endDate", updatedDates, new Date(dateRange[1]));
var data = (0, _extend.extend)({}, itemData, updatedDates);
this.notifyObserver("updateAppointmentAfterResize", {
target: itemData,
data: data,
$appointment: $element
})
},
_getDateRange: function(e, startDate, endDate) {
var itemData = this._getItemData(e.element);
var deltaTime = this.invoke("getDeltaTime", e, this._initialSize, itemData);
var renderingStrategyDirection = this.invoke("getRenderingStrategyDirection");
var cond = false;
var isAllDay = this.invoke("isAllDay", itemData);
var needCorrectDates = this.invoke("needCorrectAppointmentDates") && !isAllDay;
var startTime;
var endTime;
if ("vertical" !== renderingStrategyDirection || isAllDay) {
cond = this.option("rtlEnabled") ? e.handles.right : e.handles.left
} else {
cond = e.handles.top
}
if (cond) {
startTime = needCorrectDates ? this._correctStartDateByDelta(startDate, deltaTime) : startDate.getTime() - deltaTime;
endTime = endDate.getTime()
} else {
startTime = startDate.getTime();
endTime = needCorrectDates ? this._correctEndDateByDelta(endDate, deltaTime) : endDate.getTime() + deltaTime
}
return [startTime, endTime]
},
_correctEndDateByDelta: function(endDate, deltaTime) {
var endDayHour = this.invoke("getEndDayHour");
var startDayHour = this.invoke("getStartDayHour");
var result = endDate.getTime() + deltaTime;
var visibleDayDuration = (endDayHour - startDayHour) * toMs("hour");
var daysCount = deltaTime > 0 ? Math.ceil(deltaTime / visibleDayDuration) : Math.floor(deltaTime / visibleDayDuration);
var maxDate = new Date(endDate);
var minDate = new Date(endDate);
minDate.setHours(startDayHour, 0, 0, 0);
maxDate.setHours(endDayHour, 0, 0, 0);
if (result > maxDate.getTime() || result <= minDate.getTime()) {
var tailOfCurrentDay = maxDate.getTime() - endDate.getTime();
var tailOfPrevDays = deltaTime - tailOfCurrentDay;
var lastDay = new Date(endDate.setDate(endDate.getDate() + daysCount));
lastDay.setHours(startDayHour, 0, 0, 0);
result = lastDay.getTime() + tailOfPrevDays - visibleDayDuration * (daysCount - 1)
}
return result
},
_correctStartDateByDelta: function(startDate, deltaTime) {
var endDayHour = this.invoke("getEndDayHour");
var startDayHour = this.invoke("getStartDayHour");
var result = startDate.getTime() - deltaTime;
var visibleDayDuration = (endDayHour - startDayHour) * toMs("hour");
var daysCount = deltaTime > 0 ? Math.ceil(deltaTime / visibleDayDuration) : Math.floor(deltaTime / visibleDayDuration);
var maxDate = new Date(startDate);
var minDate = new Date(startDate);
minDate.setHours(startDayHour, 0, 0, 0);
maxDate.setHours(endDayHour, 0, 0, 0);
if (result < minDate.getTime() || result >= maxDate.getTime()) {
var tailOfCurrentDay = startDate.getTime() - minDate.getTime();
var tailOfPrevDays = deltaTime - tailOfCurrentDay;
var firstDay = new Date(startDate.setDate(startDate.getDate() - daysCount));
firstDay.setHours(endDayHour, 0, 0, 0);
result = firstDay.getTime() - tailOfPrevDays + visibleDayDuration * (daysCount - 1)
}
return result
},
_tryGetAppointmentColor: function(appointment) {
var settings = (0, _renderer2.default)(appointment).data(APPOINTMENT_SETTINGS_NAME);
if (!settings) {
return
}
return this._getAppointmentColor(appointment, settings.groupIndex)
},
_getAppointmentColor: function($appointment, groupIndex) {
var res = new _deferred.Deferred;
this.notifyObserver("getAppointmentColor", {
itemData: this._getItemData($appointment),
groupIndex: groupIndex,
callback: function(d) {
return d.done(function(color) {
return res.resolve(color)
})
}
});
return res.promise()
},
_renderDraggable: function($appointment, allDay) {
if (!this.option("allowDrag")) {
return
}
var that = this;
var $fixedContainer = this.option("fixedContainer");
var draggableArea;
var correctCoordinates = function(element, isFixedContainer) {
var coordinates = _translator2.default.locate((0, _renderer2.default)(element));
that.notifyObserver("correctAppointmentCoordinates", {
coordinates: coordinates,
allDay: allDay,
isFixedContainer: isFixedContainer,
callback: function(result) {
if (result) {
coordinates = result
}
}
});
_translator2.default.move($appointment, coordinates)
};
this.notifyObserver("getDraggableAppointmentArea", {
callback: function(result) {
if (result) {
draggableArea = result
}
}
});
this._createComponent($appointment, _draggable2.default, {
area: draggableArea,
boundOffset: that._calculateBoundOffset(),
immediate: false,
onDragStart: function(args) {
var e = args.event;
that._skipDraggableRestriction(e);
that.notifyObserver("hideAppointmentTooltip");
$fixedContainer.append($appointment);
that._$currentAppointment = (0, _renderer2.default)(args.element);
that._initialSize = {
width: args.width,
height: args.height
};
that._initialCoordinates = _translator2.default.locate(that._$currentAppointment)
},
onDrag: function(args) {
correctCoordinates(args.element)
},
onDragEnd: function(args) {
correctCoordinates(args.element, true);
var $container = that._getAppointmentContainer(allDay);
$container.append($appointment);
if (this._escPressed) {
args.event.cancel = true;
return
}
that._dragEndHandler(args)
}
})
},
_calculateBoundOffset: function() {
var result = {
top: 0
};
this.notifyObserver("getBoundOffset", {
callback: function(offset) {
result = offset
}
});
return result
},
_skipDraggableRestriction: function(e) {
if (this.option("rtlEnabled")) {
e.maxLeftOffset = null
} else {
e.maxRightOffset = null
}
e.maxBottomOffset = null
},
_dragEndHandler: function(e) {
var $element = (0, _renderer2.default)(e.element);
var itemData = this._getItemData($element);
var coordinates = this._initialCoordinates;
this.notifyObserver("updateAppointmentAfterDrag", {
data: itemData,
$appointment: $element,
coordinates: coordinates
})
},
_virtualAppointments: {},
_processVirtualAppointment: function(appointmentSetting, $appointment, appointmentData, color) {
var virtualAppointment = appointmentSetting.virtual;
var virtualGroupIndex = virtualAppointment.index;
if (!_type2.default.isDefined(this._virtualAppointments[virtualGroupIndex])) {
this._virtualAppointments[virtualGroupIndex] = {
coordinates: {
top: virtualAppointment.top,
left: virtualAppointment.left
},
items: {
data: [],
colors: []
},
isAllDay: virtualAppointment.isAllDay ? true : false,
buttonColor: color
}
}
appointmentData.settings = [appointmentSetting];
this._virtualAppointments[virtualGroupIndex].items.data.push(appointmentData);
this._virtualAppointments[virtualGroupIndex].items.colors.push(color);
$appointment.remove()
},
_renderContentImpl: function() {
this.callBase();
this._renderDropDownAppointments()
},
_renderDropDownAppointments: function() {
(0, _iterator.each)(this._virtualAppointments, function(groupIndex) {
var virtualGroup = this._virtualAppointments[groupIndex];
var virtualItems = virtualGroup.items;
var virtualCoordinates = virtualGroup.coordinates;
var $container = virtualGroup.isAllDay ? this.option("allDayContainer") : this.$element();
var left = virtualCoordinates.left;
var buttonWidth = this.invoke("getDropDownAppointmentWidth", virtualGroup.isAllDay);
var buttonHeight = this.invoke("getDropDownAppointmentHeight");
var rtlOffset = 0;
if (this.option("rtlEnabled")) {
rtlOffset = buttonWidth
}
this.notifyObserver("renderCompactAppointments", {
$container: $container,
coordinates: {
top: virtualCoordinates.top,
left: left + rtlOffset
},
items: virtualItems,
buttonColor: virtualGroup.buttonColor,
itemTemplate: this.option("itemTemplate"),
width: buttonWidth - this.option("_collectorOffset"),
height: buttonHeight,
onAppointmentClick: this.option("onItemClick"),
isCompact: this.invoke("isAdaptive") || this._isGroupCompact(virtualGroup),
applyOffset: this._isGroupCompact(virtualGroup)
})
}.bind(this))
},
_isGroupCompact: function(virtualGroup) {
return !virtualGroup.isAllDay && this.invoke("supportCompactDropDownAppointments")
},
_sortAppointmentsByStartDate: function(appointments) {
appointments.sort(function(a, b) {
var result = 0;
var firstDate = new Date(this.invoke("getField", "startDate", a.settings || a)).getTime();
var secondDate = new Date(this.invoke("getField", "startDate", b.settings || b)).getTime();
if (firstDate < secondDate) {
result = -1
}
if (firstDate > secondDate) {
result = 1
}
return result
}.bind(this))
},
_processRecurrenceAppointment: function(appointment, index, skipLongAppointments) {
var recurrenceRule = this.invoke("getField", "recurrenceRule", appointment);
var result = {
parts: [],
indexes: []
};
if (recurrenceRule) {
var dates = appointment.settings || appointment;
var startDate = new Date(this.invoke("getField", "startDate", dates));
var endDate = new Date(this.invoke("getField", "endDate", dates));
var appointmentDuration = endDate.getTime() - startDate.getTime();
var recurrenceException = this.invoke("getField", "recurrenceException", appointment);
var startViewDate = this.invoke("getStartViewDate");
var endViewDate = this.invoke("getEndViewDate");
var recurrentDates = _utils2.default.getDatesByRecurrence({
rule: recurrenceRule,
exception: recurrenceException,
start: startDate,
end: endDate,
min: startViewDate,
max: endViewDate
});
var recurrentDateCount = appointment.settings ? 1 : recurrentDates.length;
for (var i = 0; i < recurrentDateCount; i++) {
var appointmentPart = (0, _extend.extend)({}, appointment, true);
if (recurrentDates[i]) {
var appointmentSettings = this._applyStartDateToObj(recurrentDates[i], {});
this._applyEndDateToObj(new Date(recurrentDates[i].getTime() + appointmentDuration), appointmentSettings);
appointmentPart.settings = appointmentSettings
} else {
appointmentPart.settings = dates
}
result.parts.push(appointmentPart);
if (!skipLongAppointments) {
this._processLongAppointment(appointmentPart, result)
}
}
result.indexes.push(index)
}
return result
},
_processLongAppointment: function(appointment, result) {
var parts = this.splitAppointmentByDay(appointment);
var partCount = parts.length;
var endViewDate = this.invoke("getEndViewDate").getTime();
var startViewDate = this.invoke("getStartViewDate").getTime();
var startDateTimeZone = this.invoke("getField", "startDateTimeZone", appointment);
result = result || {
parts: []
};
if (partCount > 1) {
(0, _extend.extend)(appointment, parts[0]);
for (var i = 1; i < partCount; i++) {
var startDate = this.invoke("getField", "startDate", parts[i].settings).getTime();
startDate = this.invoke("convertDateByTimezone", startDate, startDateTimeZone);
if (startDate < endViewDate && startDate > startViewDate) {
result.parts.push(parts[i])
}
}
}
return result
},
_reduceRecurrenceAppointments: function(recurrenceIndexes, appointments) {
(0, _iterator.each)(recurrenceIndexes, function(i, index) {
appointments.splice(index - i, 1)
})
},
_combineAppointments: function(appointments, additionalAppointments) {
if (additionalAppointments.length) {
_array2.default.merge(appointments, additionalAppointments)
}
this._sortAppointmentsByStartDate(appointments)
},
_applyStartDateToObj: function(startDate, obj) {
this.invoke("setField", "startDate", obj, startDate);
return obj
},
_applyEndDateToObj: function(endDate, obj) {
this.invoke("setField", "endDate", obj, endDate);
return obj
},
updateDraggablesBoundOffsets: function() {
if (this.option("allowDrag")) {
this.$element().find("." + APPOINTMENT_ITEM_CLASS).each(function(_, appointmentElement) {
var $appointment = (0, _renderer2.default)(appointmentElement);
var appointmentData = this._getItemData($appointment);
if (!this.invoke("isAllDay", appointmentData)) {
_draggable2.default.getInstance($appointment).option("boundOffset", this._calculateBoundOffset())
}
}.bind(this))
}
},
moveAppointmentBack: function() {
var $appointment = this._$currentAppointment;
var size = this._initialSize;
var coords = this._initialCoordinates;
if ($appointment) {
if (coords) {
_translator2.default.move($appointment, coords);
delete this._initialSize
}
if (size) {
$appointment.outerWidth(size.width);
$appointment.outerHeight(size.height);
delete this._initialCoordinates
}
}
},
focus: function() {
var $appointment = this._$currentAppointment;
if ($appointment) {
this.option("focusedElement", (0, _dom.getPublicElement)($appointment));
_events_engine2.default.trigger(this.option("focusedElement"), "focus")
}
},
splitAppointmentByDay: function(appointment) {
var dates = appointment.settings || appointment;
var originalStartDate = new Date(this.invoke("getField", "startDate", dates));
var startDate = _date2.default.makeDate(originalStartDate);
var endDate = _date2.default.makeDate(this.invoke("getField", "endDate", dates));
var startDateTimeZone = this.invoke("getField", "startDateTimeZone", appointment);
var endDateTimeZone = this.invoke("getField", "endDateTimeZone", appointment);
var maxAllowedDate = this.invoke("getEndViewDate");
var startDayHour = this.invoke("getStartDayHour");
var endDayHour = this.invoke("getEndDayHour");
var appointmentIsLong = this.invoke("appointmentTakesSeveralDays", appointment);
var result = [];
startDate = this.invoke("convertDateByTimezone", startDate, startDateTimeZone);
endDate = this.invoke("convertDateByTimezone", endDate, endDateTimeZone);
if (startDate.getHours() <= endDayHour && startDate.getHours() >= startDayHour && !appointmentIsLong) {
result.push(this._applyStartDateToObj(new Date(startDate), {
appointmentData: appointment
}));
startDate.setDate(startDate.getDate() + 1)
}
while (appointmentIsLong && startDate.getTime() < endDate.getTime() - 1 && startDate < maxAllowedDate) {
var currentStartDate = new Date(startDate);
var currentEndDate = new Date(startDate);
this._checkStartDate(currentStartDate, originalStartDate, startDayHour);
this._checkEndDate(currentEndDate, endDate, endDayHour);
var appointmentData = _object2.default.deepExtendArraySafe({}, appointment, true);
var appointmentSettings = {};
this._applyStartDateToObj(currentStartDate, appointmentSettings);
this._applyEndDateToObj(currentEndDate, appointmentSettings);
appointmentData.settings = appointmentSettings;
result.push(appointmentData);
startDate.setDate(startDate.getDate() + 1);
startDate.setHours(startDayHour)
}
return result
},
_checkStartDate: function(currentDate, originalDate, startDayHour) {
if (!_date2.default.sameDate(currentDate, originalDate) || currentDate.getHours() <= startDayHour) {
currentDate.setHours(startDayHour, 0, 0, 0)
} else {
currentDate.setHours(originalDate.getHours(), originalDate.getMinutes(), originalDate.getSeconds(), originalDate.getMilliseconds())
}
},
_checkEndDate: function(currentDate, originalDate, endDayHour) {
if (!_date2.default.sameDate(currentDate, originalDate) || currentDate.getHours() > endDayHour) {
currentDate.setHours(endDayHour, 0, 0, 0)
} else {
currentDate.setHours(originalDate.getHours(), originalDate.getMinutes(), originalDate.getSeconds(), originalDate.getMilliseconds())
}
}
}).include(_uiScheduler2.default);
(0, _component_registrator2.default)("dxSchedulerAppointments", SchedulerAppointments);
module.exports = SchedulerAppointments;