diff --git a/chrome/content/zotero/browser.js b/chrome/content/zotero/browser.js index e02fcfe1a..c6673064d 100644 --- a/chrome/content/zotero/browser.js +++ b/chrome/content/zotero/browser.js @@ -551,9 +551,9 @@ var Zotero_Browser = new function() { function _constructLookupFunction(tab, success) { return function(e) { tab.page.translate.setTranslator(tab.page.translators[0]); - tab.page.translate.clearHandlers("done"); + tab.page.translate.clearHandlers("itemsDone"); tab.page.translate.clearHandlers("itemDone"); - tab.page.translate.setHandler("done", function(obj, status) { + tab.page.translate.setHandler("itemsDone", function(obj, status) { if(status) { success(e, obj); Zotero_Browser.progress.close(); @@ -730,10 +730,10 @@ Zotero_Browser.Tab.prototype.translate = function(libraryID, collectionID, trans // use first translator available this.page.translate.setTranslator(translator ? translator : this.page.translators[0]); - this.page.translate.clearHandlers("done"); + this.page.translate.clearHandlers("itemsDone"); this.page.translate.clearHandlers("itemDone"); - this.page.translate.setHandler("done", function(obj, item) { Zotero_Browser.finishScraping(obj, item) }); + this.page.translate.setHandler("itemsDone", function(obj, item) { Zotero_Browser.finishScraping(obj, item) }); this.page.translate.setHandler("itemDone", function(obj, dbItem, item) { Zotero_Browser.itemDone(obj, dbItem, item, collection) }); this.page.translate.translate(libraryID); diff --git a/chrome/content/zotero/xpcom/attachments.js b/chrome/content/zotero/xpcom/attachments.js index 7722b889b..17ce185f8 100644 --- a/chrome/content/zotero/xpcom/attachments.js +++ b/chrome/content/zotero/xpcom/attachments.js @@ -220,6 +220,7 @@ Zotero.Attachments = new function(){ var urlRe = /^https?:\/\/[^\s]*$/; var matches = urlRe.exec(url); if (!matches) { + callback(false); throw ("Invalid URL '" + url + "' in Zotero.Attachments.importFromURL()"); } @@ -297,9 +298,11 @@ Zotero.Attachments = new function(){ if (mimeType == 'application/pdf' && Zotero.MIME.sniffForMIMEType(str) != 'application/pdf') { - Zotero.debug("Downloaded PDF did not have MIME type " - + "'application/pdf' in Attachments.importFromURL()", 2); + var errString = "Downloaded PDF did not have MIME type " + + "'application/pdf' in Attachments.importFromURL()"; + Zotero.debug(errString, 2); attachmentItem.erase(); + callback(false, new Error(errString)); return; } @@ -311,6 +314,8 @@ Zotero.Attachments = new function(){ Zotero.Notifier.trigger('add', 'item', itemID); Zotero.Notifier.trigger('modify', 'item', sourceItemID); + + if(callback) callback(attachmentItem); // We don't have any way of knowing that the file // is flushed to disk, so we just wait a second @@ -325,6 +330,7 @@ Zotero.Attachments = new function(){ catch (e) { // Clean up attachmentItem.erase(); + callback(false, e); throw (e); } @@ -346,8 +352,6 @@ Zotero.Attachments = new function(){ nsIURL.spec = url; wbp.saveURI(nsIURL, null, null, null, null, file); - if(callback) callback(attachmentItem); - return attachmentItem; } catch (e){ @@ -553,7 +557,7 @@ Zotero.Attachments = new function(){ Zotero.Fulltext.indexDocument(document, itemID); Zotero.Notifier.trigger('refresh', 'item', itemID); if (callback) { - callback(); + callback(attachmentItem); } }; } @@ -612,6 +616,7 @@ Zotero.Attachments = new function(){ // Clean up var item = Zotero.Items.get(itemID); item.erase(); + callback(false, e); throw (e); } diff --git a/chrome/content/zotero/xpcom/connector/translate_item.js b/chrome/content/zotero/xpcom/connector/translate_item.js index e0dbcd74a..6b86351c2 100644 --- a/chrome/content/zotero/xpcom/connector/translate_item.js +++ b/chrome/content/zotero/xpcom/connector/translate_item.js @@ -79,10 +79,23 @@ Zotero.Translate.ItemSaver.prototype = { payload.cookie = this._cookie; } - Zotero.Connector.callMethod("saveItems", payload, function(success, status) { - if(success !== false) { + Zotero.Connector.callMethod("saveItems", payload, function(data, status) { + if(data !== false) { Zotero.debug("Translate: Save via Standalone succeeded"); + var haveAttachments = false; + if(data.items) { + for(var i=0; i