From deb85038634ac6f99bc7811164c8b090880e71a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adomas=20Ven=C4=8Dkauskas?= Date: Wed, 14 Dec 2016 15:28:06 +0200 Subject: [PATCH] Remove coroutine from translate.js not supported in connector From 7fc352b9 --- .../zotero/xpcom/translation/translate.js | 111 +++++++++--------- 1 file changed, 53 insertions(+), 58 deletions(-) diff --git a/chrome/content/zotero/xpcom/translation/translate.js b/chrome/content/zotero/xpcom/translation/translate.js index 29b52f6eb8d..6a866bcbb66 100644 --- a/chrome/content/zotero/xpcom/translation/translate.js +++ b/chrome/content/zotero/xpcom/translation/translate.js @@ -1540,73 +1540,68 @@ Zotero.Translate.Base.prototype = { * Saves items to the database, taking care to defer attachmentProgress notifications * until after save */ - _saveItems: Zotero.Promise.coroutine(function* (items) { + _saveItems: Zotero.Promise.method(function (items) { var itemDoneEventsDispatched = false; var deferredProgress = []; var attachmentsWithProgress = []; - 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); - } - - 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); + function attachmentCallback(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); + } + + 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); + } + } + + return this._itemSaver.saveItems(items.slice(), attachmentCallback.bind(this)).then(function(newItems) { + // Remove attachments not being saved from item.attachments + for(var i=0; i