From 2d8a9dabb4957ae1158ba000ee211b33bd0a81be Mon Sep 17 00:00:00 2001 From: Matěj Cepl Date: Tue, 31 May 2011 01:39:46 +0200 Subject: First draft of the flags handling for Mozilla bugzilla. Will fix #103 (when reviewed) --- data/mozlib/mozpage.js | 73 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 data/mozlib/mozpage.js (limited to 'data/mozlib/mozpage.js') 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()); -- cgit