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

Revision 5219, 15.4 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                var is_local = ID.match('.*_local_.*');
246                if(!is_local)
247                        cc = document.getElementById("em_message_search").value;
248                else{
249                        cc = document.getElementsByName(currentTab)[0].value;
250                }
251        }
252
253        td.innerHTML = "<div style='width:100%;border:0;padding:0;'>\n\
254                            <div id='font_border_id_" + ID+"' class='font-menu' style='width:*;'>" +
255                                borderTitle +
256                            "</div>\n\
257                            <div style='width:1px;float:left;clear:right;'>\n\
258                                <img onmousedown='javascript:return false' style='cursor:pointer' onclick=delete_border('" + ID + "','false') src='templates/"+template+"/images/close_button.gif'/>\n\ " +
259                            "</div>\n\ " +
260                                                        "<input type=\"hidden\" name=\""+ ID+"\" value=\""+cc+"\">" +
261                        "</div>";
262       
263        bb = document.getElementById("border_blank");
264        parent_bb = bb.parentNode; //Pego o tbody
265        parent_bb.insertBefore(td, bb);
266
267        if(! Element("border_id_"+id_value+"_r") ||((typeof(id_value) == 'string') && id_value.match(/_r$/)))
268                _dragArea.makeDragged(td, id_value,td.value);
269
270        BordersArray[BordersArray.length] = new setBorderAttributes(ID);
271
272        var div = document.createElement("DIV");
273        div.id = "content_id_" + ID;
274        div.className = "conteudo";
275        div.style.display='';
276
277        div.style.overflow = "hidden";
278
279        Element("exmail_main_body").insertBefore(div,Element("footer_menu"));
280        alternate_border(ID);
281        return ID;
282}
283
284function resize_borders()
285{
286        var numBorders = count_borders();
287
288        if (numBorders > 8)
289                return false;
290
291        return redim_borders(numBorders+1);
292}
293
294function count_borders()
295{
296        var numBorders = 0;
297        var children = Element('border_tr').childNodes;
298        for (var i=0; i<children.length; i++) {
299            if ((children[i].nodeName === 'TD') && (children[i].id!=='border_id_0') && (children[i].id!=='border_blank'))
300                numBorders++;
301        }
302
303        return numBorders;
304}
305
306function redim_borders(numBorders)
307{
308        var children = Element('border_tr').childNodes;
309        var clientWidth = (window.document.body.clientWidth - findPosX(Element("exmail_main_body"))) - Element("border_id_0").clientWidth - 30;
310        var newWidthTD = (clientWidth/numBorders)-6;
311        newWidthTD = newWidthTD > 200 ? 200 : (newWidthTD < 50 ? 50 : newWidthTD);
312        children = Element('border_tr').childNodes;
313        for (var i=0; i<children.length; i++) {
314                if ((children[i].nodeName === 'TD') && (children[i].id!=='border_id_0') && (children[i].id!=='border_blank')){
315                        children[i].style.width = newWidthTD;
316                        set_border_caption(children[i].id, children[i].title, newWidthTD);
317                }
318        }
319        return newWidthTD;
320}
321
322function set_border_caption(border_id, title, border_width)
323{
324        var border = document.getElementById(border_id);
325        if (border_width == null)
326        {
327            border_width = border.clientWidth;
328        }
329        var caption = "";
330        Element("font_"+border.id).style.width = (border_width - 30)+'px';
331        Element("font_"+border.id).innerHTML = title;
332        return(title);
333}
334
335function draftTests(ID, msg_sent){
336    var cancel = new LertButton(get_lang('cancel'), function() {
337        Element("border_id_"+ID).onclick = function () { alternate_border(ID);};
338        cRichTextEditor.prototype.focus(ID);
339           
340    });
341       
342    var yes = new LertButton(get_lang('Save'), function() {
343        save_msg(ID, 'undefined', true);
344        openTab.toPreserve[ID] = false;
345        close_delete(ID, msg_sent);
346        delete(openTab.type[ID]);
347                //write_msg(get_lang('Your message was save as draft in folder %1.', lang_folder('Drafts')));
348               
349    });
350    var discard = new LertButton(get_lang('Discard'), function() {
351            if (openTab.imapBox[ID] && !openTab.toPreserve[ID])
352            {
353                //delete_msgs(openTab.imapBox[ID], openTab.imapUid[ID].toString(), 0)
354                //delete(openTab.imapBox[ID]);
355                openTab.toPreserve[ID] = false;
356            }
357                        delete(openTab.type[ID]);
358            close_delete(ID, msg_sent);
359    });
360    var titulo = '<b>' + get_lang('Warning') + '!</b>';
361    var message = get_lang("Your changes are not saved. What to do?");
362    var multConfirm = new Lert(
363            titulo,
364            message,
365            [cancel,discard,yes],
366            {
367                    defaultButton:yes,
368                    icon:'js/lert/images/dialog-help.gif'
369            });
370    multConfirm.display();
371}
372
373function editTest(ID){
374    var body = document.getElementById('body_'+ ID);
375    if (body)
376    {
377        var save_link = Element("save_message_options_"+ID);
378        if (openTab.toPreserve[ID] == undefined)
379                openTab.toPreserve[ID] = false;
380        if (((! openTab.toPreserve[ID] && ! ID.toString().match("_r")) || ((body.contentWindow) == 'object' && body.contentWindow.document.designMode.toLowerCase() == 'on')) && (save_link.onclick != ''))
381        {
382            return true;
383        }
384    }
385    return false;
386}
387
388function delete_border(ID, msg_sent)
389{
390   
391        var bolExecuteClose = true;
392        var borderElem = Element("border_id_" + ID);
393        if (borderElem){
394            borderElem.onclick = null; // It's avoid a FF3 bug
395        }else{
396            return false;
397        }
398        if (msg_sent == 'false')
399        {
400            if (editTest(ID)){
401                bolExecuteClose = false;
402                return(draftTests(ID, msg_sent));
403            }
404        }
405        if (bolExecuteClose)
406        {
407            close_delete(ID, msg_sent);
408                }
409                delete(openTab.type[ID]);
410        return true;
411}
412
413function close_delete(ID, msg_sent)
414{
415        openTab.toPreserve[ID] = false;
416        openTab.imapUid[ID] = 0;
417
418        if (preferences.auto_save_draft == 1)
419        {
420                if (openTab.autosave_timer[ID])
421                        clearTimeout(openTab.autosave_timer[ID]);
422                openTab.autosave_timer[ID] = false;
423        }
424
425        hold_session = false;
426        if (exist_className(Element('border_id_'+ID),'menu-sel'))
427        {
428                if (BordersArray[BordersArray.length-2].sequence == ID)
429                        this.alternate_border(0);
430                else
431                        this.alternate_border(BordersArray[BordersArray.length-2].sequence);
432        }
433
434        // Remove TD, title
435        border = Element('border_id_' + ID);
436        border.parentNode.removeChild(border);
437        var j=0;
438        var new_BordersArray = new Array();
439        for (i=0;i<BordersArray.length;i++)
440                if (document.getElementById(BordersArray[i].border_id) != null){
441                        new_BordersArray[j] = BordersArray[i];
442                        j++;
443                }
444        if(j == 1)
445                Element("footer_menu").style.display = '';
446        BordersArray = new_BordersArray;
447
448        // Remove Div Content
449        content = Element('content_id_' + ID);
450        content.parentNode.removeChild(content);
451        resizeWindow();
452        RichTextEditor.destroy( 'body_'+ID );
453       
454        //Caso for uma mensagem anexada tem que deletar ela da lixeira apos fechar a aba
455            var isPartMsg = false;
456            var id2 = ID.replace('_r','');
457            for(var ii = 0; ii < partMsgs.length; ii++)
458               if(partMsgs[ii] == id2){           
459                  isPartMsg = true;
460                  partMsgs[ii] = null;
461               }     
462
463            if(isPartMsg === true){
464                var handler_delete_msg = function(){};
465                cExecute ("$this.imap_functions.delete_msgs&folder=INBOX"+cyrus_delimiter+trashfolder+"&msgs_number="+id2,handler_delete_msg);
466            }
467        ///////////////////////////////////////////////////////////////////////////////////
468       
469        return true;
470}
471
472function getTabPrefix() { // define o prefixo para os checkboxes das mensagens
473        if (typeof(currentTab)!='number')
474                return currentTab+"_";
475        else
476                return "";
477}
478
479function getMessageIdFromRowId(row_id) { // extrai o id da mensagem do id da linha
480        var p = row_id.search("_s");
481        if (p>0)
482                return row_id.substr(0,p);
483        else
484                return row_id;
485}
486
487function getNumBoxFromTabId(tab_id) { // extrai o numBox do id da tab
488        if (typeof(tab_id)=='number') {
489                return tab_id;
490        }
491        else {
492                var p = tab_id.search(/[0-9]/);
493                return tab_id.substr(p);
494        }
495}
Note: See TracBrowser for help on using the repository browser.