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

Revision 1608, 28.4 KB checked in by rafaelraymundo, 14 years ago (diff)

Ticket #700 - Adiciona a preferência: selecionar número de resultados na pesquisa de email.

  • 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                if (!border_id)
299                {
300                    return;
301                }
302                currentTab = border_id;
303                openTab.type[currentTab] = 1;
304                var table = document.createElement("TABLE");
305                table.id    = "table_resultsearch_" + numBox;
306                table.frame = "void";
307                table.rules = "rows";
308                table.cellPadding = "0";
309                table.cellSpacing = "0";
310                table.className = "table_box";
311
312                var tbody = document.createElement("TBODY");
313                tbody.id    = "tbody_box_" + numBox;
314
315                for( var i=0; i < nw_array.length; i++){
316                        var tr = document.createElement("TR");
317                        tr.style.height = preferences.line_height;
318
319                        if (nw_array[i].match(/.*--.*--\w*--\d{2}\/\d{2}\/\d{4}--\d+? \w*b--.*--\d*$/g) != null) //subject with "--"
320                        {
321                                var aux1 = nw_array[i].match(/\d{2}\/\d{2}\/\d{4}--\d+? \w*b--.*--\d*$/g);
322                                aux1 = aux1[0].split("--");
323                                nw_array[i] = nw_array[i].substr(0, nw_array[i].indexOf(aux1[0])-2);
324                                var aux = [];
325                                aux[0] = nw_array[i].substr(0, nw_array[i].indexOf('--'));
326                                nw_array[i] = nw_array[i].substr(nw_array[i].indexOf('--')+2);
327                                aux[1] = nw_array[i].substr(0, nw_array[i].indexOf('--'));
328                                aux[2] = nw_array[i].substr(nw_array[i].indexOf('--')+2);
329                                aux = aux.concat(aux1);
330                        }
331                        else
332                        {
333                                var aux = nw_array[i].split("--");
334                        }
335
336                        var mailbox = aux[0];
337                        var uid_msg = aux[6];
338                        var subject = aux[2];
339                        tr.id = uid_msg;
340
341                        // Keep the two lines together please
342                        tr.setAttribute('name',mailbox);
343                        tr.name = mailbox;
344
345                        if (aux[5].match("U"))
346                                add_className(tr,'tr_msg_unread');
347                        add_className(tr, i%2 != 0 ? 'tr_msg_read2' : 'tr_msg_read');
348            var _onclick = function () { proxy_mensagens.get_msg(this.parentNode.id,url_encode(this.parentNode.getAttribute('name')),false,show_msg);};
349            for(var j=0 ; j < 10 ; j++)
350                        {
351                                var td = document.createElement("TD");
352                                if (j == 0)
353                                {
354                                        td.style.width = "1%";
355                                        var td1 = '<input type="checkbox" id="check_box_message_'+uid_msg+'"></input>';
356                                       
357                                }
358                                if (j == 1)
359                                {
360                                        td.style.width = "2%";
361                                        if (aux[5].match('T'))
362                                        {
363                                                attachNum = parseInt(aux[5].substr(aux[5].indexOf('T')+1));
364                                                td1 = "<img src='templates/"+template+"/images/clip.gif' title='"+attachNum +' '+ get_lang('attachment(s)')+"'>";
365                                        }
366                                        else
367                                                td1 = '';
368                                }
369                                if (j == 2)
370                                {
371                                        td.style.width = "1%";
372                                        td.id = "td_message_answered_"+uid_msg;
373                                        if (aux[5].match('X'))
374                                                td1 = '<img src=templates/'+template+'/images/forwarded.gif title=Forwarded>';
375                                        else
376                                                if (aux[5].match('A'))
377                                                        td1 = '<img src=templates/'+template+'/images/answered.gif>';
378                                                else
379                                                        td1 = '';
380                                }
381                                if (j == 3)
382                                {
383                                        td.style.width = "1%";
384                                        td.id = "td_message_important_"+uid_msg;
385                                        if (aux[5].match("F"))
386                                        {
387                                                add_className(tr, 'flagged_msg');
388                                                td.style.background = "url(templates/"+template+"/images/important.gif) no-repeat center";
389                                        }
390                                        else
391                                                td1 = '';
392                                }
393                                if (j == 4)
394                                {
395                                        td.style.width = "1%";
396                                        td.id = "td_message_sent_"+uid_msg;
397                                        td1 = '';
398                                }
399                                if (j == 5)
400                                {
401                                        td.style.width = "14%";
402                                        td.onclick = _onclick;
403                                        var nm_box = aux[0].split(cyrus_delimiter);
404                                        var td1 = nm_box.pop();
405                                        td.setAttribute("NoWrap","true");
406                                        td.style.overflow = "hidden";
407                                        td.style.color = "#42795b";
408                                        td.style.fontWeight = "bold";
409
410                                        if(td1 == "INBOX"){
411                                                var td1  = get_lang("Inbox");
412                                        }
413
414                                        if(proxy_mensagens.is_local_folder(td1)) {
415                                                var td1 = this.aux_local_folder_display(td1);
416                                        }
417                                }
418                                if( j == 6)
419                                {
420                                        if (aux[1].length > 29)
421                                                aux[1] = aux[1].substr(0,29) + "...";
422                                        td.style.width = "20%";
423                                        td.onclick = _onclick;
424                                        td.setAttribute("NoWrap","true");
425                                        td.style.overflow = "hidden";
426                                        var td1  =  '<div style="width:100%;overflow:hidden">'+aux[1]+"</div>";
427                                }
428                                if( j == 7)
429                                {
430                                        var subject_encode = url_encode(subject);
431                                        if (! subject_encode)
432                                                aux[2] = get_lang("no subject") + "...";
433                                        if (aux[2].length > 70)
434                                                aux[2] = aux[2].substr(0,70) + "...";
435                                        td.style.width = "35%";
436                                        td.onclick = _onclick;
437                                        td.setAttribute("NoWrap","true");
438                                        td.style.overflow = "hidden";
439                                        var td1  = aux[2];
440
441                                }
442                                if( j == 8)
443                                {
444                                        td.style.width = "15%";
445                                        td.align = "center";
446                                        td.onclick = _onclick;
447                                        var td1  = aux[3];
448                                }
449                                if( j == 9)
450                                {
451                                        td.style.width = "10%";
452                                        td.align = "center";
453                                        td.onclick = _onclick;
454                                        var td1  = aux[4];
455                                }
456                                if (j == 10)
457                                {
458                                        if (aux[5].match("U"))
459                                                add_className(tr, 'tr_msg_unread');
460                                        if (aux[5].match("F"))
461                                                add_className(tr, 'flagged_msg');
462                                        var td1 = '';
463                                }
464                                td.innerHTML = td1;
465                                tr.appendChild(td);
466                        }
467                        aux.splice(0,(aux.length));
468
469                _dragArea.makeDragged(tr, uid_msg, subject, true, mailbox);
470                tbody.appendChild(tr);
471                }
472                table.appendChild(tbody);
473
474        var content_search =  Element('content_id_search_' + numBox);
475        // BEGIN MAKE THE SCROLL HEIGHT         
476        var defaultWidth = document.body.offsetWidth - 31;
477        var menuHidden = Element("folderscol").style.display == 'none' ? true : false;
478        if(!menuHidden)
479                defaultWidth -= Element("folderscol").offsetWidth;                     
480        var bar = Element("toolbar");
481        var offset = 0;
482        if(bar.style.visibility != 'hidden')
483                offset = bar.offsetHeight ? bar.offsetHeight :  bar.clientHeight;               
484        var div_scroll_result = document.createElement("DIV");
485        div_scroll_result.id = "divScrollMain_"+numBox;
486        div_scroll_result.style.height = document.body.clientHeight - offset - 120;
487        content_search.style.height = document.body.clientHeight - offset - 80;
488        div_scroll_result.style.overflow = "auto";
489        div_scroll_result.style.width = defaultWidth - (is_ie ? 7 : 0);
490        // END MAKE THE SCROLL HEIGHT           
491               
492       
493                if(is_ie)
494                        Element("border_table").width = "99.5%";
495               
496                // Put header
497                var table_element = document.createElement("TABLE");
498                var tbody_element = document.createElement("TBODY");
499                table_element.setAttribute("id", "table_message_header_box");
500                table_element.className = "table_message_header_box";
501                tr_element = document.createElement("TR");
502                tr_element.className = "message_header";
503                td_element0 = document.createElement("TD");
504                td_element0.setAttribute("width", "1%");
505                chk_box_element = document.createElement("INPUT");
506                chk_box_element.id  = "chk_box_select_all_messages";
507                chk_box_element.setAttribute("type", "checkbox");
508                chk_box_element.className = "checkbox";
509                chk_box_element.onclick = function(){select_all_search_messages(this.checked,content_search.id);};
510                chk_box_element.onmouseover = function () {this.title=get_lang('Select all messages.')};
511                chk_box_element.onkeydown = function (e){
512                        if (is_ie)
513                        {
514                                if ((window.event.keyCode) == 46)
515                                        delete_msgs(current_folder,'selected','null');
516                        }
517                        else
518                        {
519                                if ((e.keyCode) == 46)
520                                        delete_msgs(current_folder,'selected','null');
521                        }
522                };
523               
524                td_element0.appendChild(chk_box_element);
525                td_element1 = document.createElement("TD");
526                td_element1.setAttribute("width", "20%");
527                td_element1.align = "left";
528                if (sort_type == 'SORTBOX')
529                {
530                        td_element1.onclick = function () { EsearchE.mount_result(data,'SORTBOX_REVERSE'); delete_border(border_id,false);};
531                        td_element1.innerHTML ="<b>"+get_lang("Folder")+"</b><img src='templates/"+template+"/images/arrow_descendant.gif'>";
532                }
533                else
534                {
535                        td_element1.onclick = function () { EsearchE.mount_result(data,'SORTBOX'); delete_border(border_id,false);};
536                        if  (sort_type == 'SORTBOX_REVERSE')
537                                td_element1.innerHTML ="<b>"+get_lang("Folder")+"</b><img src='templates/"+template+"/images/arrow_ascendant.gif'>";
538                        else
539                                td_element1.innerHTML = get_lang("Folder");
540                }
541                td_element2 = document.createElement("TD");
542                td_element2.setAttribute("width", "20%");
543                td_element2.align = "left";
544                if (sort_type == 'SORTWHO')
545                {
546                        td_element2.onclick = function () { EsearchE.mount_result(data,'SORTWHO_REVERSE'); delete_border(border_id,false);};
547                        td_element2.innerHTML ="<b>"+get_lang("who")+"</b><img src='templates/"+template+"/images/arrow_descendant.gif'>";
548                }
549                else
550                {
551                        td_element2.onclick = function () { EsearchE.mount_result(data,'SORTWHO'); delete_border(border_id,false);};
552                        if  (sort_type == 'SORTWHO_REVERSE')
553                                td_element2.innerHTML ="<b>"+get_lang("who")+"</b><img src='templates/"+template+"/images/arrow_ascendant.gif'>";
554                        else
555                                td_element2.innerHTML = get_lang("who");
556                }
557                td_element3 = document.createElement("TD");
558                td_element3.setAttribute("width", "35%");
559                td_element3.align = "left";
560                if (sort_type == 'SORTSUBJECT')
561                {
562                        td_element3.onclick = function () { EsearchE.mount_result(data,'SORTSUBJECT_REVERSE'); delete_border(border_id,false);};
563                        td_element3.innerHTML ="<b>"+get_lang("subject")+"</b><img src='templates/"+template+"/images/arrow_descendant.gif'>";
564                }
565                else
566                {
567                        td_element3.onclick = function () { EsearchE.mount_result(data,'SORTSUBJECT'); delete_border(border_id,false);};
568                        if  (sort_type == 'SORTSUBJECT_REVERSE')
569                                td_element3.innerHTML ="<b>"+get_lang("subject")+"</b><img src='templates/"+template+"/images/arrow_ascendant.gif'>";
570                        else
571                                td_element3.innerHTML = get_lang("subject");
572                }
573                td_element4 = document.createElement("TD");
574                td_element4.setAttribute("width", "15%");
575                td_element4.align = "center";
576                if (sort_type == 'SORTDATE')
577                {
578                        td_element4.onclick = function () { EsearchE.mount_result(data,'SORTDATE_REVERSE'); delete_border(border_id,false);};
579                        td_element4.innerHTML ="<b>"+get_lang("Date")+"</b><img src='templates/"+template+"/images/arrow_descendant.gif'>";
580                }
581                else
582                {
583                        td_element4.onclick = function () { EsearchE.mount_result(data,'SORTDATE'); delete_border(border_id,false);};
584                        if  (sort_type == 'SORTDATE_REVERSE')
585                                td_element4.innerHTML ="<b>"+get_lang("Date")+"</b><img src='templates/"+template+"/images/arrow_ascendant.gif'>";
586                        else
587                                td_element4.innerHTML = get_lang("Date");
588                }
589                td_element5 = document.createElement("TD");
590                td_element5.setAttribute("width", "10%");
591                td_element5.align = "center";
592                if (sort_type == 'SORTSIZE')
593                {
594                        td_element5.onclick = function () { EsearchE.mount_result(data,'SORTSIZE_REVERSE'); delete_border(border_id,false);};
595                        td_element5.innerHTML ="<b>"+get_lang("size")+"</b><img src='templates/"+template+"/images/arrow_descendant.gif'>";
596                }
597                else
598                {
599                        td_element5.onclick = function () { EsearchE.mount_result(data,'SORTSIZE'); delete_border(border_id,false);};
600                        if  (sort_type == 'SORTSIZE_REVERSE')
601                                td_element5.innerHTML ="<b>"+get_lang("size")+"</b><img src='templates/"+template+"/images/arrow_ascendant.gif'>";
602                        else
603                                td_element5.innerHTML = get_lang("Size");
604                }
605                tr_element.appendChild(td_element0);
606                tr_element.appendChild(td_element1);
607                tr_element.appendChild(td_element2);
608                tr_element.appendChild(td_element3);
609                tr_element.appendChild(td_element4);
610                tr_element.appendChild(td_element5);
611                tbody_element.appendChild(tr_element);
612                table_element.appendChild(tbody_element);
613                content_search.appendChild(table_element);
614                /*end of "put header"*/
615               
616                if (!expresso_offline) {
617/*                      var span_options = document.createElement("SPAN");
618                        if (span_options)
619                                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> | ' +
620                                '<span title="' +
621                                get_lang("Move") +
622                                '" class="message_options" onclick=wfolders.makeWindowNew(\"' +
623                                content_search.id +
624                                '\",\"move_to\",true)>' +
625                                get_lang("Move") +
626                                '</span>';*/
627                        div_scroll_result.appendChild(table);
628                        content_search.appendChild(div_scroll_result);
629                        /*if (span_options)
630                                content_search.appendChild(span_options);*/
631                }
632                else {
633                        div_scroll_result.appendChild(table);
634                        content_search.appendChild(div_scroll_result);
635                }
636        }
637
638        searchE.prototype.open_msg = function(mailbox, uid_msg, subject){
639                var handler_get_msg = function(data){
640                        if(Element("border_id_" + uid_msg + "_r")){alert(get_lang("This message is already opened!"));}
641                        else{draw_message(data,create_border(url_decode(subject), uid_msg + "_r"));}
642                        //set_msg_as_read(msgs_to_set[i], false);
643                }
644                proxy_mensagens.get_msg(uid_msg,mailbox,false,handler_get_msg);
645                /*var args   = "$this.imap_functions.get_info_msg";
646                var params = "msg_number=" + uid_msg + "&msg_folder=" + mailbox;
647                cExecute(args,handler_get_msg,params);*/
648
649        }
650
651        // Adiciona caixas postais na busca;
652        searchE.prototype.add_mailboxes = function(){
653                var sel = Element("sel_search_nm_box1");
654                if (!proxy_mensagens.is_local_folder(this.name_box_search)) {
655                        var name_box     = this.name_box_search.split(cyrus_delimiter);
656                        if(this.name_box_search == "")
657                                return false;
658                        var name_box_def = "";
659                        if(name_box.length != 1){
660                                name_box_def = name_box[(name_box.length-1)];
661                        }else{
662                                name_box_def = get_lang("Inbox");               
663                        }
664                }
665                else {
666                        if(this.name_box_search=='local_root')
667                                return;
668                        if(this.name_box_search=='local_Inbox')
669                                name_box_def = get_lang("Inbox");
670                        else if(this.name_box_search.indexOf("/")!="-1") {
671                                final_pos = this.name_box_search.lastIndexOf("/");
672                                name_box_def = this.name_box_search.substr(final_pos+1);
673                        }
674                        else
675                                name_box_def = this.name_box_search.substr(6);//Retira o 'local_'
676                }
677                if( sel.length > 0){
678                        for(var i=0; i < sel.options.length; i++){
679                                if(sel.options[i].value == this.name_box_search){
680                                        alert(get_lang('This message is already selected!'));
681                                        return false;
682                                }
683                        }
684                }
685                var opt = new Option(lang_folder(name_box_def),this.name_box_search,false,true);
686                sel[sel.length] = opt;
687        }
688        // Remove as caixas postais na busca;
689        searchE.prototype.del_mailboxes = function(){
690                var sel = Element("sel_search_nm_box1");
691                if(sel.length > 0){
692                        for(var i=0; i < sel.options.length; i++){
693                                if(sel.options[i].selected == true){
694                                        sel.options[i] = null;
695                                        i--;
696                                }
697                        }
698                }
699       
700        }
701        // todas as caixas
702        searchE.prototype.all_mailboxes = function(){
703                var value = Element("check_all_msg").checked;
704                var cont = parseInt(0);
705                if(value){
706                        if(EsearchE.all_boxes.length > 0){
707                                EsearchE.all_boxes.splice(0,(EsearchE.all_boxes.length));                       
708                        }
709                        for(var i=0; i < folders.length; i++){
710                                EsearchE.all_boxes[cont] = folders[i].folder_id;
711                                cont++;
712                        }
713                }else{
714                        EsearchE.all_boxes.splice(0,(EsearchE.all_boxes.length));
715                }
716        }
717
718        // Search;
719        searchE.prototype.func_search = function(value){
720                var fields = "##";
721                        // Verifica se os campos estão preenchidos;
722                        if(trim(Element("txt_ass").value) != ""){
723                                fields += "SUBJECT " +  "<=>" +url_encode(Element("txt_ass").value) + "##";
724                        }
725                        if(trim(Element("txt_body").value) != ""){
726                                fields += "BODY " + "<=>" + url_encode(Element("txt_body").value) + "##";
727                        }
728                        if(trim(Element("txt_de").value) != ""){
729                                fields += "FROM " + "<=>" + url_encode(Element("txt_de").value) + "##";
730                        }
731                        if(trim(Element("txt_para").value) != ""){
732                                fields += "TO " + "<=>" + url_encode(Element("txt_para").value) + "##";
733                        }
734                        if(trim(Element("txt_cc").value) != ""){
735                                fields += "CC " + "<=>" + url_encode(Element("txt_cc").value) + "##";
736                        }
737                        if(value) {
738                                fields = "##ALL " +  "<=>" +url_encode(value) + "##";
739                        }
740
741                if(fields == "##"){
742                        alert(get_lang("Define some search parameters!"));
743                        return false;
744                }
745                var local_folders = new Array();
746                var temp;
747               
748                if(Element("check_all_msg").checked){
749                        this.all_mailboxes();
750                        var nm_box = new Array;
751                        for(var i=0; i < EsearchE.all_boxes.length; i++){
752                                nm_box[i] = EsearchE.all_boxes[i] + fields;
753                        }
754                        if (preferences.use_local_messages == 1) {
755                                temp = expresso_local_messages.list_local_folders();
756                                for (var x in temp) {
757                                        local_folders.push(temp[x][0]);
758                                }
759                        }
760                }else{
761                        var nm_box = new Array;
762                        var sel_combo = Element("sel_search_nm_box1");
763                        if( sel_combo.options.length <= 0){
764                                alert(get_lang("Define the boxes to search!"));
765                                return false;
766                        }
767                       
768                        for(var i=0; i < sel_combo.options.length; i++){
769                                sel_combo.options[i].selected = true;
770                        }
771                        for(var i=0; i < sel_combo.options.length; i++){
772                                if(sel_combo.options[i].selected == true){
773                                        if(!proxy_mensagens.is_local_folder(sel_combo.options[i].value))
774                                                nm_box[nm_box.length] = sel_combo.options[i].value + fields;
775                                        else
776                                                local_folders.push(sel_combo.options[i].value.substr(6));
777                                }
778                        }
779                }
780                var handler = function(data){
781                        var tmp;
782                        var countTmp= new Array();
783                        if (local_folders.length > 0) {
784                                tmp = expresso_local_messages.search(local_folders, fields);
785                                if (tmp!=false) {
786                                        var tmp2 = tmp.substr(2, data.length - 4);
787                                        countTmp = tmp.split('####');
788                                }
789                        }
790                        if((data == "none") && (countTmp.length==0)){alert(get_lang("None result was found."));}
791                        if (preferences.search_result_number == '65536' || (data != 'many results' && countTmp.length < preferences.search_result_number))
792                        {
793                            EsearchE.mount_result((data=='none')?tmp:(countTmp.length==0)?data:data+tmp);
794                        }
795                        else if (data == 'many results' || countTmp.length >= preferences.search_result_number)
796                        {
797                            alert(get_lang("More than %1 results. Please, try to refine your search.",preferences.search_result_number));
798                        }
799                }
800                var args   = "$this.imap_functions.search_msg";
801                var params = "condition=" + nm_box;
802                if(expresso_offline)
803                        handler('none');
804                else
805                        cExecute(args,handler,params);
806        }
807        // clean;
808        searchE.prototype.func_clean = function(){
809                // Limpa os campos;
810                for(var i=0; i < this.fields.length; i++){
811                        if(Element("txt" + this.fields[i]) != null){Element("txt" + this.fields[i]).value = "";}
812                }
813            if(Element("check_all_msg") != null){Element("check_all_msg").checked = false;}
814
815            EsearchE.all_boxes.splice(0,(EsearchE.all_boxes.length));
816                EsearchE.del_mailboxes();
817        }
818
819        // close
820        searchE.prototype.func_close = function(type){
821                var _this = this;
822                _this.name_box_search = "";
823                EsearchE.all_boxes.splice(0,(EsearchE.all_boxes.length));
824                _this.type = type;
825                _this.searchW['window_search'].close();
826        }
827        // Monta a janela em tela;
828        searchE.prototype.showWindow = function(div){
829                if(!this.searchW[div.id]) {
830                        div.style.width = "660px";
831                        div.style.height = "255px";
832                        div.style.visibility = "hidden";
833                        div.style.position = "absolute";
834                        div.style.zIndex = "10003";
835                        var title = ":: "+ get_lang("Search")+" ::";
836                        var wHeight = div.offsetHeight + "px";
837                        var wWidth =  div.offsetWidth   + "px";
838
839                        win = new dJSWin({
840                                id: 'ccList'+div.id,
841                                content_id: div.id,
842                                width: wWidth,
843                                height: wHeight,
844                                title_color: '#3978d6',
845                                bg_color: '#eee',
846                                title: title,
847                                title_text_color: 'white',
848                                button_y_img: '../phpgwapi/images/win_min.gif',
849                                button_x_img: '../phpgwapi/images/winclose.gif',
850                                border: true });
851                        this.searchW[div.id] = win;
852                        win.draw();
853                }else{
854                        var _this = this;
855                        win = this.searchW[div.id];
856                        if((_this.type == "close" && win.state == 0) || win.state == 2){EsearchE.func_clean();}
857                        win.draw();
858                }
859                win.open();     
860        }
861       
862        searchE.prototype.aux_local_folder_display = function(folder) {
863                if(!expresso_offline)
864                        return "(Local) " + lang_folder(folder.substr(6));
865                else
866                        return lang_folder(folder.substr(6));
867        }
868       
869// Cria o objeto
870        var EsearchE;
871        EsearchE = new searchE();
Note: See TracBrowser for help on using the repository browser.