summaryrefslogtreecommitdiffstats
path: root/extensions/ComponentWatching/template/en/default/hook/admin/components/edit-common-rows.html.tmpl
blob: 940fc2d115a0974b19de41359b07dbabb42a829e (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
[%# This Source Code Form is subject to the terms of the Mozilla Public
  # License, v. 2.0. If a copy of the MPL was not distributed with this
  # file, You can obtain one at http://mozilla.org/MPL/2.0/.
  #
  # This Source Code Form is "Incompatible With Secondary Licenses", as
  # defined by the Mozilla Public License, v. 2.0.
  #%]

<tr>
  <th class="field_label"><label for="watch_user">Watch User:</label></th>
  <td>
    [% IF !comp.id || !comp.watch_user %]
      <input type="checkbox" id="watch_user_auto" name="watch_user_auto" value="1" checked>
      <label for="watch_user_auto">Automatic</label>
      <span id="watch_user_suggestion"></span>
      [% edit_size = 44 %]
    [% ELSE %]
      [% edit_size = 64 %]
    [% END %]
    [% INCLUDE global/userselect.html.tmpl
       name    => "watch_user"
       id      => "watch_user"
       value   => comp.watch_user.login
       size    => edit_size
       emptyok => 1
    %]
  </td>
</tr>

<script [% script_nonce FILTER none %]>
function sanitise_name(name) {
  return name.toLowerCase()
             .replace(/[^a-z0-9_]/g, '-')
             .replace(/-+/g, '-')
             .replace(/(^-|-$)/g, '');
}

function update_watch_user() {
  var Dom = YAHOO.util.Dom;
  if (Dom.get('watch_user_auto').checked) {
    Dom.addClass('watch_user', 'bz_default_hidden');

    var component = Dom.get('component').value;
    var watch = '';
    if (component == '') {
      watch = '(no component name)';
    }
    else {
      watch = sanitise_name(component) +
              '@' + sanitise_name('[% product.name FILTER js %]') + '.bugs';
    }
    Dom.get('watch_user_suggestion').innerHTML = ' : <b>' + watch + '</b>';
    Dom.get('watch_user').value = watch;
  }
  else {
    Dom.removeClass('watch_user', 'bz_default_hidden');
    Dom.get('watch_user_suggestion').innerHTML = '';
    if (Dom.get('watch_user').value == '(no component name)')
      Dom.get('watch_user').value = '';
  }
}

YAHOO.util.Event.onDOMReady(function() {
  if (document.getElementById('watch_user_auto')) {
    YAHOO.util.Event.addListener('component', 'keyup', update_watch_user);
    YAHOO.util.Event.addListener('watch_user_auto', 'click', update_watch_user);
    update_watch_user();
  }
});
</script>