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