source: branches/2.4/expressoMail1_2/js/common_functions.js @ 6931

Revision 6931, 37.3 KB checked in by eduardow, 12 years ago (diff)

Ticket #2987 - Inconsistencia excluindo com tela modal aberta - teclas de atalho.

  • Property svn:eol-style set to native
  • Property svn:executable set to *
Line 
1// BEGIN: FUNCTION RESIZE WINDOW
2if (!expresso_offline) {
3        var _showBar = showBar;
4        var _hideBar = hideBar;
5}
6
7function __showBar(){
8        _showBar();
9        resizeWindow();
10}
11
12function __hideBar(){
13        _hideBar();
14        resizeWindow();
15}
16showBar = __showBar;
17hideBar = __hideBar;
18
19window.onresize = resizeWindow;
20
21var message = "Não Informado";
22
23function config_events(pObj, pEvent, pHandler)
24{
25    if( typeof pObj == 'object')
26    {
27        if( pEvent.substring(0, 2) == 'on')
28            pEvent = pEvent.substring(2, pEvent.length);
29
30        if ( pObj.addEventListener )
31            pObj.addEventListener(pEvent, pHandler, false);
32        else if( pObj.attachEvent )
33            pObj.attachEvent('on' + pEvent, pHandler );
34    }
35}
36
37function resizeWindow(){
38
39        var divScrollMain = Element("divScrollMain_"+numBox);
40        var table_message = Element("table_message");
41        var content_folders = Element("content_folders");
42       
43        var clientWidth = 0, clientHeight = 0;
44        if( typeof( window.innerWidth ) == 'number' ) {
45                //Non-IE
46                clientWidth = window.innerWidth;
47                clientHeight = window.innerHeight;
48        } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
49                //IE 6+ in 'standards compliant mode'
50                clientWidth = document.documentElement.clientWidth;
51                clientHeight = document.documentElement.clientHeight;
52        } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
53                //IE 4 compatible
54                clientWidth = document.body.clientWidth;
55                clientHeight = document.body.clientHeight;
56        }
57        clientHeight = clientHeight - 8;
58
59        if(divScrollMain){
60                divScrollMain.style.height = (clientHeight - (findPosY(divScrollMain) + (table_message.clientHeight ? table_message.clientHeight : table_message.offsetHeight))) + "px";
61        }
62
63        if(typeof(BordersArray) != 'undefined') {
64                for(var i = 1; BordersArray.length > 1 && i < BordersArray.length;i++) {
65                        var div_scroll = Element("div_message_scroll_"+BordersArray[i].sequence);
66                        var div = Element("content_id_"+BordersArray[i].sequence);
67
68                        if(div){
69                                div.style.height = (clientHeight - (findPosY(div) + (table_message.clientHeight ? table_message.clientHeight : table_message.offsetHeight)+2)) + "px";
70                                 div.style.width = (clientWidth - (findPosX(div)+10)) + "px";
71                        }
72                        if(div_scroll){
73                                div_scroll.style.height = (clientHeight - (findPosY(div_scroll) + (table_message.clientHeight ? table_message.clientHeight : table_message.offsetHeight)+5)) + "px";
74                                div_scroll.style.width = (clientWidth - (findPosX(div_scroll)+15)) + "px";
75                        }
76                }
77        }
78
79        if(content_folders){
80                var search_div = Element("search_div");
81                var contentFoldersY = findPosY(content_folders);
82                content_folders.style.height = (clientHeight - (contentFoldersY + (contentFoldersY > findPosY(search_div) ? 0 : (search_div.clientHeight ? search_div.clientHeight : search_div.offsetHeight) + 5))) + "px";
83        }
84        redim_borders(count_borders());
85        resizeMailList();
86}
87// END: FUNCTION RESIZE WINDOW
88
89var _beforeunload_ = window.onbeforeunload;
90
91window.onbeforeunload = unloadMess;
92
93function unloadMess(){
94        if (typeof BordersArray == 'undefined') return; // We're not on expressoMail
95        if (typeof(expresso_mail_sync) != "undefined" && expresso_mail_sync.working) {
96                var mess = get_lang("You're about archiving your e-mails from server. Do you really want to stop this action?");
97                return mess;
98        }
99        else {
100            for (var i = 0; i < BordersArray.length; i++)
101                    if(BordersArray[i].sequence > 0 && (!isNaN(BordersArray[i].sequence)&&parseInt(BordersArray[i].sequence) == BordersArray[i].sequence) )
102                            return get_lang('There are still editing posts, really want to leave the page')+'?';
103        }
104}
105
106// Translate words and phrases using user language from eGroupware.
107function get_lang(_key) {
108        if (typeof(_key) == 'undefined')
109                return false;
110        var key = _key.toLowerCase();
111        if(array_lang[key])
112                var _value = array_lang[key];
113        else
114                var _value = _key+"*";
115
116        if(arguments.length > 1)
117                for(j = 1; typeof(arguments[j]) != 'undefined'; j++)
118                        _value = _value.replace("%"+j,arguments[j]);
119        return _value;
120}
121
122// Make decimal round, using in size message
123function round(value, decimal){
124        var return_value = Math.round( value * Math.pow( 10 , decimal ) ) / Math.pow( 10 , decimal );
125        return( return_value );
126}
127
128// Change the class of message.
129// In refresh, the flags UnRead and UnSeen don't exist anymore.
130function set_msg_as_read(msg_number, selected){
131        tr_message = Element(msg_number);
132        if (exist_className(tr_message, 'tr_msg_unread'))
133                decrement_folder_unseen();
134        remove_className(tr_message, 'tr_msg_unread');
135        remove_className(tr_message, 'selected_msg');
136       
137        if( document.getElementById("td_message_unseen_"+msg_number) != null )
138                Element("td_message_unseen_"+msg_number).innerHTML = "<img src ='templates/"+template+"/images/seen.gif' title='"+get_lang('Seen')+"'>";
139       
140        connector.purgeCache();
141        return true;
142}
143
144function msg_is_read(msg_number, selected){
145        tr_message = Element(msg_number);
146        return !(tr_message && LTrim(tr_message.className).match('tr_msg_unread'))
147}
148
149function set_msg_as_unread(msg_number, isSearch){
150        tr_message = Element(msg_number);
151        if ((exist_className(tr_message, 'tr_msg_read') || exist_className(tr_message, 'tr_msg_read2')) && (!exist_className(tr_message, 'tr_msg_unread')))
152                increment_folder_unseen();
153        remove_className(tr_message, 'selected_msg');
154        add_className(tr_message, 'tr_msg_unread');
155        if(!isSearch)
156                Element("td_message_unseen_"+msg_number).innerHTML = "<img src ='templates/"+template+"/images/unseen.gif' title='"+get_lang('Unseen')+"'>";
157}
158
159function set_msg_as_flagged(msg_number, isSearch){
160        var msg = Element(msg_number);
161        remove_className(msg, 'selected_msg');
162        add_className(msg, 'flagged_msg');
163        if(isSearch)
164                Element("td_message_important_"+msg_number.substr(0,msg_number.indexOf('_'))).innerHTML = "<img src ='templates/"+template+"/images/important.png' title='"+get_lang('Important')+"'>";
165        else
166                Element("td_message_important_"+msg_number).innerHTML = "<img src ='templates/"+template+"/images/important.png' title='"+get_lang('Important')+"'>";
167}
168
169function set_msg_as_unflagged(msg_number, isSearch){
170        var msg = Element(msg_number);
171        remove_className(msg, 'selected_msg');
172        remove_className(msg, 'flagged_msg');
173        if(isSearch)
174                Element("td_message_important_"+msg_number.substr(0,msg_number.indexOf('_'))).innerHTML = "&nbsp;&nbsp;&nbsp;";
175        else
176                Element("td_message_important_"+msg_number).innerHTML = "&nbsp;&nbsp;&nbsp;";
177}
178
179function removeAll(id){
180        do
181        {
182                if (typeof(Element(id)) == 'undefined')
183                        break;
184                Element(id).parentNode.removeChild(Element(id));
185        }
186        while(Element(id));
187}
188
189function get_current_folder(){
190        return current_folder;
191}
192
193// Kill current box (folder or page).
194function kill_current_box(){
195        var box = document.getElementById("table_box");
196        if (box != null)
197                box.parentNode.removeChild(box);
198        else
199                return false;
200}
201
202//Remove as linhas da tabela sem deletar o corrent_box
203function remove_rows(el){
204        while (el.rows.length > 0)  {
205                el.deleteRow(0);
206        }
207        Element("tot_m").innerHTML = 0
208        Element("new_m").innerHTML = 0
209}
210
211// Kill current paging.
212function kill_current_paging(){
213        var paging = Element("span_paging");
214        if (paging != null)
215                paging.parentNode.removeChild(paging);
216}
217
218function show_hide_span_paging(ID){
219        if ((ID != "0") && Element("span_paging"))
220                Element("span_paging").style.display = 'none';
221        else
222                if (Element("span_paging"))
223                        Element("span_paging").style.display = '';
224}
225
226//Get the current number of messages in a page.
227function get_messages_number_in_page(){
228        //Get element tBody.
229        main = document.getElementById("tbody_box");
230
231        // Get all TR (messages) in tBody.
232        main_list = main.childNodes;
233
234        return main_list.length;
235}
236
237function download_local_attachment(url) {
238        url=encodeURI(url);
239        url=url.replace("%25","%");
240        if (div_attachment == null){
241                var div_attachment = document.createElement("DIV");
242                div_attachment.id="id_div_attachment";
243                document.body.appendChild(div_attachment);
244        }
245        div_attachment.innerHTML="<iframe style='display:none;width:0;height:0' name='attachment' src='"+url+"'></iframe>";
246}
247
248function download_attachments(msg_folder, msg_number, idx_file, msg_part, encoding, new_file_name, show_iframe){
249        div_attachment = document.getElementById("id_div_attachment");
250        var params = '';
251
252        if (div_attachment == null){
253                var div_attachment = document.createElement("DIV");
254                div_attachment.id="id_div_attachment";
255                document.body.appendChild(div_attachment);
256        }
257        if(new_file_name) {
258                var extension = /\.[^.]*$/.exec(new_file_name);
259                if (extension == ".eml")
260                        params = "&newFilename="+new_file_name; //name_of_message.eml
261                else // when more than one message
262                        params = "&newFilename="+escape(new_file_name); //mensagens.zip
263        }
264        if(encoding)
265                params += "&encoding="+encoding;
266
267        div_attachment.innerHTML="<iframe style='display:none;width:0;height:0' name='attachment' src='inc/get_archive.php?msgFolder="+msg_folder+"&msgNumber="+msg_number+"&idx_file="+idx_file+"&indexPart="+msg_part+params+"'></iframe>";
268
269}
270
271function download_all_attachments(msg_folder, msg_number){
272        var handler_source = function(data){
273                download_attachments(null, null, data, null,null,'anexos.zip');
274        }
275        cExecute("$this.exporteml.download_all_attachments",handler_source,"folder="+msg_folder+"&num_msg="+msg_number);
276}
277//ADD forwarded files
278function addForwardedFile(id_border,file_name,link,divFiles){
279        if(!divFiles)
280                var divFiles = document.getElementById("divFiles_"+id_border);
281
282        if (! divFiles)
283                return false;
284
285        if (divFiles.lastChild)
286                var countDivFiles = parseInt(divFiles.lastChild.id.split('_')[2]) + 1;
287
288        if (! countDivFiles)
289                var countDivFiles = 1;
290
291        var divFile = document.createElement('DIV');
292
293        var inputFile = document.createElement("INPUT");
294        if (!expresso_offline) {
295                if (!is_ie) {
296                        var tmp_id_border = document.createAttribute('id_border');
297                        tmp_id_border.value = id_border;
298
299                        inputFile.setAttributeNode(tmp_id_border);
300                        inputFile.id = "inputFile_" + id_border + "_" + countDivFiles;
301                        inputFile.type = 'file';
302                        inputFile.size = 50;
303                        inputFile.maxLength = 255;
304                        inputFile.name = 'file_' + countDivFiles;
305                        inputFile.style.display = "none";
306                }
307                else {
308                        inputFile = document.createElement("link");
309
310                        var tmp_id_border = document.createAttribute('id_border');
311                        tmp_id_border.value = id_border;
312
313                        inputFile.setAttributeNode(tmp_id_border);
314                        inputFile.id = "inputFile_" + id_border + "_" + countDivFiles;
315                        inputFile.name = 'file_' + countDivFiles;
316
317
318                }
319
320        }
321        else {
322                inputFile.type = 'hidden';
323                inputFile.name = 'offline_forward_' + countDivFiles;
324        }
325        divFile.appendChild(inputFile);
326
327        var a_tmp = new Array();
328        a_tmp[0] = "local_";
329        a_tmp[1] = 'file_' + countDivFiles;
330        a_tmp[2] = file_name;
331        s_tmp = escape(connector.serialize(a_tmp));
332        var checkbox = document.createElement("INPUT");
333        checkbox.type = "checkbox";
334        checkbox.id = "checkbox_"+id_border+"_"+countDivFiles;
335        checkbox.name = "local_attachments[]";
336        checkbox.setAttribute("checked", "checked");
337
338        checkbox.value = s_tmp;
339        divFile.appendChild(checkbox);
340
341        var link_attachment = document.createElement("A");
342        link_attachment.setAttribute("href", link);
343
344        link_attachment.innerHTML = file_name;
345        divFile.appendChild(link_attachment);
346
347        countDivFiles++;
348        divFile.id = "divFile_"+id_border+"_"+countDivFiles;
349        divFiles.appendChild(divFile);
350
351        return inputFile;
352}
353
354// Add Input File Dynamically.
355function addFile(id_border){
356        divFiles = document.getElementById("divFiles_"+id_border);
357        if (! divFiles)
358                return false;
359
360        if (divFiles.lastChild)
361                var countDivFiles = parseInt(divFiles.lastChild.id.split('_')[2]) + 1;
362
363        if (! countDivFiles)
364                var countDivFiles = 1;
365
366        divFile = document.createElement('div');
367
368        var inputFile = document.createElement("input");
369        inputFile.id        = "inputFile_"+id_border+"_"+countDivFiles;
370        inputFile.name      = "file_"+countDivFiles;
371        inputFile.type      = "file";
372        inputFile.size      = 50;
373        inputFile.maxlength = 255;
374        inputFile.onchange  = function () {
375            validateFileExtension(this.value, this.id.replace('input','div'), this.getAttribute('id_border'));
376        };
377
378        divFile.appendChild(inputFile);
379
380        var linkFile = document.createElement("a");
381        linkFile.id        = "linkFile_"+id_border+"_"+countDivFiles;
382        linkFile.href      = 'javascript:void(0)';
383        linkFile.onclick   = function () {removeFile("divFile_"+id_border+"_"+countDivFiles); return false;};
384        linkFile.innerHTML = get_lang("Remove");
385
386        divFile.appendChild(linkFile);
387        divFile.id = "divFile_"+id_border+"_"+countDivFiles;
388        divFiles.appendChild(divFile);
389
390        return inputFile;
391}
392//      Remove Input File Dynamically.
393function removeFile(id){
394        var el = Element(id);
395        el.parentNode.removeChild(el);
396}
397
398function validateFileExtension(fileName, id, id_border){
399
400        var error_flag  = false;
401
402        if ( fileName.indexOf('/') != -1 )
403        {
404                if (fileName[0] != '/'){ // file name is windows format?
405                        var file = fileName.substr(fileName.lastIndexOf('\\') + 1, fileName.length);
406                        if ((fileName.indexOf(':\\') != 1) && (fileName.indexOf('\\\\') != 0)) // Is stored in partition or a network file?
407                                error_flag = true;
408                }
409                else // is Unix
410                        var file = fileName.substr(fileName.lastIndexOf('/') + 1, fileName.length);
411        }
412        else  // is Firefox 3
413                var file = fileName;
414
415        var fileExtension = file.split(".");
416        fileExtension = fileExtension[(fileExtension.length-1)];
417        for(var i=0; i<denyFileExtensions.length; i++)
418        {
419                if(denyFileExtensions[i] == fileExtension)
420                {
421                        error_flag = true;
422                        break;
423                }
424
425        }
426
427        if ( error_flag == true )
428        {
429                alert(get_lang('File extension forbidden or invalid file') + '.');
430                removeFile(id);
431                addFile(id_border);
432                return false;
433        }
434        return true;
435}
436
437var setTimeout_write_msg = 0;
438var old_msg = false;   
439// Funcao usada para escrever mensagem
440// notimeout = True : mensagem nao apaga
441function write_msg(msg, notimeout){
442
443        if (setTimeout_write_msg)
444                clearTimeout(setTimeout_write_msg);
445
446        var msg_div = Element('em_div_write_msg');
447        var old_divStatusBar = Element("divStatusBar");
448
449        if(!msg_div) {
450                msg_div = document.createElement('DIV');
451                msg_div.id = 'em_div_write_msg';
452                msg_div.className = 'em_div_write_msg';
453                old_divStatusBar.parentNode.insertBefore(msg_div,old_divStatusBar);
454        }
455
456        if( document.getElementById('JabberMessenger'))
457                loadscript.adIcon();
458
459        msg_div.innerHTML = '<table width="100%" cellspacing="0" cellpadding="0" border="0"><tbody><tr><th width="40%"></th><th noWrap class="action_info_th">'+msg+'</th><th width="40%"></th></tr></tbody></table>';
460
461        old_divStatusBar.style.display = 'none';
462        msg_div.style.display = '';
463        // Nao ponha var na frente!! jakjr
464        handle_write_msg = function(){
465                try{
466                        if(!old_msg)
467                                clean_msg();
468                        else
469                                write_msg(old_msg, true);
470                }
471                catch(e){}
472        }
473        if(notimeout)
474                old_msg = msg;
475        else
476                setTimeout_write_msg = setTimeout("handle_write_msg();", 5000);
477}
478// Funcao usada para apagar mensagem sem timeout
479function clean_msg(){
480        old_msg = false;
481        var msg_div = Element('em_div_write_msg');
482        var old_divStatusBar = Element("divStatusBar");
483        if(msg_div)
484                msg_div.style.display = 'none';
485        old_divStatusBar.style.display = '';
486}
487
488function make_body_reply(body, to, date_day, date_hour){
489        to = to.replace("<","&lt;");
490        to = to.replace(">","&gt;");
491        block_quoted_body ='<div>';
492        block_quoted_body += get_lang('At %1, %2 hours, %3 wrote:', date_day, date_hour, to) + '<br type="_moz"></div>';
493        block_quoted_body += "<blockquote style=\"border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;\">";
494        block_quoted_body += body;
495        block_quoted_body += "</blockquote>";
496        return block_quoted_body;
497}
498
499function make_forward_body(body, from, date, subject, to, cc){
500        from = from.replace(/</g,"&lt;");
501        from = from.replace(/>/g,"&gt;");
502        to = to.replace(/</g,"&lt;");
503        to = to.replace(/>/g,"&gt;");
504        var forward_body = '<div>---------- ' + get_lang('Forwarded message') + ' ----------<br type="_moz"></div><div>';
505        forward_body += get_lang('From') + ': ' + from + '<br type="_moz"></div><div>';
506        forward_body += get_lang('Date') + ': ' + date + '<br type="_moz"></div><div>';
507        forward_body += get_lang('Subject') + ': ' + subject + '<br type="_moz"></div><div>';
508        forward_body += get_lang('To') + ': ' + to+ '<br type="_moz"></div><div>';
509        if(cc != undefined){
510                cc = cc.replace(/</g,"&lt;");
511                cc = cc.replace(/>/g,"&gt;");
512                forward_body += get_lang('CC') + ': ' + cc+ '<div><br type="_moz"></div><div><br type="_moz"></div><div><br type="_moz"></div>';
513        }
514        forward_body += body;
515        return forward_body;
516}
517
518function emMessageSearch(e,value){
519        var     e  = is_ie ? window.event : e;
520        if(e.keyCode == 13) {
521                search_emails(value);
522        }
523}
524
525function validateEmail(email){
526        if (typeof(email) != 'string')
527                return false;
528        var validName = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/i;
529        //emailParts = email.split('@');
530        return validName.test(email);
531}
532function validateDomain(domain){
533        var domainReg = /^(([A-Za-z\d][A-Za-z\d-]{0,61}[A-Za-z\d]\.)+[A-Za-z]{2,6}|\[\d{1,3}(\.\d{1,3}){3}\])$/i;
534        return (domainReg.test(domain));
535}
536
537function validateUrl(url){
538        var urlReg = /([A-Za-z]{2,7}:\/\/)(.*)/i;
539        urlParts = url.split(urlReg);
540        return (urlParts[1].length > 4 &&  validateDomain(urlParts[2]));
541}
542
543function performQuickSearch(keyword){
544        if (preferences.quick_search_default=='1')
545                emQuickSearch(keyword, 'null', 'null', 'expressoMail');
546        else
547                search_emails(keyword);
548}
549
550function emQuickSearch(emailList, field, ID, Type, force){
551        var quickSearchKeyBegin;
552        var quickSearchKeyEnd;
553        var content = $("#content_id_"+ID);
554       
555        if(expresso_offline) {
556                alert(get_lang('Not allowed in offline mode'));
557                return;
558        }
559        if ((field != 'null') && (ID != 'null'))
560        {
561                connector.loadScript("QuickCatalogSearch");
562                if (typeof(QuickCatalogSearch) == 'undefined'){
563                        setTimeout('emQuickSearch("'+emailList+'", "'+field+'", "'+ID+'", "'+Type+'", "'+force+'")',500);
564                        return false;
565                }
566        }
567        else
568        {
569                connector.loadScript("QuickSearchUser");
570                if (typeof(QuickSearchUser) == 'undefined'){
571                        setTimeout('emQuickSearch("'+emailList+'", "'+field+'", "'+ID+'", "'+Type+'", "'+force+'")',500);
572                        return false;
573                }
574        }       
575
576        var handler_emQuickSearch = function(data)
577        {
578
579                if ((!data.status) && (data.error == "many results")){
580                        alert(get_lang('More than %1 results. Please, try to refine your search.',data.maxResult));
581                        return false;
582                }
583
584                if (data.length > 0){
585                        if ((field != 'null') && (ID != 'null'))
586                        {
587                                QuickCatalogSearch.showList(data, quickSearchKeyBegin, quickSearchKeyEnd, ID, field);
588                        }
589                        else
590                        {
591                                QuickSearchUser.showList(data);
592                        }
593                }
594                else
595                        alert(get_lang('None result was found.'));
596                return true;
597        }
598        if ((field != 'null') && (ID != 'null'))
599        {
600                content.find(field).focus();
601                var i = getPosition(content.find(field)[0]); //inputBox.selectionStart;
602                var j = --i;
603
604                // Acha o inicio
605        while ((j >= 0) && (emailList.charAt(j) != ',')){j--};
606            quickSearchKeyBegin = ++j;
607
608            // Acha o final
609        while ((i <= emailList.length) && (emailList.charAt(i) != ',')){i++};
610            quickSearchKeyEnd = i;
611
612            // A Chave da Pesquisa
613        var search_for = trim(emailList.substring(quickSearchKeyBegin, quickSearchKeyEnd));
614        }
615        else
616                var search_for = emailList;
617        if(preferences.search_characters_number == 'x')
618                preferences.search_characters_number = 0;
619               
620        if (search_for.length < preferences.search_characters_number){
621                alert(get_lang('Your search argument must be longer than %1 characters.', preferences.search_characters_number));
622                return false;
623        }
624        if(Type == undefined)
625            cExecute ("$this.ldap_functions.quicksearchcontact&search_for="+search_for+"&field="+field+"&ID="+ID, handler_emQuickSearch);
626        else
627            cExecute ("$this.ldap_functions.quicksearchcontact&search_for="+search_for+"&field="+field+"&ID="+ID+"&Type="+Type, handler_emQuickSearch);
628}
629
630function folderbox()
631{
632        connector.loadScript("TreeS");
633
634        if( typeof(window.ttree) == 'undefined')
635                setTimeout(function(){ folderbox(); }, 200 );
636        else
637                ttree.load();
638}
639
640function filterbox(){
641        connector.loadScript("filter");
642        connector.loadScript("filters");
643        if (typeof(filters) == 'undefined')
644        {
645                 setTimeout('filterbox()',500);
646                 return false;
647        }
648        filters.Forms();
649}
650
651
652function filterbox2(){
653        init_filters();
654        jQuery('.expresso-window-container').dialog('open');
655}
656
657
658function sharebox(){
659        var handler_imap_getacl = function(data)
660        {
661                connector.loadScript("finder", "../services/");
662                connector.loadScript("sharemailbox");
663               
664                if (typeof(sharemailbox) == 'undefined')
665                {
666                        setTimeout('sharebox()',500);
667                        return false;
668                }
669               
670                sharemailbox.makeWindow(data);
671        }
672        cExecute ("$this.imap_functions.getacl", handler_imap_getacl);
673}
674
675function configureLabels(data){
676
677        dialogElement = $('.label-configure-win').html(DataLayer.render("../prototype/modules/mail/templates/label_configure.ejs", {}))
678       
679        dialogElement.dialog({
680                width:815,
681                height:410,
682                title:' Configuração do Marcador',
683                resizable:false,
684                modal: true,
685                closeOnEscape:true,
686                close:function(event, ui) {
687                        select_all_search_messages(false, 'content_id_'+currentTab);
688                        event.stopPropagation();
689                if(typeof(shortcut) != 'undefined') shortcut.disabled = false;
690                },
691                open: function(event, ui) 
692            {
693                if(typeof(shortcut) != 'undefined') shortcut.disabled = true; 
694            },
695                autoOpen:false,
696                dialogClass: 'dialog-configure-label'
697        });
698        init_label({window:dialogElement, selectedItem:data.selectedItem, applyToSelectedMessages:data.applyToSelectedMessages});       
699        dialogElement.dialog("open");
700}
701
702function configureFollowupflag(){
703
704        var messages = new Array();
705        var selectedMessageIds = new Array();
706        var folder_name;
707        if (currentTab == 0) {
708                selectedMessageIds = get_selected_messages().split(",");
709        } else {
710                selectedMessageIds = get_selected_messages_search().split(",");
711                var id_border = currentTab.replace(/[a-zA-Z_]+/, "");
712        }
713       
714        var roles = get_selected_messages_search_role().split(',');
715        for (var i=0; i<selectedMessageIds.length; i++) {
716                if (currentTab == 0) {
717                        folder_name = current_folder;
718                        var number = selectedMessageIds[i];
719                }else{
720                        var tr = $('[role="'+roles[i]+'"]');
721                        folder_name = $(tr).attr('name');
722                        var id = $(tr).attr('id');
723                        var number = id.replace(/_[a-zA-Z0-9]+/,"");
724                }
725                messages.push(onceOpenedHeadersMessages[folder_name][number]);
726        }
727
728        if(!User.followupflags)
729                DataLayer.remove('followupflag', false);
730                User.followupflags = DataLayer.get('followupflag', true);
731        var data = {
732                followupflags: User.followupflags,
733                messages: messages
734        };
735        dialogElement = $('.followupflag-configure-win').html(DataLayer.render("../prototype/modules/mail/templates/followupflag_configure.ejs", data))
736
737        dialogElement.dialog({
738                width:532,
739                height:420,
740                title:get_lang('Follow up'),
741                resizable:false,
742                modal: true,
743                closeOnEscape:true,
744                close:function(event, ui) {
745                        select_all_search_messages(false, 'content_id_'+currentTab);
746                        event.stopPropagation();
747        if(typeof(shortcut) != 'undefined') shortcut.disabled = false;
748                },
749        open: function(event, ui) 
750        {
751            if(typeof(shortcut) != 'undefined') shortcut.disabled = true; 
752        },
753                autoOpen:false
754        });     
755        init_followup({window:dialogElement, selectedMessages:selectedMessageIds});
756        dialogElement.dialog("open");
757}
758
759function open_rss(param){
760        connector.loadScript("news_edit");
761        if (typeof(news_edit) == 'undefined')
762        {
763                setTimeout('open_rss(\''+param+'\')',500);
764                return false;
765        }
766        news_edit.read_rss(param);
767        return true;
768}
769
770function editrss(){
771        connector.loadScript("news_edit");
772        if (typeof(news_edit) == 'undefined')
773        {
774                setTimeout('editrss()',500);
775                return false;
776        }
777        news_edit.makeWindow();
778}
779
780
781
782
783function preferences_mail(){
784        location.href="../preferences/preferences.php?appname=expressoMail1_2";
785}
786
787function search_emails(value, data){
788        var resize = false;
789        resize = resize_borders();
790        if (!resize){
791            var str_continue = '';
792            var bolContinue = true;                     
793                        str_continue = '\n' + get_lang('You must manually close one of your tabs before opening a new one');
794            if (preferences.auto_close_first_tab == 1){                                         
795                var children = Element('border_tr').childNodes;
796                var bolDelete = true;
797                for (var i=0; i<children.length; i++) {
798                    if ((children[i].nodeName === 'TD') && (children[i].id!=='border_id_0') && (children[i].id!=='border_blank'))
799                    {
800                        bolDelete = true;
801                        var num_child = children[i].id.toString().substr(10);
802                        alternate_border(num_child);
803                        if (editTest(num_child)){
804                            bolDelete = false;
805                        }
806                        if (bolDelete || bolContinue){
807                                                        str_fechar = '\n' + get_lang('Reached maximum tab limit. Want to close this tab');
808                                                        var confirmacao = confirm(str_fechar);
809                            if(confirmacao){
810                                                                bolContinue = false;
811                                                                delete_border(num_child, 'false');
812                                                                break;
813                                                        }else{
814                                                                return;
815                                                        }
816                                                }
817                    }
818                                }                               
819            }else{                     
820                alert(get_lang('Reached maximum tab limit') + str_continue );
821                return;
822            }
823        }
824        connector.loadScript("TreeS");
825        connector.loadScript("search");
826        if (typeof(EsearchE) == 'undefined' || typeof(ttree) == 'undefined'){
827                setTimeout("search_emails('"+value+"', '"+data+"')",500);
828                return false;
829        }
830        EsearchE.showForms(value, data);
831        $("#em_message_search").val("");
832        }
833
834function source_msg(id_msg,folder){
835        var num_msg = id_msg.substr(0,(id_msg.length - 2));
836        var handler_source = function(data){
837                download_attachments(null, null, data, null,null,'fonte_da_mensagem.eml');
838        }
839        cExecute("$this.exporteml.export_msg",handler_source,"folder="+url_decode(folder)+"&msgs_to_export="+num_msg);
840}
841
842function url_encode(str){
843        if(str === null) return false;
844    var hex_chars = "0123456789ABCDEF";
845    var noEncode = /^([a-zA-Z0-9\_\-\.])$/;
846    var n, strCode, hex1, hex2, strEncode = "";
847
848    for(n = 0; n < str.length; n++) {
849        if (noEncode.test(str.charAt(n))) {
850            strEncode += str.charAt(n);
851        } else {
852            strCode = str.charCodeAt(n);
853            hex1 = hex_chars.charAt(Math.floor(strCode / 16));
854            hex2 = hex_chars.charAt(strCode % 16);
855            strEncode += "%" + (hex1 + hex2);
856        }
857    }
858   
859    return strEncode;
860}
861
862function url_decode(str) {
863        var n, strCode, strDecode = "";
864        for (n = 0; n < str.length; n++) {
865            strDecode += str.charAt(n);
866            //if (str.charAt(n) == "%") {
867            //    strCode = str.charAt(n + 1) + str.charAt(n + 2);
868            //    strDecode += String.fromCharCode(parseInt(strCode, 16));
869            //    n += 2;
870            //} else {
871            //    strDecode += str.charAt(n);
872            //}
873        }
874        return strDecode;
875}
876//Método que remove os hexadecimais criados no enconde
877//e retorna string corretamente
878function url_decode_s(str) {
879            var result = "";
880
881     for (var i = 0; i < str.length; i++) {
882          if (str.charAt(i) == "+") result += " ";
883          else result += str.charAt(i);
884        }
885          return unescape(result);
886     
887}
888
889function Element (el) {
890        return  document.getElementById(el);
891}
892
893function getPosition(obj)
894{
895        if(typeof obj.selectionStart != "undefined")
896        {
897        return obj.selectionStart;
898        }
899        else if(document.selection && document.selection.createRange)
900        {
901                var M = document.selection.createRange();
902                try
903                {
904                        var Lp = M.duplicate();
905                        Lp.moveToElementText(obj);
906                }
907                catch(e)
908                {
909                        var Lp=obj.createTextRange();
910                }
911
912                Lp.setEndPoint("EndToStart",M);
913                var rb=Lp.text.length;
914
915                if(rb > obj.value.length)
916                {
917                        return -1;
918                }
919                return rb;
920        }
921}
922
923function trim(inputString) {
924   if (typeof inputString != "string")
925        return inputString;
926
927   var retValue = inputString;
928   var ch = retValue.substring(0, 1);
929   while (ch == " ") {
930          retValue = retValue.substring(1, retValue.length);
931          ch = retValue.substring(0, 1);
932   }
933   ch = retValue.substring(retValue.length-1, retValue.length);
934   while (ch == " ") {
935          retValue = retValue.substring(0, retValue.length-1);
936          ch = retValue.substring(retValue.length-1, retValue.length);
937   }
938   while (retValue.indexOf("  ") != -1) {
939          retValue = retValue.substring(0, retValue.indexOf("  ")) + retValue.substring(retValue.indexOf("  ")+1, retValue.length);
940   }
941   return retValue;
942}
943
944function increment_folder_unseen(){
945        var folder_id = get_current_folder();
946
947        var folder_unseen = Element('dftree_'+folder_id+'_unseen');
948        var abas_unseen = Element('new_m').innerHTML;
949    abas_unseen = abas_unseen.match(/(<font.*?>){0,1} *([0-9]+) *(<\/font>){0,1}/)[2];
950
951        if (folder_unseen)
952                folder_unseen.innerHTML = (parseInt(folder_unseen.innerHTML) + 1);
953        else
954        {
955                tree_folders.getNodeById(folder_id).alter({caption: tree_folders.getNodeById(current_folder).caption + '<font style=color:red>&nbsp(</font><span id="dftree_'+current_folder+'_unseen" style=color:red>1</span><font style=color:red>)</font>'});
956                tree_folders.getNodeById(folder_id)._refresh();
957        }
958
959        if( abas_unseen == NaN || abas_unseen == undefined )
960                abas_unseen = 1;
961        else
962                abas_unseen = parseInt(abas_unseen) + 1;
963
964        Element('new_m').innerHTML = '<font style="color:red">' + abas_unseen + '</font>';
965       
966        if ( current_folder.indexOf( 'INBOX' ) !== 0 && current_folder.indexOf( 'local_' ) !== 0 )
967        {
968                var display_unseen_in_shared_folders = Element('dftree_user_unseen');
969                if ( display_unseen_in_shared_folders )
970                        tree_folders.getNodeById( 'user' ).alter({caption:'<font style=color:red>[</font><span id="dftree_user_unseen" style="color:red">' + ( parseInt( display_unseen_in_shared_folders.innerHTML) + 1 ) + '</span><font style=color:red>]</font>' + get_lang("Shared folders")});
971                else
972                        tree_folders.getNodeById( 'user' ).alter({caption:'<font style=color:red>[</font><span id="dftree_user_unseen" style="color:red">1</span><font style=color:red>]</font>' + get_lang("Shared folders")});
973                tree_folders.getNodeById( 'user' )._refresh();
974        }
975        var display_unseen_in_mailbox = Element('dftree_root_unseen');
976        if(!expresso_offline)
977                var node_to_refresh = 'root';
978        else
979                var node_to_refresh = 'local_root';
980        tree_folders.getNodeById( node_to_refresh )._refresh();
981}
982
983function decrement_folder_unseen(){
984        var folder_id = get_current_folder();
985
986        var folder_unseen = Element('dftree_'+folder_id+'_unseen');
987        var abas_unseen = Element('new_m').innerHTML;
988    abas_unseen = abas_unseen.match( /(<font.*?>){0,1} *([0-9]+) *(<\/font>){0,1}/)[2];
989
990        if(!folder_unseen || !abas_unseen)
991                return;
992
993        if ((folder_unseen) && (parseInt(folder_unseen.innerHTML) > 1))
994        {
995                folder_unseen.innerHTML = (parseInt(folder_unseen.innerHTML) - 1);
996        }
997        else if (parseInt(folder_unseen.innerHTML) <= 1)
998        {
999                var tmp_folder_name = tree_folders.getNodeById(folder_id).caption.split('<');
1000                var folder_name = tmp_folder_name[0];
1001                tree_folders.getNodeById(folder_id).alter({caption: folder_name});
1002                tree_folders.getNodeById(folder_id)._refresh();
1003        }
1004        if (parseInt(abas_unseen) > 1) {
1005        Element('new_m').innerHTML = '<font style="color:red">' + (parseInt(abas_unseen) - 1) + '</font>';
1006        } else {
1007                Element('new_m').innerHTML = '0';
1008                $(folder_unseen).parent().empty();
1009        }
1010        if ( current_folder.indexOf( 'INBOX' ) !== 0 )
1011        {
1012                var display_unseen_in_shared_folders = Element('dftree_user_unseen');
1013                if ( display_unseen_in_shared_folders )
1014                {
1015                        var unseen_in_shared_folders = parseInt( display_unseen_in_shared_folders.innerHTML );
1016                        unseen_in_shared_folders--;
1017                        if ( unseen_in_shared_folders > 0 )
1018                                tree_folders.getNodeById( 'user' ).alter({caption:'<font style=color:red>[</font><span id="dftree_root_unseen" style="color:red">' + unseen_in_shared_folders + '</span><font style=color:red>]</font>' + get_lang("My Folders")});
1019                        else
1020                                tree_folders.getNodeById( 'user' ).alter({caption:get_lang("Shared folders")});
1021                        tree_folders.getNodeById( 'user' )._refresh();
1022                }
1023        }
1024        var display_unseen_in_mailbox = Element('dftree_root_unseen');
1025        if ( display_unseen_in_mailbox )
1026        {
1027                var unseen_in_mailbox = parseInt( display_unseen_in_mailbox.innerHTML );
1028                unseen_in_mailbox--;
1029                //if ( unseen_in_mailbox > 0 )
1030                //      tree_folders.getNodeById( 'root' ).alter({caption:'<font style=color:red>[</font><span id="dftree_root_unseen" style="color:red">' + unseen_in_mailbox + '</span><font style=color:red>]</font>' + get_lang("My Folders")});
1031                //else
1032                if(!expresso_offline)
1033                        var node_to_refresh = 'root';
1034                else
1035                        var node_to_refresh = 'local_root';
1036                tree_folders.getNodeById( node_to_refresh ).alter({caption:get_lang("My Folders")});
1037                tree_folders.getNodeById( node_to_refresh )._refresh();
1038        }
1039}
1040
1041function LTrim(value){
1042        var w_space = String.fromCharCode(32);
1043        var strTemp = "";
1044        var iTemp = 0;
1045
1046        var v_length = value ? value.length : 0;
1047        if(v_length < 1)
1048                return "";
1049
1050        while(iTemp < v_length){
1051                if(value && value.charAt(iTemp) != w_space){
1052                        strTemp = value.substring(iTemp,v_length);
1053                        break;
1054                }
1055                iTemp++;
1056        }
1057        return strTemp;
1058}
1059
1060//changes MENU background color.
1061function set_menu_bg(menu)
1062{
1063        // TODO - remover esta função, por hora, apenas um retrun true para preservar menor impacto
1064        return true;
1065        menu.style.backgroundColor = 'white';
1066        menu.style.border = '1px solid black';
1067        menu.style.padding = '0px 0px';
1068}
1069//changes MENU background color.
1070function unset_menu_bg(menu)
1071{
1072        // TODO - remover esta função, por hora, apenas um retrun true para preservar menor impacto
1073        return true;
1074        menu.style.backgroundColor = '';
1075        menu.style.border = '0px';
1076        menu.style.padding = '1px 0px';
1077}
1078
1079function array_search(needle, haystack) {
1080        var n = haystack.length;
1081        for (var i=0; i<n; i++) {
1082                if (haystack[i]==needle) {
1083                        return true;
1084                }
1085        }
1086        return false;
1087}
1088
1089function lang_folder(fn) {
1090        if (fn.toUpperCase() == "INBOX") return get_lang("Inbox");
1091        if (special_folders[fn] && typeof(special_folders[fn]) == 'string') {
1092                return get_lang(special_folders[fn]);
1093        }
1094        return fn;
1095}
1096
1097function add_className(obj, className){
1098        if (obj && !exist_className(obj, className))
1099                obj.className = obj.className + ' ' + className;
1100}
1101
1102function remove_className(obj, className){
1103        var re = new RegExp("\\s*"+className);
1104        if (obj)
1105                obj.className = obj.className.replace(re, ' ');
1106}
1107
1108function exist_className(obj, className){
1109        return ( obj && obj.className.indexOf(className) != -1 )
1110}
1111
1112//Verifica se ainda existem mensagens marcadas, se não desmarca
1113//o selecionar todas.
1114function remove_chk_box_select_all_messages(){
1115        var main = Element("tbody_box");
1116        var main_list = main.childNodes;
1117        var len_main_list = main_list.length;
1118        for (i=0; i<len_main_list; i++)
1119        {
1120                if (Element("check_box_message_"+main_list[i].id).checked){
1121                                return;
1122                }
1123        }
1124         document.getElementById("chk_box_select_all_messages").checked = false;
1125}
1126
1127function select_all_messages(select)
1128{
1129        var main = Element("tbody_box");
1130        var main_list = main.childNodes;
1131        var len_main_list = main_list.length;
1132
1133        if (select)
1134        {
1135                for (i=0; i<len_main_list; i++)
1136                {
1137                        Element("check_box_message_"+main_list[i].id).checked = true;
1138                        remove_className(Element(main_list[i].id), 'selected_msg');
1139                        if(!$("#"+main_list[i].id).hasClass("selected_shortcut_msg")){
1140                                //add_className(Element(main_list[i].id), 'selected_msg selected_shortcut_msg current_selected');
1141                                add_className(Element(main_list[i].id), 'selected_msg selected_shortcut_msg');
1142                        } else {
1143                                $("#"+main_list[i].id).addClass("selected_msg");
1144                                $("#"+main_list[i].id).addClass("selected_shortcut_msg");
1145                                $("#"+main_list[i].id).addClass("current_selected");           
1146                        }
1147                }
1148        }
1149        else
1150        {
1151                for (i=0; i<len_main_list; i++)
1152                {
1153                        Element("check_box_message_"+main_list[i].id).checked = false;
1154                        remove_className(Element(main_list[i].id), 'selected_msg selected_shortcut_msg');
1155                        $("#"+main_list[i].id).removeClass("selected_msg");
1156                        $("#"+main_list[i].id).removeClass("current_selected");
1157                }
1158        }
1159       
1160}
1161
1162function borkb(size){
1163        kbyte = 1024;
1164        mbyte = kbyte*1024;
1165        gbyte = mbyte*1024;
1166        if (!size)
1167                size = 0;
1168        if (size < kbyte)
1169                return size + ' B';
1170        else if (size < mbyte)
1171                return parseInt(size/kbyte) + ' KB';
1172        else if (size < gbyte)
1173                if (size/mbyte > 100)
1174                        return (size/mbyte).toFixed(0) + ' MB';
1175                else
1176                        return (size/mbyte).toFixed(1) + ' MB';
1177        else
1178                return (size/gbyte).toFixed(1) + ' GB';
1179}
1180
1181//valida se a primeira data é menor que a segunda data
1182function validate_date_order(dateStart, dateEnd){
1183        if ( parseInt( dateEnd.split( "/" )[2].toString() + dateEnd.split( "/" )[1].toString() + dateEnd.split( "/" )[0].toString() ) >= parseInt( dateStart.split( "/" )[2].toString() + dateStart.split( "/" )[1].toString() + dateStart.split( "/" )[0].toString() ) ){
1184                return true;
1185        }else{
1186                return false;
1187        }
1188}
1189
1190function validate_date(date){
1191    if (date.match(/^[0-3][0-9]\/[0-1][0-9]\/\d{4,4}$/))
1192    {
1193        tmp = date.split('/');
1194
1195        day = new Number(tmp[0]);
1196        month = new Number(tmp[1]);
1197        year = new Number(tmp[2]);
1198        if (month >= 1 && month <= 12 && day >= 1 && day <= 31)
1199        {
1200            if (month == 02 && day <= 29)
1201            {
1202                return true;
1203            }
1204            return true;
1205        }
1206        else
1207            {
1208                return false;
1209            }
1210    }
1211    else
1212        {
1213            return false;
1214        }
1215}
1216
1217function dateMask(inputData, e){
1218        if(document.all) // Internet Explorer
1219                var tecla = event.keyCode;
1220        else //Outros Browsers
1221                var tecla = e.which;
1222
1223        if(tecla >= 47 && tecla < 58){ // numeros de 0 a 9 e "/"
1224                var data = inputData.value;
1225                if (data.length == 2 || data.length == 5){
1226                        data += '/';
1227                        inputData.value = data;
1228                }
1229        } else {
1230                if(tecla == 8 || tecla == 0) // Backspace, Delete e setas direcionais(para mover o cursor, apenas para FF)
1231                        return true;
1232                else
1233                        return false;
1234        }
1235}
1236
1237function translateFolder(folderName){
1238
1239    for (var i = 0; i < folders.length; i++)
1240    {
1241        if (folders[i].folder_parent == 'user'
1242            && folderName == folders[i].folder_id.split(cyrus_delimiter).pop())
1243        {
1244            if (folders[i].folder_id.split(cyrus_delimiter).pop() != folders[i].folder_name)
1245            {
1246                return folders[i].folder_name;
1247            }
1248        }
1249    }
1250
1251    return folderName;
1252}
Note: See TracBrowser for help on using the repository browser.