Changeset 4757 for trunk/expressoMail1_2/js/main.js
- Timestamp:
- 07/15/11 09:36:50 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/expressoMail1_2/js/main.js
r4733 r4757 3 3 // tempo do auto save (em milisegundos) 4 4 // 20000 = 20 segundos 5 var autosave_time = 5000; 6 7 var cabecalho = '<h4>ExpressoLivre - ExpressoMail</h4>'; 5 var autosave_time = 20000; 8 6 9 7 function init(){ … … 22 20 23 21 preferences = data; 24 25 if(preferences.show_name_print_messages == "1") {26 var getUserName = document.getElementById("user_info");27 var userName = getUserName.innerHTML;28 var position = userName.indexOf("-");29 var userName = userName.substring(3, position);30 cabecalho = '<h4>' + userName;31 }32 33 22 current_folder="INBOX"; 34 23 … … 90 79 91 80 cExecute ("$this.functions.get_preferences", save_preferences); 92 cExecute ("phpgwapi.browser.isMobile", function( data ) 93 { 94 mobile_device = ( ( data.constructor == Boolean ) ? data : ( data === 'true' ) ); 95 } ); 96 81 cExecute ("phpgwapi.browser.isMobile", function( data ) 82 { 83 mobile_device = ( ( data.constructor == Boolean ) ? data : ( data === 'true' ) ); 84 } ); 97 85 setTimeout('auto_refresh()', time_refresh); 98 86 … … 902 890 } 903 891 var new_border_ID = draw_new_message(parseInt(border_ID)); 904 905 892 if(typeof(openTab.type[new_border_ID]) != "undefined") { 906 893 if(tabTypes[type] == openTab.type[new_border_ID]) { 907 if (type != 'edit') 908 { 909 return new_border_ID;910 }894 if (type != 'edit') 895 { 896 return new_border_ID; 897 } 911 898 } else { 912 899 var a_types = { 6 : get_lang("Forward"),7 : get_lang("Reply"), … … 926 913 } 927 914 } 928 929 915 if (new_border_ID == false) 930 916 { … … 1386 1372 } 1387 1373 1374 if ( ! expresso_offline ) 1375 { 1376 if ( mobile_device ) 1377 { 1378 var text_plain = document.getElementById( 'textplain_rt_checkbox_' + new_border_ID ); 1379 text_plain.click( ); 1380 text_plain.parentNode.style.display = 'none'; 1381 } 1382 } 1383 1388 1384 if (preferences.auto_save_draft == 1) 1389 1385 { … … 1670 1666 }; 1671 1667 1672 var mail_as_plain = document.getElementById( 'textplain_rt_checkbox_' + ID ); 1673 mail_as_plain = ( mail_as_plain ) ? mail_as_plain.checked : false; 1674 1668 var mail_as_plain = document.getElementById( 'textplain_rt_checkbox_' + ID ); 1669 mail_as_plain = ( mail_as_plain ) ? mail_as_plain.checked : false; 1670 1675 1671 var textArea = document.createElement("TEXTAREA"); 1676 1672 textArea.style.display='none'; 1677 1673 textArea.name = "body"; 1678 1674 body = document.getElementById("body_"+ID); 1679 1680 1675 textArea.value = ( ( mail_as_plain ) ? body.previousSibling.value : ( '<body>\r\n' + body.contentWindow.document.body.innerHTML + '\r\n</body>' ) ); 1681 1682 1676 var input_folder = document.createElement("INPUT"); 1683 1677 input_folder.style.display='none'; … … 1714 1708 form.appendChild(msg_id); 1715 1709 1716 var mail_type = document.createElement('input'); 1717 mail_type.setAttribute('type', 'hidden'); 1718 mail_type.name = 'type'; 1719 mail_type.value = ( mail_as_plain ) ? 'plain' : 'html'; 1720 form.parentNode.appendChild(mail_type); 1721 1722 1710 var mail_type = document.createElement('input'); 1711 mail_type.setAttribute('type', 'hidden'); 1712 mail_type.name = 'type'; 1713 mail_type.value = ( mail_as_plain ) ? 'plain' : 'html'; 1714 form.parentNode.appendChild(mail_type); 1715 1723 1716 var _subject = trim(Element("subject_"+ID).value); 1724 1717 if((_subject.length == 0) && !confirm(get_lang("Send this message without a subject?"))) { … … 1747 1740 } 1748 1741 else 1749 {1750 1742 cExecuteForm("$this.imap_functions.send_mail", form, handler_send_message, ID); 1751 }1752 1743 } 1753 1744 function change_tr_properties(tr_element, newUid, newSubject){ … … 1769 1760 } 1770 1761 1771 function return_save(data,border_id,folder_name,folder_id,message_id){ 1762 function return_save(data,border_id,folder_name,folder_id,message_id) 1763 { 1772 1764 Element("send_button_"+border_id).style.visibility="visible"; 1773 var handler_delete_msg = function(data){ refresh(preferences.alert_new_msg);};1774 1775 if (data == null || data.append != true)1765 var handler_delete_msg = function(data){ refresh(preferences.alert_new_msg); }; 1766 1767 if (data.append != true || !data) 1776 1768 { 1777 1778 RichTextEditor.saveFlag = 0; 1769 RichTextEditor.saveFlag = 0; 1779 1770 if (! data.append) 1780 write_msg('ERROR saving your message.'); 1771 if(data == 'Post-Content-Length') 1772 write_msg(get_lang('The size of this message has exceeded the limit (%1B).', preferences.max_attachment_size ? preferences.max_attachment_size : Element('upload_max_filesize').value)); 1773 else 1774 write_msg(get_lang('ERROR saving your message.')); 1781 1775 else 1782 1776 { … … 1798 1792 openTab.imapUid[border_id] = data.msg_no; 1799 1793 openTab.imapBox[border_id] = data.folder_id; 1800 1794 1801 1795 var newTitle = document.getElementById('subject_'+border_id).value; 1802 if (newTitle.length > 18) 1803 newTitle = newTitle.substr(18) + '...'; 1804 else if (newTitle == '') 1796 if (newTitle == '') 1805 1797 newTitle = get_lang("No subject"); 1806 document.getElementById('font_border_id_'+border_id).innerHTML = newTitle;1807 1798 set_border_caption('border_id_'+border_id, newTitle); 1799 1808 1800 // Replace the embedded images for new uids 1809 var mainField = document.getElementById('body_'+border_id).contentWindow; 1810 var content_body = mainField.document.getElementsByTagName('body').item(0).innerHTML; 1811 var body_images = content_body.match(/msg_num=\d*/g); 1812 var folder_images = content_body.match(/msg_folder=[^&]*&/g); 1813 1814 if (body_images != null) 1801 var mainField = document.getElementById('body_'+border_id).contentWindow; 1802 var content_body = mainField.document.getElementsByTagName('body').item(0).innerHTML; 1803 var body_images = content_body.match(/msg_num=\d*/g); 1804 var images_part = content_body.match(/msg_part=\d*/g); 1805 if (body_images) 1815 1806 { 1816 for (var i=0; i<body_images.length; i++) 1817 { 1818 if( folder_images != null) 1819 content_body = content_body.replace(folder_images[i], "msg_folder=INBOX" + cyrus_delimiter + draftsfolder +"&"); 1820 1821 content_body = content_body.replace(body_images[i],"msg_num="+openTab.imapUid[border_id]); 1822 } 1823 1824 var images_part = content_body.match(/msg_part=[0-9.]*/g); 1825 1826 if(images_part != null) 1827 { 1828 for (var x = 0; x < images_part.length; x++) 1829 { 1830 var position = images_part[x].substr(9,images_part[x].length); 1831 content_body = content_body.replace(images_part[x],'msg_part(||.|||.||)='+data.imagesParts[position]); 1832 } 1833 1834 } 1835 content_body = content_body.replace(/msg_part\(\|\|\.\|\|\|\.\|\|\)=/g,'msg_part='); 1836 1837 mainField.document.getElementsByTagName('body').item(0).innerHTML = content_body; 1838 } 1839 1840 1841 1807 for (var i=0; i<body_images.length; i++){ 1808 content_body = content_body.replace(body_images[i],"msg_num="+openTab.imapUid[border_id]); 1809 } 1810 var allImgs = new Array (images_part.length); 1811 var j=-1; 1812 for (var i in images_part){ 1813 1814 if (is_ie) 1815 if (i == 0) 1816 var image_number = parseInt(images_part[i].substr(9)); 1817 else 1818 image_number = "null"; 1819 else 1820 var image_number = parseInt(images_part[i].substr(9)); 1821 1822 if (! isNaN(image_number)) 1823 { 1824 if (! allImgs[image_number]) 1825 { 1826 allImgs[image_number] = true; 1827 j--; 1828 } 1829 content_body = content_body.replace(images_part[i],'msg_part='+j); 1830 } 1831 } 1832 content_body = content_body.replace(/msg_part=-/g,'msg_part='); 1833 1834 mainField.document.getElementsByTagName('body').item(0).innerHTML = content_body; 1835 } 1836 1842 1837 //Replace all files to new files 1843 1838 var divFiles = Element("divFiles_"+border_id); 1844 1845 divFiles.innerHTML = ''; 1846 1839 elFiles = divFiles.getElementsByTagName("input"); 1840 var countCheck =0; 1841 for (var i=0; i<elFiles.length; i++) { 1842 if(elFiles[i].value !=""){ 1843 if (elFiles[i].type == "checkbox") { 1844 countCheck++; 1845 } 1846 else { 1847 elFiles[i].value =""; 1848 parantNodeFile = elFiles[i].parentNode.parentNode; 1849 parantNodeFile.removeChild(elFiles[i].parentNode); 1850 i--; 1851 } 1852 1853 } 1854 }; 1855 1847 1856 var attach_files = connector.unserialize(data.files); 1848 1857 if (attach_files != null) { 1849 1858 openTab.countFile[border_id] = attach_files.length; 1850 for (att_index = 0; att_index < attach_files.length; att_index++){ 1851 1852 var link_attachment = document.createElement("a"); 1853 var fileName = attach_files[att_index].substr(0, attach_files[att_index].lastIndexOf('_SIZE_')); 1854 var fileSize = parseInt(attach_files[att_index].substr(attach_files[att_index].lastIndexOf('_SIZE_')+6))/1024 1855 link_attachment.innerHTML = fileName + " ("+parseInt(fileSize)+" kb)"; 1856 1857 var href = "'"+folder_id+"','"+data.msg_no+"','"+(att_index)+"','0."+(att_index+1)+"','base64'"; 1858 1859 link_attachment.setAttribute("href", "javascript:download_attachments("+href+")"); 1860 1861 var a_tmp = href.split(','); 1862 a_tmp[2] = fileName; 1863 s_tmp = escape(connector.serialize(a_tmp)); 1864 1865 var check_attachment = document.createElement("input"); 1866 check_attachment.type = 'checkbox'; 1867 check_attachment.name = 'forwarding_attachments[]'; 1868 check_attachment.value = s_tmp; 1869 1870 check_attachment.checked = true; 1871 check_attachment.setAttribute("checked", "checked"); 1872 1873 divFiles.appendChild(check_attachment); 1874 divFiles.appendChild(link_attachment); 1875 divFiles.appendChild(document.createElement("br")); 1876 } 1877 } 1878 1879 1859 att_index = countCheck; 1860 for (att_index; att_index < attach_files.length; att_index++){ 1861 1862 var link_attachment = document.createElement("A"); 1863 var fileName = attach_files[att_index].substr(0,attach_files[att_index].indexOf('_SIZE_')); 1864 var fileSize = parseInt(attach_files[att_index].substr(attach_files[att_index].indexOf('_SIZE_')+6))/1024 1865 link_attachment.innerHTML = fileName + " ("+borkb((parseInt(fileSize)*1024))+")"; 1866 1867 var href = "'"+folder_id+"','"+data.msg_no+"','"+(att_index)+"','"+(att_index+2)+"','base64'"; 1868 1869 link_attachment.setAttribute("href", "javascript:download_attachments("+href+")"); 1870 1871 var a_tmp = href.split(','); 1872 a_tmp[2] = fileName; 1873 s_tmp = escape(connector.serialize(a_tmp)); 1874 1875 var check_attachment = document.createElement("INPUT"); 1876 check_attachment.type = 'CHECKBOX'; 1877 check_attachment.name = 'forwarding_attachments[]'; 1878 check_attachment.value = trim(s_tmp); 1879 1880 if (!divFiles.childNodes[0]) 1881 { 1882 divFiles.appendChild(document.createElement("BR")); 1883 } 1884 else 1885 { 1886 divFiles.insertBefore(document.createElement("BR"),divFiles.childNodes[0]); 1887 } 1888 1889 divFiles.insertBefore(link_attachment,divFiles.childNodes[0]); 1890 divFiles.insertBefore(check_attachment,divFiles.childNodes[0]); 1891 1892 check_attachment.checked = true; 1893 } 1894 } 1880 1895 if (message_id) 1881 1896 { 1882 1897 cExecute ("$this.imap_functions.delete_msgs&folder="+openTab.imapBox[border_id]+"&msgs_number="+message_id,handler_delete_msg); 1883 if (openTab.imapBox[0] == "INBOX " + cyrus_delimiter +draftsfolder)1898 if (openTab.imapBox[0] == "INBOX/"+draftsfolder) 1884 1899 { 1885 1900 //Update mailbox 1886 var tr_msg = document.getElementById(message_id);1901 var tr_msg = document.getElementById(message_id); 1887 1902 change_tr_properties(tr_msg, data.msg_no, data.subject); 1888 1903 } 1889 1890 } 1904 } else { 1905 refresh(); 1906 } 1907 1891 1908 var save_link = Element("save_message_options_"+border_id); 1892 1909 save_link.onclick = ''; … … 1894 1911 watch_changes_in_msg(border_id); 1895 1912 write_msg(get_lang('Your message was save as draft in folder %1.', lang_folder(folder_name))); 1896 1897 } 1913 setTimeout( function(){ RichTextEditor.saveFlag = 1; }, 1000 ); 1914 } 1898 1915 } 1899 1916 … … 1929 1946 var handler_save_msg = function(data){ return_save(data,this.tmp_border_id,this.tmp_folder_name,this.tmp_folder_id,this.message_id); } 1930 1947 1931 var mail_as_plain = document.getElementById( 'textplain_rt_checkbox_' + border_id ); 1932 1933 1948 var mail_as_plain = document.getElementById( 'textplain_rt_checkbox_' + border_id ); 1949 mail_as_plain = ( mail_as_plain ) ? mail_as_plain.checked : false; 1950 1934 1951 var textArea = document.createElement("TEXTAREA"); 1935 1952 textArea.style.display='none'; … … 1938 1955 if (! body) 1939 1956 return; 1940 1941 1957 textArea.value = ( ( mail_as_plain ) ? body.previousSibling.value : ( '<body>\r\n' + body.contentWindow.document.body.innerHTML + '\r\n</body>' ) ); 1942 1943 1958 var input_folder = document.createElement("INPUT"); 1944 1959 input_folder.style.display='none'; … … 1955 1970 1956 1971 1957 if (is_ie){ 1972 if (is_ie) 1973 { 1958 1974 var i = 0; 1959 1975 while (document.forms(i).name != "form_message_"+border_id){i++} … … 1961 1977 } 1962 1978 else 1979 { 1963 1980 form = document.forms["form_message_"+border_id]; 1981 } 1982 1964 1983 form.appendChild(textArea); 1965 1984 form.appendChild(input_folder); … … 1967 1986 form.appendChild(input_insertImg); 1968 1987 1969 1970 var mail_type; 1971 1972 if (is_ie) 1973 { 1974 mail_type = document.createElement('<input type="hidden" />'); 1975 } 1976 else 1977 { 1978 mail_type = document.createElement('input'); 1979 mail_type.setAttribute('type', 'hidden'); 1980 } 1981 mail_type.setAttribute('name', 'type'); 1982 var mail_type_value = ( mail_as_plain ) ? 'plain' : 'html'; 1983 mail_type.setAttribute("value", mail_type_value); 1984 1985 form.parentNode.appendChild( mail_type ); 1986 1988 var mail_type; 1989 1990 if (is_ie) 1991 { 1992 mail_type = document.createElement('<input type="hidden" />'); 1993 } 1994 else 1995 { 1996 mail_type = document.createElement('input'); 1997 mail_type.setAttribute('type', 'hidden'); 1998 } 1999 mail_type.setAttribute('name', 'type'); 2000 var mail_type_value = ( mail_as_plain ) ? 'plain' : 'html'; 2001 mail_type.setAttribute("value", mail_type_value); 2002 2003 form.parentNode.appendChild(mail_type); 2004 1987 2005 cExecuteForm ("$this.imap_functions.save_msg", form, handler_save_msg,border_id); 1988 2006 } … … 2165 2183 2166 2184 var folder= Element('border_id_0').innerHTML; 2167 var body = Element('divScrollMain_'+numBox).innerHTML; 2185 var thead = Element('divScrollHead_'+numBox).firstChild.firstChild.innerHTML; 2186 var tbody = Element('divScrollMain_'+numBox).firstChild.firstChild.innerHTML; 2168 2187 var print_width = screen.width - 200; 2169 2188 var x = ((screen.width - print_width) / 2); 2170 2189 var y = ((screen.height - 400) / 2) - 35; 2171 2190 var window_print = window.open('','ExpressoMail','width='+print_width+',height=400,resizable=yes,scrollbars=yes,left='+x+',top='+y); 2172 var seekDot = /\<img /gi; 2173 body = body.replace(seekDot, "<img style='display:none' "); 2174 seekDot = /\<input /gi; 2175 body = body.replace(seekDot, "<input style='display:none' "); 2191 seekDot = /width="24"/gi; 2192 thead = thead.replace(seekDot, "style='display:none'"); 2193 tbody = tbody.replace(seekDot, "style='display:none'"); 2194 seekDot = /width="16"/gi; 2195 thead = thead.replace(seekDot, "style='display:none'"); 2196 tbody = tbody.replace(seekDot, "style='display:none'"); 2197 seekDot = /width="12"/gi; 2198 thead = thead.replace(seekDot, "style='display:none'"); 2199 tbody = tbody.replace(seekDot, "style='display:none'"); 2176 2200 2177 2201 while (1){ 2178 2202 try{ 2179 var html = '<br>'; 2180 html += cabecalho + "</h4><hr>"; 2181 html += folder+"<hr>"; 2182 2183 window_print.document.body.innerHTML = html + '<blockquote><font size="2">' + 2184 '<table style="font-size:12" width="'+(is_ie ? "94%" : "100%" )+'">' + 2185 '<TD width="25%" align="center">'+get_lang("Who")+'</TD>' + 2186 '<TD align="center" width="'+(is_ie ? "50%" : "55%" )+'">'+get_lang("Subject")+'</TD>' + 2187 '<TD align="center" width="11%">'+get_lang("Date")+'</TD>' + 2188 '<TD align="center" width="'+(is_ie ? "10%" : "9%" )+'">'+get_lang("Size")+'</TD></TR></table>' 2189 + body + '</font></blockquote>'; 2203 window_print.document.open(); 2204 var html = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"><html>' 2205 + '<head><link rel="stylesheet" type="text/css" href="templates/'+template+'/print.css"></head>' 2206 + '<body class="print-all-messages"><h1>ExpressoLivre - ExpressoMail</h1>' 2207 + '<h2>'+folder+'</h2><hr/><blockquote><font size="2">' 2208 + '<table width="100%" cellpadding="0" cellspacing="0">' 2209 + '<thead>' + thead + '</thead><tbody>' + tbody + '</tbody>' 2210 + '</table></font></blockquote></body></html>'; 2211 window_print.document.write(html); 2212 window_print.document.close(); 2190 2213 break; 2191 2214 } … … 2246 2269 var attachs = ""; 2247 2270 var show_attachs = ""; 2248 var ii = a.length >2?2:1; 2249 2271 var ii = a.length >2?2:1; 2272 for(i=ii;i<a.length;i++) 2250 2273 { 2251 2274 if(a[i].tagName && a[i].tagName == "A") … … 2257 2280 } else{ 2258 2281 show_attachs = ""; 2259 } 2260 2282 } 2261 2283 var current_path = window.location.href.substr(0,window.location.href.lastIndexOf("/")); 2262 2263 var head = '<head><title></title><link href="'+current_path+'/templates/default/main.css" type="text/css" rel="stylesheet"></head>'; 2264 window_print.document.write(head); 2265 2284 var head = '<head><title></title><link href="'+current_path+'/templates/default/main.css" type="text/css" rel="stylesheet"></head>'; 2285 window_print.document.write(head); 2286 2266 2287 while (1){ 2267 2288 try{ 2268 2289 var html ='<body>'; 2269 html += cabecalho + "</h4><hr>";2290 html += "<h4>ExpressoLivre - ExpressoMail</h4><hr>"; 2270 2291 html += '<table><tbody>'; 2271 2292 if(sender) … … 2293 2314 html += show_attachs; //to show the names of the attachments 2294 2315 html += "</tbody></table><hr>"; 2295 window_print.document.write(html + body.innerHTML); 2316 window_print.document.write(html + body.innerHTML); 2296 2317 if(!is_ie){ 2297 2318 var tab_tags = window_print.document.getElementsByTagName("IMG"); … … 2361 2382 2362 2383 function export_all_selected_msgs(){ 2363 var msgs_to_export = this.get_selected_messages();2364 2365 2384 if (openTab.type[currentTab] > 1){ 2366 msgs_to_export = currentTab.substr(0,(currentTab.length - 2)); 2367 } 2385 source_msg(currentTab,current_folder); 2386 return; 2387 } 2388 var msgs_to_export = this.get_selected_messages(); 2368 2389 2369 2390 var handler_export_all_selected_msgs = function(data){ … … 2372 2393 write_msg(get_lang('Error compressing messages (ZIP). Contact the administrator.')); 2373 2394 } 2374 else 2375 { 2376 if (data.substr(data.length-3, 3) == "zip") { 2377 download_attachments(null, null, data, null, null,'mensagens.zip'); 2378 } else if (data.substr(data.length-3, 3) == "eml") { 2379 //extracts the file name from file path 2380 var string_start = data.lastIndexOf("/") + 1; 2381 var string_length = data.length - string_start; 2382 var fname = data.substr(string_start, string_length); 2383 //extracts the session_id from file name 2384 var string_end = data.lastIndexOf("_") - 5; 2385 fname = fname.substr(0, string_end).concat(".eml"); 2386 download_attachments(null, null, data, null, null, fname); 2387 } else { 2388 download_attachments(null, null, data, null, null, 'mensagens'); 2389 } 2390 } 2395 else 2396 download_attachments(null, null, data, null,null,'mensagens.zip'); 2391 2397 } 2392 2398 … … 2536 2542 } 2537 2543 form_upload.innerHTML = '<form method="POST" name="form_import" enctype="multipart/form-data">'+get_lang('zip mails to import')+':<br>'+ 2538 '<input name="file_1" maxlength="255" size=" 40" id="file_1" type="file"><br>' +2544 '<input name="file_1" maxlength="255" size="50" id="file_1" type="file"><br>' + 2539 2545 '<input title="'+get_lang('Select a folder')+'" value="' + get_lang('Select a folder') + '"' + 'type="button" onclick="javascript:select_import_folder()"> ' + 2540 2546 '<input title="' + get_lang('Close') + '" value="' + get_lang('Close') + '"' + … … 2546 2552 function handler(data){ 2547 2553 // Its necessary to encapsulate the data returned (IE bugfix) 2548 clear_msg();2549 2554 return_import_msgs(data,wfolders_tree); 2550 2555 } … … 2562 2567 folder.value = wfolders_tree._selected.id; 2563 2568 document.form_import.appendChild(folder); 2564 write_msg(get_lang('You must wait while the messages will be imported...') , undefined, true);2569 write_msg(get_lang('You must wait while the messages will be imported...')); 2565 2570 2566 2571 cExecuteForm('$this.imap_functions.import_msgs', document.form_import, handler);
Note: See TracChangeset
for help on using the changeset viewer.