From 79bb381c21ff7844feb9faebb73497052ceb7132 Mon Sep 17 00:00:00 2001 From: Ben Morton Date: Fri, 28 Apr 2017 06:46:43 +0100 Subject: [PATCH] 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 --- lib/timeline/component/ItemSet.js | 21 +++------------------ lib/timeline/component/item/Item.js | 7 ++++++- 2 files changed, 9 insertions(+), 19 deletions(-) diff --git a/lib/timeline/component/ItemSet.js b/lib/timeline/component/ItemSet.js index e0019df8..002f294a 100644 --- a/lib/timeline/component/ItemSet.js +++ b/lib/timeline/component/ItemSet.js @@ -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; } }; diff --git a/lib/timeline/component/item/Item.js b/lib/timeline/component/item/Item.js index 6713a7ac..d7269bae 100644 --- a/lib/timeline/component/item/Item.js +++ b/lib/timeline/component/item/Item.js @@ -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();