Make libraryID optional for DataObjects, defaulting to user library
This commit is contained in:
parent
30535653a6
commit
a2b572665d
|
@ -561,8 +561,9 @@ Zotero.DataObject.prototype.hasChanged = function() {
|
||||||
}
|
}
|
||||||
|
|
||||||
Zotero.DataObject.prototype._initSave = Zotero.Promise.coroutine(function* (env) {
|
Zotero.DataObject.prototype._initSave = Zotero.Promise.coroutine(function* (env) {
|
||||||
if (!this.libraryID) {
|
// Default to user library if not specified
|
||||||
throw new Error("libraryID must be set before saving " + this._objectType);
|
if (this.libraryID === null) {
|
||||||
|
this.libraryID = Zotero.Libraries.userLibraryID;
|
||||||
}
|
}
|
||||||
|
|
||||||
env.isNew = !this.id;
|
env.isNew = !this.id;
|
||||||
|
|
|
@ -2,20 +2,17 @@ describe("Zotero.Item", function() {
|
||||||
describe("#getField()", function () {
|
describe("#getField()", function () {
|
||||||
it("should return false for valid unset fields on unsaved items", function* () {
|
it("should return false for valid unset fields on unsaved items", function* () {
|
||||||
var item = new Zotero.Item('book');
|
var item = new Zotero.Item('book');
|
||||||
item.libraryID = Zotero.Libraries.userLibraryID;
|
|
||||||
assert.equal(item.getField('rights'), false);
|
assert.equal(item.getField('rights'), false);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should return false for valid unset fields on unsaved items after setting on another field", function* () {
|
it("should return false for valid unset fields on unsaved items after setting on another field", function* () {
|
||||||
var item = new Zotero.Item('book');
|
var item = new Zotero.Item('book');
|
||||||
item.libraryID = Zotero.Libraries.userLibraryID;
|
|
||||||
item.setField('title', 'foo');
|
item.setField('title', 'foo');
|
||||||
assert.equal(item.getField('rights'), false);
|
assert.equal(item.getField('rights'), false);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should return false for invalid unset fields on unsaved items after setting on another field", function* () {
|
it("should return false for invalid unset fields on unsaved items after setting on another field", function* () {
|
||||||
var item = new Zotero.Item('book');
|
var item = new Zotero.Item('book');
|
||||||
item.libraryID = Zotero.Libraries.userLibraryID;
|
|
||||||
item.setField('title', 'foo');
|
item.setField('title', 'foo');
|
||||||
assert.equal(item.getField('invalid'), false);
|
assert.equal(item.getField('invalid'), false);
|
||||||
});
|
});
|
||||||
|
@ -25,11 +22,9 @@ describe("Zotero.Item", function() {
|
||||||
it("should create a child note", function () {
|
it("should create a child note", function () {
|
||||||
return Zotero.DB.executeTransaction(function* () {
|
return Zotero.DB.executeTransaction(function* () {
|
||||||
var item = new Zotero.Item('book');
|
var item = new Zotero.Item('book');
|
||||||
item.libraryID = Zotero.Libraries.userLibraryID;
|
|
||||||
var parentItemID = yield item.save();
|
var parentItemID = yield item.save();
|
||||||
|
|
||||||
item = new Zotero.Item('note');
|
item = new Zotero.Item('note');
|
||||||
item.libraryID = Zotero.Libraries.userLibraryID;
|
|
||||||
item.parentID = parentItemID;
|
item.parentID = parentItemID;
|
||||||
var childItemID = yield item.save();
|
var childItemID = yield item.save();
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,6 @@ describe("Zotero.Items", function() {
|
||||||
it("should return a libraryID and key within a transaction", function* () {
|
it("should return a libraryID and key within a transaction", function* () {
|
||||||
return Zotero.DB.executeTransaction(function* () {
|
return Zotero.DB.executeTransaction(function* () {
|
||||||
var item = new Zotero.Item('book');
|
var item = new Zotero.Item('book');
|
||||||
item.libraryID = Zotero.Libraries.userLibraryID;
|
|
||||||
var itemID = yield item.save();
|
var itemID = yield item.save();
|
||||||
|
|
||||||
var {libraryID, key} = Zotero.Items.getLibraryAndKeyFromID(itemID);
|
var {libraryID, key} = Zotero.Items.getLibraryAndKeyFromID(itemID);
|
||||||
|
@ -19,7 +18,6 @@ describe("Zotero.Items", function() {
|
||||||
try {
|
try {
|
||||||
yield Zotero.DB.executeTransaction(function* () {
|
yield Zotero.DB.executeTransaction(function* () {
|
||||||
var item = new Zotero.Item('book');
|
var item = new Zotero.Item('book');
|
||||||
item.libraryID = Zotero.Libraries.userLibraryID;
|
|
||||||
itemID = yield item.save();
|
itemID = yield item.save();
|
||||||
throw 'Aborting transaction -- ignore';
|
throw 'Aborting transaction -- ignore';
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue
Block a user