From 7fc352b9b73a3e7acecb0d98424d9d9ef0112a78 Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Tue, 13 Dec 2016 05:23:21 -0500 Subject: [PATCH] Fix "Add Item by Identifier" (broken by 78b1d2ee3) And make lookup tests run when not on Travis, though we should still mock the HTTP requests. --- .../zotero/xpcom/translation/translate.js | 118 +++++++++--------- test/tests/lookupTest.js | 19 ++- 2 files changed, 74 insertions(+), 63 deletions(-) diff --git a/chrome/content/zotero/xpcom/translation/translate.js b/chrome/content/zotero/xpcom/translation/translate.js index 7e01065501..29b52f6eb8 100644 --- a/chrome/content/zotero/xpcom/translation/translate.js +++ b/chrome/content/zotero/xpcom/translation/translate.js @@ -202,6 +202,7 @@ Zotero.Translate.Sandbox = { // TODO: This used to only be used for some modes. Since it's now used for everything with // async saving, there's probably a bunch of code for the non-queued mode that can be removed. translate.saveQueue.push(item); + translate._savingItems++; }, /** @@ -1539,71 +1540,74 @@ Zotero.Translate.Base.prototype = { * Saves items to the database, taking care to defer attachmentProgress notifications * until after save */ - _saveItems: function (items) { + _saveItems: Zotero.Promise.coroutine(function* (items) { var itemDoneEventsDispatched = false; var deferredProgress = []; var attachmentsWithProgress = []; - this._savingItems++; - return this._itemSaver.saveItems( - items.slice(), - function (attachment, progress, error) { - var attachmentIndex = this._savingAttachments.indexOf(attachment); - if(progress === false || progress === 100) { - if(attachmentIndex !== -1) { - this._savingAttachments.splice(attachmentIndex, 1); + try { + var newItems = yield this._itemSaver.saveItems( + items.slice(), + function (attachment, progress, error) { + var attachmentIndex = this._savingAttachments.indexOf(attachment); + if(progress === false || progress === 100) { + if(attachmentIndex !== -1) { + this._savingAttachments.splice(attachmentIndex, 1); + } + } else if(attachmentIndex === -1) { + this._savingAttachments.push(attachment); } - } else if(attachmentIndex === -1) { - this._savingAttachments.push(attachment); - } - - if(itemDoneEventsDispatched) { - // itemDone event has already fired, so we can fire attachmentProgress - // notifications - this._runHandler("attachmentProgress", attachment, progress, error); - this._checkIfDone(); - } else { - // Defer until after we fire the itemDone event - deferredProgress.push([attachment, progress, error]); - attachmentsWithProgress.push(attachment); - } - }.bind(this) - ) - .then(function (newItems) { - // Remove attachments not being saved from item.attachments - for(var i=0; i