Templatize sieve rules editor; return success/fail state of serverwrite
[citadel.git] / webcit / static / t / sieve / display.html
1
2 /*
3  * This script should get called by every onChange event...
4  *
5  */
6 <script type="text/javascript">
7
8 var highest_active_rule = (-1);
9
10 function UpdateRules() {
11 /*
12  * Show only the active rows...
13  */
14   highest_active_rule = (-1);
15   for (i=0; i< <?SIEVE:MAX_RULES>; ++i) {
16    if ($('active'+i).checked) {
17      $('rule' + i).style.display = 'block';
18      highest_active_rule = i;
19    }
20    else {
21      $('rule' + i).style.display = 'none';
22    }
23   }
24 /*
25  * Show only the fields relevant to the rules...
26  */
27   for (i=0; i<=highest_active_rule; ++i) {
28     d = ($('movedown'+i));
29     if (i < highest_active_rule) {
30       d.style.display = 'block';
31     }
32     else {
33       d.style.display = 'none';
34     }
35     d = ($('hfield'+i).options[$('hfield'+i).selectedIndex].value);
36     if (d == 'all') {
37       $('div_size'+i).style.display = 'none';    
38       $('div_compare'+i).style.display = 'none';
39       $('div_nocompare'+i).style.display = 'block';
40     }
41     else if (d == 'size') {
42       $('div_size'+i).style.display = 'block';   
43       $('div_compare'+i).style.display = 'none';
44       $('div_nocompare'+i).style.display = 'none';
45     }
46     else {
47       $('div_size'+i).style.display = 'none';    
48       $('div_compare'+i).style.display = 'block';
49       $('div_nocompare'+i).style.display = 'none';
50     }
51     d = ($('action'+i).options[$('action'+i).selectedIndex].value);
52     if (d == 'fileinto') {
53       $('div_fileinto'+i).style.display = 'block';
54       $('div_redirect'+i).style.display = 'none';
55       $('div_automsg'+i).style.display = 'none';
56     } else if (d == 'redirect') {
57       $('div_fileinto'+i).style.display = 'none';
58       $('div_redirect'+i).style.display = 'block';
59       $('div_automsg'+i).style.display = 'none';
60     } else if ((d == 'reject') || (d == 'vacation'))  {
61       $('div_fileinto'+i).style.display = 'none';
62       $('div_redirect'+i).style.display = 'none';
63       $('div_automsg'+i).style.display = 'block';
64     } else {
65       $('div_fileinto'+i).style.display = 'none';
66       $('div_redirect'+i).style.display = 'none';
67       $('div_automsg'+i).style.display = 'none';
68     }
69     if (highest_active_rule < <?SIEVE:MAX_RULES> - 1) {
70       $('div_addrule').style.display = 'block';
71     } else {
72       $('div_addrule').style.display = 'none';
73     }
74   }
75 }
76 /*
77  * Add a rule (really, just un-hide it)
78  */
79 function AddRule() {
80   highest_active_rule = highest_active_rule + 1;
81   $('active'+highest_active_rule).checked = true;
82   UpdateRules();
83 }
84 /*
85  * Swap two rules
86  */
87 function SwapRules(ra, rb) {
88
89   var things = new Array();
90   things[0] = 'hfield';
91   things[1] = 'compare';
92   things[2] = 'htext';
93   things[3] = 'action';
94   things[4] = 'fileinto';
95   things[5] = 'redirect';
96   things[6] = 'final';
97   things[7] = 'sizecomp';
98   things[8] = 'sizeval';
99   things[9] = 'automsg';
100
101   for (i=0; i<=9; ++i) {
102     tempval=$(things[i]+ra).value;
103     $(things[i]+ra).value = $(things[i]+rb).value;
104     $(things[i]+rb).value = tempval;
105   }
106 }
107 /*
108  * Delete a rule (percolate the deleted rule out to the end, then deactivate it)
109  */
110 function DeleteRule(rd) {
111   for (j=rd; j<=highest_active_rule; ++j) {
112     SwapRules(j, (j+1));
113   }
114   $('active'+highest_active_rule).checked = false;
115 }
116 </script>
117
118
119 <br>
120
121 <div id="div_addrule"><a href="javascript:AddRule();"><?_("Add rule")></a><br></div>
122 <script type="text/javascript">UpdateRules();</script>
123