diff --git a/chrome/content/zotero/xpcom/data/collection.js b/chrome/content/zotero/xpcom/data/collection.js index 54469b11c9..7cf6b7aeed 100644 --- a/chrome/content/zotero/xpcom/data/collection.js +++ b/chrome/content/zotero/xpcom/data/collection.js @@ -676,9 +676,12 @@ Zotero.Collection.prototype.serialize = function(nested) { } -Zotero.Collection.prototype.fromJSON = Zotero.Promise.coroutine(function* (json) { - yield this.loadAllData(); - +/** + * Populate the object's data from an API JSON data object + * + * If this object is identified (has an id or library/key), loadAllData() must have been called. + */ +Zotero.Collection.prototype.fromJSON = function (json) { if (!json.name) { throw new Error("'name' property not provided for collection"); } @@ -687,7 +690,7 @@ Zotero.Collection.prototype.fromJSON = Zotero.Promise.coroutine(function* (json) // TODO //this.setRelations(json.relations); -}); +} Zotero.Collection.prototype.toResponseJSON = Zotero.Promise.coroutine(function* (options = {}) { diff --git a/chrome/content/zotero/xpcom/data/item.js b/chrome/content/zotero/xpcom/data/item.js index 6e78c9209b..1380a3c466 100644 --- a/chrome/content/zotero/xpcom/data/item.js +++ b/chrome/content/zotero/xpcom/data/item.js @@ -3708,11 +3708,12 @@ Zotero.Item.prototype.isCollection = function() { } -Zotero.Item.prototype.fromJSON = Zotero.Promise.coroutine(function* (json) { - if (this._identified) { - yield this.loadAllData(); - } - +/** + * Populate the object's data from an API JSON data object + * + * If this object is identified (has an id or library/key), loadAllData() must have been called. + */ +Zotero.Item.prototype.fromJSON = function (json) { if (!json.itemType && !this._itemTypeID) { throw new Error("itemType property not provided"); } @@ -3843,7 +3844,7 @@ Zotero.Item.prototype.fromJSON = Zotero.Promise.coroutine(function* (json) { let note = json.note; this.setNote(note !== undefined ? note : ""); } -}); +} /** diff --git a/chrome/content/zotero/xpcom/search.js b/chrome/content/zotero/xpcom/search.js index 7b296f80d5..8b593d4c04 100644 --- a/chrome/content/zotero/xpcom/search.js +++ b/chrome/content/zotero/xpcom/search.js @@ -819,9 +819,12 @@ Zotero.Search.prototype.search = Zotero.Promise.coroutine(function* (asTempTable }); -Zotero.Search.prototype.fromJSON = Zotero.Promise.coroutine(function* (json) { - yield this.loadAllData(); - +/** + * Populate the object's data from an API JSON data object + * + * If this object is identified (has an id or library/key), loadAllData() must have been called. + */ +Zotero.Search.prototype.fromJSON = function (json) { if (!json.name) { throw new Error("'name' property not provided for search"); } @@ -835,7 +838,7 @@ Zotero.Search.prototype.fromJSON = Zotero.Promise.coroutine(function* (json) { condition.value ); } -}); +} Zotero.Collection.prototype.toResponseJSON = Zotero.Promise.coroutine(function* (options = {}) { var json = yield this.constructor._super.prototype.toResponseJSON.apply(this, options); diff --git a/test/tests/itemTest.js b/test/tests/itemTest.js index 5960fab115..486677187b 100644 --- a/test/tests/itemTest.js +++ b/test/tests/itemTest.js @@ -954,7 +954,7 @@ describe("Zotero.Item", function () { dateModified: "2015-06-07T20:58:00Z", }; var item = new Zotero.Item; - yield item.fromJSON(json); + item.fromJSON(json); assert.equal(item.getField('accessDate'), '2015-06-07 20:56:00'); assert.equal(item.dateAdded, '2015-06-07 20:57:00'); assert.equal(item.dateModified, '2015-06-07 20:58:00'); @@ -968,7 +968,7 @@ describe("Zotero.Item", function () { dateModified: "2015-06-07 20:58:00", }; var item = new Zotero.Item; - yield item.fromJSON(json); + item.fromJSON(json); assert.strictEqual(item.getField('accessDate'), ''); // DEBUG: Should these be null, or empty string like other fields from getField()? assert.isNull(item.dateAdded); @@ -992,14 +992,14 @@ describe("Zotero.Item", function () { }; var item = new Zotero.Item; - yield item.fromJSON(json); + item.fromJSON(json); var id = yield item.saveTx(); assert.sameDeepMembers(item.getCreatorsJSON(), json.creators); }) it("should map a base field to an item-specific field", function* () { var item = new Zotero.Item("bookSection"); - yield item.fromJSON({ + item.fromJSON({ "itemType":"bookSection", "publicationTitle":"Publication Title" });