-/********************************************************************************
-* include/philter.js : philter javascript functions
-* ------------------
-*
-* This file is part of the philter distribution
-* Copyright: See COPYING files that comes with this distribution
-********************************************************************************/
-
-function text_onfocus(object,val) {
- if(object.value == val)
- object.value = '';
-}
-
-function text_onblur(object,val) {
- if(object.value == '')
- object.value = val;
-}
-
-function cleanChilds(Node, nbChilds) {
- while(Node.childNodes.length>nbChilds)
- Node.removeChild(Node.childNodes[nbChilds]);
-}
-
-/********** ORDER FORM FUNCTIONS **********/
-
-function order_up() {
- form = document.forms['order'];
- select = form.elements['order[select]'];
-
- if(select.selectedIndex>1) {
- i = select.selectedIndex;
- value1 = select.options[i].value;
- text1 = select.options[i].text;
- value2 = select.options[i-1].value;
- text2 = select.options[i-1].text;
-
- select.options[i] = new Option(text2,value2,false,false);
- select.options[i-1] = new Option(text1,value1,false,false);
- select.selectedIndex = i-1;
-
- form.elements['order['+value1+']'].value = i-1;
- form.elements['order['+value2+']'].value = i;
- }
-}
-
-function order_dn() {
- form = document.forms['order'];
- select = form.elements['order[select]'];
-
- if(select.selectedIndex>0 && select.selectedIndex<select.length-1) {
- i = select.selectedIndex;
- value1 = select.options[i].value;
- text1 = select.options[i].text;
- value2 = select.options[i+1].value;
- text2 = select.options[i+1].text;
-
- select.options[i] = new Option(text2,value2,false,false);
- select.options[i+1] = new Option(text1,value1,false,false);
- select.selectedIndex = i+1;
-
- form.elements['order['+value1+']'].value = i+1;
- form.elements['order['+value2+']'].value = i;
- }
-}
-
-function order_submit(obj) {
- if(obj.name == 'order[submit]')
- obj.form.elements['order[action]'].value = 'submit';
- if(obj.name == 'order[delete]')
- obj.form.elements['order[action]'].value = 'delete';
- obj.form.submit();
-}
-
-/********** RULE FORM GLOBALS **********/
-
-var matches_list = new Array();
-var matches_func = new Array();
-
-var actions_list = new Array()
-var actions_func = new Array();
-
-var mail_pool = new Array();
-var filter = new Array();
-
-var current_rule;
-
-var actions_i = 0;
-var matches_i = 0;
-
-/********** RULE.ACTION FORM FUNCTIONS **********/
-
-function createActionSelect(data,base) {
- var i,j;
- var select = document.createElement("select");
- select.name = base+'[0]';
-
- for(i=0, j=0; i<actions_list.length; i++)
- if(actions_list[i])
- select.options[j++] = new Option(actions_list[i],i,false,(data==i));
-
- select.setAttribute("onchange", "changeRow(this,actions_func)");
-
- if(select.selectedIndex<0)
- select.selectedIndex = 0;
- return select;
-}
-
-function createActionRow(Node,data) {
- var div = document.createElement("div");
- div.className = 'row';
- div.name = 'rule[actions]['+actions_i+']';
- actions_i++;
- Node.appendChild(div);
-
- var del = document.createElement("input");
- del.setAttribute("type", "submit");
- del.setAttribute("value", "Del");
- del.setAttribute("onclick", "parentNode.parentNode.removeChild(parentNode)");
- div.appendChild(del);
-
- div.appendChild(document.createTextNode(" "));
-
- var select = createActionSelect(data[0],div.name);
- div.appendChild(select);
-
- actions_func[select.options[select.selectedIndex].value](div,data);
-}
-
-function newAction() {
- createActionRow(document.all['actions_row'], 0);
-}
-
-/********** RULE.MATCH FORM FUNCTIONS **********/
-
-function createMatchSelect(data,base) {
- var i,j;
- var select = document.createElement("select");
- select.name = base+'[0]';
-
- for(i=0, j=0; i<matches_list.length; i++)
- if(matches_list[i])
- select.options[j++] = new Option(matches_list[i],i,false,(data==i));
-
- select.setAttribute("onchange", "changeRow(this,matches_func)");
-
- if(select.selectedIndex<0)
- select.selectedIndex = 0;
- return select;
-}
-
-function createMatchRow(Node,data) {
- var div = document.createElement("div");
- div.className = 'row';
- div.name = 'rule[matches]['+actions_i+']';
- actions_i++;
- Node.appendChild(div);
-
- var del = document.createElement("input");
- del.setAttribute("type", "submit");
- del.setAttribute("value", "Del");
- del.setAttribute("onclick", "parentNode.parentNode.removeChild(parentNode)");
- div.appendChild(del);
-
- div.appendChild(document.createTextNode(" "));
-
- var select = createMatchSelect(data[0],div.name);
- div.appendChild(select);
-
- matches_func[select.options[select.selectedIndex].value](div,data);
-}
-
-function newMatch() {
- createMatchRow(document.all['matches_row'], 0);
-}
-
-/********** RULE FORM FUNCTIONS **********/
-
-function changeRow(sel, funcs) {
- var row = sel.parentNode;
- cleanChilds(row,3);
- funcs[sel.options[sel.selectedIndex].value](row,0);
-}
-
-function createRuleForm() {
- var i;
- var sel = document.all['order[select]'];
- var index = sel.options[sel.selectedIndex].value;
-
- actions_i = matches_i = 0;
- current_rule = filter[index];
-
- document.all['rule[id]'].value = index;
- document.all['rule[name]'].value = current_rule.name;
- document.all['rule[all]'][1-current_rule.all].checked = true;
- document.all['rule[block]'].checked = current_rule.block;
-
- var mr = document.all['matches_row'];
- cleanChilds(mr,0);
- for(i=0; i<current_rule.matches.length; i++)
- createMatchRow(mr, current_rule.matches[i]);
-
- var ar = document.all['actions_row'];
- cleanChilds(ar,0);
- for(i=0; i<current_rule.actions.length; i++)
- createActionRow(ar, current_rule.actions[i]);
-}
-
-/********************************************************************************
-* $Id$
-* vim: set expandtab shiftwidth=4 tabstop=4 softtabstop=4 textwidth=100:
-********************************************************************************/