[interface] itemsTreeView correctly handles notify(erase)

[data access] Collection.removeItem() calls trigger() with the right type
This commit is contained in:
David Norton 2006-06-09 14:01:07 +00:00
parent 14ba1b8fbc
commit 9f7437f5ca
2 changed files with 19 additions and 27 deletions

View file

@ -191,20 +191,20 @@ Scholar.ItemTreeView.prototype.getCollectionID = function()
//CALLED BY DATA LAYER ON CHANGE: //CALLED BY DATA LAYER ON CHANGE:
Scholar.ItemTreeView.prototype.notify = function(action, type, ids) Scholar.ItemTreeView.prototype.notify = function(action, type, ids)
{ {
ids = Scholar.flattenArguments(ids);
var madeChanges = false; var madeChanges = false;
this.selection.selectEventsSuppressed = true; this.selection.selectEventsSuppressed = true;
this.saveSelection(); this.saveSelection();
if(action == 'remove') if((action == 'remove' && !this._itemGroup.isLibrary()) || (action == 'delete' && this._itemGroup.isLibrary()))
{ {
ids = Scholar.flattenArguments(ids);
//Since a remove involves shifting of rows, we have to do it in order //Since a remove involves shifting of rows, we have to do it in order
//sort the ids by row //sort the ids by row
var rows = new Array(); var rows = new Array();
for(var i=0, len=ids.length; i<len; i++) for(var i=0, len=ids.length; i<len; i++)
if(this._itemRowMap[ids[i]] != null) if(action == 'delete' || !this._itemGroup.ref.hasItem(ids[i]))
rows.push(this._itemRowMap[ids[i]]); rows.push(this._itemRowMap[ids[i]]);
if(rows.length > 0) if(rows.length > 0)
@ -222,33 +222,25 @@ Scholar.ItemTreeView.prototype.notify = function(action, type, ids)
} }
} }
else else if(action == 'modify') //must check for null because it could legitimately be 0
{ {
for (var i=0, len=ids.length; i<len; i++) if(this._itemRowMap[ids])
{ {
var row = this._itemRowMap[ids[i]];
if(action == 'modify' && row != null) //must check for null because it could legitimately be 0
{
var item = Scholar.Items.get(ids[i]);
this._treebox.invalidateRow(row); this._treebox.invalidateRow(row);
madeChanges = true; madeChanges = true;
} }
else if(action == 'add' && row == null) }
else if(action == 'add')
{ {
var item = Scholar.Items.get(ids[i]); var item = Scholar.Items.get(ids);
if(this._itemGroup.isLibrary() || item.inCollection(this.getCollectionID())) if(this._itemGroup.isLibrary() || item.inCollection(this.getCollectionID()))
{ {
this._showItem(item,this.rowCount); this._showItem(item,this.rowCount);
this._treebox.rowCountChanged(this.rowCount-1,1); this._treebox.rowCountChanged(this.rowCount-1,1);
}
madeChanges = true; madeChanges = true;
} }
}
} }
if(madeChanges) if(madeChanges)

View file

@ -1234,7 +1234,7 @@ Scholar.Collection.prototype.removeItem = function(itemID){
// If this was the last item, set collection to empty // If this was the last item, set collection to empty
if (!this._childItems.length){ if (!this._childItems.length){
this._hasChildItems = false; this._hasChildItems = false;
Scholar.Notifier.trigger('modify', 'collections', this.getID()); Scholar.Notifier.trigger('modify', 'collection', this.getID());
} }
Scholar.Notifier.trigger('remove', 'item', itemID); Scholar.Notifier.trigger('remove', 'item', itemID);