commit 7253a2dd8c3e04fbf00e57727b4e06163f80be71
parent 87db29f060eefce0dad6836c9c36193332cb4594
Author: Simon Kornblith <simon@simonster.com>
Date: Wed, 3 Jun 2015 23:42:08 -0400
Map base fields to item-specific fields in Item#fromJSON()
Diffstat:
2 files changed, 16 insertions(+), 2 deletions(-)
diff --git a/chrome/content/zotero/xpcom/data/item.js b/chrome/content/zotero/xpcom/data/item.js
@@ -3816,7 +3816,8 @@ Zotero.Item.prototype.fromJSON = Zotero.Promise.coroutine(function* (json) {
yield this.loadAllData();
}
- this.setType(Zotero.ItemTypes.getID(json.itemType));
+ let itemTypeID = Zotero.ItemTypes.getID(json.itemType);
+ this.setType(itemTypeID);
var isValidForType = {};
var setFields = {};
@@ -3895,8 +3896,10 @@ Zotero.Item.prototype.fromJSON = Zotero.Promise.coroutine(function* (json) {
// Item fields
default:
+ let fieldID = Zotero.ItemFields.getID(field);
isValidForType[field] = Zotero.ItemFields.isValidForType(
- Zotero.ItemFields.getID(field), this.itemTypeID
+ Zotero.ItemFields.getFieldIDFromTypeAndBase(itemTypeID, fieldID) || fieldID,
+ this.itemTypeID
);
if (!isValidForType[field]) {
Zotero.logError("Discarding unknown JSON field " + field);
diff --git a/test/tests/itemTest.js b/test/tests/itemTest.js
@@ -739,4 +739,15 @@ describe("Zotero.Item", function () {
assert.isUndefined(json.numPages);
})
})
+
+ describe("#fromJSON()", function () {
+ it("should map a base field to an item-specific field", function* () {
+ var item = new Zotero.Item("bookSection");
+ yield item.fromJSON({
+ "itemType":"bookSection",
+ "publicationTitle":"Publication Title"
+ });
+ assert.equal(item.getField("bookTitle"), "Publication Title");
+ });
+ });
});