source: branches/2.0/expressoMail1_2/js/filter.js @ 2658

Revision 2658, 23.0 KB checked in by niltonneto, 14 years ago (diff)

Ticket #1056 - Corrigido problema que remove todas as regras ao criar um nova.

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