From 9675ac9d0159078425523889f759e006e5773bfc Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Mon, 5 Jun 2006 21:58:01 +0000 Subject: [PATCH] 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 --- .../content/scholar/xpcom/data_access.js | 60 +++++++++++++++++++ 1 file changed, 60 insertions(+) diff --git a/chrome/chromeFiles/content/scholar/xpcom/data_access.js b/chrome/chromeFiles/content/scholar/xpcom/data_access.js index 43f6c2e15e..5dc6db0e6b 100644 --- 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