aboutsummaryrefslogtreecommitdiffstats
path: root/data/mozlib/mozpage.js
blob: 86c15598fa5ea1d7daeb302affcd16e55047ac27 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
// 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], "-");
  }

  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
  };

})();

// Currently empty message handler
function MozOnMessageHandler(msg, nextHandler) {
  switch (msg.cmd) {
  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;
  }
}

/**
 * Additional commands specific for this subclass, overriding superclass one.
 */
function MozCentralCommandDispatch(cmdLabel, cmdParams) {
  switch (cmdLabel) {
  // Set up our own commands
  case "setFlag":
    mozFlags.set(cmdParams);
    break;
  case "unsetFlag":
    mozFlags.reject(cmdParams);
    break;
  case "askFlag":
    mozFlags.ask(cmdParams);
    break;
  case "clearFlag":
    mozFlags.unset(cmdParams);
    break;
  default:
    console.error("Unknown command:\n" + cmdLabel + "\nparameters:\n" + cmdParams);
  break;
  }
}