commit 406f50a3fdc305fc759b96c68f8d6a7de46e3fa3
parent d8fed095789226a69ca177963e9568b996ffdb81
Author: Adomas VenĨkauskas <adomas.ven@gmail.com>
Date: Fri, 7 Apr 2017 13:25:09 +0300
Restore progress for attachments indication in connectors
78b1d2e regression
Diffstat:
2 files changed, 21 insertions(+), 13 deletions(-)
diff --git a/chrome/content/zotero/xpcom/server_connector.js b/chrome/content/zotero/xpcom/server_connector.js
@@ -387,21 +387,25 @@ Zotero.Server.Connector.SaveItem.prototype = {
proxy
});
try {
- let items = yield itemSaver.saveItems(
+ var deferred = Zotero.Promise.defer();
+ itemSaver.saveItems(
data.items,
- Zotero.Server.Connector.AttachmentProgressManager.onProgress
- );
- // Remove attachments not being saved from item.attachments
- for(var i=0; i<data.items.length; i++) {
- var item = data.items[i];
- for(var j=0; j<item.attachments.length; j++) {
- if(!Zotero.Server.Connector.AttachmentProgressManager.has(item.attachments[j])) {
- item.attachments.splice(j--, 1);
+ Zotero.Server.Connector.AttachmentProgressManager.onProgress,
+ function() {
+ // Remove attachments not being saved from item.attachments
+ for(var i=0; i<data.items.length; i++) {
+ var item = data.items[i];
+ for(var j=0; j<item.attachments.length; j++) {
+ if(!Zotero.Server.Connector.AttachmentProgressManager.has(item.attachments[j])) {
+ item.attachments.splice(j--, 1);
+ }
+ }
}
+
+ deferred.resolve([201, "application/json", JSON.stringify({items: data.items})]);
}
- }
-
- return [201, "application/json", JSON.stringify({items: data.items})];
+ );
+ return deferred.promise;
}
catch (e) {
Zotero.logError(e);
diff --git a/chrome/content/zotero/xpcom/translation/translate_item.js b/chrome/content/zotero/xpcom/translation/translate_item.js
@@ -81,8 +81,10 @@ Zotero.Translate.ItemSaver.prototype = {
* @param {Function} [attachmentCallback] A callback that receives information about attachment
* save progress. The callback will be called as attachmentCallback(attachment, false, error)
* on failure or attachmentCallback(attachment, progressPercent) periodically during saving.
+ * @param {Function} [itemsDoneCallback] A callback that is called once all top-level items are
+ * done saving with a list of items. Will include saved notes, but exclude attachments.
*/
- saveItems: Zotero.Promise.coroutine(function* (items, attachmentCallback) {
+ saveItems: Zotero.Promise.coroutine(function* (items, attachmentCallback, itemsDoneCallback) {
let newItems = [], standaloneAttachments = [], childAttachments = [];
yield Zotero.DB.executeTransaction(function* () {
for (let iitem=0; iitem<items.length; iitem++) {
@@ -159,6 +161,8 @@ Zotero.Translate.ItemSaver.prototype = {
newItems.push(newItem);
}
}.bind(this));
+
+ itemsDoneCallback(newItems.splice());
// Handle attachments outside of the transaction, because they can involve downloading
for (let item of standaloneAttachments) {