Inital commit
[patchwork] / templates / patchwork / filters.html
1
2 <script type="text/javascript" language="JavaScript">
3 var filterform_displayed = false;
4 function filter_click()
5 {
6     form = document.getElementById('filterform');
7     if (!form) {
8         return;
9     }
10
11     if (filterform_displayed) {
12         form.style['display'] = 'none';
13         filterform_displayed = false;
14     } else {
15         form.style['display'] = 'block';
16         filterform_displayed = true;
17     }
18
19
20 }
21 function enable_selected_submitter(select, input)
22 {
23     select.name = 'submitter';
24     input.name = '';
25 }
26 function filter_form_submit(form)
27 {
28     var i;
29
30     submitter_select = document.getElementById("submitter_select");
31     submitter_input = document.getElementById("submitter_input");
32     if (!submitter_select || !submitter_input) {
33         req = null;
34         return;
35     }
36
37     /* submitter handling. if possible, use the select box, otherwise leave
38      * as-is (and so the text box is used). */
39
40     if (submitter_select.options.length == 0) {
41         /* if there's no match, just use the input */
42
43     } else if (submitter_select.options.length == 1) {
44         /* if there's only one match, request by id */
45         submitter_select.selectedIndex = 0;
46         enable_selected_submitter(submitter_select, submitter_input);
47
48     } else if (submitter_select.selectedIndex != -1) {
49         /* if the user has explicitly selected, request by id */
50         enable_selected_submitter(submitter_select, submitter_input);
51
52     }
53
54     for (i = 0; i < form.elements.length; i++) {
55         var e = form.elements[i];
56         if (e.type == 'submit') {
57             continue;
58         }
59
60         /* handle submitter data */
61         if (e.type == 'select-one') {
62             if (e.name == '') {
63                 e.disabled = true;
64             }
65             if (e.selectedIndex != -1
66                     && e.options[e.selectedIndex].value == '') {
67                 e.disabled = true;
68             }
69
70             continue;
71         }
72
73         if (e.value == '') {
74             e.disabled = true;
75         }
76     }
77 }
78
79 var req = null;
80
81 function submitter_complete_response()
82 {
83     if (req.readyState != 4) {
84         return
85     }
86
87     var completions;
88     eval("completions = " + req.responseText);
89
90     if (completions.length == 0) {
91         req = null;
92         return;
93     }
94
95     submitter_select = document.getElementById("submitter_select");
96     submitter_input = document.getElementById("submitter_input");
97     if (!submitter_select || !submitter_input) {
98         req = null;
99         return;
100     }
101
102     submitter_select.options = [];
103
104     for (i = 0; i < completions.length; i++) {
105         name = completions[i]['fields']['name'];
106         if (name) {
107             name = completions[i]['fields']['name'] +
108                 ' <' + completions[i]['fields']['email'] + '>';
109         } else {
110             name = completions[i]['fields']['email'];
111         }
112         o = new Option(name, completions[i]['pk']);
113         submitter_select.options[i] = o;
114     }
115     submitter_select.disabled = false;
116     req = null;
117 }
118
119 function submitter_field_change(field)
120 {
121     var value = field.value;
122     if (value.length < 4) {
123         return;
124     }
125
126     if (req) {
127          return;
128     }
129
130     var url = '{% url patchwork.views.submitter_complete %}?q=' + value;
131     req = new XMLHttpRequest();
132     req.onreadystatechange = submitter_complete_response;
133     req.open("GET", url, true);
134     req.send('');
135 }
136 </script>
137
138 <div class="filters">
139  <div id="filtersummary">
140   <strong><a href="javascript:filter_click()">Filters</a>:</strong>
141  {% if filters.applied_filters %}
142   {% for filter in filters.applied_filters %}
143    {{ filter.name }} = {{ filter.condition }}
144     {% if not filter.forced %}
145      <a href="{{ filter.url_without_me }}"><img
146       src="/images/filter-remove.png"></a>
147     {% endif %}
148    {% if not forloop.last %}&nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;{% endif %}
149   {% endfor %}
150  {% else %}
151   none
152   <a href="javascript:filter_click()"><img src="/images/filter-add.png"></a>
153  {% endif %}
154  </div>
155  <div id="filterform" style="padding-top: 1em; display: none">
156   <form action="" method="get" onSubmit="return filter_form_submit(this)">
157     <table>
158     {% for filter in filters.available_filters %}
159      <tr>
160       <td>{{ filter.name }}</td>
161       <td>{{ filter.form }}</td>
162      </tr>
163     {% endfor %}
164      <tr>
165       <td/>
166       <td><input type="submit" value="Apply"/></td>
167      </tr>
168     </table>
169   </form>
170  </div>
171 </div>
172
173