Fix loadAllData() on regular items without notes
Set a flag when setting the item type that instructs loadAllData() whether to attempt to call loadNote()
This commit is contained in:
parent
beb17436f8
commit
01f04802f0
3 changed files with 36 additions and 1 deletions
|
@ -51,6 +51,7 @@ Zotero.DataObject = function () {
|
||||||
this._parentKey = null;
|
this._parentKey = null;
|
||||||
|
|
||||||
this._loaded = {};
|
this._loaded = {};
|
||||||
|
this._skipDataTypeLoad = {};
|
||||||
this._markAllDataTypeLoadStates(false);
|
this._markAllDataTypeLoadStates(false);
|
||||||
|
|
||||||
this._clearChanged();
|
this._clearChanged();
|
||||||
|
@ -471,7 +472,10 @@ Zotero.DataObject.prototype._loadDataType = function (dataType, reload) {
|
||||||
Zotero.DataObject.prototype.loadAllData = function (reload) {
|
Zotero.DataObject.prototype.loadAllData = function (reload) {
|
||||||
let loadPromises = new Array(this._dataTypes.length);
|
let loadPromises = new Array(this._dataTypes.length);
|
||||||
for (let i=0; i<this._dataTypes.length; i++) {
|
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);
|
return Zotero.Promise.all(loadPromises);
|
||||||
|
|
|
@ -463,6 +463,11 @@ Zotero.Item.prototype.setType = function(itemTypeID, loadIn) {
|
||||||
return true;
|
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;
|
var oldItemTypeID = this._itemTypeID;
|
||||||
if (oldItemTypeID) {
|
if (oldItemTypeID) {
|
||||||
if (loadIn) {
|
if (loadIn) {
|
||||||
|
|
|
@ -3,6 +3,32 @@
|
||||||
describe("Zotero.DataObject", function() {
|
describe("Zotero.DataObject", function() {
|
||||||
var types = ['collection', 'item', 'search'];
|
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 () {
|
describe("#save()", function () {
|
||||||
it("should add new identifiers to cache", function* () {
|
it("should add new identifiers to cache", function* () {
|
||||||
// Collection
|
// Collection
|
||||||
|
|
Loading…
Reference in a new issue