source: trunk/expressoMail1_2/js/search.js @ 1477

Revision 1477, 28.0 KB checked in by eduardoalex, 14 years ago (diff)

Ticket #611 - Adição da funcionalidade. (aqui é para completar os 40 caracteres)

  • Property svn:eol-style set to native
  • Property svn:executable set to *
Line 
1/**************************************************************************\
2 Início
3\**************************************************************************/
4        function searchE()
5        {
6                this.searchW   = new Array;
7                this.name_box_search = "";
8                this.all_boxes = new Array;
9                this.type = "";
10                this.fields = new Array("_ass","_de","_body","_para","_cc","_cco");
11        }
12       
13        //Monta os forms dentro da janela;
14        searchE.prototype.showForms = function(value){
15                // Principal
16                if(!Element("window_search")) {
17                        var form_search = document.createElement("DIV");
18                        form_search.style.visibility = 'hidden';
19                        form_search.style.top = '0px';
20                        form_search.style.left = '0px';
21                        form_search.id = "window_search";
22                        document.body.appendChild(form_search);                 
23                }
24               
25                // Pesquisa
26                if(!Element("div_form_search")){
27                        var div_form_search = document.createElement("DIV");
28                        div_form_search.id = "div_form_search";
29                        div_form_search.style.position = "absolute";
30                        div_form_search.style.left = "10px";
31                        div_form_search.style.top  = "10px";
32                        div_form_search.style.width = "770px";
33                        div_form_search.style.height = "300px";
34                        div_form_search.style.overflow = "hidden";
35                        div_form_search.innerHTML = "";
36                        var call_form_search = EsearchE.mount_form();
37                        div_form_search.appendChild(call_form_search);
38                        form_search.appendChild(div_form_search);
39
40                }       
41               
42                if(!Element("div_button_search")){
43                        var div_button_search    = document.createElement("DIV");
44                                div_button_search.id = "div_button_search";
45                                div_button_search.style.position = "absolute";
46                                div_button_search.style.left = "10px";
47                                div_button_search.style.top = "223px";
48                                div_button_search.style.width = "615px";
49                                div_button_search.style.height = "25px";
50                                div_button_search.innerHTML = "<table border='0' width='50%' cellpadding='0' cellspacing='0' align='right'>"+
51                                                                                          "<tr>"+
52                                                                                          "<td><input type='button' value=" + get_lang('Search') + " onclick='EsearchE.func_search()'></td>"+
53                                                                                          "<td><input type='button' value=" + get_lang('Clean') + " onclick='EsearchE.func_clean()'></td>"+
54                                                                                          "<td><input type='button' value=" + get_lang('Close') + " onclick='EsearchE.func_close(\"hidden\")'></td>"+
55                                                                                          "</tr>"+
56                                                                                          "</table>";
57                                form_search.appendChild(div_button_search);
58                }
59               
60                if(!Element("table_layer")){
61                        var table_layer    = "";
62                }
63               
64                if(value == "")
65                        EsearchE.showWindow(Element("window_search"));
66       
67                // Cria as caixas postais;
68                EsearchE.mount_folders();
69
70                if(value){
71                        Element("check_all_msg").checked = true;
72                        EsearchE.all_mailboxes();
73                        EsearchE.func_search(value);
74                }
75
76        }
77       
78        //Form
79        searchE.prototype.mount_form = function(value){
80                var form_sch = document.createElement("FORM");
81                form_sch.id  = "form_sch";
82
83                form_sch.innerHTML =  '<fieldset style="width:266px; text-align:right; padding: 5px; position:absolute;">'
84                                                        + '     <legend>'+get_lang('Inform your search in the text fields')+'</legend>'
85                                                        + '     <label>'+get_lang("From")+':</label>'
86                                                        + '     <input type="text" id="txt_de" size="19">'
87                                                        + '     <br style="margin-bottom:15px"/>'
88                                                        + '     <label>'+get_lang('To')+':</label>'
89                                                        + '     <input type="text" id="txt_para" size="19">'
90                                                        + '     <br style="margin-bottom:15px"/>'
91                                                        + '     <label>'+get_lang('Cc')+':</label>'
92                                                        + '     <input type="text" id="txt_cc" size="19">'
93                                                        + '     <br style="margin-bottom:15px"/>'
94                                                        + '     <label>'+get_lang('Subject')+':</label>'
95                                                        + '     <input type="text" id="txt_ass" size="19">'
96                                                        + '     <br style="margin-bottom:15px"/>'
97                                                        + '     <label>'+get_lang('Message body')+':</label>'
98                                                        + '     <input type="text" id="txt_body" size="19">'
99                                                        + '     <br style="margin-bottom:60px"/>'
100                                                        + '</fieldset>'
101                                                        + '<fieldset style="width:350px; padding: 5px; position:absolute; margin-left: 280px">'
102                                                        + '     <legend>'+get_lang('Search the messages in these folders')+'</legend>'
103                                                        + '     <div id="folders" style="width:160px; height:150px;float:left;margin-bottom:10px;"></div>'
104                                                        + '     <div style="float:left;height:100px;padding-top:50px;margin: 0 3px;">'
105                                                        + '             <input type="button" id="incluir" name="incluir" value=">>" onclick="EsearchE.add_mailboxes()">'
106                                                        + '             <br style="margin-bottom:15px">'
107                                                        + '             <input type="button" id="excluir" name="excluir" value="<<" onclick="EsearchE.del_mailboxes()">'
108                                                        + '     </div>'
109                                                        + ' <div style="float:left;">' 
110                                                        + '      <select multiple id="sel_search_nm_box1" name="sel_search_nm_box1" style="width:140px;height:150px;"></select>'
111                                                        + ' </div>'
112                                                        + '     <br clear="both">'
113                                                        + '     <input type="checkBox" id="check_all_msg" name="check_all_msg" onclick="EsearchE.all_mailboxes()">'
114                                                        + '     <b>'+get_lang('In all the folders')+'</b>'
115                                                        + '</fieldset>';
116               
117                return form_sch;
118        }
119
120        // Pastas;
121        searchE.prototype.mount_folders = function(){
122                connector.loadScript("TreeS");
123
124                if( Element("div_folders_search") == null){
125                        var div_folders = document.createElement("DIV");
126                                div_folders.id = "div_folders_search";
127                                div_folders.style.width = "155px";
128                                div_folders.style.height = "152px";
129                                div_folders.style.borderStyle = "outset";
130                                div_folders.style.borderColor = "black";
131                                div_folders.style.borderWidth = "1px";
132                                div_folders.style.background  = "#F7F7F7";
133                                div_folders.style.overflow = "auto";
134                                div_folders.innerHTML = "";
135                                var dest_div = Element("folders");
136                                dest_div.appendChild(div_folders);
137                }               
138                ttree.make_tree(folders,"div_folders_search","_folders_tree_search","","","","");
139        }
140       
141        //This func returns the most recent date
142        function date_comp(a,b)
143        {
144                var data1 = a.match(/\d{2}\/\d{2}\/\d{4}--\d+? \w*b--.*--\d*$/g);
145                data1 = data1[0].substr(0, data1[0].indexOf('--'))
146                with ( data1 )
147                        data1 = Date.UTC(substr(6), substr(3, 2), substr(0, 2));
148                var data2 = b.match(/\d{2}\/\d{2}\/\d{4}--\d+? \w*b--.*--\d*$/g);
149                data2 = data2[0].substr(0, data2[0].indexOf('--'))
150                with ( data2 )
151                        data2 = Date.UTC(substr(6), substr(3, 2), substr(0, 2));
152                return data2 - data1;
153        }
154        function date_comp_reverse(a,b)
155        {
156                return date_comp(b,a);
157        }
158       
159        function box_comp(a,b)
160        {
161        var compare = [];
162        compare[0] = a.substr(0, a.indexOf('--'));
163        compare[0] = compare[0].toLowerCase();
164        var temp=compare[0];
165        compare[1] = b.substr(0, b.indexOf('--'))
166        compare[1] = compare[1].toLowerCase();
167        compare.sort();
168        if (temp != compare[0])
169                return +1;
170        else
171                return -1;
172        }
173        function box_comp_reverse(a,b)
174        {
175                return box_comp(b,a);
176        }
177
178        function who_comp(a,b)
179        {
180        var compare = [];
181        compare[0] = a.substr(a.indexOf('--')+2);
182        compare[0] = compare[0].toLowerCase();
183        var temp=compare[0];
184        compare[1] = b.substr(b.indexOf('--')+2);
185        compare[1] = compare[1].toLowerCase();
186        compare.sort();
187        if (temp != compare[0])
188                return +1;
189        else
190                return -1;
191        }
192        function who_comp_reverse(a,b)
193        {
194                return who_comp(b,a);
195        }
196
197        function subject_comp(a,b)
198        {
199        var compare = [];
200        compare[0] = a.substr(a.indexOf('--')+2);
201        compare[0] = compare[0].substr(compare[0].indexOf('--')+2);
202        compare[0] = compare[0].toLowerCase();
203        var temp=compare[0];
204        compare[1] = b.substr(b.indexOf('--')+2);
205        compare[1] = compare[1].substr(compare[1].indexOf('--')+2);
206        compare[1] = compare[1].toLowerCase();
207        compare.sort();
208        if (temp != compare[0])
209                return +1;
210        else
211                return -1;
212        }
213        function subject_comp_reverse(a,b)
214        {
215                return subject_comp(b,a);
216        }
217
218        function size_comp(a,b)
219        {
220                var data1 = a.match(/\d{2}\/\d{2}\/\d{4}--\d+? \w*b--.*--\d*$/g);
221                data1 = data1[0].substr(data1[0].indexOf('--')+2)
222                data1 = data1.substr(0,data1.indexOf('--'))
223                var size_a = parseInt(data1.substr(0,data1.indexOf(' ')));
224                if (data1.match("k"))
225                        size_a = size_a * 1024;
226                else
227                        if (data1.match("m"))
228                                size_a = size_a * 1048576;
229                var data2 = b.match(/\d{2}\/\d{2}\/\d{4}--\d+? \w*b--.*--\d*$/g);
230                data2 = data2[0].substr(data2[0].indexOf('--')+2)
231                data2 = data2.substr(0,data2.indexOf('--'))
232                var size_b = parseInt(data2.substr(0,data2.indexOf(' ')));
233                if (data2.match("k"))
234                        size_b = size_b * 1024;
235                else
236                        if (data2.match("m"))
237                                size_b = size_b * 1048576;
238                return size_b - size_a;
239        }
240        function size_comp_reverse(a,b)
241        {
242                return size_comp(b,a);
243        }
244
245        // Form resultado
246        searchE.prototype.mount_result = function(data,sort_type){
247                var nw_array = new Array;
248                var var_tmp = data.substr(2, data.length - 4);
249                var_tmp  = var_tmp.split("####");
250                var cont = parseInt(0);
251                switch (sort_type)
252                {
253                        case 'SORTDATE':
254                                var_tmp.sort(date_comp);
255                                break;
256                        case 'SORTDATE_REVERSE':
257                                var_tmp.sort(date_comp_reverse);
258                                break;
259                        case 'SORTBOX':
260                                var_tmp.sort(box_comp);
261                                break;
262                        case 'SORTBOX_REVERSE':
263                                var_tmp.sort(box_comp_reverse);
264                                break;
265                        case 'SORTSUBJECT':
266                                var_tmp.sort(subject_comp);
267                                break;
268                        case 'SORTSUBJECT_REVERSE':
269                                var_tmp.sort(subject_comp_reverse);
270                                break;
271                        case 'SORTWHO':
272                                var_tmp.sort(who_comp);
273                                break;
274                        case 'SORTWHO_REVERSE':
275                                var_tmp.sort(who_comp_reverse);
276                                break;
277                        case 'SORTSIZE':
278                                var_tmp.sort(size_comp);
279                                break;
280                        case 'SORTSIZE_REVERSE':
281                                var_tmp.sort(size_comp_reverse);
282                                break;
283                        default:
284                                var showMsg = 1;
285                }
286
287                for(var i=0; i < var_tmp.length; i++){
288                        if(var_tmp[i] != "")
289                        {
290                                nw_array[cont] = var_tmp[i];
291                                cont++;
292                        }
293                }
294                if(nw_array.length > 0 && showMsg)
295                        write_msg(nw_array.length + " "+ get_lang('results found'));
296                numBox++;
297                var border_id = create_border(get_lang("Search Results"), "search_" + numBox);
298                currentTab = border_id;
299                openTab.type[currentTab] = 1;
300                var table = document.createElement("TABLE");
301                table.id    = "table_resultsearch_" + numBox;
302                table.frame = "void";
303                table.rules = "rows";
304                table.cellPadding = "0";
305                table.cellSpacing = "0";
306                table.className = "table_box";
307
308                var tbody = document.createElement("TBODY");
309                tbody.id    = "tbody_box_" + numBox;
310
311                for( var i=0; i < nw_array.length; i++){
312                        var tr = document.createElement("TR");
313                        tr.style.height = preferences.line_height;
314
315                        if (nw_array[i].match(/.*--.*--\w*--\d{2}\/\d{2}\/\d{4}--\d+? \w*b--.*--\d*$/g) != null) //subject with "--"
316                        {
317                                var aux1 = nw_array[i].match(/\d{2}\/\d{2}\/\d{4}--\d+? \w*b--.*--\d*$/g);
318                                aux1 = aux1[0].split("--");
319                                nw_array[i] = nw_array[i].substr(0, nw_array[i].indexOf(aux1[0])-2);
320                                var aux = [];
321                                aux[0] = nw_array[i].substr(0, nw_array[i].indexOf('--'));
322                                nw_array[i] = nw_array[i].substr(nw_array[i].indexOf('--')+2);
323                                aux[1] = nw_array[i].substr(0, nw_array[i].indexOf('--'));
324                                aux[2] = nw_array[i].substr(nw_array[i].indexOf('--')+2);
325                                aux = aux.concat(aux1);
326                        }
327                        else
328                        {
329                                var aux = nw_array[i].split("--");
330                        }
331
332                        var mailbox = aux[0];
333                        var uid_msg = aux[6];
334                        var subject = aux[2];
335                        tr.id = uid_msg;
336
337                        // Keep the two lines together please
338                        tr.setAttribute('name',mailbox);
339                        tr.name = mailbox;
340
341                        if (aux[5].match("U"))
342                                add_className(tr,'tr_msg_unread');
343                        add_className(tr, i%2 != 0 ? 'tr_msg_read2' : 'tr_msg_read');
344            var _onclick = function () { proxy_mensagens.get_msg(this.parentNode.id,url_encode(this.parentNode.getAttribute('name')),false,show_msg);};
345            for(var j=0 ; j < 10 ; j++)
346                        {
347                                var td = document.createElement("TD");
348                                if (j == 0)
349                                {
350                                        td.style.width = "1%";
351                                        var td1 = '<input type="checkbox" id="check_box_message_'+uid_msg+'"></input>';
352                                       
353                                }
354                                if (j == 1)
355                                {
356                                        td.style.width = "2%";
357                                        if (aux[5].match('T'))
358                                        {
359                                                attachNum = parseInt(aux[5].substr(aux[5].indexOf('T')+1));
360                                                td1 = "<img src='templates/"+template+"/images/clip.gif' title='"+attachNum +' '+ get_lang('attachment(s)')+"'>";
361                                        }
362                                        else
363                                                td1 = '';
364                                }
365                                if (j == 2)
366                                {
367                                        td.style.width = "1%";
368                                        td.id = "td_message_answered_"+uid_msg;
369                                        if (aux[5].match('X'))
370                                                td1 = '<img src=templates/'+template+'/images/forwarded.gif title=Forwarded>';
371                                        else
372                                                if (aux[5].match('A'))
373                                                        td1 = '<img src=templates/'+template+'/images/answered.gif>';
374                                                else
375                                                        td1 = '';
376                                }
377                                if (j == 3)
378                                {
379                                        td.style.width = "1%";
380                                        td.id = "td_message_important_"+uid_msg;
381                                        if (aux[5].match("F"))
382                                        {
383                                                add_className(tr, 'flagged_msg');
384                                                td.style.background = "url(templates/"+template+"/images/important.gif) no-repeat center";
385                                        }
386                                        else
387                                                td1 = '';
388                                }
389                                if (j == 4)
390                                {
391                                        td.style.width = "1%";
392                                        td.id = "td_message_sent_"+uid_msg;
393                                        td1 = '';
394                                }
395                                if (j == 5)
396                                {
397                                        td.style.width = "14%";
398                                        td.onclick = _onclick;
399                                        var nm_box = aux[0].split(cyrus_delimiter);
400                                        var td1 = nm_box.pop();
401                                        td.setAttribute("NoWrap","true");
402                                        td.style.overflow = "hidden";
403                                        td.style.color = "#42795b";
404                                        td.style.fontWeight = "bold";
405
406                                        if(td1 == "INBOX"){
407                                                var td1  = get_lang("Inbox");
408                                        }
409
410                                        if(proxy_mensagens.is_local_folder(td1)) {
411                                                var td1 = this.aux_local_folder_display(td1);
412                                        }
413                                }
414                                if( j == 6)
415                                {
416                                        if (aux[1].length > 29)
417                                                aux[1] = aux[1].substr(0,29) + "...";
418                                        td.style.width = "20%";
419                                        td.onclick = _onclick;
420                                        td.setAttribute("NoWrap","true");
421                                        td.style.overflow = "hidden";
422                                        var td1  =  '<div style="width:100%;overflow:hidden">'+aux[1]+"</div>";
423                                }
424                                if( j == 7)
425                                {
426                                        var subject_encode = url_encode(subject);
427                                        if (! subject_encode)
428                                                aux[2] = get_lang("no subject") + "...";
429                                        if (aux[2].length > 70)
430                                                aux[2] = aux[2].substr(0,70) + "...";
431                                        td.style.width = "35%";
432                                        td.onclick = _onclick;
433                                        td.setAttribute("NoWrap","true");
434                                        td.style.overflow = "hidden";
435                                        var td1  = aux[2];
436
437                                }
438                                if( j == 8)
439                                {
440                                        td.style.width = "15%";
441                                        td.align = "center";
442                                        td.onclick = _onclick;
443                                        var td1  = aux[3];
444                                }
445                                if( j == 9)
446                                {
447                                        td.style.width = "10%";
448                                        td.align = "center";
449                                        td.onclick = _onclick;
450                                        var td1  = aux[4];
451                                }
452                                if (j == 10)
453                                {
454                                        if (aux[5].match("U"))
455                                                add_className(tr, 'tr_msg_unread');
456                                        if (aux[5].match("F"))
457                                                add_className(tr, 'flagged_msg');
458                                        var td1 = '';
459                                }
460                                td.innerHTML = td1;
461                                tr.appendChild(td);
462                        }
463                        aux.splice(0,(aux.length));
464
465                _dragArea.makeDragged(tr, uid_msg, subject, true, mailbox);
466                tbody.appendChild(tr);
467                }
468                table.appendChild(tbody);
469
470        var content_search =  Element('content_id_search_' + numBox);
471        // BEGIN MAKE THE SCROLL HEIGHT         
472        var defaultWidth = document.body.offsetWidth - 31;
473        var menuHidden = Element("folderscol").style.display == 'none' ? true : false;
474        if(!menuHidden)
475                defaultWidth -= Element("folderscol").offsetWidth;                     
476        var bar = Element("toolbar");
477        var offset = 0;
478        if(bar.style.visibility != 'hidden')
479                offset = bar.offsetHeight ? bar.offsetHeight :  bar.clientHeight;               
480        var div_scroll_result = document.createElement("DIV");
481        div_scroll_result.id = "divScrollMain_"+numBox;
482        div_scroll_result.style.height = document.body.clientHeight - offset - 120;
483        content_search.style.height = document.body.clientHeight - offset - 80;
484        div_scroll_result.style.overflow = "auto";
485        div_scroll_result.style.width = defaultWidth - (is_ie ? 7 : 0);
486        // END MAKE THE SCROLL HEIGHT           
487               
488       
489                if(is_ie)
490                        Element("border_table").width = "99.5%";
491               
492                // Put header
493                var table_element = document.createElement("TABLE");
494                var tbody_element = document.createElement("TBODY");
495                table_element.setAttribute("id", "table_message_header_box");
496                table_element.className = "table_message_header_box";
497                tr_element = document.createElement("TR");
498                tr_element.className = "message_header";
499                td_element0 = document.createElement("TD");
500                td_element0.setAttribute("width", "1%");
501                chk_box_element = document.createElement("INPUT");
502                chk_box_element.id  = "chk_box_select_all_messages";
503                chk_box_element.setAttribute("type", "checkbox");
504                chk_box_element.className = "checkbox";
505                chk_box_element.onclick = function(){select_all_search_messages(this.checked,content_search.id);};
506                chk_box_element.onmouseover = function () {this.title=get_lang('Select all messages.')};
507                chk_box_element.onkeydown = function (e){
508                        if (is_ie)
509                        {
510                                if ((window.event.keyCode) == 46)
511                                        delete_msgs(current_folder,'selected','null');
512                        }
513                        else
514                        {
515                                if ((e.keyCode) == 46)
516                                        delete_msgs(current_folder,'selected','null');
517                        }
518                };
519               
520                td_element0.appendChild(chk_box_element);
521                td_element1 = document.createElement("TD");
522                td_element1.setAttribute("width", "20%");
523                td_element1.align = "left";
524                if (sort_type == 'SORTBOX')
525                {
526                        td_element1.onclick = function () { EsearchE.mount_result(data,'SORTBOX_REVERSE'); delete_border(border_id,false);};
527                        td_element1.innerHTML ="<b>"+get_lang("Folder")+"</b><img src='templates/"+template+"/images/arrow_descendant.gif'>";
528                }
529                else
530                {
531                        td_element1.onclick = function () { EsearchE.mount_result(data,'SORTBOX'); delete_border(border_id,false);};
532                        if  (sort_type == 'SORTBOX_REVERSE')
533                                td_element1.innerHTML ="<b>"+get_lang("Folder")+"</b><img src='templates/"+template+"/images/arrow_ascendant.gif'>";
534                        else
535                                td_element1.innerHTML = get_lang("Folder");
536                }
537                td_element2 = document.createElement("TD");
538                td_element2.setAttribute("width", "20%");
539                td_element2.align = "left";
540                if (sort_type == 'SORTWHO')
541                {
542                        td_element2.onclick = function () { EsearchE.mount_result(data,'SORTWHO_REVERSE'); delete_border(border_id,false);};
543                        td_element2.innerHTML ="<b>"+get_lang("who")+"</b><img src='templates/"+template+"/images/arrow_descendant.gif'>";
544                }
545                else
546                {
547                        td_element2.onclick = function () { EsearchE.mount_result(data,'SORTWHO'); delete_border(border_id,false);};
548                        if  (sort_type == 'SORTWHO_REVERSE')
549                                td_element2.innerHTML ="<b>"+get_lang("who")+"</b><img src='templates/"+template+"/images/arrow_ascendant.gif'>";
550                        else
551                                td_element2.innerHTML = get_lang("who");
552                }
553                td_element3 = document.createElement("TD");
554                td_element3.setAttribute("width", "35%");
555                td_element3.align = "left";
556                if (sort_type == 'SORTSUBJECT')
557                {
558                        td_element3.onclick = function () { EsearchE.mount_result(data,'SORTSUBJECT_REVERSE'); delete_border(border_id,false);};
559                        td_element3.innerHTML ="<b>"+get_lang("subject")+"</b><img src='templates/"+template+"/images/arrow_descendant.gif'>";
560                }
561                else
562                {
563                        td_element3.onclick = function () { EsearchE.mount_result(data,'SORTSUBJECT'); delete_border(border_id,false);};
564                        if  (sort_type == 'SORTSUBJECT_REVERSE')
565                                td_element3.innerHTML ="<b>"+get_lang("subject")+"</b><img src='templates/"+template+"/images/arrow_ascendant.gif'>";
566                        else
567                                td_element3.innerHTML = get_lang("subject");
568                }
569                td_element4 = document.createElement("TD");
570                td_element4.setAttribute("width", "15%");
571                td_element4.align = "center";
572                if (sort_type == 'SORTDATE')
573                {
574                        td_element4.onclick = function () { EsearchE.mount_result(data,'SORTDATE_REVERSE'); delete_border(border_id,false);};
575                        td_element4.innerHTML ="<b>"+get_lang("Date")+"</b><img src='templates/"+template+"/images/arrow_descendant.gif'>";
576                }
577                else
578                {
579                        td_element4.onclick = function () { EsearchE.mount_result(data,'SORTDATE'); delete_border(border_id,false);};
580                        if  (sort_type == 'SORTDATE_REVERSE')
581                                td_element4.innerHTML ="<b>"+get_lang("Date")+"</b><img src='templates/"+template+"/images/arrow_ascendant.gif'>";
582                        else
583                                td_element4.innerHTML = get_lang("Date");
584                }
585                td_element5 = document.createElement("TD");
586                td_element5.setAttribute("width", "10%");
587                td_element5.align = "center";
588                if (sort_type == 'SORTSIZE')
589                {
590                        td_element5.onclick = function () { EsearchE.mount_result(data,'SORTSIZE_REVERSE'); delete_border(border_id,false);};
591                        td_element5.innerHTML ="<b>"+get_lang("size")+"</b><img src='templates/"+template+"/images/arrow_descendant.gif'>";
592                }
593                else
594                {
595                        td_element5.onclick = function () { EsearchE.mount_result(data,'SORTSIZE'); delete_border(border_id,false);};
596                        if  (sort_type == 'SORTSIZE_REVERSE')
597                                td_element5.innerHTML ="<b>"+get_lang("size")+"</b><img src='templates/"+template+"/images/arrow_ascendant.gif'>";
598                        else
599                                td_element5.innerHTML = get_lang("Size");
600                }
601                tr_element.appendChild(td_element0);
602                tr_element.appendChild(td_element1);
603                tr_element.appendChild(td_element2);
604                tr_element.appendChild(td_element3);
605                tr_element.appendChild(td_element4);
606                tr_element.appendChild(td_element5);
607                tbody_element.appendChild(tr_element);
608                table_element.appendChild(tbody_element);
609                content_search.appendChild(table_element);
610                /*end of "put header"*/
611               
612                if (!expresso_offline) {
613/*                      var span_options = document.createElement("SPAN");
614                        if (span_options)
615                                span_options.innerHTML = '<span title="' + get_lang("Delete") + '" style="margin-top:3px;margin-left:8px" class="message_options" onclick="javascript:move_search_msgs(\'' + content_search.id + '\');">' + get_lang("Delete") + '</span> | ' +
616                                '<span title="' +
617                                get_lang("Move") +
618                                '" class="message_options" onclick=wfolders.makeWindowNew(\"' +
619                                content_search.id +
620                                '\",\"move_to\",true)>' +
621                                get_lang("Move") +
622                                '</span>';*/
623                        div_scroll_result.appendChild(table);
624                        content_search.appendChild(div_scroll_result);
625                        /*if (span_options)
626                                content_search.appendChild(span_options);*/
627                }
628                else {
629                        div_scroll_result.appendChild(table);
630                        content_search.appendChild(div_scroll_result);
631                }
632        }
633
634        searchE.prototype.open_msg = function(mailbox, uid_msg, subject){
635                var handler_get_msg = function(data){
636                        if(Element("border_id_" + uid_msg + "_r")){alert(get_lang("This message is already opened!"));}
637                        else{draw_message(data,create_border(url_decode(subject), uid_msg + "_r"));}
638                        //set_msg_as_read(msgs_to_set[i], false);
639                }
640                proxy_mensagens.get_msg(uid_msg,mailbox,false,handler_get_msg);
641                /*var args   = "$this.imap_functions.get_info_msg";
642                var params = "msg_number=" + uid_msg + "&msg_folder=" + mailbox;
643                cExecute(args,handler_get_msg,params);*/
644
645        }
646
647        // Adiciona caixas postais na busca;
648        searchE.prototype.add_mailboxes = function(){
649                var sel = Element("sel_search_nm_box1");
650                if (!proxy_mensagens.is_local_folder(this.name_box_search)) {
651                        var name_box     = this.name_box_search.split(cyrus_delimiter);
652                        if(this.name_box_search == "")
653                                return false;
654                        var name_box_def = "";
655                        if(name_box.length != 1){
656                                name_box_def = name_box[(name_box.length-1)];
657                        }else{
658                                name_box_def = get_lang("Inbox");               
659                        }
660                }
661                else {
662                        if(this.name_box_search=='local_root')
663                                return;
664                        if(this.name_box_search=='local_Inbox')
665                                name_box_def = get_lang("Inbox");
666                        else if(this.name_box_search.indexOf("/")!="-1") {
667                                final_pos = this.name_box_search.lastIndexOf("/");
668                                name_box_def = this.name_box_search.substr(final_pos+1);
669                        }
670                        else
671                                name_box_def = this.name_box_search.substr(6);//Retira o 'local_'
672                }
673                if( sel.length > 0){
674                        for(var i=0; i < sel.options.length; i++){
675                                if(sel.options[i].value == this.name_box_search){
676                                        alert(get_lang('This message is already selected!'));
677                                        return false;
678                                }
679                        }
680                }
681                var opt = new Option(lang_folder(name_box_def),this.name_box_search,false,true);
682                sel[sel.length] = opt;
683        }
684        // Remove as caixas postais na busca;
685        searchE.prototype.del_mailboxes = function(){
686                var sel = Element("sel_search_nm_box1");
687                if(sel.length > 0){
688                        for(var i=0; i < sel.options.length; i++){
689                                if(sel.options[i].selected == true){
690                                        sel.options[i] = null;
691                                        i--;
692                                }
693                        }
694                }
695       
696        }
697        // todas as caixas
698        searchE.prototype.all_mailboxes = function(){
699                var value = Element("check_all_msg").checked;
700                var cont = parseInt(0);
701                if(value){
702                        if(EsearchE.all_boxes.length > 0){
703                                EsearchE.all_boxes.splice(0,(EsearchE.all_boxes.length));                       
704                        }
705                        for(var i=0; i < folders.length; i++){
706                                EsearchE.all_boxes[cont] = folders[i].folder_id;
707                                cont++;
708                        }
709                }else{
710                        EsearchE.all_boxes.splice(0,(EsearchE.all_boxes.length));
711                }
712        }
713
714        // Search;
715        searchE.prototype.func_search = function(value){
716                var fields = "##";
717                        // Verifica se os campos estão preenchidos;
718                        if(trim(Element("txt_ass").value) != ""){
719                                fields += "SUBJECT " +  "<=>" +url_encode(Element("txt_ass").value) + "##";
720                        }
721                        if(trim(Element("txt_body").value) != ""){
722                                fields += "BODY " + "<=>" + url_encode(Element("txt_body").value) + "##";
723                        }
724                        if(trim(Element("txt_de").value) != ""){
725                                fields += "FROM " + "<=>" + url_encode(Element("txt_de").value) + "##";
726                        }
727                        if(trim(Element("txt_para").value) != ""){
728                                fields += "TO " + "<=>" + url_encode(Element("txt_para").value) + "##";
729                        }
730                        if(trim(Element("txt_cc").value) != ""){
731                                fields += "CC " + "<=>" + url_encode(Element("txt_cc").value) + "##";
732                        }
733                        if(value) {
734                                fields = "##ALL " +  "<=>" +url_encode(value) + "##";
735                        }
736
737                if(fields == "##"){
738                        alert(get_lang("Define some search parameters!"));
739                        return false;
740                }
741                var local_folders = new Array();
742                var temp;
743               
744                if(Element("check_all_msg").checked){
745                        this.all_mailboxes();
746                        var nm_box = new Array;
747                        for(var i=0; i < EsearchE.all_boxes.length; i++){
748                                nm_box[i] = EsearchE.all_boxes[i] + fields;
749                        }
750                        if (preferences.use_local_messages == 1) {
751                                temp = expresso_local_messages.list_local_folders();
752                                for (var x in temp) {
753                                        local_folders.push(temp[x][0]);
754                                }
755                        }
756                }else{
757                        var nm_box = new Array;
758                        var sel_combo = Element("sel_search_nm_box1");
759                        if( sel_combo.options.length <= 0){
760                                alert(get_lang("Define the boxes to search!"));
761                                return false;
762                        }
763                       
764                        for(var i=0; i < sel_combo.options.length; i++){
765                                sel_combo.options[i].selected = true;
766                        }
767                        for(var i=0; i < sel_combo.options.length; i++){
768                                if(sel_combo.options[i].selected == true){
769                                        if(!proxy_mensagens.is_local_folder(sel_combo.options[i].value))
770                                                nm_box[nm_box.length] = sel_combo.options[i].value + fields;
771                                        else
772                                                local_folders.push(sel_combo.options[i].value.substr(6));
773                                }
774                        }
775                }
776                var handler = function(data){
777                        var tmp;
778                        var countTmp= new Array();
779                        if (local_folders.length > 0) {
780                                tmp = expresso_local_messages.search(local_folders, fields);
781                                if (tmp!=false) {
782                                        var tmp2 = tmp.substr(2, data.length - 4);
783                                        countTmp = tmp.split('####');
784                                }
785                        }
786                        if((data == "none") && (countTmp.length==0)){alert(get_lang("None result was found."));}
787                        else if(countTmp.length > 50){alert(get_lang("More than %1 results. Please, try to refine your search.",50));}
788                        else if(data == "many results"){alert(get_lang("More than %1 results. Please, try to refine your search.",50));}
789                        else{EsearchE.mount_result((data=='none')?tmp:(countTmp.length==0)?data:data+tmp);}
790                }
791                var args   = "$this.imap_functions.search_msg";
792                var params = "condition=" + nm_box;
793                if(expresso_offline)
794                        handler('none');
795                else
796                        cExecute(args,handler,params);
797        }
798        // clean;
799        searchE.prototype.func_clean = function(){
800                // Limpa os campos;
801                for(var i=0; i < this.fields.length; i++){
802                        if(Element("txt" + this.fields[i]) != null){Element("txt" + this.fields[i]).value = "";}
803                }
804            if(Element("check_all_msg") != null){Element("check_all_msg").checked = false;}
805
806            EsearchE.all_boxes.splice(0,(EsearchE.all_boxes.length));
807                EsearchE.del_mailboxes();
808        }
809
810        // close
811        searchE.prototype.func_close = function(type){
812                var _this = this;
813                _this.name_box_search = "";
814                EsearchE.all_boxes.splice(0,(EsearchE.all_boxes.length));
815                _this.type = type;
816                _this.searchW['window_search'].close();
817        }
818        // Monta a janela em tela;
819        searchE.prototype.showWindow = function(div){
820                if(!this.searchW[div.id]) {
821                        div.style.width = "660px";
822                        div.style.height = "255px";
823                        div.style.visibility = "hidden";
824                        div.style.position = "absolute";
825                        div.style.zIndex = "10003";
826                        var title = ":: "+ get_lang("Search")+" ::";
827                        var wHeight = div.offsetHeight + "px";
828                        var wWidth =  div.offsetWidth   + "px";
829
830                        win = new dJSWin({
831                                id: 'ccList'+div.id,
832                                content_id: div.id,
833                                width: wWidth,
834                                height: wHeight,
835                                title_color: '#3978d6',
836                                bg_color: '#eee',
837                                title: title,
838                                title_text_color: 'white',
839                                button_y_img: '../phpgwapi/images/win_min.gif',
840                                button_x_img: '../phpgwapi/images/winclose.gif',
841                                border: true });
842                        this.searchW[div.id] = win;
843                        win.draw();
844                }else{
845                        var _this = this;
846                        win = this.searchW[div.id];
847                        if((_this.type == "close" && win.state == 0) || win.state == 2){EsearchE.func_clean();}
848                        win.draw();
849                }
850                win.open();     
851        }
852       
853        searchE.prototype.aux_local_folder_display = function(folder) {
854                if(!expresso_offline)
855                        return "(Local) " + lang_folder(folder.substr(6));
856                else
857                        return lang_folder(folder.substr(6));
858        }
859       
860// Cria o objeto
861        var EsearchE;
862        EsearchE = new searchE();
Note: See TracBrowser for help on using the repository browser.