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

Revision 5459, 15.9 KB checked in by cristiano, 12 years ago (diff)

Ticket #2475 - Problema no registro da função autosave

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