From e1fb28faa91da4b50539b3edaf3443b4cb79cc7c Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Tue, 23 May 2017 02:10:26 -0400 Subject: [PATCH] Convert some object ids from strings to integers after 4e1937680 --- chrome/content/zotero/bindings/relatedbox.xml | 2 +- chrome/content/zotero/xpcom/data/item.js | 2 +- chrome/content/zotero/xpcom/zotero.js | 4 ++-- test/tests/itemTest.js | 20 +++++++++++++++++++ 4 files changed, 24 insertions(+), 4 deletions(-) diff --git a/chrome/content/zotero/bindings/relatedbox.xml b/chrome/content/zotero/bindings/relatedbox.xml index b421720719..617e4655a2 100644 --- a/chrome/content/zotero/bindings/relatedbox.xml +++ b/chrome/content/zotero/bindings/relatedbox.xml @@ -193,7 +193,7 @@ var remove = document.createElement("label"); remove.setAttribute('value','-'); remove.setAttribute('onclick', - "document.getBindingParent(this).remove('" + id + "');"); + "document.getBindingParent(this).remove(" + id + ");"); remove.setAttribute('class','zotero-clicky zotero-clicky-minus'); } diff --git a/chrome/content/zotero/xpcom/data/item.js b/chrome/content/zotero/xpcom/data/item.js index 92fbab47fe..82a7a897c3 100644 --- a/chrome/content/zotero/xpcom/data/item.js +++ b/chrome/content/zotero/xpcom/data/item.js @@ -1792,7 +1792,7 @@ Zotero.Item.prototype._saveData = Zotero.Promise.coroutine(function* (env) { if (reloadParentChildItems) { for (let parentItemID in reloadParentChildItems) { // Keep in sync with Zotero.Items.trash() - let parentItem = yield this.ObjectsClass.getAsync(parentItemID); + let parentItem = yield this.ObjectsClass.getAsync(parseInt(parentItemID)); yield parentItem.reload(['primaryData', 'childItems'], true); parentItem.clearBestAttachmentState(); } diff --git a/chrome/content/zotero/xpcom/zotero.js b/chrome/content/zotero/xpcom/zotero.js index daae1cb888..d6647d5621 100644 --- a/chrome/content/zotero/xpcom/zotero.js +++ b/chrome/content/zotero/xpcom/zotero.js @@ -2334,12 +2334,12 @@ Zotero.DragDrop = { if (dt.types.contains('zotero/collection')) { dragData.dataType = 'zotero/collection'; - var ids = dt.getData('zotero/collection').split(","); + let ids = dt.getData('zotero/collection').split(",").map(id => parseInt(id)); dragData.data = ids; } else if (dt.types.contains('zotero/item')) { dragData.dataType = 'zotero/item'; - var ids = dt.getData('zotero/item').split(","); + let ids = dt.getData('zotero/item').split(",").map(id => parseInt(id)); dragData.data = ids; } else { diff --git a/test/tests/itemTest.js b/test/tests/itemTest.js index a90a9ac0b4..9bbb2bf73e 100644 --- a/test/tests/itemTest.js +++ b/test/tests/itemTest.js @@ -1066,6 +1066,26 @@ describe("Zotero.Item", function () { assert.ok(e); assert.equal(e.message, "Item type must be set before saving"); }) + + it("should reload child items for parent items", function* () { + var item = yield createDataObject('item'); + var attachment = yield importFileAttachment('test.png', { parentItemID: item.id }); + var note1 = new Zotero.Item('note'); + note1.parentItemID = item.id; + yield note1.saveTx(); + var note2 = new Zotero.Item('note'); + note2.parentItemID = item.id; + yield note2.saveTx(); + + assert.lengthOf(item.getAttachments(), 1); + assert.lengthOf(item.getNotes(), 2); + + note2.parentItemID = null; + yield note2.saveTx(); + + assert.lengthOf(item.getAttachments(), 1); + assert.lengthOf(item.getNotes(), 1); + }); })