Inital commit
[patchwork] / htdocs / js / filters.js
1
2 var available_filters = new Array();
3
4 function Filter(param, input_html, fn)
5 {
6         this.param = param;
7         this.input_html = input_html;
8         this.fn = fn;
9 }
10
11 function add_filter_change(input)
12 {
13         index = input.selectedIndex - 1;
14
15         if (index < 0 || index >= available_filters.length)
16                 return;
17
18         filter = available_filters[index];
19
20         value_element = document.getElementById("addfiltervalue");
21         value_element.innerHTML = filter.input_html;
22 }
23
24 function filter_form_submit(form)
25 {
26         filter_index = form.filtertype.selectedIndex - 1;
27
28         if (filter_index < 0 || filter_index >= available_filters.length)
29                 return false;
30
31         filter = available_filters[filter_index];
32
33         value = filter.fn(form);
34         updated = false;
35
36         form = document.forms.filterparams;
37
38         for (x = 0; x < form.elements.length; x++) {
39                 if (form.elements[x].name == filter.param) {
40                         form.elements[x].value = value;
41                         updated = true;
42                 }
43         }
44
45         if (!updated && value) {
46                 form.innerHTML = form.innerHTML +
47                         '<input type="hidden" name="' + filter.param +
48                         '" value="' + value + '"/>';
49         }
50
51         form.submit();
52
53         return false;
54 }
55
56
57 var submitter_input_prev_value = '';
58
59 function submitter_input_change(input)
60 {
61         value = input.value;
62
63         if (value.length < 3)
64                 return;
65
66         if (value == submitter_input_prev_value)
67                 return;
68
69         div = document.getElementById('submitter_complete');
70         div.innerHTML = value;
71         div.style.display = 'block';
72         div.style.position = 'relative';
73         div.style.top = '4em';
74         div.style.width = '15em';
75         div.style.background = '#f0f0f0';
76         div.style.padding = '0.2em';
77         div.style.border = 'thin solid red';
78 }