Fixes #507, Twisty on collection is not removed after deleting last subcollection

Same thing happened on New Subcollection -- data layer wasn't updating hasChildCollections
This commit is contained in:
Dan Stillman 2007-01-30 23:37:49 +00:00
parent 97de1a41e2
commit 2b1fbf5e9a
2 changed files with 24 additions and 18 deletions

View File

@ -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)

View File

@ -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<result.length; i++){
var collectionID = result[i]['collectionID'];
collectionIDs.push(collectionID);
// If collection doesn't exist, create new object and stuff in array
if (!_collections[collectionID]){
@ -3081,6 +3078,14 @@ Zotero.Collections = new function(){
}
}
}
// Remove old collections that no longer exist
for each(var c in _collections) {
if (collectionIDs.indexOf(c.getID()) == -1) {
this.unload(c.getID());
}
}
_collectionsLoaded = true;
}
}