aboutsummaryrefslogtreecommitdiffstats
path: root/data/rhlib/xorgBugCategories.js
blob: 894eca137add30a1cee49c6acfa23afa37c00ff8 (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
// Released under the MIT/X11 license
// http://www.opensource.org/licenses/mit-license.php
"use strict";

/**
 * Returns true if the bug is in a good shape
 *
 * @return Boolean if the bug is either not in the category where we care about
 *         it (i.e., we don't have set up categories for this component) or if
 *         it is in the concerned categories, then it has a category recorded in
 *         the whiteboard input box.
 *
 */
function hasXorgBugsCategory() {
  var catRE = /\s*\[cat:.*?\]\s*/; // RE for testing whether
  // there is already category tag in the Whiteboard

  var isXOrgBug = filterByRegexp(
      constantData.xorgBugsCategories, getComponent());
  var whiteboardContent = document
      .getElementById("status_whiteboard").value;

  if (isXOrgBug) { // is it XOR?
    return catRE.test(whiteboardContent);
  }
  else {
    return true;
  }
}

/**
 * Create a category list to the upper toolbar
 */
function makeBugCategoriesList(catList) {
  var catRE = /\s*\[cat:.*?\]\s*/; // RE for testing whether
  // there is already category tag in the Whiteboard

  // Create <select> element and add it first blank <option>
  var targetDiv = document.getElementById("commit_top").parentNode;
  var categoryList = document.createElement("select");
  categoryList.setAttribute("id", "xorgBugsCategoriesSelect");
  categoryList.setAttribute("name", "xorgBugsCategoriesSelect");
  var optionElement = document.createElement("option");
  optionElement.value = null;
  optionElement.setAttribute("id", "catId_blank");
  optionElement.appendChild(document.createTextNode("---"));
  categoryList.appendChild(optionElement);

  // Fill-in <select> with <options>s for each category one
  if (catList) {
    catList.forEach(function(cat) {
      optionElement = document.createElement("option");
      optionElement.value = cat;
      optionElement.setAttribute("id", "catId_"
          + cat.replace(" ", "").toLowerCase());
      optionElement.appendChild(document.createTextNode(cat));
      categoryList.appendChild(optionElement);
    });
  }

  categoryList.addEventListener("change", function(evt) {
    var selectedCategory = "[cat:" + this.value + "]";
    var whiteboardElement = document
        .getElementById("status_whiteboard");

    if (hasXorgBugsCategory()) {
      whiteboardElement.value = whiteboardElement.value.replace(
          catRE, "");
    }
    addStuffToTextBox("status_whiteboard", selectedCategory);
  }, false);

  targetDiv.insertBefore(categoryList, targetDiv.firstChild);
}

//vim: set ts=2 et sw=2 textwidth=80: