www

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

commit 9675ac9d0159078425523889f759e006e5773bfc
parent b31be7af7e5b9ccd35c5ca837a37000b5bbe92e6
Author: Dan Stillman <dstillman@zotero.org>
Date:   Mon,  5 Jun 2006 21:58:01 +0000

New function Scholar.Collection.changeParent([parentCollectionID]) -- move a collection into another collection in the DB

parentCollectionID is optional and defaults to moving item to root

Returns true on success, false on attempt to move collection into its existing parent, itself or a descendent collection; throws exception on invalid parentCollectionID

Sends a columnTree notify() with previous parent ID, id of collection itself, and new parent ID (unless the previous or new are the root, in which case it's omitted) -- that may or may not make sense for the interface code and can be changed if needed


Diffstat:
Mchrome/chromeFiles/content/scholar/xpcom/data_access.js | 60++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 60 insertions(+), 0 deletions(-)

diff --git a/chrome/chromeFiles/content/scholar/xpcom/data_access.js b/chrome/chromeFiles/content/scholar/xpcom/data_access.js @@ -1047,6 +1047,66 @@ Scholar.Collection.prototype.rename = function(name){ return true; } + +/** +* Change the parentCollectionID of a collection +* +* Returns TRUE on success, FALSE on error +**/ +Scholar.Collection.prototype.changeParent = function(parent){ + if (!parent){ + parent = null; + } + + var previousParent = this.getParent(); + + if (parent==previousParent){ + Scholar.debug('Collection ' + this.getID() + ' is already in ' + + (parent ? 'collection ' + parent : 'root collection'), 2); + return false; + } + + if (parent && !Scholar.Collections.get(parent)){ + throw('Invalid parentCollectionID ' + parent + ' in changeParent()'); + } + + if (parent && parent==this.getID()){ + Scholar.debug('Cannot move collection into itself!', 2); + return false; + } + + if (parent){ + var descendents = this._getDescendents(); + for (var i=0, len=descendents.length; i<len; i++){ + if (descendents[i]['isCollection'] && parent==descendents[i]['id']){ + Scholar.debug('Cannot move collection into one of its own ' + + 'descendents!', 2); + return false; + } + } + } + + var parentParam = parent ? {'int':parent} : {'null':true}; + + var sql = "UPDATE collections SET parentCollectionID=? " + + "WHERE collectionID=?"; + + Scholar.DB.query(sql, [parentParam, {'int':this.getID()}]); + this._parent = parent; + + var notifyIDs = [this.getID()]; + if (previousParent){ + notifyIDs.push(previousParent); + } + if (parent){ + notifyIDs.push(parent); + } + + Scholar.Notifier.trigger('modify', 'collection', notifyIDs); + return true; +} + + /** * Add an item to the collection **/