diff --git a/chrome/content/zotero/xpcom/collectionTreeView.js b/chrome/content/zotero/xpcom/collectionTreeView.js index be4863528..413bf95f5 100644 --- a/chrome/content/zotero/xpcom/collectionTreeView.js +++ b/chrome/content/zotero/xpcom/collectionTreeView.js @@ -269,15 +269,16 @@ Zotero.CollectionTreeView.prototype.isContainerOpen = function(row) return this._dataItems[row][1]; } +/* + * Returns true if the collection has no child collections + */ Zotero.CollectionTreeView.prototype.isContainerEmpty = function(row) { - //NOTE: this returns true if the collection has no child collections - var itemGroup = this._getItemAtRow(row); - if(itemGroup.isCollection()) + if (itemGroup.isCollection()) { return !itemGroup.ref.hasChildCollections(); - else - return true; + } + return true; } Zotero.CollectionTreeView.prototype.getLevel = function(row) diff --git a/chrome/content/zotero/xpcom/data_access.js b/chrome/content/zotero/xpcom/data_access.js index 603a926df..49b183eba 100644 --- a/chrome/content/zotero/xpcom/data_access.js +++ b/chrome/content/zotero/xpcom/data_access.js @@ -2714,8 +2714,8 @@ Zotero.Collection.prototype.changeParent = function(parent){ (parent ? parent : null) ]; - // TODO: only reload the necessary ones Zotero.Collections.reloadAll(); + Zotero.Notifier.trigger('move', 'collection', notifyIDs, notifierData); return true; } @@ -2852,6 +2852,8 @@ Zotero.Collection.prototype.erase = function(deleteItems){ // Clear deleted collection from internal memory Zotero.Collections.unload(collections); + Zotero.Collections.reloadAll(); + Zotero.Notifier.trigger('delete', 'collection', collections, notifierData); } @@ -2979,7 +2981,7 @@ Zotero.Collections = new function(){ */ function get(id){ if (!_collectionsLoaded){ - _load(); + this.reloadAll(); } return (typeof _collections[id]!='undefined') ? _collections[id] : false; } @@ -3015,22 +3017,14 @@ Zotero.Collections = new function(){ Zotero.DB.commitTransaction(); - _load(rnd); + this.reloadAll(); + Zotero.Notifier.trigger('add', 'collection', rnd); return this.get(rnd); } - /** - * Clears internal cache and reloads collection data from DB - **/ - function reloadAll(){ - _collections = new Array(); - _load(); - } - - /** * Clear collection from internal cache (used by Zotero.Collection.erase()) * @@ -3048,7 +3042,7 @@ Zotero.Collections = new function(){ /** * Loads collection data from DB and adds to internal cache **/ - function _load(){ + function reloadAll() { // This should be the same as the query in Zotero.Collection.loadFromID, // just without a specific collectionID var sql = "SELECT collectionID, collectionName, parentCollectionID, " @@ -3065,9 +3059,12 @@ Zotero.Collections = new function(){ var result = Zotero.DB.query(sql); + var collectionIDs = []; + if (result){ for (var i=0; i