source: trunk/expressoMail1_2/js/jscode/filter.js @ 2668

Revision 2668, 23.2 KB checked in by amuller, 14 years ago (diff)

Ticket #1056 - Corrige problema do undefined e outros

Line 
1
2        function charCounter(form)
3        {
4                if (form.value.length >= 300)
5                {
6                        alert(get_lang("You have exceeded the number of allowed characters"));
7                        return false;
8                }
9        }
10
11        function cfilter(){
12
13                this.criticalError = false;
14                this.mode_in   = "";
15                this.rulest              = new Array;
16                this.rulesVoip   = new Array;
17                this.out_officeR = "";
18                this.out_officeF = false;
19                this.email_deny  = new Array;
20                this.ac_form     = "";
21                this.ind                 = "";
22                this.email_deny  = new Array;
23                this.email_ld    = "";
24                this.values = new Array("",
25                                        ",checkBox1",
26                                        ",select_size=1",
27                                        ",checkBox1,select_size=1",
28                                        ",select_rules=1",
29                                        ",checkBox1,select_rules=1",                           
30                                        ",select_size=1,select_rules=1",                               
31                                        ",checkBox1,select_size=1,select_rules=1",
32                                        ",checkBox2",                           
33                                        ",checkBox1,checkBox2",                         
34                                        ",checkBox2,select_size=1",
35                                        ",ckeckBox1,checkBox2,select_size=1",
36                                        ",checkBox2,select_rules=1",                                                                                                                                                           
37                                        ",checkBox1,checkBox2,select_rules=1",                         
38                                        ",checkBox2,select_size=1,select_rules=1",                             
39                                        ",checkBox1,checkBox2,select_size=1,select_rules=1");
40               
41        }
42
43       
44        cfilter.prototype.load_rules = function( posHandler, param )
45        {
46                var _this = this;
47                var cont1 = parseInt(0);
48                var cont2 = parseInt(0);
49                               
50                if( _this.rulest.length == 0 )
51                {
52                        var handler_sieve = function(data)
53                        {
54                                if (data.toString().indexOf('Error:') == 0)
55                                {
56                                        _this.criticalError = true;
57                                        alert(data);
58                                }
59                                else
60                                try{
61                                if(data.rule.length > 0){
62                                        for(var i=0 ; i < data.rule.length; i++)
63                                        {
64                                                var fields = data.rule[i].split("&&");
65                                                if( fields[6] == 'notify' && fields[7] == preferences.voip_email_redirect )
66                                                        _this.rulesVoip[cont1++] = data.rule[i];
67                                                else
68                                                        _this.rulest[cont2++] = data.rule[i];
69                                        }
70                                }
71                                _this.out_officeR = data.vacation[0];
72                                _this.out_officeR = _this.out_officeR ? trim(_this.out_officeR.toString().replace("\n","")) : "";
73                                if(data.mode.length > 0){_this.mode_in = data.mode[0];}
74                        }
75                                catch(e){
76                                        _this.criticalError = true;
77                                        alert("Expresso:"+e.description);
78                                }
79                                if (typeof(posHandler) == 'function')
80                                        posHandler(param);
81                        }
82                        if(Element('form_status') != null)
83                                Element('form_status').innerHTML = "<span style='background:#cc4444;'>&nbsp;&nbsp;<font color='WHITE'>Aguarde...</font>&nbsp;</span>";
84                        cExecute("expressoMail1_2.ScriptS.init_a",handler_sieve);
85                        _this.get_email();
86            }
87        }
88       
89        cfilter.prototype.form_m = function(){
90                Element('form_body').innerHTML = "";
91                Element('form_buttons').style.display = '';
92                filters.mount_list();
93                this.ac_form = "";             
94        }
95       
96        cfilter.prototype.form_out = function(){
97                Element('form_body').innerHTML = "";
98                Element('form_body').innerHTML = this.forms_();
99                Element('div_vacation').style.display = "";
100                this.ac_form = "old_out";               
101                this.r_rules_out();             
102        }
103       
104        cfilter.prototype.form_r = function(pos,type)
105        {
106                Element('form_body').innerHTML = "";
107                Element('form_body').innerHTML = this.forms_();
108                this.ind = pos;         
109               
110                if( type === 'voip')
111                {
112                        this.ac_form = "old_voip";
113                        Element('div_voipFilter').style.display = "";
114                        this.r_rules_form(pos, type);   
115                }
116                else
117                {
118                        this.ac_form = "old_rule";
119                        Element('div_rule').style.display = "";
120                        this.r_rules_form(pos, type);
121                }
122        }
123       
124        cfilter.prototype.get_email = function()
125        {
126                var _this = this;
127                var handler_get_email = function(data)
128                {
129                        _this.email_ld = data ? data : "";
130                }
131                cExecute("expressoMail1_2.user.get_email",handler_get_email);
132        }
133       
134        cfilter.prototype.sel_boxes = function()
135        {
136                var nm_folders = tree_folders.getNodesList(cyrus_delimiter);
137                if(document.getElementById("select_mailboxes") != null){
138                        var sel_nm = document.getElementById("select_mailboxes");
139                        if(sel_nm.length > 0 ){
140                                for(var i=0; i < sel_nm.options.length; i++){
141                                        sel_nm.options[i] = null;
142                                        i--;
143                                }
144                        }
145                        for(var i=0; i < nm_folders.length; i++){
146                                if(nm_folders[i].id != "root" && !proxy_mensagens.is_local_folder(nm_folders[i].id)){
147                                        var opt = new Option(nm_folders[i].caption,nm_folders[i].id,false,true);
148                                        sel_nm[sel_nm.length] = opt;
149                                }
150                        }
151                        sel_nm[0].selected = true;
152                }
153        }
154
155        cfilter.prototype.box_select = function(param){
156                var aux = this.BoxSelection[param].split(",");
157                var ele1 = document.getElementById(aux[0]);
158                var ele2 = document.getElementById(aux[1]);
159                var noption = "";
160                if(param == 0 || param == 1){
161                        if(ele1.selectedIndex != -1){
162                                noption = new Option(ele1.value,ele1.value,false,false);
163                                ele2.options[ele2.length] = noption;
164                                ele1.options[ele1.selectedIndex] = null;
165                                ele1.selectedIndex = 0;
166                        }
167                }
168        }
169
170        cfilter.prototype.r_rules_form = function(ind, type)
171        {
172                var fields = new Array;
173                var _this = this;
174               
175                // hide buttons
176                Element('form_buttons').style.display = 'none';
177               
178                if( type === 'voip')
179                {
180                        fields = _this.rulesVoip[ind].split("&&");
181                        document.getElementById("field9").value = fields[5];                   
182                }
183                else
184                {
185                        this.sel_boxes();
186                        if(this.rulest.length == 0){
187                                return false;
188                        }
189                        fields = _this.rulest[ind].split("&&");
190                        document.getElementById("field1").value = fields[3];
191                        document.getElementById("field2").value = fields[4];
192                        document.getElementById("field3").value = fields[5];
193                        document.getElementById("field4").value = fields[11];                           
194                       
195                        switch(fields[6]){
196                                case "folder":
197                                        document.getElementById("radio1").checked  = true;
198                                        var name_mb = fields[7];
199                                        var sel_mb = document.getElementById("select_mailboxes");
200                                        for(var i=0; i < sel_mb.options.length; i++){if((sel_mb.options[i].value) ==  name_mb){sel_mb.options[i].selected = true;}}
201                                        break;
202                                case "address":
203                                        document.getElementById("radio2").checked   = true;
204                                        document.getElementById("field5").value         = fields[7];
205                                        break;
206                                case "reject":
207                                         document.getElementById("radio3").checked  = true;
208                                         var text0 = fields[7].split("\\n");                                   
209                                         for(var i=0; i < text0.length; i++){document.getElementById("field6").value += text0[i] + "\n";}
210                                         break;
211                                case "discard":
212                                        document.getElementById("radio4").checked       = true;
213                                        break;
214                        }
215                        var mark_values = this.values[fields[8]].split(",");
216                        for(var i=0; i < mark_values.length; i++){
217                                if( mark_values[i] == "checkBox1" || mark_values[i] == "checkBox2"){
218                                        document.getElementById(mark_values[i]).checked = true;
219                                }
220                                if( mark_values[i] == "select_size=1" || mark_values[i] == "select_rules=1"){
221                                        var mark_val = mark_values[i].split("=");
222                                        document.getElementById(mark_val[0]).options[mark_val[1]].selected = true;
223                                }
224                        }
225                }
226        }
227
228        cfilter.prototype.r_rules_out = function(){
229       
230                var _this = this;
231                if(_this.out_officeR.length == 0){
232                        return false;
233                }
234               
235                // hide buttons
236                Element('form_buttons').style.display = 'none';
237       
238                var aux = _this.out_officeR.split("&&");
239                var days   = aux[1];
240                var emails = aux[2];
241                var mens   = aux[3];           
242                var p_emails = new Array;
243                var d_emails = new Array;
244                               
245                var p_aux = emails.split(", ");
246                for(var i=0; i < p_aux.length; i++){
247                        p_emails[i] = p_aux[i].substr(0,(p_aux[i].length - 1));
248                        p_emails[i] = p_emails[i].substr(1,(p_aux[i].length));
249                }
250                for(var i=0; i < _this.email_ld.length; i++){
251                        d_emails[i] = _this.email_ld[i];
252                }
253
254                diff = function(vet, comp){
255                        var sel1 = new Array;
256                        for(var i=0; i < vet.length; i++){
257                                for(var j=0; j < comp.length; j++){
258                                        if(vet[i] == comp[j]){
259                                                comp.splice(j,1);
260                                                j--;
261                                        }
262                                }
263                        }
264                };     
265                diff(p_emails,d_emails);
266                var text    = mens.split("\\n");
267                for(var i=0; i < text.length; i++){document.getElementById("field8").value += text[i] + " ";}
268                for(var i=0; i < _this.email_ld.length; i++){
269                        d_emails[i] = _this.email_ld[i];
270                }
271
272        }
273
274        /*
275         * Corrige bug 65, solução: desabilitar radio3 e field6 e desmarcar radio3 (ação de rejeição)
276         * quando a caixa de seleção para manter o e-mail na caixa de entrada do usuário for selecionada
277         */
278        cfilter.prototype.disable_radio3 =  function()
279        {
280                radio3 = Element('radio3');
281                field6 = Element('field6');
282                cb2 = Element('checkBox2');
283
284                if (cb2.checked)
285                {
286                        radio3.disabled = true;
287                        field6.disabled = true;
288
289                        if (radio3.checked)
290                        {
291                                radio3.checked = false;
292                        }
293                }
294                else
295                {
296                        radio3.disabled = false;
297                        field6.disabled = false;
298                }
299
300        }
301
302        cfilter.prototype.forms_ = function()
303        {
304                         var form = "";
305                                 form = "<div id='div_rule' style='display:none'><table id='table_rule' border='0' cellpading='0' cellspacing='0' width='100%'>"+
306                                                "<tr><td colspan='2'><input type='checkBox' id='checkBox1' name='checkb'>"+get_lang('Also check message against next rule') + "</td></tr>"+
307                                                "<tr><td colspan='2'><input type='checkBox' id='checkBox2' onclick='filter.disable_radio3();' name='checkb'>"+get_lang('Keep a copy of the message at your Inbox')+ "</td><tr>"+
308                                                "<tr><td colspan='2'><hr size='1' width='100%'></td></tr><tr>"+
309                                                "<td rowspan='4' width='20%'>"+get_lang('Coincident')+"<br><select id='select_rules' name='select_rules'>"+
310                                                "<option value='0'>"+get_lang("with all")+"</option><option value='1'>"+get_lang("with some")+"</option>"+
311                                                "</select></td><td>"+get_lang('The field \"%1\" of the message it contains',get_lang('From'))+".: <input type='text' id='field1' name='field1' size='35' maxlength='200'></td>"+
312                                                "</tr><tr><td>"+get_lang('The field \"%1\" of the message it contains', get_lang('To'))+".: <input type='text' id='field2' name='field2' size='35' maxlength='200'></td>"+
313                                                "</tr><tr><td>"+get_lang('The field \"%1\" of the message it contains', get_lang('Subject'))+".: <input type='text' id='field3' name='field3' size='35' maxlength='200'></td>"+
314                                                "</tr><tr><td>"+get_lang('The size of the message is')+".: &nbsp<select id='select_size' name='select_size'>"+
315                                                "<option value='0'>"+get_lang("Less than")+"</option><option value='1'>"+get_lang("Greater than")+"</option>"+                                           
316                                                "</select>&nbsp;<input type='text' id='field4' name='field4' size='8' maxlength='8'> Kb</td>"+
317                                                "</tr><tr><td colspan='2'><hr size='1' width='100%'></td></tr>"+
318                                                "</table><table id='table_rule1' border='0' cellpading='0' cellspacing='0' width='100%'>"+
319                                                "<tr><td width='50%'><input type='radio' id='radio1' name='radio' value='folder'>"+get_lang('Store at')+".:</td>"+
320                                                "<td width='50%'><select id='select_mailboxes' name='select_mailboxes'></select></td>"+
321                                                "</tr><tr><td width='50%'><input type='radio' id='radio2' name='radio' value='address'>"+get_lang('Forward to the address')+".:</td>"+
322                                                "<td width='50%'><input type='text' id='field5' name='field5' size='35' maxlength='70'></td>"+
323                                                "</tr><tr><td width='50%'><input type='radio' id='radio3' name='radio' value='reject'>"+get_lang('Send a rejection message')+".:</td>"+
324                                                "<td width='50%'><textarea id='field6' onkeypress='return charCounter(this);' name='field6' rows='3' cols='25'></textarea></td>"+
325                                                "</tr><tr><td colspan='2'><input type='radio' id='radio4' name='radio' value='discard'>"+get_lang('Erase the message')+"</td>"+
326                                                "</tr></table></div><div id='div_vacation' style='display:none'>"+
327                                                "<table id='table_vacation' border='0' cellpading='0' cellspacing='0' width='100%'>"+
328                                                "<tr><td colspan='3'><br><b>"+get_lang('out office')+"</b></td></tr>"+
329                                                //"<tr><td colspan='3'><br>"+get_lang('Subject')+".: <input type='text' id='field7' name='field7' size='35' maxlength='200'/></td></tr>"+
330                                                "<tr><td colspan='3'><br>"+get_lang('With the following message')+".:</td>"+
331                                                "</tr><tr><td colspan='3'><textarea id='field8' onkeypress='return charCounter(this);' rows='8' cols='50'></textarea></td></tr></table></div>" +
332                                                "<div id='div_voipFilter' style='display:none'>" +
333                                                "<br/><table id='table_voipFilter'>" +
334                                                "<tr><td>"+get_lang("Type the subject of the message for receiving a phone warning")+" .:"+
335                                                "</td></tr><tr><td><input type='text' id='field9' size='50' maxlength='200'>" +
336                                                "</td></tr><br/></table></div>" +
337                                                "<span align='right'><input type='button' value="+get_lang("Back")+" onclick='filter.form_m()'></span>"+
338                                                "<span align='right'><input type='button' value="+get_lang("Save")+" onclick='filter.saved_rules()'></span>";
339                return form;
340        }
341
342        cfilter.prototype.enabled_disabled = function(param){
343
344                // Rules
345                if(Element("rule_0") != null){
346                        for(var i=0; i < this.rulest.length; i++){
347                                if(Element("rule_"+i).checked){
348                                        var aux_rul = this.rulest[i].split("&&");
349                                        if(aux_rul[2] != param){
350                                                aux_rul[2] = param;                                     
351                                                var rl = "";
352                                                for(var j=0; j < aux_rul.length; j++){
353                                                        rl += aux_rul[j] + "&&";
354                                                }
355                                                rl = rl.substr(0,(rl.length - 2));
356                                                this.rulest[i] = rl;                                   
357                                        }
358                                }
359                        }
360                }
361                // Out Office
362                if(Element("out_0") != null){
363                        if(Element("out_0").checked){
364                                var aux_out = this.out_officeR.split("&&");
365                                if(param == "ENABLED")
366                                        aux_out[4] = "on ";
367                                else
368                                        aux_out[4] = "off";
369                                var out = "";
370                                for(var i=0; i < aux_out.length; i++){
371                                        out += aux_out[i] + "&&";
372                                }                               
373                                out = out.substr(0,(out.length - 2));
374                                this.out_officeR = out;
375                        }
376                }
377
378                // Voip
379                if(Element("voip_rule_0") != null){
380                        for(var i=0; i < this.rulesVoip.length; i++){
381                                if(Element("voip_rule_"+i).checked){
382                                        var aux_rul = this.rulesVoip[i].split("&&");
383                                        if(aux_rul[2] != param){
384                                                aux_rul[2] = param;                                     
385                                                var rl = "";
386                                                for(var j=0; j < aux_rul.length; j++){
387                                                        rl += aux_rul[j] + "&&";
388                                                }
389                                                rl = rl.substr(0,(rl.length - 2));
390                                                this.rulesVoip[i] = rl;                                 
391                                        }
392                                }
393                        }
394                }
395               
396                this.reload_rules();
397        }
398       
399        cfilter.prototype.new_rule = function(email){
400                var createFilter = function (param){
401                        if(filter.rulest.length > 0){
402                                var blockedReg = new RegExp('#rule&&[0-9]+&&ENABLED&&'+param+'&&&&&&discard&&&&0&&&&&&0');
403                                for(var i=0 ; i < filter.rulest.length; i++){
404                                        if(blockedReg.test(filter.rulest[i])){
405                                                alert(get_lang("Sender blocked")+"!");
406                                                return false;
407                                        }
408                                }
409                        }
410                        if(confirm(get_lang("Do you want to block this e-mail?"))){
411                                new_r = "&&ENABLED&&" + param + "&&&&&&discard&&&&0&&&&&&0";
412                                //setTimeout("filter.e_newrule('" + new_r + "')",2000);         
413                                if (filter.e_newrule(new_r)){
414                                        filter.email_deny.push(param);
415                                        write_msg(get_lang("The sender was blocked"));                                                 
416                                }else
417                                        write_msg(get_lang("You have reached the maximum number of rules"));
418                        }
419                };
420                if ( filter.rulest.length > 0 )
421                        createFilter(email);
422                else
423                        this.load_rules( createFilter, email );
424        }
425       
426        cfilter.prototype.e_newrule = function(nw_rule)
427        {
428
429                var new_rl = "";
430                if (this.rulest.length >= rules_limit)
431                        return false;
432                       
433                if(this.rulest.length == 0){
434                        new_rl = "#rule&&1" + nw_rule;
435                }else{
436                        var aux = this.rulest[this.rulest.length -1 ].split("&&");
437                        new_rl = "#rule&&" + (parseInt(aux[1]) + parseInt(2)) + nw_rule;
438                }
439                this.rulest.push(new_rl);
440                this.saved_all();
441                return true;
442        }
443       
444        cfilter.prototype.delete_r = function(){
445       
446                // rule
447                var _this = this;
448                if(Element("rule_0") != null){
449                        for(var i=0; i < _this.rulest.length; i++){
450                                if(Element("rule_"+i).checked){_this.rulest[i] = "delete";}
451                        }
452                        for(var i=0; i < _this.rulest.length; i++){
453                                if(_this.rulest[i] == "delete"){_this.rulest.splice(i,1);i--;}
454                        }
455                }
456       
457                if(_this.rulest.length > 0){
458                        var cont = parseInt(1);
459                        for(var i=0; i < _this.rulest.length ; i++){
460                                var n_rulest = _this.rulest[i].split("&&");
461                                n_rulest[1] = cont;
462                                cont = cont + parseInt(2);
463                                var aux = "";
464                                for(var j=0; j < n_rulest.length; j++){aux += n_rulest[j] + "&&";}
465                                aux = aux.substr(0,(aux.length - 2));
466                                _this.rulest[i] = aux;
467                        }
468                }
469                // out office
470                if(Element("out_0") != null){
471                        if(Element("out_0").checked){
472                                _this.out_officeR ='';
473                                _this.out_officeF = false;
474                                //Save outoffice in prefs:
475                                expresso.connector.loadScript("jscode/preferences");
476                                prefe.save("outoffice", _this.out_officeF);
477                        }
478                }
479               
480                // Voip
481                if(Element("voip_rule_0") != null){
482                        for(var i=0; i < _this.rulesVoip.length; i++){
483                                if(Element("voip_rule_"+i).checked){_this.rulesVoip[i] = "delete";}
484                        }
485                        for(var i=0; i < _this.rulesVoip.length; i++){
486                                if(_this.rulesVoip[i] == "delete"){_this.rulesVoip.splice(i,1);i--;}
487                        }
488                }
489       
490                if(_this.rulesVoip.length > 0){
491                        var cont = parseInt(1);
492                        for(var i=0; i < _this.rulesVoip.length ; i++){
493                                var n_rulest = _this.rulesVoip[i].split("&&");
494                                n_rulest[1] = cont;
495                                cont = cont + parseInt(2);
496                                var aux = "";
497                                for(var j=0; j < n_rulest.length; j++){aux += n_rulest[j] + "&&";}
498                                aux = aux.substr(0,(aux.length - 2));
499                                _this.rulesVoip[i] = aux;
500                        }
501                }
502
503                _this.reload_rules();
504        }
505       
506        cfilter.prototype.reload_rules = function()
507        {
508                this.saved_all();
509                Element('form_body').innerHTML = "";
510                this.load_rules();
511
512                if(this.out_officeF)
513                {
514                        write_msg(get_lang("Attention, you are in out of office mode."), true);
515                }else{
516                        clean_msg();
517                        this.out_officeF = false;
518                }
519                filters.mount_list();
520        }
521
522        cfilter.prototype.saved_rules = function(){
523
524                var mount_rule = "";
525                var form = this.ac_form.split("_");
526                var n_rule = "";
527
528                if(form[1] == "rule")
529                {
530                        mount_rule = "#rule&&";
531                        if(form[0] == "new")
532                        {
533                                n_rule = "1&&";
534                                if(this.rulest.length > 0)
535                                {
536                                        aux = this.rulest[this.rulest.length - parseInt(1)].split("&&");
537                                        n_rule = (parseInt(aux[1]) + parseInt(2)) + "&&";
538                                }
539                                mount_rule += n_rule + "ENABLED&&";
540                        }
541                        else
542                        {
543                                n_rule = this.rulest[this.ind].split("&&");
544                                mount_rule += n_rule[1] + "&&";
545                                mount_rule += n_rule[2] + "&&";
546                        }
547
548                        if(LTrim(Element("field1").value) == "" && LTrim(Element("field2").value) == "" && LTrim(Element("field3").value) == "" && Element("field4").value == "")
549                        {
550                                alert(get_lang("Define some criterion to the fields Sender, To and Subject with more than 3 characters!"));
551                                return false;
552                        }
553
554                        if((LTrim(Element("field1").value).length <= 3) && (LTrim(Element("field2").value).length <= 3) && (LTrim(Element("field3").value).length <= 3 && Element("field4").value == "")){
555                                alert(get_lang("Define some criterion to the fields Sender, To and Subject with more than 3 characters!"));
556                                return false;
557                        }
558                       
559                        for(var i=1; i < 4; i++){mount_rule += LTrim(Element("field"+i).value) + "&&";}
560                        var v_checked = false;
561                        if(Element("radio1").checked){
562                                mount_rule += "folder&&";
563                                var sel_nameBox = Element("select_mailboxes");
564                                for(var i=0; i < sel_nameBox.options.length; i++){if(sel_nameBox.options[i].selected == true){mount_rule += sel_nameBox.options[i].value + "&&";}}
565                                v_checked = true;
566                        }
567                        if(Element("radio2").checked){
568                                mount_rule += "address&&";
569                                if(Element("field5").value == ""){
570                                        alert(get_lang("Inform a forwarding e-mail!"));
571                                        return false;
572                                }else{
573                                        var emailReg = /^[a-z][a-z-_0-9\.]+@[a-z-_=>0-9\.]+\.[a-z]{2,3}$/i
574                                if(emailReg.test(Element("field5").value)){
575                                                mount_rule += Element("field5").value + "&&";
576                                        }else{
577                                                alert(get_lang("Inform a valid e-mail!"));
578                                                return false;
579                                        }
580                                }
581                                v_checked = true;
582                        }
583                        if(Element("radio3").checked){
584                                mount_rule += "reject&&";
585                                if(Element("field6").value == ""){
586                                        alert(get_lang("Inform a text for rejection!"));
587                                        return false;
588                                }else{
589                                        mount_rule += Element("field6").value + "&&";
590                                }
591                                v_checked = true;
592                        }                               
593                        if(Element("radio4").checked){
594                                mount_rule += "discard&&&&";
595                                v_checked = true;
596                        }
597                        if(!v_checked){
598                                alert(get_lang("No option marked!"));
599                                return false;
600                        }
601                        var opts = "";
602                        if(Element("checkBox1").checked == true){opts += ",checkBox1";}
603                        if(Element("checkBox2").checked == true){opts += ",checkBox2";}
604                        if(Element("select_size").options[1].selected == true){opts += ",select_size=1";}
605                        if(Element("select_rules").options[1].selected == true){opts += ",select_rules=1";}
606                        for(var i=0; i < this.values.length; i++){if(this.values[i] == opts){mount_rule += i + "&&";}}
607                        mount_rule += "&&&&";
608                        if(LTrim(Element("field4").value) != ""){
609                                mount_rule += LTrim(Element("field4").value);
610                        }else{
611                                mount_rule += 0;
612                        }
613                        if(form[0] == "new")
614                        {
615                                this.rulest[this.rulest.length] = mount_rule;
616                        }
617                        else
618                                this.rulest[this.ind] = mount_rule;
619                }
620                else if(form[1] == "out")
621                {
622                        mount_rule = "";
623                        var fld_emails = this.email_ld; // Get first email of list!
624                        var fld_men        = Element("field8");
625                        mount_rule = "#vacation&&";
626                        mount_rule += "1&&";
627                        mount_rule += "\"" + fld_emails + "\", ";                       
628                        mount_rule = mount_rule.substr(0,(mount_rule.length - 2));
629                        mount_rule += "&&";
630                        mount_rule += fld_men.value + "&&on";
631                        if(LTrim(fld_men.value) == ""){
632                                alert(get_lang("Inform a message!"));
633                                return false;
634                        }
635                        this.out_officeR = mount_rule;
636                }
637                else if(form[1] == "voip")
638                {
639                        if( Element("field9").value != "" && LTrim(Element("field9").value) != "" )
640                        {
641                                mount_rule = "#rule&&";
642                                if(form[0] == "new")
643                                {
644                                        n_rule = "1&&";
645                                        if( this.rulesVoip.length > 0 )
646                                        {
647                                                aux = this.rulesVoip[this.rulesVoip.length - parseInt(1)].split("&&");
648                                                n_rule = (parseInt(aux[1]) + parseInt(2)) + "&&";
649                                        }
650                                        mount_rule += n_rule + "ENABLED&&";
651                                }
652                                else
653                                {
654                                        n_rule = this.rulesVoip[this.ind].split("&&");
655                                        mount_rule += n_rule[1] + "&&";
656                                        mount_rule += n_rule[2] + "&&";
657                                }
658
659                                if ( Element("field9").value.indexOf("#") >= 0 )
660                                {
661                                        alert(get_lang('Caracter "#" is not allowed!'));
662                                        return false;
663                                }
664                               
665                                mount_rule = mount_rule + "&&&&" + Element("field9").value + "&&notify&&" + preferences.voip_email_redirect + "&&8&&&&&&0";
666
667                                if( form[0] == "new" )
668                                {
669                                        this.rulesVoip[this.rulesVoip.length] = mount_rule;
670                                }
671                                else
672                                {
673                                        this.rulesVoip[this.ind] = mount_rule;
674                                }
675                        }
676                        else
677                        {
678                                alert( 'CAMPOS EM BRANCO !!' );
679                                return false;
680                        }
681                }
682               
683                Element('form_buttons').style.display = '';
684                this.reload_rules();
685        }
686
687        cfilter.prototype.close_frm= function()
688        {
689                filters.filter_Sh['window_ffilter_ccform'].close();
690        }
691       
692        cfilter.prototype.saved_all = function()
693        {
694                var aux_rul = "";
695                var _this = this;
696                var cont = 0;
697               
698                // Regras Gerais
699                if(_this.rulest.length > 0)
700                {
701                        for(var i=0; i < _this.rulest.length; i++)
702                        {
703                                var fieldsNormal = _this.rulest[i].split("&&");                         
704                                aux_rul += "_begin_##";
705                                for(var j=0 ; j < fieldsNormal.length; j++)
706                                {
707                                        aux_rul += url_encode(fieldsNormal[j]) + "##";
708                                        cont = parseInt(fieldsNormal[1]);                                       
709                                }       
710                                aux_rul += "_end_\n";
711                        }
712                }
713       
714                // Voip
715                if(_this.rulesVoip.length > 0)
716                {
717                        for(var i=0; i < _this.rulesVoip.length; i++)
718                        {
719                                var fieldsVoip = _this.rulesVoip[i].split("&&");
720                                aux_rul += "_begin_##";
721                                for(var j=0 ; j < fieldsVoip.length; j++)
722                                {
723                                        if(j == 1)
724                                        {
725                                                if( cont == 0 )
726                                                        cont = parseInt(1);
727                                                else
728                                                        cont = parseInt(cont) + parseInt(2);
729                                                aux_rul += cont;
730                                                aux_rul += "##";
731                                        }
732                                        else
733                                                aux_rul += url_encode(fieldsVoip[j]) + "##";
734                                }
735                                aux_rul += "_end_\n";
736                        }
737                }
738               
739                // Fora do Escritório
740                if(_this.out_officeR.length > 0)
741                {
742                                var aux = _this.out_officeR.split("&&");                               
743                                aux_rul += "_begin_##";
744                                for(var j=0 ; j < aux.length; j++)
745                                {
746                                        aux_rul += url_encode(aux[j]) + "##";                                   
747                                }       
748                                aux_rul += "_end_\n";
749                                _this.out_officeF = (aux[4].replace("\n","") === "off") ? false : true;
750                                //Save outoffice in prefs:
751                                expresso.connector.loadScript("jscode/preferences");
752                                prefe.save("outoffice", _this.out_officeF);
753                }
754               
755                var h_filter = function(data)
756                {
757                        if(data != "Ok"){alert("Erro : \n" + data);}
758                }
759                var args   = "expressoMail1_2.ScriptS.rec_rules";
760                var params = "arfilter="+aux_rul;
761                if(!_this.criticalError)
762                        cExecute(args,h_filter,params);
763        }
764
765// build object
766   var filter;
767   filter = new cfilter();
Note: See TracBrowser for help on using the repository browser.