commit a6caa14412b0e9cbf1beb5308e0729a415cb2cd0
parent 741ca99c10e6ac0637178f601e0c9f8816f3850b
Author: Dan Stillman <dstillman@zotero.org>
Date: Tue, 2 Feb 2016 05:25:06 -0500
Fix Add Item by Identifier (and search translation in general)
Diffstat:
3 files changed, 13 insertions(+), 9 deletions(-)
diff --git a/chrome/content/zotero/lookup.js b/chrome/content/zotero/lookup.js
@@ -141,7 +141,7 @@ var Zotero_Lookup = new function () {
if(collection) collection.addItem(item.id);
});
- translate.translate(libraryID);
+ translate.translate({ libraryID });
});
})(item);
}
diff --git a/chrome/content/zotero/xpcom/translation/translate.js b/chrome/content/zotero/xpcom/translation/translate.js
@@ -1196,6 +1196,9 @@ Zotero.Translate.Base.prototype = {
};
}
+ var me = this;
+ var deferred = Zotero.Promise.defer()
+
if(!this.translator || !this.translator.length) {
Zotero.debug("Translate: translate called without specifying a translator. Running detection first.");
this.setHandler('translators', function(me, translators) {
@@ -1203,11 +1206,11 @@ Zotero.Translate.Base.prototype = {
me.complete(false, "Could not find an appropriate translator");
} else {
me.setTranslator(translators);
- Zotero.Translate.Base.prototype.translate.call(me, options);
+ deferred.resolve(Zotero.Translate.Base.prototype.translate.call(me, options));
}
});
this.getTranslators();
- return;
+ return deferred.promise;
}
this._currentState = "translate";
@@ -1220,8 +1223,7 @@ Zotero.Translate.Base.prototype = {
this._waitingForSave = false;
// Attach handlers for promise
- var me = this,
- deferred = Zotero.Promise.defer();
+ var me = this;
var doneHandler = function (obj, returnValue) {
if (returnValue) deferred.resolve(me.newItems);
me.removeHandler("done", doneHandler);
@@ -1235,7 +1237,6 @@ Zotero.Translate.Base.prototype = {
this.setHandler("done", doneHandler);
this.setHandler("error", errorHandler);
- var me = this;
if(typeof this.translator[0] === "object") {
// already have a translator object, so use it
this._loadTranslator(this.translator[0]).then(function() { me._translateTranslatorLoaded() });
@@ -2428,8 +2429,11 @@ Zotero.Translate.Search.prototype.setTranslator = function(translator) {
* translation fails
*/
Zotero.Translate.Search.prototype.complete = function(returnValue, error) {
- if(this._currentState == "translate" && (!this.newItems || !this.newItems.length)
- && this.translator.length) { //length is 0 only when translate was called without translators
+ if(this._currentState == "translate"
+ && (!this.newItems || !this.newItems.length)
+ && !this._savingItems
+ //length is 0 only when translate was called without translators
+ && this.translator.length) {
Zotero.debug("Translate: Could not find a result using "+this.translator[0].label, 3);
if(error) Zotero.debug(this._generateErrorString(error), 3);
if(this.translator.length > 1) {
diff --git a/chrome/content/zotero/xpcom/translation/translate_firefox.js b/chrome/content/zotero/xpcom/translation/translate_firefox.js
@@ -405,7 +405,7 @@ Zotero.Translate.SandboxManager = function(sandboxLocation) {
var wrappedObj = obj.wrappedJSObject || obj;
wrappedObj.__exposedProps__ = {"parseFromString":"r"};
wrappedObj.parseFromString = function(str, contentType) {
- var xhr = sandbox.XMLHttpRequest();
+ var xhr = new sandbox.XMLHttpRequest();
xhr.open("GET", "data:"+contentType+";charset=utf-8,"+encodeURIComponent(str), false);
xhr.send();
if (!xhr.responseXML) throw new Error("error parsing XML");