summaryrefslogtreecommitdiffstats
path: root/js/create_bug.js
blob: 3716f2aefc64cf65f1de40b3c329a290905430ec (plain)
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
function toggleAdvancedFields() {
  TUI_toggle_class('expert_fields');
  var elements = YAHOO.util.Dom.getElementsByClassName('expert_fields');
  if (YAHOO.util.Dom.hasClass(elements[0], TUI_HIDDEN_CLASS)) {
    handleWantsBugFlags(false);
  }
}

function handleWantsBugFlags(wants) {
  if (wants) {
    hideElementById('bug_flags_false');
    showElementById('bug_flags_true');
  }
  else {
    showElementById('bug_flags_false');
    hideElementById('bug_flags_true');
    clearBugFlagFields();
  }
}

function clearBugFlagFields() {
  var flags_table;
  flags_table = document.getElementById('bug_flags');
  if (flags_table) {
    var selects = flags_table.getElementsByTagName('select');
    for (var i = 0, il = selects.length; i < il; i++) {
      if (selects[i].value != 'X') {
        selects[i].value = 'X';
        toggleRequesteeField(selects[i]);
      }
    }
  }
  flags_table = document.getElementById('bug_tracking_flags');
  if (flags_table) {
    var selects = flags_table.getElementsByTagName('select');
    for (var i = 0, il = selects.length; i < il; i++) {
      selects[i].value = '---';
    }
  }
}

YAHOO.util.Event.onDOMReady(function() {
  function set_width(id, width) {
    var el = document.getElementById(id);
    if (!el) return;
    el.style.width = width + 'px';
  }

  // force field widths

  var width = document.getElementById('short_desc').clientWidth + 'px';
  var el;

  el = document.getElementById('comment');
  el.style.width = width;

  el = document.getElementById('cf_crash_signature');
  if (el) el.style.width = width;

  // show the bug flags if a flag is set

  var flag_set = false;
  var flags_table;
  flags_table = document.getElementById('bug_flags');
  if (flags_table) {
    var selects = flags_table.getElementsByTagName('select');
    for (var i = 0, il = selects.length; i < il; i++) {
      if (selects[i].value != 'X') {
        flag_set = true;
        break;
      }
    }
  }
  if (!flag_set) {
    flags_table = document.getElementById('bug_tracking_flags');
    if (flags_table) {
      var selects = flags_table.getElementsByTagName('select');
      for (var i = 0, il = selects.length; i < il; i++) {
        if (selects[i].value != '---') {
          flag_set = true;
          break;
        }
      }
    }
  }

  if (flag_set) {
    hideElementById('bug_flags_false');
    showElementById('bug_flags_true');
  } else {
    hideElementById('bug_flags_true');
    showElementById('bug_flags_false');
  }
  showElementById('btn_no_bug_flags')
});

function take_bug(user) {
  var el = Dom.get('assigned_to');
  el.value = user;
  el.focus();
  el.select();
  assignee_change(user);
  return false;
}

function assignee_change(user) {
  var el = Dom.get('take_bug');
  if (!el) return;
  el.style.display = Dom.get('assigned_to').value == user ? 'none' : '';
}

function init_take_handler(user) {
  YAHOO.util.Event.addListener(
    'assigned_to', 'change', function() { assignee_change(user); });
  assignee_change(user);
}