source: trunk/expressoMail1_2/js/abas.js @ 5222

Revision 5222, 15.5 KB checked in by douglasz, 12 years ago (diff)

Ticket #2339 - Ao reordenar a pesquisa aparece novamente a mensagem das pastas locais

  • Property svn:eol-style set to native
  • Property svn:executable set to *
Line 
1var BordersArray = new Array();
2BordersArray[0] = new setBorderAttributes(0);
3var countBorders = 0;
4var partMsgs = new Array();
5
6
7function setBorderAttributes(ID)
8{
9        this.border_id = "border_id_"+ID;
10        this.sequence = ID;
11}
12
13
14function alternate_border(ID)
15{
16        if( document.getElementById("div_menu_c3") != null )
17        {
18                var node = document.getElementById("div_menu_c3").firstChild;
19               
20                while ( node )
21                {
22                        node.style.display = "none";
23                        node = node.nextSibling;
24                }
25               
26                if( document.getElementById("span_paging"+ID) != null )
27                        document.getElementById("span_paging"+ID).style.display = "block";
28        }
29       
30        if ( typeof win == 'object' && win.close && win.close.constructor == Function ){
31            var search_win = document.getElementById( 'window_QuickCatalogSearch' );
32            if(search_win){
33                search_win.style.visibility = 'hidden';
34            }
35            win.close( );
36        }
37               
38        if (! Element('border_id_'+ID))
39                return false; // Not possible to alternate
40        show_hide_span_paging(ID);
41        spanD = Element("span_D");
42        if (spanD)
43                spanD.style.display = (openTab.type[ID] == 0 ? '' : 'none');
44
45        var footer_menu = Element("footer_menu");       
46        var aba = Element('border_id_'+ID);
47        if (footer_menu != null) {
48                footer_menu.style.display = (openTab.type[ID] != 4 ? '' : 'none');
49                var alternate_menu = document.getElementById('localOption');
50               
51                if(alternate_menu != null && alternate_menu != 'undefined'){ //Quando Carregado o expresso mail
52                        if(openTab.imapBox[ID]!= null && openTab.imapBox[ID]!= 'undefined' ){ //Quando abrir uma Nova Mensagem
53                                if((openTab.imapBox[ID].indexOf("local_") >= 0)){                                               
54                                                alternate_menu.title = get_lang("Unarchive");
55                                                alternate_menu.removeAttribute("onclick");
56                                                if(!is_ie)
57                                                        alternate_menu.setAttribute("onclick",  'expresso_local_messages.unarchive_msgs(\''+openTab.imapBox[ID]+'\', null)');
58                                                else{
59                                                        alternate_menu.onclick = function(){
60                                                                expresso_local_messages.unarchive_msgs(openTab.imapBox[ID], null);
61                                                        }
62                                                }
63                                                alternate_menu.innerHTML = get_lang("Unarchive");
64                                               
65                                        }else{
66                                                alternate_menu.title = get_lang("Archive");
67                                                alternate_menu.removeAttribute("onclick");
68                                                if(!is_ie)
69                                                        alternate_menu.setAttribute("onclick", 'archive_msgs(\''+openTab.imapBox[ID]+'\', null)');             
70                                                else{
71                                                        alternate_menu.onclick = function(){
72                                                                archive_msgs(openTab.imapBox[ID], null);
73                                                        }       
74                                                }
75                                                alternate_menu.innerHTML = get_lang("Archive");
76                                        }
77                                       
78                        }
79                }
80               
81                if((aba.id.indexOf("_r") < 0) && (aba.id.indexOf("_0") < 0) && (aba.id.indexOf("id_search_") < 0) && (aba.id.indexOf("_s") < 0)){
82                        spanD.style.display = 'none';
83                        footer_menu.style.display = 'none';                     
84                }
85        }
86
87
88        var len = BordersArray.length;
89        for (var i=0; i < len; i++)
90        {
91                m = document.getElementById(BordersArray[i].border_id);
92                if ((m)&&(m.className == 'menu-sel'))
93                {
94                        m.className = 'menu';
95                        c = document.getElementById("content_id_"+BordersArray[i].sequence);
96                        c.style.display = 'none';
97                        if(Element("font_border_id_"+BordersArray[i].sequence))
98                                Element("font_border_id_"+BordersArray[i].sequence).className = 'font-menu';   
99
100                }
101        }
102
103        m = Element("border_id_"+ID);
104        if (m)
105                m.className = 'menu-sel';
106        if(Element("font_border_id_" + ID))
107                Element("font_border_id_" + ID).className = 'font-menu-sel';
108        var c = Element("content_id_"+ID)
109        if (c)
110                c.style.display = '';
111
112
113        // hide the DropDrowContact, if necessary
114        window_DropDownContacts = Element('tipDiv');
115        if ((window_DropDownContacts)&&(window_DropDownContacts.style.visibility != 'hidden')){
116                window_DropDownContacts.style.visibility = 'hidden';
117        }
118
119        numBox = getNumBoxFromTabId(ID);
120        if (typeof(ID)=='number') {
121                 numBox = ID;
122         }
123         else {
124             if (ID.match("search_"))
125             {
126                 if (ID.match("search_local_msg"))
127                 {
128                         var p = ID.search(/[0-9]/);
129                         numBox =  ID.substr(p);
130                 }
131                 else
132                 {
133                         numBox = ID.substr(7);
134                 }
135             }
136         }
137
138        currentTab=ID;
139       
140        if( document.getElementById('to_'+ID) && document.getElementById('to_'+ID).type == "textarea"){
141                document.getElementById('to_'+ID).focus();
142        }
143       
144        RichTextEditor.setEditable(ID);
145        return ID;
146}
147
148function create_border(borderTitle, id_value, search)
149{
150       
151        borderTitle = ( ( borderTitle && borderTitle.constructor == String && borderTitle.length > 0 ) ? borderTitle : '&nbsp;' );
152
153        var resize = false;
154        resize = resize_borders();
155        if (!resize){
156            var str_continue = '';
157            var bolContinue = true;
158                        str_continue = '\n' + get_lang('You must manually close one of your tabs before opening a new one');
159            if (preferences.auto_close_first_tab == 1){
160                var children = Element('border_tr').childNodes;
161                var bolDelete = true;
162                for (var i=0; i<children.length; i++) {
163                    if ((children[i].nodeName === 'TD') && (children[i].id!=='border_id_0') && (children[i].id!=='border_blank'))
164                    {
165                        bolDelete = true;
166                        var num_child = children[i].id.toString().substr(10);
167                        alternate_border(num_child);
168                        if (editTest(num_child)){
169                            bolDelete = false;
170                        }
171                        if (bolDelete || bolContinue){
172                                                        str_fechar = '\n' + get_lang('Reached maximum tab limit. Want to close this tab');
173                                                        var confirmacao = confirm(str_fechar);
174                            if(confirmacao){
175                            bolContinue = false;
176                            delete_border(num_child, 'false');
177                            break;
178                                                        }else{
179                                                                return 'maximo';
180                        }
181                    }
182                }
183            }
184            }else{                     
185                alert(get_lang('Reached maximum tab limit') + str_continue );
186                return 'maximo';
187            }
188        }
189       
190        if (! id_value){ // Is new message?
191                var ID = parseInt(BordersArray[(BordersArray.length-1)].sequence) + 1;
192                        if(isNaN(ID)){
193                                var aux = BordersArray[(BordersArray.length-1)].sequence.split("_");
194                                ID = parseInt(aux[1]) + 1;
195                        }
196        }else
197        {
198                if (Element("border_id_"+id_value)) // It's opened already!
199                        return alternate_border(id_value);
200               
201                var ID = id_value;
202                if(isNaN(ID) && ID.indexOf("search_local") >= 0){
203                        if(current_folder.indexOf("local") >= 0)
204                                openTab.imapBox[ID] = current_folder;
205                        else
206                                openTab.imapBox[ID] = 'local_search';
207                }else if(isNaN(ID) && ID.indexOf("search_") >= 0){
208                        if(current_folder.indexOf("local") < 0)
209                                openTab.imapBox[ID] = current_folder;
210                        else
211                                openTab.imapBox[ID] = 'search';
212                }else if((currentTab != 0) && (currentTab.indexOf("search") >= 0) && (ID.indexOf("msg") < 0)) {
213                        var id_border = currentTab.replace(/[a-zA-Z_]+/, "");
214                        ID_TR = ID.toString().substr(0,ID.toString().indexOf("_r"));
215                        var tr = Element(ID_TR);
216                        openTab.imapBox[ID] = (tr.getAttribute('name') == null?get_current_folder():tr.getAttribute('name'));
217                }else
218                        openTab.imapBox[ID] = current_folder;
219        }
220        td = document.createElement("TD");
221        td.id="border_id_" + ID;
222        if(resize)
223        {
224                td.setAttribute("width", parseInt(resize)+"px");
225                td.style.width = parseInt(resize)+"px";
226        }
227        else
228                td.setAttribute("width", "200px");
229
230        td.setAttribute("align", "right");
231        td.onclick = function(){alternate_border(ID);resizeWindow()};
232        td.setAttribute("noWrap","true");
233    td.alt = borderTitle.replace( '&nbsp;', ' ' );
234    td.title = borderTitle;
235        borderTitle = borderTitle ?  borderTitle : id_value ? get_lang("No Subject") : "&nbsp;" ;
236        td.value = borderTitle;
237        if (borderTitle.length > 21)
238                borderTitle = borderTitle.substring(0,21) + "...";
239
240        if ( resize )
241                borderTitle = borderTitle.substring(0, resize*0.08);
242       
243        var cc = search;
244        if(!cc){
245                if(isNaN(ID)){
246                        var is_local = ID.match('.*_local_.*');
247                        if(!is_local)
248                                cc = document.getElementById("em_message_search").value;
249                        else{
250                                cc = document.getElementsByName(currentTab)[0].value;
251                        }
252                }else{
253                        cc ="";
254                }
255        }
256
257        td.innerHTML = "<div style='width:100%;border:0;padding:0;'>\n\
258                            <div id='font_border_id_" + ID+"' class='font-menu' style='width:*;'>" +
259                                borderTitle +
260                            "</div>\n\
261                            <div style='width:1px;float:left;clear:right;'>\n\
262                                <img onmousedown='javascript:return false' style='cursor:pointer' onclick=delete_border('" + ID + "','false') src='templates/"+template+"/images/close_button.gif'/>\n\ " +
263                            "</div>\n\ " +
264                                                        "<input type=\"hidden\" name=\""+ ID+"\" value=\""+cc+"\">" +
265                        "</div>";
266       
267        bb = document.getElementById("border_blank");
268        parent_bb = bb.parentNode; //Pego o tbody
269        parent_bb.insertBefore(td, bb);
270
271        if(! Element("border_id_"+id_value+"_r") ||((typeof(id_value) == 'string') && id_value.match(/_r$/)))
272                _dragArea.makeDragged(td, id_value,td.value);
273
274        BordersArray[BordersArray.length] = new setBorderAttributes(ID);
275
276        var div = document.createElement("DIV");
277        div.id = "content_id_" + ID;
278        div.className = "conteudo";
279        div.style.display='';
280
281        div.style.overflow = "hidden";
282
283        Element("exmail_main_body").insertBefore(div,Element("footer_menu"));
284        alternate_border(ID);
285        return ID;
286}
287
288function resize_borders()
289{
290        var numBorders = count_borders();
291
292        if (numBorders > 8)
293                return false;
294
295        return redim_borders(numBorders+1);
296}
297
298function count_borders()
299{
300        var numBorders = 0;
301        var children = Element('border_tr').childNodes;
302        for (var i=0; i<children.length; i++) {
303            if ((children[i].nodeName === 'TD') && (children[i].id!=='border_id_0') && (children[i].id!=='border_blank'))
304                numBorders++;
305        }
306
307        return numBorders;
308}
309
310function redim_borders(numBorders)
311{
312        var children = Element('border_tr').childNodes;
313        var clientWidth = (window.document.body.clientWidth - findPosX(Element("exmail_main_body"))) - Element("border_id_0").clientWidth - 30;
314        var newWidthTD = (clientWidth/numBorders)-6;
315        newWidthTD = newWidthTD > 200 ? 200 : (newWidthTD < 50 ? 50 : newWidthTD);
316        children = Element('border_tr').childNodes;
317        for (var i=0; i<children.length; i++) {
318                if ((children[i].nodeName === 'TD') && (children[i].id!=='border_id_0') && (children[i].id!=='border_blank')){
319                        children[i].style.width = newWidthTD;
320                        set_border_caption(children[i].id, children[i].title, newWidthTD);
321                }
322        }
323        return newWidthTD;
324}
325
326function set_border_caption(border_id, title, border_width)
327{
328        var border = document.getElementById(border_id);
329        if (border_width == null)
330        {
331            border_width = border.clientWidth;
332        }
333        var caption = "";
334        Element("font_"+border.id).style.width = (border_width - 30)+'px';
335        Element("font_"+border.id).innerHTML = title;
336        return(title);
337}
338
339function draftTests(ID, msg_sent){
340    var cancel = new LertButton(get_lang('cancel'), function() {
341        Element("border_id_"+ID).onclick = function () { alternate_border(ID);};
342        cRichTextEditor.prototype.focus(ID);
343           
344    });
345       
346    var yes = new LertButton(get_lang('Save'), function() {
347        save_msg(ID, 'undefined', true);
348        openTab.toPreserve[ID] = false;
349        close_delete(ID, msg_sent);
350        delete(openTab.type[ID]);
351                //write_msg(get_lang('Your message was save as draft in folder %1.', lang_folder('Drafts')));
352               
353    });
354    var discard = new LertButton(get_lang('Discard'), function() {
355            if (openTab.imapBox[ID] && !openTab.toPreserve[ID])
356            {
357                //delete_msgs(openTab.imapBox[ID], openTab.imapUid[ID].toString(), 0)
358                //delete(openTab.imapBox[ID]);
359                openTab.toPreserve[ID] = false;
360            }
361                        delete(openTab.type[ID]);
362            close_delete(ID, msg_sent);
363    });
364    var titulo = '<b>' + get_lang('Warning') + '!</b>';
365    var message = get_lang("Your changes are not saved. What to do?");
366    var multConfirm = new Lert(
367            titulo,
368            message,
369            [cancel,discard,yes],
370            {
371                    defaultButton:yes,
372                    icon:'js/lert/images/dialog-help.gif'
373            });
374    multConfirm.display();
375}
376
377function editTest(ID){
378    var body = document.getElementById('body_'+ ID);
379    if (body)
380    {
381        var save_link = Element("save_message_options_"+ID);
382        if (openTab.toPreserve[ID] == undefined)
383                openTab.toPreserve[ID] = false;
384        if (((! openTab.toPreserve[ID] && ! ID.toString().match("_r")) || ((body.contentWindow) == 'object' && body.contentWindow.document.designMode.toLowerCase() == 'on')) && (save_link.onclick != ''))
385        {
386            return true;
387        }
388    }
389    return false;
390}
391
392function delete_border(ID, msg_sent)
393{
394   
395        var bolExecuteClose = true;
396        var borderElem = Element("border_id_" + ID);
397        if (borderElem){
398            borderElem.onclick = null; // It's avoid a FF3 bug
399        }else{
400            return false;
401        }
402        if (msg_sent == 'false')
403        {
404            if (editTest(ID)){
405                bolExecuteClose = false;
406                return(draftTests(ID, msg_sent));
407            }
408        }
409        if (bolExecuteClose)
410        {
411            close_delete(ID, msg_sent);
412                }
413                delete(openTab.type[ID]);
414        return true;
415}
416
417function close_delete(ID, msg_sent)
418{
419        openTab.toPreserve[ID] = false;
420        openTab.imapUid[ID] = 0;
421
422        if (preferences.auto_save_draft == 1)
423        {
424                if (openTab.autosave_timer[ID])
425                        clearTimeout(openTab.autosave_timer[ID]);
426                openTab.autosave_timer[ID] = false;
427        }
428
429        hold_session = false;
430        if (exist_className(Element('border_id_'+ID),'menu-sel'))
431        {
432                if (BordersArray[BordersArray.length-2].sequence == ID)
433                        this.alternate_border(0);
434                else
435                        this.alternate_border(BordersArray[BordersArray.length-2].sequence);
436        }
437
438        // Remove TD, title
439        border = Element('border_id_' + ID);
440        border.parentNode.removeChild(border);
441        var j=0;
442        var new_BordersArray = new Array();
443        for (i=0;i<BordersArray.length;i++)
444                if (document.getElementById(BordersArray[i].border_id) != null){
445                        new_BordersArray[j] = BordersArray[i];
446                        j++;
447                }
448        if(j == 1)
449                Element("footer_menu").style.display = '';
450        BordersArray = new_BordersArray;
451
452        // Remove Div Content
453        content = Element('content_id_' + ID);
454        content.parentNode.removeChild(content);
455        resizeWindow();
456        RichTextEditor.destroy( 'body_'+ID );
457       
458        //Caso for uma mensagem anexada tem que deletar ela da lixeira apos fechar a aba
459            var isPartMsg = false;
460            var id2 = ID.replace('_r','');
461            for(var ii = 0; ii < partMsgs.length; ii++)
462               if(partMsgs[ii] == id2){           
463                  isPartMsg = true;
464                  partMsgs[ii] = null;
465               }     
466
467            if(isPartMsg === true){
468                var handler_delete_msg = function(){};
469                cExecute ("$this.imap_functions.delete_msgs&folder=INBOX"+cyrus_delimiter+trashfolder+"&msgs_number="+id2,handler_delete_msg);
470            }
471        ///////////////////////////////////////////////////////////////////////////////////
472       
473        return true;
474}
475
476function getTabPrefix() { // define o prefixo para os checkboxes das mensagens
477        if (typeof(currentTab)!='number')
478                return currentTab+"_";
479        else
480                return "";
481}
482
483function getMessageIdFromRowId(row_id) { // extrai o id da mensagem do id da linha
484        var p = row_id.search("_s");
485        if (p>0)
486                return row_id.substr(0,p);
487        else
488                return row_id;
489}
490
491function getNumBoxFromTabId(tab_id) { // extrai o numBox do id da tab
492        if (typeof(tab_id)=='number') {
493                return tab_id;
494        }
495        else {
496                var p = tab_id.search(/[0-9]/);
497                return tab_id.substr(p);
498        }
499}
Note: See TracBrowser for help on using the repository browser.