Opera7 compatibility cvs upcvs upcvs upcvs up! some IE ameliorations, still
[old-projects.git] / philter / philter / include / philter.js
CommitLineData
dd8de1ec
PH
1/********************************************************************************
2* include/philter.js : philter javascript functions
3* ------------------
4*
5* This file is part of the philter distribution
6* Copyright: See COPYING files that comes with this distribution
7********************************************************************************/
8
693b6ec6
PH
9function ta_onfocus(obj) {
10 obj.setAttribute('rows', '10');
11}
12
13function ta_onblur(obj) {
14 obj.setAttribute('rows', '2');
15}
16
dd8de1ec
PH
17function text_onfocus(object,val) {
18 if(object.value == val)
19 object.value = '';
20}
21
22function text_onblur(object,val) {
23 if(object.value == '')
24 object.value = val;
25}
26
27function cleanChilds(Node, nbChilds) {
28 while(Node.childNodes.length>nbChilds)
29 Node.removeChild(Node.childNodes[nbChilds]);
30}
31
693b6ec6
PH
32function getElement(obj, index) {
33 if(document.getElementById)
34 return document.getElementById(obj);
3e328a2d 35 if(document.all)
693b6ec6 36 return document.all[obj];
0aa1a917
PH
37}
38
dd8de1ec
PH
39/********** ORDER FORM FUNCTIONS **********/
40
41function order_up() {
42 form = document.forms['order'];
43 select = form.elements['order[select]'];
44
45 if(select.selectedIndex>1) {
46 i = select.selectedIndex;
47 value1 = select.options[i].value;
48 text1 = select.options[i].text;
49 value2 = select.options[i-1].value;
50 text2 = select.options[i-1].text;
51
52 select.options[i] = new Option(text2,value2,false,false);
53 select.options[i-1] = new Option(text1,value1,false,false);
54 select.selectedIndex = i-1;
55
56 form.elements['order['+value1+']'].value = i-1;
57 form.elements['order['+value2+']'].value = i;
58 }
59}
60
61function order_dn() {
62 form = document.forms['order'];
63 select = form.elements['order[select]'];
64
65 if(select.selectedIndex>0 && select.selectedIndex<select.length-1) {
66 i = select.selectedIndex;
67 value1 = select.options[i].value;
68 text1 = select.options[i].text;
69 value2 = select.options[i+1].value;
70 text2 = select.options[i+1].text;
71
72 select.options[i] = new Option(text2,value2,false,false);
73 select.options[i+1] = new Option(text1,value1,false,false);
74 select.selectedIndex = i+1;
75
76 form.elements['order['+value1+']'].value = i+1;
77 form.elements['order['+value2+']'].value = i;
78 }
79}
80
81function order_submit(obj) {
82 if(obj.name == 'order[submit]')
83 obj.form.elements['order[action]'].value = 'submit';
84 if(obj.name == 'order[delete]')
85 obj.form.elements['order[action]'].value = 'delete';
86 obj.form.submit();
87}
88
89/********** RULE FORM GLOBALS **********/
90
91var matches_list = new Array();
92var matches_func = new Array();
93
94var actions_list = new Array()
95var actions_func = new Array();
96
97var mail_pool = new Array();
98var filter = new Array();
99
100var current_rule;
101
102var actions_i = 0;
103var matches_i = 0;
104
105/********** RULE.ACTION FORM FUNCTIONS **********/
106
107function createActionSelect(data,base) {
108 var i,j;
109 var select = document.createElement("select");
110 select.name = base+'[0]';
111
112 for(i=0, j=0; i<actions_list.length; i++)
113 if(actions_list[i])
114 select.options[j++] = new Option(actions_list[i],i,false,(data==i));
115
116 select.setAttribute("onchange", "changeRow(this,actions_func)");
117
118 if(select.selectedIndex<0)
119 select.selectedIndex = 0;
120 return select;
121}
122
123function createActionRow(Node,data) {
124 var div = document.createElement("div");
125 div.className = 'row';
126 div.name = 'rule[actions]['+actions_i+']';
127 actions_i++;
128 Node.appendChild(div);
129
130 var del = document.createElement("input");
131 del.setAttribute("type", "submit");
132 del.setAttribute("value", "Del");
133 del.setAttribute("onclick", "parentNode.parentNode.removeChild(parentNode)");
134 div.appendChild(del);
135
136 div.appendChild(document.createTextNode(" "));
137
138 var select = createActionSelect(data[0],div.name);
139 div.appendChild(select);
140
141 actions_func[select.options[select.selectedIndex].value](div,data);
142}
143
144function newAction() {
693b6ec6 145 createActionRow(getElement('actionsRow'), [-1]);
dd8de1ec
PH
146}
147
148/********** RULE.MATCH FORM FUNCTIONS **********/
149
150function createMatchSelect(data,base) {
151 var i,j;
152 var select = document.createElement("select");
153 select.name = base+'[0]';
154
155 for(i=0, j=0; i<matches_list.length; i++)
156 if(matches_list[i])
157 select.options[j++] = new Option(matches_list[i],i,false,(data==i));
158
159 select.setAttribute("onchange", "changeRow(this,matches_func)");
160
161 if(select.selectedIndex<0)
162 select.selectedIndex = 0;
163 return select;
164}
165
166function createMatchRow(Node,data) {
167 var div = document.createElement("div");
168 div.className = 'row';
169 div.name = 'rule[matches]['+actions_i+']';
170 actions_i++;
171 Node.appendChild(div);
172
173 var del = document.createElement("input");
174 del.setAttribute("type", "submit");
175 del.setAttribute("value", "Del");
176 del.setAttribute("onclick", "parentNode.parentNode.removeChild(parentNode)");
177 div.appendChild(del);
178
179 div.appendChild(document.createTextNode(" "));
180
181 var select = createMatchSelect(data[0],div.name);
182 div.appendChild(select);
183
184 matches_func[select.options[select.selectedIndex].value](div,data);
185}
186
187function newMatch() {
693b6ec6 188 createMatchRow(getElement('matchesRow'), [-1]);
dd8de1ec
PH
189}
190
191/********** RULE FORM FUNCTIONS **********/
192
193function changeRow(sel, funcs) {
194 var row = sel.parentNode;
195 cleanChilds(row,3);
196 funcs[sel.options[sel.selectedIndex].value](row,0);
197}
198
199function createRuleForm() {
200 var i;
0aa1a917 201 var sel = getElement('order[select]');
dd8de1ec
PH
202 var index = sel.options[sel.selectedIndex].value;
203
204 actions_i = matches_i = 0;
205 current_rule = filter[index];
206
0aa1a917
PH
207 getElement('rule[id]').value = index;
208 getElement('rule[name]').value = current_rule.name;
693b6ec6
PH
209 var c = (current_rule.all ? '1' : '0');
210 getElement('rule[all'+c+']').checked = true;
0aa1a917 211 getElement('rule[block]').checked = current_rule.block;
dd8de1ec 212
693b6ec6 213 var mr = getElement('matchesRow');
dd8de1ec
PH
214 cleanChilds(mr,0);
215 for(i=0; i<current_rule.matches.length; i++)
216 createMatchRow(mr, current_rule.matches[i]);
217
693b6ec6 218 var ar = getElement('actionsRow');
dd8de1ec
PH
219 cleanChilds(ar,0);
220 for(i=0; i<current_rule.actions.length; i++)
221 createActionRow(ar, current_rule.actions[i]);
222}
223
224/********************************************************************************
225* $Id$
226* vim: set expandtab shiftwidth=4 tabstop=4 softtabstop=4 textwidth=100:
227********************************************************************************/