diff --git a/chrome/content/zotero/xpcom/collectionTreeView.js b/chrome/content/zotero/xpcom/collectionTreeView.js index 3728369bea..e01de969d0 100644 --- a/chrome/content/zotero/xpcom/collectionTreeView.js +++ b/chrome/content/zotero/xpcom/collectionTreeView.js @@ -2032,10 +2032,7 @@ Zotero.CollectionTreeView.prototype.drop = Zotero.Promise.coroutine(function* (r // Collections if (desc.type == 'collection') { var c = yield Zotero.Collections.getAsync(desc.id); - - var newCollection = new Zotero.Collection; - newCollection.libraryID = targetLibraryID; - c.clone(false, newCollection); + let newCollection = c.clone(targetLibraryID); if (parentID) { newCollection.parentID = parentID; } diff --git a/chrome/content/zotero/xpcom/data/collection.js b/chrome/content/zotero/xpcom/data/collection.js index 6aaaaf827c..c5770a723f 100644 --- a/chrome/content/zotero/xpcom/data/collection.js +++ b/chrome/content/zotero/xpcom/data/collection.js @@ -533,34 +533,31 @@ Zotero.Collection.prototype.diff = function (collection, includeMatches) { /** - * Returns an unsaved copy of the collection + * Returns an unsaved copy of the collection without id and key * - * Does not copy parent collection or child items - * - * @param {Boolean} [includePrimary=false] - * @param {Zotero.Collection} [newCollection=null] + * Doesn't duplicate subcollections or items, because the collection isn't saved */ -Zotero.Collection.prototype.clone = function (includePrimary, newCollection) { +Zotero.Collection.prototype.clone = function (libraryID) { Zotero.debug('Cloning collection ' + this.id); - if (newCollection) { - var sameLibrary = newCollection.libraryID == this.libraryID; - } - else { - var newCollection = new this.constructor; - var sameLibrary = true; - - if (includePrimary) { - newCollection.id = this.id; - newCollection.libraryID = this.libraryID; - newCollection.key = this.key; - - // TODO: This isn't used, but if it were, it should probably include - // parent collection and child items - } + if (libraryID !== undefined && libraryID !== null && typeof libraryID !== 'number') { + throw new Error("libraryID must be null or an integer"); } - newCollection.name = this.name; + if (libraryID === undefined || libraryID === null) { + libraryID = this.libraryID; + } + var sameLibrary = libraryID == this.libraryID; + + var newCollection = new Zotero.Collection; + newCollection.libraryID = libraryID; + + var json = this.toJSON(); + if (!sameLibrary) { + delete json.parentCollection; + delete json.relations; + } + newCollection.fromJSON(json); return newCollection; } diff --git a/chrome/content/zotero/xpcom/data/search.js b/chrome/content/zotero/xpcom/data/search.js index ad00bdd71c..21fbc0d40b 100644 --- a/chrome/content/zotero/xpcom/data/search.js +++ b/chrome/content/zotero/xpcom/data/search.js @@ -254,18 +254,7 @@ Zotero.Search.prototype._finalizeSave = Zotero.Promise.coroutine(function* (env) Zotero.Search.prototype.clone = function (libraryID) { var s = new Zotero.Search(); s.libraryID = libraryID === undefined ? this.libraryID : libraryID; - - var conditions = this.getConditions(); - - for (let condition of Object.values(conditions)) { - var name = condition.mode ? - condition.condition + '/' + condition.mode : - condition.condition - - s.addCondition(name, condition.operator, condition.value, - condition.required); - } - + s.fromJSON(this.toJSON()); return s; };