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

Revision 2519, 22.7 KB checked in by rodsouza, 14 years ago (diff)

Ticket #1009 - Permitindo que o ExpressoMail? não realize reload de página.

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