diff options
author | Matěj Cepl <mcepl@redhat.com> | 2010-07-16 13:02:51 +0200 |
---|---|---|
committer | Matěj Cepl <mcepl@redhat.com> | 2010-07-16 16:28:08 +0200 |
commit | 641d7c3743be440112952140ca799b6748b261c7 (patch) | |
tree | bd52a73063daa459cace130eea68666eb5e7f6f2 /lib/bzpage.js | |
parent | 3f70ba468a91e0f5abe20034dd50e3c63a6fcb1a (diff) | |
download | bugzilla-triage-641d7c3743be440112952140ca799b6748b261c7.tar.gz |
Bail out if we are not logged in.
Adding our own exception and checking it.
Move configuration button to special method of BZPage.
A bit of cleanup.
Fixes #20 (I hope).
Diffstat (limited to 'lib/bzpage.js')
-rw-r--r-- | lib/bzpage.js | 77 |
1 files changed, 49 insertions, 28 deletions
diff --git a/lib/bzpage.js b/lib/bzpage.js index 45e1196..3f0f81b 100644 --- a/lib/bzpage.js +++ b/lib/bzpage.js @@ -16,15 +16,21 @@ var BTSPrefNS = "bugzilla-triage.setting."; exports.BTSPrefNS = BTSPrefNS; var BTSPassRealm = "BTSXMLRPCPass"; +// ============================================ + +var NotLoggedinException = function NotLoggedinException (message) { + this.message = message; + this.name = "NotLoggedinException"; +}; + +NotLoggedinException.prototype.toString = function () { + return this.name + ': "' + this.message + '"'; +}; +exports.NotLoggedinException = NotLoggedinException; + // ==================================================================================== // BZPage's methods var BZPage = function BZPage(win, config) { - var keys = ""; - for (var key in config) { - keys += key + ", "; - } - console.log("config keys = " + keys); - // constants this.SalmonPink = new Color(255, 224, 176); // RGB 255, 224, 176; HSL 36, 2, // 85 @@ -34,6 +40,18 @@ var BZPage = function BZPage(win, config) { var that = this; this.win = win; this.doc = win.document; + + // First, preflight check ... if we are not logged in, there + // is nothing we can do. + var logoutLink = Array.some(this.doc.links, function (x) { + return x.search === "?logout=1" ; + }); + if (!logoutLink) { + throw new NotLoggedinException("Not logged in"); + } + + // So, now we know we are logged in, so we can get to + // the real work. this.packages = this.getInstalledPackages(config); if ("commentStrings" in config.gJSONData) { @@ -59,28 +77,7 @@ var BZPage = function BZPage(win, config) { this.setUpLogging(); } - // configuration button - var additionalButtons = this.doc.querySelector("#bugzilla-body *.related_actions"); - var configurationButtonUI = this.doc.createElement("li"); - configurationButtonUI.innerHTML = "\u00A0-\u00A0<a href='#' id='configurationButton'>" - + "Configuration buttons</a>"; - additionalButtons.appendChild(configurationButtonUI); - this.doc.getElementById("configurationButton").addEventListener( - "click", - function(evt) { - var prfNm = BTSPrefNS+"JSONURL"; - var url = preferences.get(prfNm,""); - - var reply = that.win.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!"); - } - - evt.stopPropagation(); - evt.preventDefault(); - }, false); - + this.setConfigurationButton(); this.submitHandlerInstalled = false; this.bugNo = util.getBugNo(this.doc.location.toString()); @@ -439,6 +436,30 @@ BZPage.prototype.generateButtons = function generateButtons () { } }; +BZPage.prototype.setConfigurationButton = function setConfigurationButton () { + var additionalButtons = this.doc.querySelector("#bugzilla-body *.related_actions"); + var configurationButtonUI = this.doc.createElement("li"); + configurationButtonUI.innerHTML = "\u00A0-\u00A0<a href='#' id='configurationButton'>" + + "Triage configuration</a>"; + additionalButtons.appendChild(configurationButtonUI); + this.doc.getElementById("configurationButton").addEventListener( + "click", + function(evt) { + 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); + if (reply) { + preferences.set(prfNm,reply.trim()); + that.win.alert("For now, you should really restart Firefox!"); + } + + evt.stopPropagation(); + evt.preventDefault(); + }, false); +}; + /** * Get the current email of the reporter of the bug. * |