diff --git a/chrome/content/zotero/xpcom/data/item.js b/chrome/content/zotero/xpcom/data/item.js
index 16fd6e583a..1532f7a7ed 100644
--- a/chrome/content/zotero/xpcom/data/item.js
+++ b/chrome/content/zotero/xpcom/data/item.js
@@ -2222,7 +2222,6 @@ Zotero.Item.prototype.isAttachment = function() {
return Zotero.ItemTypes.getName(this.itemTypeID) == 'attachment';
}
-
/**
* @return {Promise}
*/
@@ -2240,7 +2239,6 @@ Zotero.Item.prototype.isImportedAttachment = function() {
return false;
}
-
/**
* @return {Promise}
*/
@@ -2255,7 +2253,6 @@ Zotero.Item.prototype.isWebAttachment = function() {
return true;
}
-
/**
* @return {Boolean}
*/
@@ -2266,7 +2263,6 @@ Zotero.Item.prototype.isFileAttachment = function() {
return this.attachmentLinkMode != Zotero.Attachments.LINK_MODE_LINKED_URL;
}
-
/**
* @return {Boolean}
*/
@@ -2274,6 +2270,13 @@ Zotero.Item.prototype.isLinkedFileAttachment = function() {
return this.isAttachment() && this.attachmentLinkMode == Zotero.Attachments.LINK_MODE_LINKED_FILE;
}
+/**
+ * @return {Boolean}
+ */
+Zotero.Item.prototype.isEmbeddedImageAttachment = function() {
+ return this.isAttachment() && this.attachmentLinkMode == Zotero.Attachments.LINK_MODE_EMBEDDED_IMAGE;
+}
+
/**
* Returns number of child attachments of item
@@ -3513,6 +3516,10 @@ for (let name of ['type', 'text', 'comment', 'color', 'pageLabel', 'sortIndex'])
return;
}
+ if (name != 'type' && !this._getLatestField('annotationType')) {
+ throw new Error("annotationType must be set before other annotation properties");
+ }
+
switch (name) {
case 'type': {
let currentType = this._getLatestField('annotationType');
@@ -4592,12 +4599,15 @@ Zotero.Item.prototype.fromJSON = function (json, options = {}) {
case 'key':
case 'version':
case 'itemType':
- case 'note':
- case 'noteSchemaVersion':
// Use?
case 'md5':
case 'mtime':
+
+ //
// Handled below
+ //
+ case 'note':
+ case 'noteSchemaVersion':
case 'collections':
case 'parentItem':
case 'deleted':
@@ -4678,6 +4688,20 @@ Zotero.Item.prototype.fromJSON = function (json, options = {}) {
this.attachmentPath = val;
break;
+ //
+ // Annotation fields
+ //
+ case 'annotationType':
+ case 'annotationType':
+ case 'annotationText':
+ case 'annotationComment':
+ case 'annotationColor':
+ case 'annotationPageLabel':
+ case 'annotationSortIndex':
+ case 'annotationPosition':
+ this[field] = val;
+ break;
+
// Item fields
default:
let fieldID = Zotero.ItemFields.getID(field);
@@ -4872,6 +4896,8 @@ Zotero.Item.prototype.toJSON = function (options = {}) {
obj.version = this.version;
obj.itemType = Zotero.ItemTypes.getName(this.itemTypeID);
+ var embeddedImage = this.isEmbeddedImageAttachment();
+
// Fields
for (let i in this._itemData) {
let val = this.getField(i) + '';
@@ -4896,7 +4922,9 @@ Zotero.Item.prototype.toJSON = function (options = {}) {
obj.linkMode = Zotero.Attachments.linkModeToName(linkMode);
obj.contentType = this.attachmentContentType;
- obj.charset = this.attachmentCharset;
+ if (!embeddedImage) {
+ obj.charset = this.attachmentCharset;
+ }
if (linkMode == Zotero.Attachments.LINK_MODE_LINKED_FILE) {
obj.path = this.attachmentPath;
@@ -4929,29 +4957,49 @@ Zotero.Item.prototype.toJSON = function (options = {}) {
}
// Notes and embedded attachment notes
- let note = this.note;
- if (note !== "" || mode == 'full' || (mode == 'new' && this.isNote())) {
- obj.note = note;
- obj.noteSchemaVersion = this.noteSchemaVersion || 0;
+ if (this.isAttachment() || this.isNote()) {
+ let note = this.note;
+ if (note !== "" || mode == 'full' || (mode == 'new' && this.isNote())) {
+ obj.note = note;
+ obj.noteSchemaVersion = this.noteSchemaVersion || 0;
+ }
+ }
+
+ if (this.isAnnotation()) {
+ let type = this.annotationType;
+ obj.annotationType = type;
+ if (type == 'highlight') {
+ obj.annotationText = this.annotationText || '';
+ }
+ obj.annotationComment = this.annotationComment || '';
+ obj.annotationColor = this.annotationColor || '';
+ obj.annotationPageLabel = this.annotationPageLabel || '';
+ obj.annotationSortIndex = this.annotationSortIndex || '';
+ obj.annotationPosition = JSON.stringify(this.annotationPosition) || '';
}
}
- // Tags
- obj.tags = [];
- var tags = this.getTags();
- for (let i=0; iFoo
",
noteSchemaVersion: 3
});
+ assert.equal(item.note, "Foo
");
assert.equal(item.noteSchemaVersion, 3);
});
+
+ it("should import annotation fields", function () {
+ var item = new Zotero.Item();
+ var json = {
+ itemType: "annotation",
+ annotationType: 'highlight',
+ annotationText: "This is highlighted text.",
+ annotationComment: "This is a comment with rich-text\nAnd a new line",
+ annotationSortIndex: '00015|002431|00000.000',
+ annotationPosition: JSON.stringify({
+ pageIndex: 123,
+ rects: [
+ [314.4, 412.8, 556.2, 609.6]
+ ]
+ }),
+ tags: [
+ {
+ tag: "tagA"
+ }
+ ]
+ };
+ item.fromJSON(json, { strict: true });
+ for (let i in json) {
+ if (i == 'tags') {
+ assert.deepEqual(item.getTags(), json[i]);
+ }
+ else {
+ assert.equal(item[i], json[i]);
+ }
+ }
+ });
});
});