Browse Source

Add check for parent existence when changing group in Item.setData. (#2985)

Add subgroup updates to Item.setData.
Remove group updating logic from ItemSet._updateItem.
Fixes #2939
gemini
Ben Morton 7 years ago
committed by yotamberk
parent
commit
79bb381c21
2 changed files with 9 additions and 19 deletions
  1. +3
    -18
      lib/timeline/component/ItemSet.js
  2. +6
    -1
      lib/timeline/component/item/Item.js

+ 3
- 18
lib/timeline/component/ItemSet.js View File

@ -1196,14 +1196,6 @@ ItemSet.prototype._addItem = function(item) {
* @private
*/
ItemSet.prototype._updateItem = function(item, itemData) {
var oldGroupId = item.data.group;
var oldSubGroupId = item.data.subgroup;
if (oldGroupId != itemData.group) {
var oldGroup = this.groups[oldGroupId];
if (oldGroup) oldGroup.remove(item);
}
// update the items data (will redraw the item when displayed)
item.setData(itemData);
@ -1214,14 +1206,6 @@ ItemSet.prototype._updateItem = function(item, itemData) {
} else if (group && group.data && group.data.showNested) {
item.groupShowing = true;
}
// update group
if (group) {
if (oldGroupId != item.data.group) {
group.add(item);
} else if (oldSubGroupId != item.data.subgroup) {
group.changeSubgroup(item, oldSubGroupId);
}
}
};
/**
@ -1587,10 +1571,11 @@ ItemSet.prototype._moveToGroup = function(item, groupId) {
var oldGroup = item.parent;
oldGroup.remove(item);
oldGroup.order();
item.data.group = group.groupId;
group.add(item);
group.order();
item.data.group = group.groupId;
}
};

+ 6
- 1
lib/timeline/component/item/Item.js View File

@ -61,9 +61,14 @@ Item.prototype.unselect = function() {
*/
Item.prototype.setData = function(data) {
var groupChanged = data.group != undefined && this.data.group != data.group;
if (groupChanged) {
if (groupChanged && this.parent != null) {
this.parent.itemSet._moveToGroup(this, data.group);
}
var subGroupChanged = data.subgroup != undefined && this.data.subgroup != data.subgroup;
if (subGroupChanged && this.parent != null) {
this.parent.changeSubgroup(this, this.data.subgroup, data.subgroup);
}
this.data = data;
this._updateEditStatus();

Loading…
Cancel
Save