diff options
author | Matěj Cepl <mcepl@redhat.com> | 2011-05-31 01:39:46 +0200 |
---|---|---|
committer | Matěj Cepl <mcepl@redhat.com> | 2011-06-05 14:53:48 +0200 |
commit | 3a7b19da58572396648df1ab215228d01129aede (patch) | |
tree | a4cdf30fe609e0c0336c089906995053c14f4475 | |
parent | 16b78ccadf021cc9255016ab5dac31558d28dea4 (diff) | |
download | bugzilla-triage-3a7b19da58572396648df1ab215228d01129aede.tar.gz |
First draft of the flags handling for Mozilla bugzilla.
Will fix #103 (when reviewed)
-rw-r--r-- | data/lib/bzpage.js | 2 | ||||
-rw-r--r-- | data/mozlib/mozpage.js | 73 | ||||
-rw-r--r-- | data/rhlib/rhbzpage.js | 20 | ||||
-rw-r--r-- | data/tweaks/bug-page-mod.js | 7 | ||||
-rw-r--r-- | lib/main.js | 1 |
5 files changed, 97 insertions, 6 deletions
diff --git a/data/lib/bzpage.js b/data/lib/bzpage.js index aa496cf..c1898eb 100644 --- a/data/lib/bzpage.js +++ b/data/lib/bzpage.js @@ -45,7 +45,7 @@ self.on('message', function onMessage(msg) { break; default: if (TweakOnMessageHandler) { - TweakOnMessageHandler(msg, RHOnMessageHandler); + TweakOnMessageHandler(msg, [RHOnMessageHandler, MozOnMessageHandler]); } else { console.error("Error: unknown RPC call " + msg.toSource()); diff --git a/data/mozlib/mozpage.js b/data/mozlib/mozpage.js new file mode 100644 index 0000000..51af8b5 --- /dev/null +++ b/data/mozlib/mozpage.js @@ -0,0 +1,73 @@ +// Released under the MIT/X11 license +// http://www.opensource.org/licenses/mit-license.php + + +// END OF CONSTANTS + +var btSnippet = null; + +function MozOnMessageHandler(msg, nextHandler) { + switch (msg.cmd) { + case "Error": + alert("Error " + msg.data); + break; + case "Unhandled": + break; + default: + if (nextHandler) { + var nextHandler = nextHandlerList.splice(0, 1); + if (nextHandler[0]) { + nextHandler[0](msg, nextHandlerList); + } + } + else { + console.error("Error: unknown RPC call " + msg.toSource()); + } + break; + } +} + +// MozBugzillaPage object +function collectFlags() { + var flags = {}; + var tdColumn2 = document.getElementById("bz_show_bug_column_2"); + var flag_selects = tdColumn2.querySelectorAll("td.field_value select"); + Array.forEach(flag_selects, function(sel) { + var label = tdColumn2.querySelector("label[for='" + sel.id + "']"); + if (label) { + var key = label.textContent.trim().replace(/\s*:?$/,""); + flags[key] = sel.id; + } + }); + return flags; +} + +function changeFlag(flags, label, newValue) { + selectOption(flags[label], newValue); +} + +/** + * Additional commands specific for this subclass, overriding superclass one. + */ +function MozCentralCommandDispatch(cmdLabel, cmdParams) { + switch (cmdLabel) { + // Set up our own commands + case "setFlag": + changeFlag(mozFlags, cmdParams, "+"); + break; + case "unsetFlag": + changeFlag(mozFlags, cmdParams, "-"); + break; + case "clearFlag": + changeFlag(mozFlags, cmdParams, "---"); + break; + // FIXME what is the meaning of value == "?" + default: + console.error("Unknown command:\n" + cmdLabel + "\nparameters:\n" + cmdParams); + break; + } +} + + +var mozFlags = collectFlags(); +console.log("mozFlags = " + mozFlags.toSource()); diff --git a/data/rhlib/rhbzpage.js b/data/rhlib/rhbzpage.js index b9325a1..a130306 100644 --- a/data/rhlib/rhbzpage.js +++ b/data/rhlib/rhbzpage.js @@ -56,7 +56,8 @@ var ProfessionalProducts = [ var btSnippet = null; -function RHOnMessageHandler(msg) { + +function RHOnMessageHandler(msg, nextHandler) { switch (msg.cmd) { case "Error": alert("Error " + msg.data); @@ -77,7 +78,15 @@ function RHOnMessageHandler(msg) { queryUpstreamCallback(msg.data, constantData.queryUpstreamBug); break; default: - console.error("Error: unknown RPC call " + msg.toSource()); + if (nextHandler) { + var nextHandler = nextHandlerList.splice(0, 1); + if (nextHandler[0]) { + nextHandler[0](msg, nextHandlerList); + } + } + else { + console.error("Error: unknown RPC call " + msg.toSource()); + } break; } } @@ -136,7 +145,12 @@ function RHcentralCommandDispatch(cmdLabel, cmdParams) { break; // If we don't have it here, call superclass method default: - console.error("Unknown command:\n" + cmdLabel + "\nparameters:\n" + cmdParams); + if (MozCentralCommandDispatch) { + MozCentralCommandDispatch(cmdLabel, cmdParams); + } + else { + console.error("Unknown command:\n" + cmdLabel + "\nparameters:\n" + cmdParams); + } break; } } diff --git a/data/tweaks/bug-page-mod.js b/data/tweaks/bug-page-mod.js index d0f8095..9be8551 100644 --- a/data/tweaks/bug-page-mod.js +++ b/data/tweaks/bug-page-mod.js @@ -33,7 +33,7 @@ * ***** END LICENSE BLOCK ***** */ -function TweakOnMessageHandler(msg, nextHandler) { +function TweakOnMessageHandler(msg, nextHandlerList) { switch (msg.cmd) { case "Unhandled": break; @@ -42,7 +42,10 @@ function TweakOnMessageHandler(msg, nextHandler) { break; default: if (nextHandler) { - nextHandler(msg); + var nextHandler = nextHandlerList.splice(0, 1); + if (nextHandler[0]) { + nextHandler[0](msg, nextHandlerList); + } } else { console.error("Error: unknown RPC call " + msg.toSource()); diff --git a/lib/main.js b/lib/main.js index de355d7..d0cf298 100644 --- a/lib/main.js +++ b/lib/main.js @@ -148,6 +148,7 @@ var contentScriptLibraries = [ self.data.url("rhlib/fixingAttMIME.js"), self.data.url("lib/logging-front.js"), self.data.url('tweaks/bug-page-mod.js'), + self.data.url('mozlib/mozpage.js'), self.data.url("rhlib/rhbzpage.js"), self.data.url("lib/bzpage.js") ]; |