Map base fields to item-specific fields in Item#fromJSON()
This commit is contained in:
parent
87db29f060
commit
7253a2dd8c
2 changed files with 16 additions and 2 deletions
|
@ -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);
|
||||
|
|
|
@ -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");
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue