commit 01f04802f05da3c69d557d542f30bd9af286708d
parent beb17436f8b301c5f599c0ee432c188c460a8430
Author: Dan Stillman <dstillman@zotero.org>
Date: Tue, 5 May 2015 14:39:24 -0400
Fix loadAllData() on regular items without notes
Set a flag when setting the item type that instructs loadAllData()
whether to attempt to call loadNote()
Diffstat:
3 files changed, 36 insertions(+), 1 deletion(-)
diff --git a/chrome/content/zotero/xpcom/data/dataObject.js b/chrome/content/zotero/xpcom/data/dataObject.js
@@ -51,6 +51,7 @@ Zotero.DataObject = function () {
this._parentKey = null;
this._loaded = {};
+ this._skipDataTypeLoad = {};
this._markAllDataTypeLoadStates(false);
this._clearChanged();
@@ -471,7 +472,10 @@ Zotero.DataObject.prototype._loadDataType = function (dataType, reload) {
Zotero.DataObject.prototype.loadAllData = function (reload) {
let loadPromises = new Array(this._dataTypes.length);
for (let i=0; i<this._dataTypes.length; i++) {
- loadPromises[i] = this._loadDataType(this._dataTypes[i], reload);
+ let type = this._dataTypes[i];
+ if (!this._skipDataTypeLoad[type]) {
+ loadPromises[i] = this._loadDataType(type, reload);
+ }
}
return Zotero.Promise.all(loadPromises);
diff --git a/chrome/content/zotero/xpcom/data/item.js b/chrome/content/zotero/xpcom/data/item.js
@@ -463,6 +463,11 @@ Zotero.Item.prototype.setType = function(itemTypeID, loadIn) {
return true;
}
+ // Adjust 'note' data type based on whether the item is an attachment or note
+ var isAttachment = Zotero.ItemTypes.getID('attachment') == itemTypeID;
+ var isNote = Zotero.ItemTypes.getID('note') == itemTypeID;
+ this._skipDataTypeLoad.note = !(isAttachment || isNote);
+
var oldItemTypeID = this._itemTypeID;
if (oldItemTypeID) {
if (loadIn) {
diff --git a/test/tests/dataObjectTest.js b/test/tests/dataObjectTest.js
@@ -3,6 +3,32 @@
describe("Zotero.DataObject", function() {
var types = ['collection', 'item', 'search'];
+ describe("#loadAllData()", function () {
+ it("should load data on a regular item", function* () {
+ var item = new Zotero.Item('book');
+ var id = yield item.save();
+ item = yield Zotero.Items.getAsync(id);
+ yield item.loadAllData();
+ assert.throws(item.getNote.bind(item), 'getNote() can only be called on notes and attachments');
+ })
+
+ it("should load data on an attachment item", function* () {
+ var item = new Zotero.Item('attachment');
+ var id = yield item.save();
+ item = yield Zotero.Items.getAsync(id);
+ yield item.loadAllData();
+ assert.equal(item.getNote(), '');
+ })
+
+ it("should load data on a note item", function* () {
+ var item = new Zotero.Item('note');
+ var id = yield item.save();
+ item = yield Zotero.Items.getAsync(id);
+ yield item.loadAllData();
+ assert.equal(item.getNote(), '');
+ })
+ })
+
describe("#save()", function () {
it("should add new identifiers to cache", function* () {
// Collection