diff options
author | Matěj Cepl <mcepl@redhat.com> | 2011-05-31 11:49:59 +0200 |
---|---|---|
committer | Matěj Cepl <mcepl@redhat.com> | 2011-06-05 14:53:48 +0200 |
commit | 6aee928f6346ea93e5958a016f156619f5131c89 (patch) | |
tree | a9a37b27c722ffabf6684dcd62e45b7b7a4ecf36 /data/mozlib/mozpage.js | |
parent | 3a7b19da58572396648df1ab215228d01129aede (diff) | |
download | bugzilla-triage-6aee928f6346ea93e5958a016f156619f5131c89.tar.gz |
Make one nice closure mozFlags instead of spreading yet another group of functions.
Fixes #103.
Diffstat (limited to 'data/mozlib/mozpage.js')
-rw-r--r-- | data/mozlib/mozpage.js | 94 |
1 files changed, 60 insertions, 34 deletions
diff --git a/data/mozlib/mozpage.js b/data/mozlib/mozpage.js index 51af8b5..86c1559 100644 --- a/data/mozlib/mozpage.js +++ b/data/mozlib/mozpage.js @@ -1,18 +1,65 @@ // Released under the MIT/X11 license // http://www.opensource.org/licenses/mit-license.php +/** + * Abstract model of flags found on BMO (and not only there) + * + * @return Object with function properties: + * - set Approve flag (currently "+"), + * - reject Reject flag (currently "-"), + * - ask ask for decision (currently "?"), + * - unset clear the flag to the initial state (currently "--"), and + * - dump dump internal variable to console + */ +var mozFlags = (function() { + var flags = {}; + + function _init() { + 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; + } + }); + } + + function _setFlag(label) { + selectOption(flags[label], "+"); + } + + function _rejectFlag(label) { + selectOption(flags[label], "-"); + } -// END OF CONSTANTS + function _askFlag(label) { + selectOption(flags[label], "?"); + } -var btSnippet = null; + function _unsetFlag(label) { + selectOption(flags[label], "--"); + } + + function _dumpFlags() { + console.log("collected flags are " + flags.toSource()); + } + _init(); + return { + set: _setFlag, + reject: _rejectFlag, + ask: _askFlag, + unset: _unsetFlag, + dump: _dumpFlags + }; + +})(); + +// Currently empty message handler 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); @@ -27,25 +74,6 @@ function MozOnMessageHandler(msg, nextHandler) { } } -// 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. */ @@ -53,21 +81,19 @@ function MozCentralCommandDispatch(cmdLabel, cmdParams) { switch (cmdLabel) { // Set up our own commands case "setFlag": - changeFlag(mozFlags, cmdParams, "+"); + mozFlags.set(cmdParams); break; case "unsetFlag": - changeFlag(mozFlags, cmdParams, "-"); + mozFlags.reject(cmdParams); + break; + case "askFlag": + mozFlags.ask(cmdParams); break; case "clearFlag": - changeFlag(mozFlags, cmdParams, "---"); + mozFlags.unset(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()); |