aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorMatěj Cepl <mcepl@redhat.com>2010-07-16 17:45:14 +0200
committerMatěj Cepl <mcepl@redhat.com>2010-07-16 17:45:14 +0200
commitd53b9140d0768522eeb6a024a17fc41dc73b4966 (patch)
treeb34cd2e97df964d3f7012bb110b70d0cf8025422 /lib
parent641d7c3743be440112952140ca799b6748b261c7 (diff)
downloadbugzilla-triage-d53b9140d0768522eeb6a024a17fc41dc73b4966.tar.gz
Create a special library prompts, add prompts.prompt, and switch bzpage
and logger to use it.
Diffstat (limited to 'lib')
-rw-r--r--lib/bzpage.js8
-rw-r--r--lib/logger.js3
-rw-r--r--lib/prompts.js82
-rw-r--r--lib/util.js52
4 files changed, 88 insertions, 57 deletions
diff --git a/lib/bzpage.js b/lib/bzpage.js
index 3f0f81b..3735328 100644
--- a/lib/bzpage.js
+++ b/lib/bzpage.js
@@ -7,6 +7,7 @@ var passUtils = require("passwords");
var apiUtils = require("api-utils");
var simpleStorage = require("simple-storage");
var preferences = require("preferences-service");
+var prompts = require("prompts");
var Color = require("color").Color;
var TriagedDistro = 13;
@@ -448,8 +449,7 @@ BZPage.prototype.setConfigurationButton = function setConfigurationButton () {
var prfNm = BTSPrefNS+"JSONURL";
var url = preferences.get(prfNm,"");
- // FIXME don't use window.prompt, but create util.prompt instead
- var reply = that.win.prompt("New location of JSON configuration file",url);
+ var reply = prompts.prompt("New location of JSON configuration file",url);
if (reply) {
preferences.set(prfNm,reply.trim());
that.win.alert("For now, you should really restart Firefox!");
@@ -712,13 +712,13 @@ BZPage.prototype.getPassword = function getPassword (login) {
var pass = passUtils.getPassword(login, domain, BTSPassRealm);
// pass === null means no appropriate password in the storage
if (!preferences.get(prefName,false) && (pass === null)) {
- var passwordText = util.getPassword(passPrompt);
+ var passwordText = prompts.promptPassword(passPrompt);
if (passwordText && passwordText.length > 0) {
passUtils.setLogin(login, passwordText, domain,
BTSPassRealm);
return passwordText;
} else {
- var switchOff = util.promptOKNoCancel(switchPrompt);
+ var switchOff = prompts.promptYesNoCancel(switchPrompt);
if (switchOff) {
preferences.set(prefName,true);
}
diff --git a/lib/logger.js b/lib/logger.js
index df01d37..5926bea 100644
--- a/lib/logger.js
+++ b/lib/logger.js
@@ -5,6 +5,7 @@ var urlMod = require("url");
var utilMod = require("util");
var Color = require("color").Color;
var tabs = require("tabs");
+var prompts = require("prompts");
var apiUtils = require("api-utils");
function Logger(store, abbsMap) {
@@ -23,7 +24,7 @@ Logger.prototype.addLogRecord = function(that) {
rec.date = new Date();
rec.url = that.doc.location.toString();
rec.title = that.title;
- var comment = tabs.activeTab.contentWindow.prompt(
+ var comment = prompts.prompt(
"Enter comments for this comment");
console.log("comment = " + comment);
if (comment && comment.length > 0) {
diff --git a/lib/prompts.js b/lib/prompts.js
new file mode 100644
index 0000000..ac21c49
--- /dev/null
+++ b/lib/prompts.js
@@ -0,0 +1,82 @@
+/*global exports: false, require: false, console: false */
+/*jslint onevar: false */
+// Released under the MIT/X11 license
+// http://www.opensource.org/licenses/mit-license.php
+"use strict";
+// ==============================================================
+var {Cc,Ci} = require("chrome");
+// just for JSLINT var Cc, Ci = {};
+var promptTitle = "Bugzilla Triage Script";
+
+/**
+ * general prompts for a string method
+ *
+ * @return String with the password
+ */
+exports.prompt = function prompt(prompt, defaultValue) {
+ var stringValue = {
+ value: defaultValue ? defaultValue : ""
+ };
+
+ var prompts = Cc["@mozilla.org/embedcomp/prompt-service;1"]
+ .getService(Ci.nsIPromptService);
+ var result = prompts.prompt(null, promptTitle, prompt,
+ stringValue, null, {});
+ if (result) {
+ return stringValue.value;
+ } else {
+ return undefined;
+ }
+};
+
+/**
+ * returns password with a special password
+ *
+ * @return String with the password
+ */
+exports.promptPassword = function promptPassword(prompt) {
+ if (!prompt) { // either undefined or null
+ prompt = "Enter password:";
+ }
+ var prompts = Cc["@mozilla.org/embedcomp/prompt-service;1"]
+ .getService(Ci.nsIPromptService);
+ var password = {
+ value : ""
+ }; // default the password to pass
+ var check = {
+ value : true
+ }; // default the checkbox to true
+ var result = prompts.promptPassword(null, "Bugzilla Triage Script", prompt,
+ password, null, check);
+ // result is true if OK was pressed, false if cancel was pressed.
+ // password.value is set if OK was pressed.
+ // The checkbox is not displayed.
+ if (result) {
+ return password.value ? password.value : null;
+ } else {
+ return undefined;
+ }
+};
+
+/**
+ * YES/NO prompt; returns boolean or null (for Cancel)
+ * https://developer.mozilla.org/en/XPCOM_Interface_Reference/nsIPromptService
+ */
+exports.promptYesNoCancel = function promptOKNoCancel(prompt) {
+ if (!prompt) { // either undefined or null
+ console.error("Prompt is required!");
+ return undefined;
+ }
+ var prompts = Cc["@mozilla.org/embedcomp/prompt-service;1"]
+ .getService(Ci.nsIPromptService);
+
+ var result = prompts.confirmEx(null, "Bugzilla Triage Script", prompt,
+ prompts.STD_YES_NO_BUTTONS, null, null, null, null, {});
+ if (result === 0) {
+ return true;
+ } else if (result === 1) {
+ return false;
+ } else {
+ return null;
+ }
+};
diff --git a/lib/util.js b/lib/util.js
index dd4c4f9..e3676ca 100644
--- a/lib/util.js
+++ b/lib/util.js
@@ -191,55 +191,3 @@ var filterByRegexp = exports.filterByRegexp =
return "";
}
};
-
-/**
- * returns password with a special password
- *
- * @return String with the password
- */
-exports.getPassword = function getPassword(prompt) {
- if (!prompt) { // either undefined or null
- prompt = "Enter password:";
- }
- var prompts = Cc["@mozilla.org/embedcomp/prompt-service;1"]
- .getService(Ci.nsIPromptService);
- var password = {
- value : ""
- }; // default the password to pass
- var check = {
- value : true
- }; // default the checkbox to true
- var result = prompts.promptPassword(null, "Bugzilla Triage Script", prompt,
- password, null, check);
- // result is true if OK was pressed, false if cancel was pressed.
- // password.value is set if OK was pressed.
- // The checkbox is not displayed.
- if (result) {
- return password.value ? password.value : null;
- } else {
- return undefined;
- }
-};
-
-/**
- * YES/NO prompt; returns boolean or null (for Cancel)
- * https://developer.mozilla.org/en/XPCOM_Interface_Reference/nsIPromptService
- */
-exports.promptOKNoCancel = function promptOKNoCancel(prompt) {
- if (!prompt) { // either undefined or null
- console.error("Prompt is required!");
- return undefined;
- }
- var prompts = Cc["@mozilla.org/embedcomp/prompt-service;1"]
- .getService(Ci.nsIPromptService);
-
- var result = prompts.confirmEx(null, "Bugzilla Triage Script", prompt,
- prompts.STD_YES_NO_BUTTONS, null, null, null, null, {});
- if (result === 0) {
- return true;
- } else if (result === 1) {
- return false;
- } else {
- return null;
- }
-}; \ No newline at end of file