[ Index ] |
|
Code source de vtiger CRM 5.0.2 |
1 /********************************************************************************* 2 ** The contents of this file are subject to the vtiger CRM Public License Version 1.0 3 * ("License"); You may not use this file except in compliance with the License 4 * The Original Code is: vtiger CRM Open Source 5 * The Initial Developer of the Original Code is vtiger. 6 * Portions created by vtiger are Copyright (C) vtiger. 7 * All Rights Reserved. 8 * 9 ********************************************************************************/ 10 function load_webmail(mid) { 11 var node = $("row_"+mid); 12 if(node.className == "unread_email") { 13 var unread = parseInt($(mailbox+"_unread").innerHTML); 14 if(unread != 0) 15 $(mailbox+"_unread").innerHTML = (unread-1); 16 17 $("unread_img_"+mid).removeChild($("unread_img_"+mid).firstChild); 18 $("unread_img_"+mid).appendChild(Builder.node('a', 19 {href: 'javascript:;', onclick: 'OpenCompose('+mid+',"reply")'}, 20 [Builder.node('img',{src: 'modules/Webmails/images/stock_mail-read.png', border: '0', width: '10', height: '11'})] 21 )); 22 } 23 node.className='read_email'; 24 25 $("from_addy").innerHTML = " "+webmail[mid]["from"]; 26 $("to_addy").innerHTML = " "+webmail[mid]["to"]; 27 $("webmail_subject").innerHTML = " "+webmail[mid]["subject"]; 28 $("webmail_date").innerHTML = " "+webmail[mid]["date"]; 29 30 $("body_area").removeChild($("body_area").firstChild); 31 $("body_area").appendChild(Builder.node('iframe',{src: 'index.php?module=Webmails&action=body&mailid='+mid+'&mailbox='+mailbox, width: '100%', height: '210', frameborder: '0'},'You must enable iframes')); 32 33 tmp = document.getElementsByClassName("previewWindow"); 34 for(var i=0;i<tmp.length;i++) { 35 if(tmp[i].style.visibility === "hidden") { 36 tmp[i].style.visibility="visible"; 37 } 38 } 39 40 $("delete_button").removeChild($("delete_button").firstChild); 41 $("delete_button").appendChild(Builder.node('input',{type: 'button', name: 'Button', value: 'Delete', className: 'classWebBtn', onclick: 'runEmailCommand(\'delete_msg\','+mid+')'})); 42 43 $("reply_button_all").removeChild($("reply_button_all").firstChild); 44 $("reply_button_all").appendChild(Builder.node('input',{type: 'button', name: 'reply', value: ' Reply To All ', className: 'classWebBtn', onclick: 'OpenCompose('+mid+',\'replyall\')'})); 45 46 $("reply_button").removeChild($("reply_button").firstChild); 47 $("reply_button").appendChild(Builder.node('input',{type: 'button', name: 'reply', value: ' Reply To Sender ', className: 'classWebBtn', onclick: 'OpenCompose('+mid+',\'reply\')'})); 48 49 $("forward_button").removeChild($("forward_button").firstChild); 50 $("forward_button").appendChild(Builder.node('input',{type: 'button', name: 'forward', value: ' Forward ', className: 'classWebBtn', onclick: 'OpenCompose('+mid+',\'forward\')'})); 51 52 $("qualify_button").removeChild($("qualify_button").firstChild); 53 $("qualify_button").appendChild(Builder.node('input',{type: 'button', name: 'Qualify2', value: ' Qualify ', className: 'classWebBtn', onclick: 'showRelationships('+mid+')'})); 54 55 $("download_attach_button").removeChild($("download_attach_button").firstChild); 56 $("download_attach_button").appendChild(Builder.node('input',{type: 'button', name: 'download', value: ' Download Attachments ', className: 'classWebBtn', onclick: 'displayAttachments('+mid+')'})); 57 58 $("full_view").removeChild($("full_view").firstChild); 59 $("full_view").appendChild(Builder.node('a',{href: 'javascript:;', onclick: 'OpenCompose('+mid+',\'full_view\')'},'Full Email View')); 60 61 } 62 function displayAttachments(mid) { 63 var url = "index.php?module=Webmails&action=dlAttachments&mailid="+mid+"&mailbox="+mailbox; 64 window.open(url,"Download Attachments",'menubar=no,toolbar=no,location=no,status=no,resizable=no,width=450,height=450'); 65 } 66 function showRelationships(mid) { 67 // TODO: present the user with a simple DHTML div to 68 // choose what type of relationship they would like to create 69 // before creating it. 70 alert('Are you sure you wish to Qualify this Mail as Contact?'); 71 add_to_vtiger(mid); 72 } 73 function add_to_vtiger(mid) { 74 // TODO: update this function to allow you to set what entity type 75 // you would like to associate to 76 $("status").style.display="block"; 77 new Ajax.Request( 78 'index.php', 79 {queue: {position: 'end', scope: 'command'}, 80 method: 'post', 81 postBody: 'module=Webmails&action=Save&mailid='+mid+'&ajax=true', 82 onComplete: function(t) { 83 $("status").style.display="block"; 84 } 85 } 86 ); 87 } 88 function select_all() { 89 var els = document.getElementsByClassName("msg_check"); 90 var id=''; 91 for(var i=0;i<els.length;i++) { 92 id = els[i].name.substr((els[i].name.indexOf("_")+1),els[i].name.length); 93 var tels = $("row_"+id); 94 if(tels.className == "deletedRow") { 95 els[i].checked = false; 96 } else { 97 if(els[i].checked) 98 els[i].checked = false; 99 else 100 els[i].checked = true; 101 } 102 } 103 } 104 function check_in_all_boxes(mymbox) { 105 // TODO: There is possibly still a bug in the mailbox counting code 106 // check for NaN 107 new Ajax.Request( 108 'index.php', 109 {queue: {position: 'end', scope: 'command'}, 110 method: 'post', 111 postBody: 'module=Webmails&action=WebmailsAjax&command=check_mbox_all&mailbox='+mymbox+'&ajax=true&file=ListView', 112 onComplete: function(t) { 113 //alert(t.responseText); 114 if(t.responseText != "") { 115 var data = eval('(' + t.responseText + ')'); 116 for (var i=0;i<data.msgs.length;i++) { 117 var mbox = data.msgs[i].msg.box; 118 if(mbox != mailbox) { 119 var numnew = parseInt(data.msgs[i].msg.newmsgs); 120 121 var read = parseInt($(mbox+"_read").innerHTML); 122 $(mbox+"_read").innerHTML = (read+numnew); 123 var unread = parseInt($(mbox+"_unread").innerHTML); 124 $(mbox+"_unread").innerHTML = (unread+numnew); 125 } 126 } 127 } 128 $("status").style.display="none"; 129 } 130 } 131 ); 132 } 133 function check_for_new_mail(mbox) { 134 if(degraded_service == 'true') { 135 window.location=window.location; 136 return; 137 } 138 $("status").style.display="block"; 139 new Ajax.Request( 140 'index.php', 141 {queue: {position: 'end', scope: 'command'}, 142 method: 'post', 143 postBody: 'module=Webmails&action=WebmailsAjax&mailbox='+mbox+'&command=check_mbox&ajax=true&file=ListView', 144 onComplete: function(t) { 145 //alert(t.responseText); 146 try { 147 // TODO: replace this at some point with prototype JSON 148 // tools 149 var data = eval('(' + t.responseText + ')'); 150 var read = parseInt($(mailbox+"_read").innerHTML); 151 $(mailbox+"_read").innerHTML = (read+data.mails.length); 152 var unread = parseInt($(mailbox+"_unread").innerHTML); 153 $(mailbox+"_unread").innerHTML = (unread+data.mails.length); 154 for (var i=0;i<data.mails.length;i++) { 155 var mailid = data.mails[i].mail.mailid; 156 var date = data.mails[i].mail.date; 157 var subject=data.mails[i].mail.subject; 158 var attachments=data.mails[i].mail.attachments; 159 var from=data.mails[i].mail.from; 160 161 webmail[mailid] = new Array(); 162 webmail[mailid]["from"] = from; 163 webmail[mailid]["to"] = data.mails[i].mail.to; 164 webmail[mailid]["subject"] = subject; 165 webmail[mailid]["date"] = date; 166 167 // main row 168 var tr = Builder.node( 169 'tr', 170 {id:'row_'+mailid, className: 'unread_email'} 171 ); 172 173 // checkbox 174 var check = Builder.node( 175 'td', 176 [ Builder.node( 177 'input', 178 {type: 'checkbox', name: 'checkbox_'+mailid, className: 'msg_check'} 179 )] 180 ); 181 182 tr.appendChild(check); 183 // images 184 // Attachment 185 imgtd = Builder.node('td'); 186 if(attachments === "1") { 187 var attach = Builder.node('a', 188 {href: 'javascript:;', onclick: 'displayAttachments('+mailid+')'}, 189 [ Builder.node('img', 190 {src: 'modules/Webmails/images/stock_attach.png', border: '0', width: '14px', height: '14px'} 191 )] 192 ); 193 } else { 194 var attach = Builder.node('a', 195 {src: 'modules/Webmails/images/blank.png', border: '0', width: '14px', height: '14px'} 196 ); 197 } 198 imgtd.appendChild(attach); 199 imgtd.innerHTML += " "; 200 201 var unread = Builder.node('span', 202 {id: 'unread_img_'+mailid}, 203 [ Builder.node('a', 204 {href: 'javascript:;', onclick: 'OpenCompose('+mailid+',\'reply\')'}, 205 [ Builder.node('img', 206 {src: 'modules/Webmails/images/stock_mail-unread.png', border: '0', width: '10', height: '14'} 207 )] 208 )] 209 ); 210 imgtd.appendChild(unread); 211 imgtd.innerHTML += " "; 212 213 var flag = Builder.node('span', 214 {id: 'set_td_'+mailid}, 215 [ Builder.node('a', 216 {href: 'javascript:void(0);', onclick: 'runEmailCommand(\'set_flag\','+mailid+')'}, 217 [ Builder.node('img', 218 {src: 'modules/Webmails/images/plus.gif', border: '0', width: '11px', height: '11px', id: 'set_flag_img_'+mailid} 219 )] 220 )] 221 ); 222 imgtd.appendChild(flag); 223 tr.appendChild(imgtd); 224 225 226 // MSG details 227 tr.appendChild( Builder.node('td', 228 [ Builder.node('a', 229 {href: 'javascript:;', onclick: 'load_webmail(\''+mailid+'\')', id: 'ndeleted_subject_'+mailid}, 230 ''+subject+'' 231 )] 232 )); 233 tr.appendChild( Builder.node('td', 234 {id: 'ndeleted_date_'+mailid}, 235 ''+date+'' 236 )); 237 tr.appendChild( Builder.node('td', 238 {id: 'ndeleted_from_'+mailid}, 239 ''+from+'' 240 )); 241 242 var del = Builder.node('td', 243 {align: 'center', id:'ndeleted_td_'+mailid}, 244 [ Builder.node('span', 245 {id: 'del_link_'+mailid}, 246 [ Builder.node('a', 247 {href: 'javascript:;', onclick: 'runEmailCommand(\'delete_msg\','+mailid+')'}, 248 [ Builder.node('img', 249 {src: 'modules/Webmails/images/gnome-fs-trash-empty.png', border: '0', width: '14', height: '14', alt: 'del'} 250 )] 251 )] 252 )] 253 ); 254 tr.appendChild(del); 255 256 // TODO: this is ugly, replace using prototype child walker tools 257 tr.style.display='none'; 258 var tels = $("message_table").childNodes[1].childNodes; 259 for(var j=0;j<tels.length;j++) { 260 try { 261 if(tels[j].id.match(/row_/)) { 262 $("message_table").childNodes[1].insertBefore(tr,tels[j]); 263 break; 264 } 265 }catch(f){} 266 } 267 new Effect.Appear("row_"+mailid); 268 } 269 }catch(e) {} 270 check_in_all_boxes(mailbox); 271 //$("status").style.display="none"; 272 } 273 } 274 ); 275 } 276 function periodic_event() { 277 // NOTE: any functions you put in here may race. This could probably 278 // be avoided by executing functions in a 0'ed timeout, or a prototype 279 // enumerator 280 check_for_new_mail(mailbox); 281 window.setTimeout("periodic_event()",box_refresh); 282 } 283 function show_hidden() { 284 // prototype uses enumerable lists to queue events for execution. 285 // because of this, this function executes and returns imediately and 286 // the status spinner is never seen. The status spinner below is a hack 287 // and doesn't even attempt to pretend like it knows the event is finished. 288 // this cannot be fixed with the scriptaculous beforeStart and afterFinish 289 // event hooks for some reason, maybe because the event duration is too quick? 290 window.setTimeout(function() { 291 $("status").style.display="block"; 292 window.setTimeout(function() { 293 $("status").style.display="none"; 294 },2000); 295 },0); 296 var els = document.getElementsByClassName("deletedRow"); 297 for(var i=0;i<els.length;i++) { 298 if(els[i].style.display == "none") 299 new Effect.Appear(els[i],{queue: {position: 'end', scope: 'show'}, duration: 0.2}); 300 else 301 new Effect.Fade(els[i],{queue: {position: 'end', scope: 'show'}, duration: 0.2}); 302 } 303 } 304 function mass_delete() { 305 var ok = confirm("Are you sure you want to delete these messages?"); 306 if(ok) { 307 // TODO: CHANGE THIS ASAP. This spikes the client proc @ 100% and 308 // depending on the mbox size may seem completely unresponsive for 309 // extended periods. Could be changed with getElementsByClassName() 310 // to shorten the loop. The majority of the slowdown probably comes from 311 // executing an AJAX delete_msg for each mailid :). 312 $("status").style.display="block"; 313 var els = document.getElementsByTagName("INPUT"); 314 var cnt = (els.length-1); 315 var nids=''; 316 var j=0; 317 for(var i=cnt;i>0;i--) { 318 if(els[i].type === "checkbox" && els[i].name.indexOf("_")) { 319 if(els[i].checked) { 320 var nid = els[i].name.substr((els[i].name.indexOf("_")+1),els[i].name.length); 321 if(typeof nid == 'undefined' || nid == "checkbox") 322 nids += ''; 323 else 324 nids += nid+":"; 325 } 326 } 327 j++; 328 } 329 runEmailCommand("delete_multi_msg",nids); 330 } 331 } 332 function move_messages() { 333 $("status").style.display="block"; 334 var els = document.getElementsByTagName("INPUT"); 335 var cnt = (els.length-1); 336 for(var i=cnt;i>0;i--) { 337 if(els[i].type === "checkbox" && els[i].name.indexOf("_")) { 338 if(els[i].checked) { 339 var nid = els[i].name.substr((els[i].name.indexOf("_")+1),els[i].name.length); 340 var mvmbox = $("mailbox_select").value; 341 new Ajax.Request( 342 'index.php', 343 {queue: {position: 'end', scope: 'command'}, 344 method: 'post', 345 postBody: 'module=Webmails&action=ListView&mailbox=INBOX&command=move_msg&ajax=true&mailid='+nid+'&mvbox='+mvmbox, 346 onComplete: function(t) { 347 //alert(t.responseText); 348 } 349 } 350 ); 351 } 352 } 353 } 354 runEmailCommand('expunge',''); 355 $("status").style.display="none"; 356 } 357 function search_emails() { 358 // TODO: find a way to search in degraded functionality mode. 359 var search_query = $("search_input").value; 360 var search_type = $("search_type").value; 361 window.location = "index.php?module=Webmails&action=index&search=true&search_type="+search_type+"&search_input="+search_query; 362 } 363 function runEmailCommand(com,id) { 364 $("status").style.display="block"; 365 command=com; 366 id=id; 367 new Ajax.Request( 368 'index.php', 369 {queue: {position: 'end', scope: 'command'}, 370 method: 'post', 371 postBody: 'module=Webmails&action=WebmailsAjax&command='+command+'&mailid='+id+'&mailbox='+mailbox, 372 onComplete: function(t) { 373 resp = t.responseText; 374 if(resp.match(/ajax failed/)) {return;} 375 switch(command) { 376 case 'expunge': 377 // NOTE: we either have to reload the page or count up from the messages that 378 // are deleted and moved or we introduce a bug from invalid mail ids 379 window.location = window.location; 380 break; 381 case 'delete_multi_msg': 382 var ids=resp; 383 var rows = ids.split(":"); 384 for(i=0;i<rows.length;i++) { 385 var id = rows[i]; 386 var row = $("row_"+id); 387 if(row.className == "unread_email") { 388 var unread = parseInt($(mailbox+"_unread").innerHTML); 389 $(mailbox+"_unread").innerHTML = (unread-1); 390 } 391 row.className = "deletedRow"; 392 393 Try.these ( 394 function() { 395 $("ndeleted_subject_"+id).innerHTML = "<s>"+$("ndeleted_subject_"+id).innerHTML+"</s>"; 396 $("ndeleted_date_"+id).innerHTML = "<s>"+$("ndeleted_date_"+id).innerHTML+"</s>"; 397 $("ndeleted_from_"+id).innerHTML = "<s>"+$("ndeleted_from_"+id).innerHTML+"</s>"; 398 }, 399 function() { 400 $("deleted_subject_"+id).innerHTML = "<s>"+$("deleted_subject_"+id).innerHTML+"</s>"; 401 $("deleted_date_"+id).innerHTML = "<s>"+$("deleted_date_"+id).innerHTML+"</s>"; 402 $("deleted_from_"+id).innerHTML = "<s>"+$("deleted_from_"+id).innerHTML+"</s>"; 403 } 404 ); 405 406 try { 407 $("del_link_"+id).innerHTML = '<a href="javascript:void(0);" onclick="runEmailCommand(\'undelete_msg\','+id+');"><img src="modules/Webmails/images/gnome-fs-trash-full.png" border="0" width="14" height="14" alt="del"></a>'; 408 409 new Effect.Fade(row,{queue: {position: 'end', scope: 'effect'},duration: '0.5'}); 410 tmp = document.getElementsByClassName("previewWindow"); 411 tmp[0].style.visibility="hidden"; 412 }catch(g){} 413 414 $("status").style.display="none"; 415 } 416 break; 417 case 'delete_msg': 418 id=resp; 419 var row = $("row_"+id); 420 if(row.className == "unread_email") { 421 var unread = parseInt($(mailbox+"_unread").innerHTML); 422 $(mailbox+"_unread").innerHTML = (unread-1); 423 } 424 row.className = "deletedRow"; 425 426 Try.these ( 427 function() { 428 $("ndeleted_subject_"+id).innerHTML = "<s>"+$("ndeleted_subject_"+id).innerHTML+"</s>"; 429 $("ndeleted_date_"+id).innerHTML = "<s>"+$("ndeleted_date_"+id).innerHTML+"</s>"; 430 $("ndeleted_from_"+id).innerHTML = "<s>"+$("ndeleted_from_"+id).innerHTML+"</s>"; 431 }, 432 function() { 433 $("deleted_subject_"+id).innerHTML = "<s>"+$("deleted_subject_"+id).innerHTML+"</s>"; 434 $("deleted_date_"+id).innerHTML = "<s>"+$("deleted_date_"+id).innerHTML+"</s>"; 435 $("deleted_from_"+id).innerHTML = "<s>"+$("deleted_from_"+id).innerHTML+"</s>"; 436 } 437 ); 438 439 $("del_link_"+id).innerHTML = '<a href="javascript:void(0);" onclick="runEmailCommand(\'undelete_msg\','+id+');"><img src="modules/Webmails/images/gnome-fs-trash-full.png" border="0" width="14" height="14" alt="del"></a>'; 440 441 new Effect.Fade(row,{queue: {position: 'end', scope: 'effect'},duration: '1.0'}); 442 tmp = document.getElementsByClassName("previewWindow"); 443 for(var i=0;i<tmp.length;i++) { 444 if(tmp[i].style.visibility === "visible") { 445 tmp[i].style.visibility="hidden"; 446 } 447 } 448 break; 449 case 'undelete_msg': 450 id=resp; 451 var node = $("row_"+id); 452 node.className=''; 453 node.style.display = ''; 454 var newhtml = remove(remove(node.innerHTML,'<s>'),'</s>'); 455 node.innerHTML=newhtml; 456 $("del_link_"+id).innerHTML = '<a href="javascript:void(0);" onclick="runEmailCommand(\'delete_msg\','+id+');"><img src="modules/Webmails/images/gnome-fs-trash-empty.png" border="0" width="14" height="14" alt="del"></a>'; 457 $("status").style.display="none"; 458 break; 459 case 'clear_flag': 460 var nm = "clear_td_"+id; 461 var el = $(nm); 462 var tmp = el.innerHTML; 463 el.innerHTML ='<a href="javascript:void(0);" onclick="runEmailCommand(\'set_flag\','+id+');"><img src="modules/Webmails/images/plus.gif" border="0" width="11" height="11" id="set_flag_img_'+id+'"></a>'; 464 el.id = "set_td_"+id; 465 break; 466 case 'set_flag': 467 var nm = "set_td_"+id; 468 var el = $(nm); 469 var tmp = el.innerHTML; 470 el.innerHTML ='<a href="javascript:void(0);" onclick="runEmailCommand(\'clear_flag\','+id+');"><img src="modules/Webmails/images/stock_mail-priority-high.png" border="0" width="11" height="11" id="clear_flag_img'+id+'"></a>'; 471 el.id = "clear_td_"+id; 472 break; 473 474 } 475 $("status").style.display="none"; 476 } 477 } 478 ); 479 } 480 function remove(s, t) { 481 /* 482 ** Remove all occurrences of a token in a string 483 ** s string to be processed 484 ** t token to be removed 485 ** returns new string 486 */ 487 i = s.indexOf(t); 488 r = ""; 489 if (i == -1) return s; 490 r += s.substring(0,i) + remove(s.substring(i + t.length), t); 491 return r; 492 } 493 function changeMbox(box) { 494 location.href = "index.php?module=Webmails&action=index&mailbox="+box; 495 } 496 // TODO: these two functions should be tied into a mailbox management panel of some kind. 497 // could be a DHTML div with AJAX calls to execute the commands on the mailbox. 498 function show_addfolder() { 499 var fldr = $("folderOpts"); 500 if(fldr.style.display == 'none') 501 $("folderOpts").style.display=""; 502 else 503 $("folderOpts").style.display="none"; 504 } 505 function show_remfolder(mb) { 506 var fldr = $("remove_"+mb); 507 if(fldr.style.display == 'none') 508 fldr.style.display=""; 509 else 510 fldr.style.display="none"; 511 }
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Sun Feb 25 10:22:19 2007 | par Balluche grâce à PHPXref 0.7 |