|
|
@ -35,10 +35,10 @@ function ItemSet(body, options) { |
|
|
|
align: 'auto', // alignment of box items
|
|
|
|
stack: true, |
|
|
|
stackSubgroups: true, |
|
|
|
groupOrderSwap: function(fromGroup, toGroup, groups) { |
|
|
|
var targetOrder = toGroup.order; |
|
|
|
toGroup.order = fromGroup.order; |
|
|
|
fromGroup.order = targetOrder; |
|
|
|
groupOrderSwap: function(fromGroup, toGroup, groups) { // eslint-disable-line no-unused-vars
|
|
|
|
var targetOrder = toGroup.order; |
|
|
|
toGroup.order = fromGroup.order; |
|
|
|
fromGroup.order = targetOrder; |
|
|
|
}, |
|
|
|
groupOrder: 'order', |
|
|
|
|
|
|
@ -131,26 +131,26 @@ function ItemSet(body, options) { |
|
|
|
|
|
|
|
// listeners for the DataSet of the items
|
|
|
|
this.itemListeners = { |
|
|
|
'add': function (event, params, senderId) { |
|
|
|
'add': function (event, params, senderId) { // eslint-disable-line no-unused-vars
|
|
|
|
me._onAdd(params.items); |
|
|
|
}, |
|
|
|
'update': function (event, params, senderId) { |
|
|
|
'update': function (event, params, senderId) { // eslint-disable-line no-unused-vars
|
|
|
|
me._onUpdate(params.items); |
|
|
|
}, |
|
|
|
'remove': function (event, params, senderId) { |
|
|
|
'remove': function (event, params, senderId) { // eslint-disable-line no-unused-vars
|
|
|
|
me._onRemove(params.items); |
|
|
|
} |
|
|
|
}; |
|
|
|
|
|
|
|
// listeners for the DataSet of the groups
|
|
|
|
this.groupListeners = { |
|
|
|
'add': function (event, params, senderId) { |
|
|
|
'add': function (event, params, senderId) { // eslint-disable-line no-unused-vars
|
|
|
|
me._onAddGroups(params.items); |
|
|
|
}, |
|
|
|
'update': function (event, params, senderId) { |
|
|
|
'update': function (event, params, senderId) { // eslint-disable-line no-unused-vars
|
|
|
|
me._onUpdateGroups(params.items); |
|
|
|
}, |
|
|
|
'remove': function (event, params, senderId) { |
|
|
|
'remove': function (event, params, senderId) { // eslint-disable-line no-unused-vars
|
|
|
|
me._onRemoveGroups(params.items); |
|
|
|
} |
|
|
|
}; |
|
|
@ -550,13 +550,14 @@ ItemSet.prototype.getSelection = function() { |
|
|
|
*/ |
|
|
|
ItemSet.prototype.getVisibleItems = function() { |
|
|
|
var range = this.body.range.getRange(); |
|
|
|
var right, left; |
|
|
|
|
|
|
|
if (this.options.rtl) { |
|
|
|
var right = this.body.util.toScreen(range.start); |
|
|
|
var left = this.body.util.toScreen(range.end); |
|
|
|
right = this.body.util.toScreen(range.start); |
|
|
|
left = this.body.util.toScreen(range.end); |
|
|
|
} else { |
|
|
|
var left = this.body.util.toScreen(range.start); |
|
|
|
var right = this.body.util.toScreen(range.end); |
|
|
|
left = this.body.util.toScreen(range.start); |
|
|
|
right = this.body.util.toScreen(range.end); |
|
|
|
} |
|
|
|
|
|
|
|
var ids = []; |
|
|
@ -634,8 +635,8 @@ ItemSet.prototype.redraw = function() { |
|
|
|
var visibleInterval = range.end - range.start; |
|
|
|
var zoomed = (visibleInterval != this.lastVisibleInterval) || (this.props.width != this.props.lastWidth); |
|
|
|
var scrolled = range.start != this.lastRangeStart; |
|
|
|
var changedStackOption = options.stack != this.lastStack |
|
|
|
var changedStackSubgroupsOption = options.stackSubgroups != this.lastStackSubgroups |
|
|
|
var changedStackOption = options.stack != this.lastStack; |
|
|
|
var changedStackSubgroupsOption = options.stackSubgroups != this.lastStackSubgroups; |
|
|
|
var forceRestack = (zoomed || scrolled || changedStackOption || changedStackSubgroupsOption); |
|
|
|
this.lastVisibleInterval = visibleInterval; |
|
|
|
this.lastRangeStart = range.start; |
|
|
@ -712,7 +713,6 @@ ItemSet.prototype._firstGroup = function() { |
|
|
|
*/ |
|
|
|
ItemSet.prototype._updateUngrouped = function() { |
|
|
|
var ungrouped = this.groups[UNGROUPED]; |
|
|
|
var background = this.groups[BACKGROUND]; |
|
|
|
var item, itemId; |
|
|
|
|
|
|
|
if (this.groupsData) { |
|
|
@ -866,7 +866,7 @@ ItemSet.prototype.setGroups = function(groups) { |
|
|
|
groupsData.update(updatedNestedGroup); |
|
|
|
}) |
|
|
|
} |
|
|
|
}) |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
// subscribe to new dataset
|
|
|
@ -903,8 +903,7 @@ ItemSet.prototype.getGroups = function() { |
|
|
|
*/ |
|
|
|
ItemSet.prototype.removeItem = function(id) { |
|
|
|
var item = this.itemsData.get(id), |
|
|
|
dataset = this.itemsData.getDataSet(), |
|
|
|
itemObj = this.items[id]; |
|
|
|
dataset = this.itemsData.getDataSet(); |
|
|
|
|
|
|
|
if (item) { |
|
|
|
// confirm deletion
|
|
|
@ -1178,12 +1177,12 @@ ItemSet.prototype._orderNestedGroups = function(groupIds) { |
|
|
|
}, |
|
|
|
order: this.options.groupOrder |
|
|
|
}); |
|
|
|
var nestedGroupIds = nestedGroups.map(function(nestedGroup) { return nestedGroup.id }) |
|
|
|
var nestedGroupIds = nestedGroups.map(function(nestedGroup) { return nestedGroup.id }); |
|
|
|
newGroupIdsOrder = newGroupIdsOrder.concat(nestedGroupIds); |
|
|
|
} |
|
|
|
}, this) |
|
|
|
}, this); |
|
|
|
return newGroupIdsOrder; |
|
|
|
} |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
@ -1199,9 +1198,9 @@ ItemSet.prototype._addItem = function(item) { |
|
|
|
var group = this.groups[groupId]; |
|
|
|
|
|
|
|
if (!group) { |
|
|
|
item.groupShowing = false; |
|
|
|
item.groupShowing = false; |
|
|
|
} else if (group && group.data && group.data.showNested) { |
|
|
|
item.groupShowing = true; |
|
|
|
item.groupShowing = true; |
|
|
|
} |
|
|
|
|
|
|
|
if (group) group.add(item); |
|
|
@ -1383,14 +1382,16 @@ ItemSet.prototype._onDragStart = function (event) { |
|
|
|
* @private |
|
|
|
*/ |
|
|
|
ItemSet.prototype._onDragStartAddItem = function (event) { |
|
|
|
var xAbs; |
|
|
|
var x; |
|
|
|
var snap = this.options.snap || null; |
|
|
|
|
|
|
|
if (this.options.rtl) { |
|
|
|
var xAbs = util.getAbsoluteRight(this.dom.frame); |
|
|
|
var x = xAbs - event.center.x + 10; // plus 10 to compensate for the drag starting as soon as you've moved 10px
|
|
|
|
xAbs = util.getAbsoluteRight(this.dom.frame); |
|
|
|
x = xAbs - event.center.x + 10; // plus 10 to compensate for the drag starting as soon as you've moved 10px
|
|
|
|
} else { |
|
|
|
var xAbs = util.getAbsoluteLeft(this.dom.frame); |
|
|
|
var x = event.center.x - xAbs - 10; // minus 10 to compensate for the drag starting as soon as you've moved 10px
|
|
|
|
xAbs = util.getAbsoluteLeft(this.dom.frame); |
|
|
|
x = event.center.x - xAbs - 10; // minus 10 to compensate for the drag starting as soon as you've moved 10px
|
|
|
|
} |
|
|
|
|
|
|
|
var time = this.body.util.toTime(x); |
|
|
@ -1446,11 +1447,12 @@ ItemSet.prototype._onDrag = function (event) { |
|
|
|
|
|
|
|
var me = this; |
|
|
|
var snap = this.options.snap || null; |
|
|
|
var xOffset; |
|
|
|
|
|
|
|
if (this.options.rtl) { |
|
|
|
var xOffset = this.body.dom.root.offsetLeft + this.body.domProps.right.width; |
|
|
|
xOffset = this.body.dom.root.offsetLeft + this.body.domProps.right.width; |
|
|
|
} else { |
|
|
|
var xOffset = this.body.dom.root.offsetLeft + this.body.domProps.left.width; |
|
|
|
xOffset = this.body.dom.root.offsetLeft + this.body.domProps.left.width; |
|
|
|
} |
|
|
|
|
|
|
|
var scale = this.body.util.getScale(); |
|
|
@ -1477,11 +1479,16 @@ ItemSet.prototype._onDrag = function (event) { |
|
|
|
this.touchParams.itemProps.forEach(function (props) { |
|
|
|
var current = me.body.util.toTime(event.center.x - xOffset); |
|
|
|
var initial = me.body.util.toTime(props.initialX - xOffset); |
|
|
|
var offset; |
|
|
|
var initialStart; |
|
|
|
var initialEnd; |
|
|
|
var start; |
|
|
|
var end; |
|
|
|
|
|
|
|
if (this.options.rtl) { |
|
|
|
var offset = -(current - initial); // ms
|
|
|
|
offset = -(current - initial); // ms
|
|
|
|
} else { |
|
|
|
var offset = (current - initial); // ms
|
|
|
|
offset = (current - initial); // ms
|
|
|
|
} |
|
|
|
|
|
|
|
var itemData = this._cloneItemData(props.item.data); // clone the data
|
|
|
@ -1499,15 +1506,15 @@ ItemSet.prototype._onDrag = function (event) { |
|
|
|
// drag left side of a range item
|
|
|
|
if (this.options.rtl) { |
|
|
|
if (itemData.end != undefined) { |
|
|
|
var initialEnd = util.convert(props.data.end, 'Date'); |
|
|
|
var end = new Date(initialEnd.valueOf() + offset); |
|
|
|
initialEnd = util.convert(props.data.end, 'Date'); |
|
|
|
end = new Date(initialEnd.valueOf() + offset); |
|
|
|
// TODO: pass a Moment instead of a Date to snap(). (Breaking change)
|
|
|
|
itemData.end = snap ? snap(end, scale, step) : end; |
|
|
|
} |
|
|
|
} else { |
|
|
|
if (itemData.start != undefined) { |
|
|
|
var initialStart = util.convert(props.data.start, 'Date'); |
|
|
|
var start = new Date(initialStart.valueOf() + offset); |
|
|
|
initialStart = util.convert(props.data.start, 'Date'); |
|
|
|
start = new Date(initialStart.valueOf() + offset); |
|
|
|
// TODO: pass a Moment instead of a Date to snap(). (Breaking change)
|
|
|
|
itemData.start = snap ? snap(start, scale, step) : start; |
|
|
|
} |
|
|
@ -1517,15 +1524,15 @@ ItemSet.prototype._onDrag = function (event) { |
|
|
|
// drag right side of a range item
|
|
|
|
if (this.options.rtl) { |
|
|
|
if (itemData.start != undefined) { |
|
|
|
var initialStart = util.convert(props.data.start, 'Date'); |
|
|
|
var start = new Date(initialStart.valueOf() + offset); |
|
|
|
initialStart = util.convert(props.data.start, 'Date'); |
|
|
|
start = new Date(initialStart.valueOf() + offset); |
|
|
|
// TODO: pass a Moment instead of a Date to snap(). (Breaking change)
|
|
|
|
itemData.start = snap ? snap(start, scale, step) : start; |
|
|
|
} |
|
|
|
} else { |
|
|
|
if (itemData.end != undefined) { |
|
|
|
var initialEnd = util.convert(props.data.end, 'Date'); |
|
|
|
var end = new Date(initialEnd.valueOf() + offset); |
|
|
|
initialEnd = util.convert(props.data.end, 'Date'); |
|
|
|
end = new Date(initialEnd.valueOf() + offset); |
|
|
|
// TODO: pass a Moment instead of a Date to snap(). (Breaking change)
|
|
|
|
itemData.end = snap ? snap(end, scale, step) : end; |
|
|
|
} |
|
|
@ -1535,11 +1542,11 @@ ItemSet.prototype._onDrag = function (event) { |
|
|
|
// drag both start and end
|
|
|
|
if (itemData.start != undefined) { |
|
|
|
|
|
|
|
var initialStart = util.convert(props.data.start, 'Date').valueOf(); |
|
|
|
var start = new Date(initialStart + offset); |
|
|
|
initialStart = util.convert(props.data.start, 'Date').valueOf(); |
|
|
|
start = new Date(initialStart + offset); |
|
|
|
|
|
|
|
if (itemData.end != undefined) { |
|
|
|
var initialEnd = util.convert(props.data.end, 'Date'); |
|
|
|
initialEnd = util.convert(props.data.end, 'Date'); |
|
|
|
var duration = initialEnd.valueOf() - initialStart.valueOf(); |
|
|
|
|
|
|
|
// TODO: pass a Moment instead of a Date to snap(). (Breaking change)
|
|
|
@ -1550,13 +1557,10 @@ ItemSet.prototype._onDrag = function (event) { |
|
|
|
// TODO: pass a Moment instead of a Date to snap(). (Breaking change)
|
|
|
|
itemData.start = snap ? snap(start, scale, step) : start; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (updateGroupAllowed && (!props.dragLeft && !props.dragRight) && newGroupBase!=null) { |
|
|
|
if (itemData.group != undefined) { |
|
|
|
var newOffset = newGroupBase - props.groupOffset; |
|
|
@ -1677,10 +1681,10 @@ ItemSet.prototype._onGroupClick = function (event) { |
|
|
|
util.addClassName(group.dom.label, 'expanded'); |
|
|
|
} else { |
|
|
|
util.removeClassName(group.dom.label, 'expanded'); |
|
|
|
var collapsedDirClassName = this.options.rtl ? 'collapsed-rtl' : 'collapsed' |
|
|
|
var collapsedDirClassName = this.options.rtl ? 'collapsed-rtl' : 'collapsed'; |
|
|
|
util.addClassName(group.dom.label, collapsedDirClassName); |
|
|
|
} |
|
|
|
} |
|
|
|
}; |
|
|
|
|
|
|
|
ItemSet.prototype._onGroupDragStart = function (event) { |
|
|
|
if (this.options.groupEditable.order) { |
|
|
@ -1690,11 +1694,11 @@ ItemSet.prototype._onGroupDragStart = function (event) { |
|
|
|
event.stopPropagation(); |
|
|
|
|
|
|
|
this.groupTouchParams.originalOrder = this.groupsData.getIds({ |
|
|
|
order: this.options.groupOrder |
|
|
|
}); |
|
|
|
order: this.options.groupOrder |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
}; |
|
|
|
|
|
|
|
ItemSet.prototype._onGroupDrag = function (event) { |
|
|
|
if (this.options.groupEditable.order && this.groupTouchParams.group) { |
|
|
@ -1740,8 +1744,8 @@ ItemSet.prototype._onGroupDrag = function (event) { |
|
|
|
|
|
|
|
// fetch current order of groups
|
|
|
|
var newOrder = groupsData.getIds({ |
|
|
|
order: this.options.groupOrder |
|
|
|
}); |
|
|
|
order: this.options.groupOrder |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
// in case of changes since _onGroupDragStart
|
|
|
@ -1769,17 +1773,17 @@ ItemSet.prototype._onGroupDrag = function (event) { |
|
|
|
// if dragged group was move upwards everything below should have an offset
|
|
|
|
if (newOrder[curPos+newOffset] == draggedId) { |
|
|
|
newOffset = 1; |
|
|
|
continue; |
|
|
|
|
|
|
|
} |
|
|
|
// if dragged group was move downwards everything above should have an offset
|
|
|
|
else if (origOrder[curPos+orgOffset] == draggedId) { |
|
|
|
orgOffset = 1; |
|
|
|
continue; |
|
|
|
|
|
|
|
} |
|
|
|
// found a group (apart from dragged group) that has the wrong position -> switch with the
|
|
|
|
// group at the position where other one should be, fix index arrays and continue
|
|
|
|
else { |
|
|
|
var slippedPosition = newOrder.indexOf(origOrder[curPos+orgOffset]) |
|
|
|
var slippedPosition = newOrder.indexOf(origOrder[curPos+orgOffset]); |
|
|
|
var switchGroup = groupsData.get(newOrder[curPos+newOffset]); |
|
|
|
var shouldBeGroup = groupsData.get(origOrder[curPos+orgOffset]); |
|
|
|
this.options.groupOrderSwap(switchGroup, shouldBeGroup, groupsData); |
|
|
@ -1797,69 +1801,68 @@ ItemSet.prototype._onGroupDrag = function (event) { |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
}; |
|
|
|
|
|
|
|
ItemSet.prototype._onGroupDragEnd = function (event) { |
|
|
|
if (this.options.groupEditable.order && this.groupTouchParams.group) { |
|
|
|
event.stopPropagation(); |
|
|
|
if (this.options.groupEditable.order && this.groupTouchParams.group) { |
|
|
|
event.stopPropagation(); |
|
|
|
|
|
|
|
// update existing group
|
|
|
|
var me = this; |
|
|
|
var id = me.groupTouchParams.group.groupId; |
|
|
|
var dataset = me.groupsData.getDataSet(); |
|
|
|
var groupData = util.extend({}, dataset.get(id)); // clone the data
|
|
|
|
me.options.onMoveGroup(groupData, function (groupData) { |
|
|
|
if (groupData) { |
|
|
|
// apply changes
|
|
|
|
groupData[dataset._fieldId] = id; // ensure the group contains its id (can be undefined)
|
|
|
|
dataset.update(groupData); |
|
|
|
} |
|
|
|
else { |
|
|
|
|
|
|
|
// fetch current order of groups
|
|
|
|
var newOrder = dataset.getIds({ |
|
|
|
order: me.options.groupOrder |
|
|
|
}); |
|
|
|
|
|
|
|
// restore original order
|
|
|
|
if (!util.equalArray(newOrder, me.groupTouchParams.originalOrder)) { |
|
|
|
var origOrder = me.groupTouchParams.originalOrder; |
|
|
|
var numGroups = Math.min(origOrder.length, newOrder.length); |
|
|
|
var curPos = 0; |
|
|
|
while (curPos < numGroups) { |
|
|
|
// as long as the groups are where they should be step down along the groups order
|
|
|
|
while (curPos < numGroups && newOrder[curPos] == origOrder[curPos]) { |
|
|
|
curPos++; |
|
|
|
} |
|
|
|
|
|
|
|
// all ok
|
|
|
|
if (curPos >= numGroups) { |
|
|
|
break; |
|
|
|
} |
|
|
|
|
|
|
|
// found a group that has the wrong position -> switch with the
|
|
|
|
// group at the position where other one should be, fix index arrays and continue
|
|
|
|
var slippedPosition = newOrder.indexOf(origOrder[curPos]) |
|
|
|
var switchGroup = dataset.get(newOrder[curPos]); |
|
|
|
var shouldBeGroup = dataset.get(origOrder[curPos]); |
|
|
|
me.options.groupOrderSwap(switchGroup, shouldBeGroup, dataset); |
|
|
|
dataset.update(switchGroup); |
|
|
|
dataset.update(shouldBeGroup); |
|
|
|
|
|
|
|
var switchGroupId = newOrder[curPos]; |
|
|
|
newOrder[curPos] = origOrder[curPos]; |
|
|
|
newOrder[slippedPosition] = switchGroupId; |
|
|
|
|
|
|
|
curPos++; |
|
|
|
} |
|
|
|
} |
|
|
|
// update existing group
|
|
|
|
var me = this; |
|
|
|
var id = me.groupTouchParams.group.groupId; |
|
|
|
var dataset = me.groupsData.getDataSet(); |
|
|
|
var groupData = util.extend({}, dataset.get(id)); // clone the data
|
|
|
|
me.options.onMoveGroup(groupData, function (groupData) { |
|
|
|
if (groupData) { |
|
|
|
// apply changes
|
|
|
|
groupData[dataset._fieldId] = id; // ensure the group contains its id (can be undefined)
|
|
|
|
dataset.update(groupData); |
|
|
|
} |
|
|
|
else { |
|
|
|
|
|
|
|
} |
|
|
|
// fetch current order of groups
|
|
|
|
var newOrder = dataset.getIds({ |
|
|
|
order: me.options.groupOrder |
|
|
|
}); |
|
|
|
|
|
|
|
me.body.emitter.emit('groupDragged', { groupId: id }); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// restore original order
|
|
|
|
if (!util.equalArray(newOrder, me.groupTouchParams.originalOrder)) { |
|
|
|
var origOrder = me.groupTouchParams.originalOrder; |
|
|
|
var numGroups = Math.min(origOrder.length, newOrder.length); |
|
|
|
var curPos = 0; |
|
|
|
while (curPos < numGroups) { |
|
|
|
// as long as the groups are where they should be step down along the groups order
|
|
|
|
while (curPos < numGroups && newOrder[curPos] == origOrder[curPos]) { |
|
|
|
curPos++; |
|
|
|
} |
|
|
|
|
|
|
|
// all ok
|
|
|
|
if (curPos >= numGroups) { |
|
|
|
break; |
|
|
|
} |
|
|
|
|
|
|
|
// found a group that has the wrong position -> switch with the
|
|
|
|
// group at the position where other one should be, fix index arrays and continue
|
|
|
|
var slippedPosition = newOrder.indexOf(origOrder[curPos]); |
|
|
|
var switchGroup = dataset.get(newOrder[curPos]); |
|
|
|
var shouldBeGroup = dataset.get(origOrder[curPos]); |
|
|
|
me.options.groupOrderSwap(switchGroup, shouldBeGroup, dataset); |
|
|
|
dataset.update(switchGroup); |
|
|
|
dataset.update(shouldBeGroup); |
|
|
|
|
|
|
|
var switchGroupId = newOrder[curPos]; |
|
|
|
newOrder[curPos] = origOrder[curPos]; |
|
|
|
newOrder[slippedPosition] = switchGroupId; |
|
|
|
|
|
|
|
curPos++; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
|
|
|
|
me.body.emitter.emit('groupDragged', { groupId: id }); |
|
|
|
} |
|
|
|
}; |
|
|
|
|
|
|
|
/** |
|
|
|
* Handle selecting/deselecting an item when tapping it |
|
|
@ -1984,7 +1987,7 @@ ItemSet.prototype._onMouseWheel = function(event) { |
|
|
|
if (this.touchParams.itemIsDragging) { |
|
|
|
this._onDragEnd(event); |
|
|
|
} |
|
|
|
} |
|
|
|
}; |
|
|
|
|
|
|
|
/** |
|
|
|
* Handle updates of an item on double tap |
|
|
@ -2006,7 +2009,7 @@ ItemSet.prototype._onUpdateItem = function (item) { |
|
|
|
} |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
}; |
|
|
|
|
|
|
|
/** |
|
|
|
* Handle creation of an item on double tap |
|
|
@ -2022,30 +2025,33 @@ ItemSet.prototype._onAddItem = function (event) { |
|
|
|
var item = this.itemFromTarget(event); |
|
|
|
|
|
|
|
if (!item) { |
|
|
|
var xAbs; |
|
|
|
var x; |
|
|
|
// add item
|
|
|
|
if (this.options.rtl) { |
|
|
|
var xAbs = util.getAbsoluteRight(this.dom.frame); |
|
|
|
var x = xAbs - event.center.x; |
|
|
|
xAbs = util.getAbsoluteRight(this.dom.frame); |
|
|
|
x = xAbs - event.center.x; |
|
|
|
} else { |
|
|
|
var xAbs = util.getAbsoluteLeft(this.dom.frame); |
|
|
|
var x = event.center.x - xAbs; |
|
|
|
xAbs = util.getAbsoluteLeft(this.dom.frame); |
|
|
|
x = event.center.x - xAbs; |
|
|
|
} |
|
|
|
// var xAbs = util.getAbsoluteLeft(this.dom.frame);
|
|
|
|
// var x = event.center.x - xAbs;
|
|
|
|
var start = this.body.util.toTime(x); |
|
|
|
var scale = this.body.util.getScale(); |
|
|
|
var step = this.body.util.getStep(); |
|
|
|
var end; |
|
|
|
|
|
|
|
var newItemData; |
|
|
|
if (event.type == 'drop') { |
|
|
|
newItemData = JSON.parse(event.dataTransfer.getData("text")) |
|
|
|
newItemData.content = newItemData.content ? newItemData.content : 'new item' |
|
|
|
newItemData.start = newItemData.start ? newItemData.start : (snap ? snap(start, scale, step) : start) |
|
|
|
newItemData = JSON.parse(event.dataTransfer.getData("text")); |
|
|
|
newItemData.content = newItemData.content ? newItemData.content : 'new item'; |
|
|
|
newItemData.start = newItemData.start ? newItemData.start : (snap ? snap(start, scale, step) : start); |
|
|
|
newItemData.type = newItemData.type || 'box'; |
|
|
|
newItemData[this.itemsData._fieldId] = newItemData.id || util.randomUUID(); |
|
|
|
|
|
|
|
if (newItemData.type == 'range' && !newItemData.end) { |
|
|
|
var end = this.body.util.toTime(x + this.props.width / 5); |
|
|
|
end = this.body.util.toTime(x + this.props.width / 5); |
|
|
|
newItemData.end = snap ? snap(end, scale, step) : end; |
|
|
|
} |
|
|
|
} else { |
|
|
@ -2057,7 +2063,7 @@ ItemSet.prototype._onAddItem = function (event) { |
|
|
|
|
|
|
|
// when default type is a range, add a default end date to the new item
|
|
|
|
if (this.options.type === 'range') { |
|
|
|
var end = this.body.util.toTime(x + this.props.width / 5); |
|
|
|
end = this.body.util.toTime(x + this.props.width / 5); |
|
|
|
newItemData.end = snap ? snap(end, scale, step) : end; |
|
|
|
} |
|
|
|
} |
|
|
@ -2103,7 +2109,7 @@ ItemSet.prototype._onMultiSelectItem = function (event) { |
|
|
|
if (shiftKey && this.options.multiselect) { |
|
|
|
// select all items between the old selection and the tapped item
|
|
|
|
var itemGroup = this.itemsData.get(item.id).group; |
|
|
|
|
|
|
|
|
|
|
|
// when filtering get the group of the last selected item
|
|
|
|
var lastSelectedGroup = undefined; |
|
|
|
if (this.options.multiselectPerGroup) { |
|
|
@ -2111,7 +2117,7 @@ ItemSet.prototype._onMultiSelectItem = function (event) { |
|
|
|
lastSelectedGroup = this.itemsData.get(selection[0]).group; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// determine the selection range
|
|
|
|
if (!this.options.multiselectPerGroup || lastSelectedGroup == undefined || lastSelectedGroup == itemGroup) { |
|
|
|
selection.push(item.id); |
|
|
|