Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 18 additions & 3 deletions core/model/extensions/ClientFilter.js
Original file line number Diff line number Diff line change
Expand Up @@ -376,8 +376,23 @@ define([
t.onNew.apply(t, arguments);
},

_onDelete: function(id, index, row){
var t = this, indexes = t._indexes, ids = t._ids;
_onDelete: function(id, index, path){
var t = this, indexes = t._indexes, ids = t._ids, st = t._struct;
// remove id in the struct
if (path.length && ids) {
var parentId = path[path.length - 1],
sIndex = indexOf(st[parentId], id),
children = st[id];

st[parentId].splice(sIndex, 1);
delete st[id];
if(children){
for(var i = children.length - 1; i > 0; --i){
delete st[i];
}
}
}

if(ids){
var i = indexOf(ids, id),
idx = indexes[id];
Expand All @@ -396,7 +411,7 @@ define([
t._refilter = 1;
}
}
t.onDelete(id, index, row);
t.onDelete(id, index, path);
}
});
});
91 changes: 52 additions & 39 deletions modules/View.js
Original file line number Diff line number Diff line change
Expand Up @@ -517,62 +517,75 @@ define([
}else if(msg === 'clearFilter'){
this._openInfo = this.__openInfo;
this._parentOpenInfo = this.__parentOpenInfo;
delete this.__openInfo;
delete this.__parentOpenInfo;
}
},

_onDelete: function(rowId, rowIndex, treePath){
if(treePath){
if (treePath) {
var t = this,
openInfo = t._openInfo,
parentOpenInfo = t._parentOpenInfo,
info = openInfo[rowId],
model = t.model,
parentId = treePath.pop(),
count = 1,
deleteItem = function(id, parentId){
var info = openInfo[id],
openedChildren = parentOpenInfo[id] || [];
array.forEach(openedChildren, function(child){
deleteItem(child);
});
delete parentOpenInfo[id];
if(info){
delete openInfo[id];
parentId = info.parentId;
}else if(!model.isId(parentId)){
//FIXME: don't know what to do here...
return;
}
var ppoi = parentOpenInfo[parentId],
i = array.indexOf(ppoi, id);
if(i >= 0){
ppoi.splice(i, 1);
}
};
if(info){
count += info.count;
info = openInfo[info.parentId];
}else if(model.isId(parentId)){
info = openInfo[parentId];
}
deleteItem(rowId, parentId);
while(info){
info.count -= count;
info = openInfo[info.parentId];
}
parentId = treePath[treePath.length - 1],
count = t._deleteInfo(rowId, rowIndex, treePath, t._openInfo, t._parentOpenInfo),
rootIndex = model.idToIndex(model.rootId(rowId));

// delete info from the filtering view
if (t.__openInfo) count = t._deleteInfo(rowId, rowIndex, treePath, t.__openInfo, t.__parentOpenInfo);

//sometimes number typed ID can be accidentally changed to string type.
if(String(parentId) == String(model.layerId()) && rowIndex >= t.rootStart && rowIndex < t.rootStart + t.rootCount){
t.rootCount--;
}
var rootIndex = model.idToIndex(model.rootId(rowId));
if(rootIndex >= t.rootStart && rootIndex < t.rootStart + t.rootCount){
if (rootIndex >= t.rootStart && rootIndex < t.rootStart + t.rootCount) {
t.visualCount -= count;
}
}else{
//FIXME: what to do if some unknown row is deleted?
this._clear();
}
this.grid.body.lazyRefresh();
},

_deleteInfo: function(rowId, rowIndex, treePath, openInfo, parentOpenInfo) {
var t = this,
info = openInfo[rowId],
model = t.model,
parentId = treePath[treePath.length - 1],
count = 1,
deleteItem = function(id, parentId){
var info = openInfo[id],
openedChildren = parentOpenInfo[id] || [];
array.forEach(openedChildren, function(child){
deleteItem(child);
});
delete parentOpenInfo[id];
if(info){
delete openInfo[id];
parentId = info.parentId;
}else if(!model.isId(parentId)){
//FIXME: don't know what to do here...
return;
}
var ppoi = parentOpenInfo[parentId],
i = array.indexOf(ppoi, id);
if(i >= 0){
ppoi.splice(i, 1);
}
};
if(info){
count += info.count;
info = openInfo[info.parentId];
}else if(model.isId(parentId)){
info = openInfo[parentId];
}
deleteItem(rowId, parentId);
while(info){
info.count -= count;
info = openInfo[info.parentId];
}

return count;
}
});
});