source: branches/2.0/expressoMail1_2/js/search.js @ 2605

Revision 2605, 27.6 KB checked in by niltonneto, 14 years ago (diff)

Ticket #1040 - Corrige problemas ao redimensionar altura das divs principais.

  • 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        var defaultWidth = document.body.offsetWidth - 31;
476        var menuHidden = Element("folderscol").style.display == 'none' ? true : false;
477        if(!menuHidden)
478                defaultWidth -= Element("folderscol").offsetWidth;                     
479        var div_scroll_result = document.createElement("DIV");
480        div_scroll_result.id = "divScrollMain_"+numBox;
481        div_scroll_result.style.overflow = "auto";
482        div_scroll_result.style.width = defaultWidth - (is_ie ? 7 : 0);
483       
484                if(is_ie)
485                        Element("border_table").width = "99.5%";
486               
487                // Put header
488                var table_element = document.createElement("TABLE");
489                var tbody_element = document.createElement("TBODY");
490                table_element.setAttribute("id", "table_message_header_box");
491                table_element.className = "table_message_header_box";
492                tr_element = document.createElement("TR");
493                tr_element.className = "message_header";
494                td_element0 = document.createElement("TD");
495                td_element0.setAttribute("width", "1%");
496                chk_box_element = document.createElement("INPUT");
497                chk_box_element.id  = "chk_box_select_all_messages";
498                chk_box_element.setAttribute("type", "checkbox");
499                chk_box_element.className = "checkbox";
500                chk_box_element.onclick = function(){select_all_search_messages(this.checked,content_search.id);};
501                chk_box_element.onmouseover = function () {this.title=get_lang('Select all messages.')};
502                chk_box_element.onkeydown = function (e){
503                        if (is_ie)
504                        {
505                                if ((window.event.keyCode) == 46)
506                                        delete_msgs(current_folder,'selected','null');
507                        }
508                        else
509                        {
510                                if ((e.keyCode) == 46)
511                                        delete_msgs(current_folder,'selected','null');
512                        }
513                };
514               
515                td_element0.appendChild(chk_box_element);
516                td_element1 = document.createElement("TD");
517                td_element1.setAttribute("width", "20%");
518                td_element1.align = "left";
519                if (sort_type == 'SORTBOX')
520                {
521                        td_element1.onclick = function () { EsearchE.mount_result(data,'SORTBOX_REVERSE'); delete_border(border_id,false);};
522                        td_element1.innerHTML ="<b>"+get_lang("Folder")+"</b><img src='templates/"+template+"/images/arrow_descendant.gif'>";
523                }
524                else
525                {
526                        td_element1.onclick = function () { EsearchE.mount_result(data,'SORTBOX'); delete_border(border_id,false);};
527                        if  (sort_type == 'SORTBOX_REVERSE')
528                                td_element1.innerHTML ="<b>"+get_lang("Folder")+"</b><img src='templates/"+template+"/images/arrow_ascendant.gif'>";
529                        else
530                                td_element1.innerHTML = get_lang("Folder");
531                }
532                td_element2 = document.createElement("TD");
533                td_element2.setAttribute("width", "20%");
534                td_element2.align = "left";
535                if (sort_type == 'SORTWHO')
536                {
537                        td_element2.onclick = function () { EsearchE.mount_result(data,'SORTWHO_REVERSE'); delete_border(border_id,false);};
538                        td_element2.innerHTML ="<b>"+get_lang("who")+"</b><img src='templates/"+template+"/images/arrow_descendant.gif'>";
539                }
540                else
541                {
542                        td_element2.onclick = function () { EsearchE.mount_result(data,'SORTWHO'); delete_border(border_id,false);};
543                        if  (sort_type == 'SORTWHO_REVERSE')
544                                td_element2.innerHTML ="<b>"+get_lang("who")+"</b><img src='templates/"+template+"/images/arrow_ascendant.gif'>";
545                        else
546                                td_element2.innerHTML = get_lang("who");
547                }
548                td_element3 = document.createElement("TD");
549                td_element3.setAttribute("width", "35%");
550                td_element3.align = "left";
551                if (sort_type == 'SORTSUBJECT')
552                {
553                        td_element3.onclick = function () { EsearchE.mount_result(data,'SORTSUBJECT_REVERSE'); delete_border(border_id,false);};
554                        td_element3.innerHTML ="<b>"+get_lang("subject")+"</b><img src='templates/"+template+"/images/arrow_descendant.gif'>";
555                }
556                else
557                {
558                        td_element3.onclick = function () { EsearchE.mount_result(data,'SORTSUBJECT'); delete_border(border_id,false);};
559                        if  (sort_type == 'SORTSUBJECT_REVERSE')
560                                td_element3.innerHTML ="<b>"+get_lang("subject")+"</b><img src='templates/"+template+"/images/arrow_ascendant.gif'>";
561                        else
562                                td_element3.innerHTML = get_lang("subject");
563                }
564                td_element4 = document.createElement("TD");
565                td_element4.setAttribute("width", "15%");
566                td_element4.align = "center";
567                if (sort_type == 'SORTDATE')
568                {
569                        td_element4.onclick = function () { EsearchE.mount_result(data,'SORTDATE_REVERSE'); delete_border(border_id,false);};
570                        td_element4.innerHTML ="<b>"+get_lang("Date")+"</b><img src='templates/"+template+"/images/arrow_descendant.gif'>";
571                }
572                else
573                {
574                        td_element4.onclick = function () { EsearchE.mount_result(data,'SORTDATE'); delete_border(border_id,false);};
575                        if  (sort_type == 'SORTDATE_REVERSE')
576                                td_element4.innerHTML ="<b>"+get_lang("Date")+"</b><img src='templates/"+template+"/images/arrow_ascendant.gif'>";
577                        else
578                                td_element4.innerHTML = get_lang("Date");
579                }
580                td_element5 = document.createElement("TD");
581                td_element5.setAttribute("width", "10%");
582                td_element5.align = "center";
583                if (sort_type == 'SORTSIZE')
584                {
585                        td_element5.onclick = function () { EsearchE.mount_result(data,'SORTSIZE_REVERSE'); delete_border(border_id,false);};
586                        td_element5.innerHTML ="<b>"+get_lang("size")+"</b><img src='templates/"+template+"/images/arrow_descendant.gif'>";
587                }
588                else
589                {
590                        td_element5.onclick = function () { EsearchE.mount_result(data,'SORTSIZE'); delete_border(border_id,false);};
591                        if  (sort_type == 'SORTSIZE_REVERSE')
592                                td_element5.innerHTML ="<b>"+get_lang("size")+"</b><img src='templates/"+template+"/images/arrow_ascendant.gif'>";
593                        else
594                                td_element5.innerHTML = get_lang("Size");
595                }
596                tr_element.appendChild(td_element0);
597                tr_element.appendChild(td_element1);
598                tr_element.appendChild(td_element2);
599                tr_element.appendChild(td_element3);
600                tr_element.appendChild(td_element4);
601                tr_element.appendChild(td_element5);
602                tbody_element.appendChild(tr_element);
603                table_element.appendChild(tbody_element);
604                content_search.appendChild(table_element);
605                /*end of "put header"*/
606               
607                if (!expresso_offline) {
608/*                      var span_options = document.createElement("SPAN");
609                        if (span_options)
610                                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> | ' +
611                                '<span title="' +
612                                get_lang("Move") +
613                                '" class="message_options" onclick=wfolders.makeWindowNew(\"' +
614                                content_search.id +
615                                '\",\"move_to\",true)>' +
616                                get_lang("Move") +
617                                '</span>';*/
618                        div_scroll_result.appendChild(table);
619                        content_search.appendChild(div_scroll_result);
620                        /*if (span_options)
621                                content_search.appendChild(span_options);*/
622                }
623                else {
624                        div_scroll_result.appendChild(table);
625                        content_search.appendChild(div_scroll_result);
626                }
627                resizeWindow();
628        }
629
630        searchE.prototype.open_msg = function(mailbox, uid_msg, subject){
631                var handler_get_msg = function(data){
632                        if(Element("border_id_" + uid_msg + "_r")){alert(get_lang("This message is already opened!"));}
633                        else{draw_message(data,create_border(url_decode(subject), uid_msg + "_r"));}
634                        //set_msg_as_read(msgs_to_set[i], false);
635                }
636                proxy_mensagens.get_msg(uid_msg,mailbox,false,handler_get_msg);
637                /*var args   = "$this.imap_functions.get_info_msg";
638                var params = "msg_number=" + uid_msg + "&msg_folder=" + mailbox;
639                cExecute(args,handler_get_msg,params);*/
640
641        }
642
643        // Adiciona caixas postais na busca;
644        searchE.prototype.add_mailboxes = function(){
645                var sel = Element("sel_search_nm_box1");
646                if (!proxy_mensagens.is_local_folder(this.name_box_search)) {
647                        var name_box     = this.name_box_search.split(cyrus_delimiter);
648                        if(this.name_box_search == "")
649                                return false;
650                        var name_box_def = "";
651                        if(name_box.length != 1){
652                                name_box_def = name_box[(name_box.length-1)];
653                        }else{
654                                name_box_def = get_lang("Inbox");               
655                        }
656                }
657                else {
658                        if(this.name_box_search=='local_root')
659                                return;
660                        if(this.name_box_search=='local_Inbox')
661                                name_box_def = get_lang("Inbox");
662                        else
663                                name_box_def = this.name_box_search.substr(6);//Retira o 'local_'
664                }
665                if( sel.length > 0){
666                        for(var i=0; i < sel.options.length; i++){
667                                if(sel.options[i].value == this.name_box_search){
668                                        alert(get_lang('This message is already selected!'));
669                                        return false;
670                                }
671                        }
672                }
673                var opt = new Option(lang_folder(name_box_def),this.name_box_search,false,true);
674                sel[sel.length] = opt;
675        }
676        // Remove as caixas postais na busca;
677        searchE.prototype.del_mailboxes = function(){
678                var sel = Element("sel_search_nm_box1");
679                if(sel.length > 0){
680                        for(var i=0; i < sel.options.length; i++){
681                                if(sel.options[i].selected == true){
682                                        sel.options[i] = null;
683                                        i--;
684                                }
685                        }
686                }
687       
688        }
689        // todas as caixas
690        searchE.prototype.all_mailboxes = function(){
691                var value = Element("check_all_msg").checked;
692                var cont = parseInt(0);
693                if(value){
694                        if(EsearchE.all_boxes.length > 0){
695                                EsearchE.all_boxes.splice(0,(EsearchE.all_boxes.length));                       
696                        }
697                        for(var i=0; i < folders.length; i++){
698                                EsearchE.all_boxes[cont] = folders[i].folder_id;
699                                cont++;
700                        }
701                }else{
702                        EsearchE.all_boxes.splice(0,(EsearchE.all_boxes.length));
703                }
704        }
705
706        // Search;
707        searchE.prototype.func_search = function(value){
708                var fields = "##";
709                        // Verifica se os campos estão preenchidos;
710                        if(trim(Element("txt_ass").value) != ""){
711                                fields += "SUBJECT " +  "<=>" +url_encode(Element("txt_ass").value) + "##";
712                        }
713                        if(trim(Element("txt_body").value) != ""){
714                                fields += "BODY " + "<=>" + url_encode(Element("txt_body").value) + "##";
715                        }
716                        if(trim(Element("txt_de").value) != ""){
717                                fields += "FROM " + "<=>" + url_encode(Element("txt_de").value) + "##";
718                        }
719                        if(trim(Element("txt_para").value) != ""){
720                                fields += "TO " + "<=>" + url_encode(Element("txt_para").value) + "##";
721                        }
722                        if(trim(Element("txt_cc").value) != ""){
723                                fields += "CC " + "<=>" + url_encode(Element("txt_cc").value) + "##";
724                        }
725                        if(value) {
726                                fields = "##ALL " +  "<=>" +url_encode(value) + "##";
727                        }
728
729                if(fields == "##"){
730                        alert(get_lang("Define some search parameters!"));
731                        return false;
732                }
733                var local_folders = new Array();
734                var temp;
735               
736                if(Element("check_all_msg").checked){
737                        this.all_mailboxes();
738                        var nm_box = new Array;
739                        for(var i=0; i < EsearchE.all_boxes.length; i++){
740                                nm_box[i] = EsearchE.all_boxes[i] + fields;
741                        }
742                        if (preferences.use_local_messages == 1) {
743                                temp = expresso_local_messages.list_local_folders();
744                                for (var x in temp) {
745                                        local_folders.push(temp[x][0]);
746                                }
747                        }
748                }else{
749                        var nm_box = new Array;
750                        var sel_combo = Element("sel_search_nm_box1");
751                        if( sel_combo.options.length <= 0){
752                                alert(get_lang("Define the boxes to search!"));
753                                return false;
754                        }
755                       
756                        for(var i=0; i < sel_combo.options.length; i++){
757                                sel_combo.options[i].selected = true;
758                        }
759                        for(var i=0; i < sel_combo.options.length; i++){
760                                if(sel_combo.options[i].selected == true){
761                                        if(!proxy_mensagens.is_local_folder(sel_combo.options[i].value))
762                                                nm_box[nm_box.length] = sel_combo.options[i].value + fields;
763                                        else
764                                                local_folders.push(sel_combo.options[i].value.substr(6));
765                                }
766                        }
767                }
768                var handler = function(data){
769                        var tmp;
770                        var countTmp= new Array();
771                        if (local_folders.length > 0) {
772                                tmp = expresso_local_messages.search(local_folders, fields);
773                                if (tmp!=false) {
774                                        var tmp2 = tmp.substr(2, data.length - 4);
775                                        countTmp = tmp.split('####');
776                                }
777                        }
778                        if((data == "none") && (countTmp.length==0)){alert(get_lang("None result was found."));}
779                        else if(countTmp.length > 50){alert(get_lang("More than %1 results. Please, try to refine your search.",50));}
780                        else if(data == "many results"){alert(get_lang("More than %1 results. Please, try to refine your search.",50));}
781                        else{EsearchE.mount_result((data=='none')?tmp:(countTmp.length==0)?data:data+tmp);}
782                }
783                var args   = "$this.imap_functions.search_msg";
784                var params = "condition=" + nm_box;
785                if(expresso_offline)
786                        handler('none');
787                else
788                        cExecute(args,handler,params);
789        }
790        // clean;
791        searchE.prototype.func_clean = function(){
792                // Limpa os campos;
793                for(var i=0; i < this.fields.length; i++){
794                        if(Element("txt" + this.fields[i]) != null){Element("txt" + this.fields[i]).value = "";}
795                }
796            if(Element("check_all_msg") != null){Element("check_all_msg").checked = false;}
797
798            EsearchE.all_boxes.splice(0,(EsearchE.all_boxes.length));
799                EsearchE.del_mailboxes();
800        }
801
802        // close
803        searchE.prototype.func_close = function(type){
804                var _this = this;
805                _this.name_box_search = "";
806                EsearchE.all_boxes.splice(0,(EsearchE.all_boxes.length));
807                _this.type = type;
808                _this.searchW['window_search'].close();
809        }
810        // Monta a janela em tela;
811        searchE.prototype.showWindow = function(div){
812                if(!this.searchW[div.id]) {
813                        div.style.width = "660px";
814                        div.style.height = "255px";
815                        div.style.visibility = "hidden";
816                        div.style.position = "absolute";
817                        div.style.zIndex = "10003";
818                        var title = ":: "+ get_lang("Search")+" ::";
819                        var wHeight = div.offsetHeight + "px";
820                        var wWidth =  div.offsetWidth   + "px";
821
822                        win = new dJSWin({
823                                id: 'ccList'+div.id,
824                                content_id: div.id,
825                                width: wWidth,
826                                height: wHeight,
827                                title_color: '#3978d6',
828                                bg_color: '#eee',
829                                title: title,
830                                title_text_color: 'white',
831                                button_y_img: '../phpgwapi/images/win_min.gif',
832                                button_x_img: '../phpgwapi/images/winclose.gif',
833                                border: true });
834                        this.searchW[div.id] = win;
835                        win.draw();
836                }else{
837                        var _this = this;
838                        win = this.searchW[div.id];
839                        if((_this.type == "close" && win.state == 0) || win.state == 2){EsearchE.func_clean();}
840                        win.draw();
841                }
842                win.open();     
843        }
844       
845        searchE.prototype.aux_local_folder_display = function(folder) {
846                if(!expresso_offline)
847                        return "(Local) " + lang_folder(folder.substr(6));
848                else
849                        return lang_folder(folder.substr(6));
850        }
851       
852// Cria o objeto
853        var EsearchE;
854        EsearchE = new searchE();
Note: See TracBrowser for help on using the repository browser.