commit 4f9366749c7cb2b8229afe84f9110987d58206bd
parent 9511c434329645cc44ae2ca37efbdd0b757d6377
Author: Dan Stillman <dstillman@zotero.org>
Date: Tue, 14 Apr 2015 16:09:55 -0400
Add Zotero.alert() method
This is just a wrapper around nsIPromptService.alert() that takes
Zotero.noUserInput into consideration, which avoids long timeouts during
testing (e.g., for lookup failures).
Diffstat:
2 files changed, 33 insertions(+), 8 deletions(-)
diff --git a/chrome/content/zotero/lookup.js b/chrome/content/zotero/lookup.js
@@ -87,10 +87,11 @@ const Zotero_Lookup = new function () {
}
if(!items.length) {
- var prompts = Components.classes["@mozilla.org/embedcomp/prompt-service;1"]
- .getService(Components.interfaces.nsIPromptService);
- prompts.alert(window, Zotero.getString("lookup.failure.title"),
- Zotero.getString("lookup.failureToID.description"));
+ Zotero.alert(
+ window,
+ Zotero.getString("lookup.failure.title"),
+ Zotero.getString("lookup.failureToID.description")
+ );
return false;
}
@@ -127,10 +128,11 @@ const Zotero_Lookup = new function () {
if(successful) {
document.getElementById("zotero-lookup-panel").hidePopup();
} else {
- var prompts = Components.classes["@mozilla.org/embedcomp/prompt-service;1"]
- .getService(Components.interfaces.nsIPromptService);
- prompts.alert(window, Zotero.getString("lookup.failure.title"),
- Zotero.getString("lookup.failure.description"));
+ Zotero.alert(
+ window,
+ Zotero.getString("lookup.failure.title"),
+ Zotero.getString("lookup.failure.description")
+ );
}
}
});
diff --git a/chrome/content/zotero/xpcom/zotero.js b/chrome/content/zotero/xpcom/zotero.js
@@ -1308,6 +1308,29 @@ Components.utils.import("resource://gre/modules/Services.jsm");
err.lineNumber ? err.lineNumber : null, null);
}
+
+ /**
+ * Display an alert in a given window
+ *
+ * This is just a wrapper around nsIPromptService.alert() that takes the Zotero.noUserInput
+ * flag into consideration
+ *
+ * @param {Window}
+ * @param {String} title
+ * @param {String} msg
+ */
+ this.alert = function (window, title, msg) {
+ if (this.noUserInput) {
+ Zotero.debug("Not displaying alert: " + title + ": " + msg);
+ return;
+ }
+
+ var ps = Components.classes["@mozilla.org/embedcomp/prompt-service;1"]
+ .getService(Components.interfaces.nsIPromptService);
+ ps.alert(window, title, msg);
+ }
+
+
function getErrors(asStrings) {
var errors = [];