www

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | Submodules | README | LICENSE

commit 70630a2e702ded4f6dbee0de3420d530eaaee488
parent 4e0dbb3885aa4d11cdb09df25daf8f063300e171
Author: Dan Stillman <dstillman@zotero.org>
Date:   Thu,  1 Jun 2006 22:19:21 +0000

- Change: Scholar.Notifier.trigger() can be passed an array of ids in some cases rather than a single id -- trees that implement notify() should use Scholar.flattenArguments(ids) to get an array either way

- Added Notifier triggers to Item.erase() (which only runs if not in a nested transaction) and Collections.erase()

- notify() in ItemTreeView updated with example of taking multiple ids, though it doesn't actually work (and notify() implementations may decide just to refresh the whole tree when ids.length>1 rather than dealing with changes individually)

- When deleting collections, use DB tables that actually exist



Diffstat:
Mchrome/chromeFiles/content/scholar/itemTreeView.js | 52+++++++++++++++++++++++++++++-----------------------
Mchrome/chromeFiles/content/scholar/xpcom/data_access.js | 21+++++++++++++++------
Mchrome/chromeFiles/content/scholar/xpcom/notifier.js | 11++++++-----
3 files changed, 50 insertions(+), 34 deletions(-)

diff --git a/chrome/chromeFiles/content/scholar/itemTreeView.js b/chrome/chromeFiles/content/scholar/itemTreeView.js @@ -156,32 +156,38 @@ Scholar.ItemTreeView.prototype.getCollectionID = function() } //CALLED BY DATA LAYER ON CHANGE: -Scholar.ItemTreeView.prototype.notify = function(action, type, id) +Scholar.ItemTreeView.prototype.notify = function(action, type, ids) { - var row = this._itemRowMap[id]; - if(action == 'remove' && row) - { - this._hideItem(row); - this._treebox.rowCountChanged(row,-1); - } - else if(action == 'modify' && row) - { - this._treebox.invalidateRow(row) - } - else if(action == 'add' && !row) - { - var item = Scholar.Items.get(id); - - if(this._itemGroup.isLibrary() || item.inCollection(this.getCollectionID())) + ids = Scholar.flattenArguments(ids); + + for (var i=0, len=ids.length; i<len; i++){ + + var row = this._itemRowMap[ids[i]]; + if(action == 'remove' && row) { - this._showItem(item,this.rowCount); - this._treebox.rowCountChanged(this.rowCount,1); + this._hideItem(row); + this._treebox.rowCountChanged(row,-1); } - //TODO: sorted? figure it out later - } - else - { - return; + else if(action == 'modify' && row) + { + this._treebox.invalidateRow(row) + } + else if(action == 'add' && !row) + { + var item = Scholar.Items.get(ids[i]); + + if(this._itemGroup.isLibrary() || item.inCollection(this.getCollectionID())) + { + this._showItem(item,this.rowCount); + this._treebox.rowCountChanged(this.rowCount,1); + } + //TODO: sorted? figure it out later + } + else + { + return; + } + } this._refreshHashMap(); diff --git a/chrome/chromeFiles/content/scholar/xpcom/data_access.js b/chrome/chromeFiles/content/scholar/xpcom/data_access.js @@ -324,6 +324,7 @@ Scholar.Item.prototype.setField = function(field, value, loadIn){ } } + /* * Save changes back to database */ @@ -634,9 +635,12 @@ Scholar.Item.prototype.erase = function(){ throw (e); } - Scholar.Items.unload(this.getID()); + // If we're not in the middle of a larger commit, trigger the notifier now + if (!Scholar.DB.transactionInProgress()){ + Scholar.Notifier.trigger('remove', 'item', this.getID()); + } - // TODO: trigger reloading of treeview + Scholar.Items.unload(this.getID()); } @@ -1043,6 +1047,7 @@ Scholar.Collection.prototype.erase = function(deleteItems){ var descendents = this._getDescendents(); var collections = new Array(this._id); + var items = new Array(); for(var i=0, len=descendents.length; i<len; i++){ // Descendent collections @@ -1055,21 +1060,25 @@ Scholar.Collection.prototype.erase = function(deleteItems){ // Delete items from DB Scholar.Items.get(descendents[i]['id']).erase(); } + items.push(descendents[i]['id']); } } // Remove item associations for all descendent collections - Scholar.DB.query('DELETE FROM itemCollections WHERE collectionID IN (' + Scholar.DB.query('DELETE FROM collectionItems WHERE collectionID IN (' + collections.join() + ')'); // And delete all descendent collections - Scholar.DB.query('DELETE FROM collection WHERE collectionID IN (' + Scholar.DB.query('DELETE FROM collections WHERE collectionID IN (' + collections.join() + ')'); + Scholar.DB.commitTransaction(); + + Scholar.Notifier.trigger('remove', 'collection', collections); + Scholar.Notifier.trigger('remove', 'item', items); + // Clear deleted collection from internal memory Scholar.Collections.unload(collections); - - Scholar.DB.commitTransaction(); } diff --git a/chrome/chromeFiles/content/scholar/xpcom/notifier.js b/chrome/chromeFiles/content/scholar/xpcom/notifier.js @@ -26,10 +26,11 @@ Scholar.Notifier = new function(){ } /** - * event is one of 'add', 'remove', 'modify' - * type is one of 'collection', 'smartcollection', 'item' + * event - 'add', 'remove', 'modify' + * type - 'collection', 'smartcollection', 'item' + * ids - single id or array of ids **/ - function trigger(event, type, id){ + function trigger(event, type, ids){ switch (type){ case 'item': var treeType = 'itemTree'; @@ -44,8 +45,8 @@ Scholar.Notifier = new function(){ for (i in _observers[treeType]){ Scholar.debug("Calling _observers['" + treeType + "']['" + i + "'].notify('" + event - + "', " + type + "', " + id + ")", 4); - _observers[treeType][i].notify(event, type, id); + + "', " + type + "', " + ids.join() + ")", 4); + _observers[treeType][i].notify(event, type, ids); } }