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

Revision 1614, 29.4 KB checked in by rafaelraymundo, 14 years ago (diff)

Ticket #720 - Na pesquisa de e-mails mostra resultados até limite quando ultrapassa.

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