Fix fromJSON() not importing parentItem for annotations
This commit is contained in:
parent
7ea14aa34e
commit
b2aee30410
2 changed files with 13 additions and 4 deletions
|
@ -4871,12 +4871,14 @@ Zotero.Item.prototype.fromJSON = function (json, options = {}) {
|
|||
}
|
||||
|
||||
// Both notes and attachments might have parents and notes
|
||||
if (this.isNote() || this.isAttachment()) {
|
||||
if (this.isNote() || this.isAttachment() || this.isAnnotation()) {
|
||||
let parentKey = json.parentItem;
|
||||
this.parentKey = parentKey ? parentKey : false;
|
||||
|
||||
let note = json.note;
|
||||
this.setNote(note !== undefined ? note : "", json.noteSchemaVersion);
|
||||
if (!this.isAnnotation()) {
|
||||
let note = json.note;
|
||||
this.setNote(note !== undefined ? note : "", json.noteSchemaVersion);
|
||||
}
|
||||
}
|
||||
|
||||
// Update boolean fields that might not be present in JSON
|
||||
|
|
|
@ -2393,10 +2393,14 @@ describe("Zotero.Item", function () {
|
|||
assert.equal(item.noteSchemaVersion, 3);
|
||||
});
|
||||
|
||||
it("should import annotation fields", function () {
|
||||
it("should import annotation fields", async function () {
|
||||
var attachment = await importPDFAttachment();
|
||||
|
||||
var item = new Zotero.Item();
|
||||
item.libraryID = attachment.libraryID;
|
||||
var json = {
|
||||
itemType: "annotation",
|
||||
parentItem: attachment.key,
|
||||
annotationType: 'highlight',
|
||||
annotationText: "This is highlighted text.",
|
||||
annotationComment: "This is a comment with <i>rich-text</i>\nAnd a new line",
|
||||
|
@ -2418,6 +2422,9 @@ describe("Zotero.Item", function () {
|
|||
if (i == 'tags') {
|
||||
assert.deepEqual(item.getTags(), json[i]);
|
||||
}
|
||||
else if (i == 'parentItem') {
|
||||
assert.equal(item.parentKey, json[i]);
|
||||
}
|
||||
else {
|
||||
assert.equal(item[i], json[i]);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue