diff options
-rw-r--r-- | data/lib/collectingMetadata.js | 2 | ||||
-rw-r--r-- | data/mozlib/mozpage.js | 105 |
2 files changed, 63 insertions, 44 deletions
diff --git a/data/lib/collectingMetadata.js b/data/lib/collectingMetadata.js index 8a0160f..5bd956c 100644 --- a/data/lib/collectingMetadata.js +++ b/data/lib/collectingMetadata.js @@ -196,4 +196,4 @@ AttachList.prototype.forEach = function forEach(fce) { this.attachments.forEach(fce); }; -//vim: set ts=2 et sw=2 textwidth=80: +// ------------------------------------------------------------------- diff --git a/data/mozlib/mozpage.js b/data/mozlib/mozpage.js index aa7a7c9..c1aa53e 100644 --- a/data/mozlib/mozpage.js +++ b/data/mozlib/mozpage.js @@ -2,6 +2,38 @@ // http://www.opensource.org/licenses/mit-license.php /** + * + */ +function Flag(element,column) { + this.element = element; + this.id = element.id; + var label = column.querySelector("label[for='" + this.id + "']"); + this.key = label.textContent.trim().replace(/\s*:?$/, ""); +} + +Flag.prototype = { + get id() { return this.id }, + set value(what) { + selectOption(this.id, what); + }, + set: function() { + this.value = "+"; + }, + reject: function() { + this.value = "-"; + }, + ask: function() { + this.value = "?"; + }, + unset: function() { + this.value = "--"; + }, + toString: function() { + return this.value; + } +}; + +/** * Abstract model of flags found on BMO (and not only there) * * @return Object with function properties: @@ -11,53 +43,40 @@ * - unset clear the flag to the initial state (currently "--"), and * - dump dump internal variable to console */ -var mozFlags = (function() { - var flags = {}; +function FlagList() { + this.flags = {}; + var tdColumn2 = document.getElementById("custom_flags"); + var flag_selects = tdColumn2.getElementsByTagName("select"); + Array.forEach(flag_selects, function(sel) { + var object = new Flag(sel, tdColumn2); + this.flags[object.id] = object; + }); +} - function _init() { - var tdColumn2 = document.getElementById("bz_show_bug_column_2"); - if (tdColumn2) { // TODO we should really make some configuration for non-Mozilla - 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; - } - }); +FlagList.prototype = { + set: function(label) { + this.flags[label].set(); + }, + reject: function(label) { + this.flags[label].reject(); + }, + ask: function(label) { + this.flags[label].ask(); + }, + unset: function(label) { + this.flags[label].unset(); + }, + toString: function() { + var out = "flags:\n"; + for (var key in this.flags) { + out += this.flags[key] + ",\n"; } + return out; } +}; - function _setFlag(label) { - selectOption(flags[label], "+"); - } - - function _rejectFlag(label) { - selectOption(flags[label], "-"); - } - - function _askFlag(label) { - selectOption(flags[label], "?"); - } - - 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 - }; - -})(); +// ----------------------------------------------------- +var mozFlags = new FlagList(); // Currently empty message handler function MozOnMessageHandler(msg, nextHandlerList) { |