[Vtigercrm-commits] [vtiger-commits] r6513 - in /vtigercrm/trunk/modules/Webmails: ListView.php webmails.js
vtigercrm-commits at vtiger.fosslabs.com
vtigercrm-commits at vtiger.fosslabs.com
Fri May 26 22:03:52 EDT 2006
Author: mmbrich
Date: Fri May 26 20:03:51 2006
New Revision: 6513
Log:
move massive set of javascript functions to own file
Added:
vtigercrm/trunk/modules/Webmails/webmails.js
Modified:
vtigercrm/trunk/modules/Webmails/ListView.php
Modified: vtigercrm/trunk/modules/Webmails/ListView.php
==============================================================================
--- vtigercrm/trunk/modules/Webmails/ListView.php (original)
+++ vtigercrm/trunk/modules/Webmails/ListView.php Fri May 26 20:03:51 2006
@@ -37,366 +37,26 @@
$show_hidden=$_REQUEST["show_hidden"];
-// BEGIN MASSIVE AMOUNTS OF JAVASCRIPT
?>
<script language="JavaScript" type="text/javascript" src="include/scriptaculous/prototype.js"></script>
<script language="JavaScript" type="text/javascript" src="include/scriptaculous/scriptaculous.js?load=effects,builder"></script>
+<script language="JavaScript" type="text/javascript" src="modules/Webmails/webmails.js"></script>
<script type="text/javascript">
+var mailbox = "<?php echo $mailbox;?>";
+var box_refresh=<?php echo $box_refresh;?>;
var webmail = new Array();
-function load_webmail(mid) {
- var node = $("row_"+mid);
- node.className='read_email';
- // gracefully handle this if the mail is already read.
- try {
- $("unread_img_"+mid).appendChild(Builder.node('a',
- {href: 'javascript:;', onclick: 'OpenCompose('+mid+',"reply")'},
- [Builder.node('img',{src: 'modules/Webmails/images/stock_mail-read.png', border: '0', width: '10', height: '11'})]
- ));
- }catch(e){}
-
- $("from_addy").innerHTML = " "+webmail[mid]["from"];
- $("to_addy").innerHTML = " "+webmail[mid]["to"];
- $("webmail_subject").innerHTML = " "+webmail[mid]["subject"];
- $("webmail_date").innerHTML = " "+webmail[mid]["date"];
-
- $("body_area").removeChild($("body_area").firstChild);
- $("body_area").appendChild(Builder.node('iframe',{src: 'index.php?module=Webmails&action=body&mailid='+mid+'&mailbox=<?php echo $mailbox;?>', width: '100%', height: '210', frameborder: '0'},'You must enable iframes'));
-
- tmp = document.getElementsByClassName("previewWindow");
- for(var i=0;i<tmp.length;i++) {
- if(tmp[i].style.visibility === "hidden") {
- tmp[i].style.visibility="visible";
- }
- }
-
- $("delete_button").removeChild($("delete_button").firstChild);
- $("delete_button").appendChild(Builder.node('input',{type: 'button', name: 'Button', value: 'Delete', className: 'classWebBtn', onclick: 'runEmailCommand(\'delete_msg\','+mid+')'}));
-
- $("reply_button_all").removeChild($("reply_button_all").firstChild);
- $("reply_button_all").appendChild(Builder.node('input',{type: 'button', name: 'reply', value: ' Reply To All ', className: 'classWebBtn', onclick: 'window.location = \'index.php?module=Webmails&action=EditView&mailid='+mid+'&reply=all&return_action=index&return_module=Webmails\''}));
-
- $("reply_button").removeChild($("reply_button").firstChild);
- $("reply_button").appendChild(Builder.node('input',{type: 'button', name: 'reply', value: ' Reply To Sender ', className: 'classWebBtn', onclick: 'window.location = \'index.php?module=Webmails&action=EditView&mailid='+mid+'&reply=single&return_action=index&return_module=Webmails\''}));
-
- $("qualify_button").removeChild($("qualify_button").firstChild);
- $("qualify_button").appendChild(Builder.node('input',{type: 'button', name: 'Qualify2', value: ' Qualify ', className: 'classWebBtn', onclick: 'showRelationships('+mid+')'}));
-
- $("download_attach_button").removeChild($("download_attach_button").firstChild);
- $("download_attach_button").appendChild(Builder.node('input',{type: 'button', name: 'download', value: ' Download Attachments ', className: 'classWebBtn', onclick: 'displayAttachments('+mid+')'}));
-
-}
-function displayAttachments(mid) {
- var url = "index.php?module=Webmails&action=dlAttachments&mailid="+mid;
- window.open(url,"Download Attachments",'menubar=no,toolbar=no,location=no,status=no,resizable=no,width=450,height=450');
-}
-function showRelationships(mid) {
- // just add to vtiger for now
- add_to_vtiger(mid);
-}
-function add_to_vtiger(mid) {
- $("status").style.display="block";
- new Ajax.Request(
- 'index.php',
- {queue: {position: 'end', scope: 'command'},
- method: 'post',
- postBody: 'module=Webmails&action=Save&mailid='+mid+'&ajax=true',
- onComplete: function(t) {
- $("status").style.display="none";
- }
- }
- );
-}
-function select_all() {
- var els = document.getElementsByClassName("msg_check");
- for(var i=0;i<els.length;i++) {
- if(els[i].checked)
- els[i].checked = false;
- else
- els[i].checked = true;
- }
-}
-function check_for_new_mail(mbox) {
- $("status").style.display="block";
- new Ajax.Request(
- 'modules/Webmails/WebmailsAjax.php',
- {queue: {position: 'end', scope: 'command'},
- method: 'post',
- postBody: 'module=Webmails&action=ListView&mailbox='+mbox+'&command=check_mbox&ajax=true',
- onComplete: function(t) {
- try {
- var data = eval('(' + t.responseText + ')');
- for (var i=0;i<data.mails.length;i++) {
- var mailid = data.mails[i].mail.mailid;
- var date = data.mails[i].mail.date;
- var subject=data.mails[i].mail.subject;
- var attachments=data.mails[i].mail.attachments;
- var from=data.mails[i].mail.from;
-
- webmail[mailid] = new Array();
- webmail[mailid]["from"] = from;
- webmail[mailid]["to"] = data.mails[i].mail.to;
- webmail[mailid]["subject"] = subject;
- webmail[mailid]["date"] = date;
-
- // main row
- var tr = Builder.node(
- 'tr',
- {id:'row_'+mailid, className: 'unread_email'}
- );
-
- // checkbox
- var check = Builder.node(
- 'td',
- [ Builder.node(
- 'input',
- {type: 'checkbox', name: 'checkbox_'+mailid, className: 'msg_check'}
- )]
- );
-
- tr.appendChild(check);
-
- // images
- // Attachment
- imgtd = Builder.node('td');
- if(attachments === "1") {
- var attach = Builder.node('a',
- {href: 'javascript:;', onclick: 'displayAttachments('+mailid+')'},
- [ Builder.node('img',
- {src: 'modules/Webmails/images/stock_attach.png', border: '0', width: '14px', height: '14px'}
- )]
- );
- } else {
- var attach = Builder.node('a',
- {src: 'modules/Webmails/images/blank.png', border: '0', width: '14px', height: '14px'}
- );
- }
- imgtd.appendChild(attach);
-
- var unread = Builder.node('span',
- {id: 'unread_img_'+mailid},
- [ Builder.node('a',
- {href: 'index.php?module=Webmails&action=DetailView&record='+mailid+'&mailbox=<?php echo $mailbox;?>&mailid='+mailid},
- [ Builder.node('img',
- {src: 'modules/Webmails/images/stock_mail-unread.png', border: '0', width: '10', height: '14'}
- )]
- )]
- );
- imgtd.appendChild(unread);
-
- var flag = Builder.node('span',
- {id: 'set_td_'+mailid},
- [ Builder.node('a',
- {href: 'javascript:void(0);', onclick: 'runEmailCommand(\'set_flag\','+mailid+')'},
- [ Builder.node('img',
- {src: 'modules/Webmails/images/plus.gif', border: '0', width: '11px', height: '11px', id: 'set_flag_img_'+mailid}
- )]
- )]
- );
- imgtd.appendChild(flag);
- tr.appendChild(imgtd);
-
-
- // MSG details
- tr.appendChild( Builder.node('td',
- [ Builder.node('a',
- {href: 'javascript:;', onclick: 'load_webmail(\''+mailid+'\')', id: 'ndeleted_subject_'+mailid},
- ''+subject+''
- )]
- ));
- tr.appendChild( Builder.node('td',
- {id: 'ndeleted_date_'+mailid},
- ''+date+''
- ));
- tr.appendChild( Builder.node('td',
- {id: 'ndeleted_from_'+mailid},
- ''+from+''
- ));
-
- var del = Builder.node('td',
- {align: 'center', id:'ndeleted_td_'+mailid},
- [ Builder.node('span',
- {id: 'del_link_'+mailid},
- [ Builder.node('a',
- {href: 'javascript:;', onclick: 'runEmailCommand(\'delete_msg\','+mailid+')'},
- [ Builder.node('img',
- {src: 'modules/Webmails/images/gnome-fs-trash-empty.png', border: '0', width: '14', height: '14', alt: 'del'}
- )]
- )]
- )]
- );
- tr.appendChild(del);
-
- tr.style.display='none';
- var tels = $("message_table").childNodes[1].childNodes;
- for(var j=0;j<tels.length;j++) {
- try {
- if(tels[j].id.match(/row_/)) {
- $("message_table").childNodes[1].insertBefore(tr,tels[j]);
- break;
- }
- }catch(e){}
- }
- new Effect.Appear("row_"+mailid);
- }
- }catch(e) {}
- $("status").style.display="none";
- window.setTimeout("check_for_new_mail('<?php echo $mailbox;?>')",box_refresh);
- }
- }
- );
-}
-function show_hidden() {
- var els = document.getElementsByClassName("deletedRow");
- for(var i=0;i<els.length;i++) {
- if(els[i].style.display == "none")
- new Effect.Appear(els[i],{queue: {position: 'end', scope: 'command'}, duration: 0.3});
- else
- new Effect.Fade(els[i],{queue: {position: 'end', scope: 'command'}, duration: 0.3});
- }
-}
-function move_messages() {
- var els = document.getElementsByTagName("INPUT");
- var cnt = (els.length-1);
- for(var i=cnt;i>0;i--) {
- if(els[i].type === "checkbox" && els[i].name.indexOf("_")) {
- if(els[i].checked) {
- var nid = els[i].name.substr((els[i].name.indexOf("_")+1),els[i].name.length);
- var mvmbox = $("mailbox_select").value;
- new Ajax.Request(
- 'index.php',
- {queue: {position: 'end', scope: 'command'},
- method: 'post',
- postBody: 'module=Webmails&action=ListView&mailbox=INBOX&command=move_msg&ajax=true&mailid='+nid+'&mvbox='+mvmbox,
- onComplete: function(t) {
- //alert(t.responseText);
- }
- }
- );
- }
- }
- }
- runEmailCommand('expunge','');
-}
-function search_emails() {
- var search_query = $("search_input").value;
- var search_type = $("search_type").value;
- window.location = "index.php?module=Webmails&action=index&search=true&search_type="+search_type+"&search_input="+search_query;
-}
-
-var box_refresh=<?php echo $box_refresh;?>;
-var timer = addOnloadEvent(function() {
- window.setTimeout("check_for_new_mail('<?php echo $mailbox;?>')",box_refresh);
- }
- );
-
+var timer;
var command;
var id;
-function runEmailCommand(com,id) {
- $("status").style.display="block";
- command=com;
- id=id;
- new Ajax.Request(
- 'index.php',
- {queue: {position: 'end', scope: 'command'},
- method: 'post',
- postBody: 'module=Webmails&action=body&command='+command+'&mailid='+id+'&mailbox=<?php echo $_REQUEST["mailbox"];?>',
- onComplete: function(t) {
- resp = t.responseText;
- if(resp.match(/ajax failed/)) {return;}
- switch(command) {
- case 'expunge':
- // NOTE: we either have to reload the page or count up from the messages that
- // are deleted and moved or we introduce a bug from invalid mail ids
- window.location = window.location;
- break;
- case 'delete_msg':
- var row = $("row_"+id);
- row.className = "deletedRow";
- try {
- $("ndeleted_subject_"+id).innerHTML = "<s>"+$("ndeleted_subject_"+id).innerHTML+"</s>";
- $("ndeleted_date_"+id).innerHTML = "<s>"+$("ndeleted_date_"+id).innerHTML+"</s>";
- $("ndeleted_from_"+id).innerHTML = "<s>"+$("ndeleted_from_"+id).innerHTML+"</s>";
- }catch(e){
- $("deleted_subject_"+id).innerHTML = "<s>"+$("deleted_subject_"+id).innerHTML+"</s>";
- $("deleted_date_"+id).innerHTML = "<s>"+$("deleted_date_"+id).innerHTML+"</s>";
- $("deleted_from_"+id).innerHTML = "<s>"+$("deleted_from_"+id).innerHTML+"</s>";
- }
-
- $("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>';
-
- new Effect.Fade(row,{queue: {position: 'end', scope: 'effect'}});
- tmp = document.getElementsByClassName("previewWindow");
- for(var i=0;i<tmp.length;i++) {
- if(tmp[i].style.visibility === "visible") {
- tmp[i].style.visibility="hidden";
- }
- }
- break;
- case 'undelete_msg':
- var node = $("row_"+id);
- node.className='';
- node.style.display = '';
- var newhtml = remove(remove(node.innerHTML,'<s>'),'</s>');
- node.innerHTML=newhtml;
- $("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>';
- break;
- case 'clear_flag':
- var nm = "clear_td_"+id;
- var el = $(nm);
- var tmp = el.innerHTML;
- 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>';
- el.id = "set_td_"+id;
- break;
- case 'set_flag':
- var nm = "set_td_"+id;
- var el = $(nm);
- var tmp = el.innerHTML;
- 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>';
- el.id = "clear_td_"+id;
- break;
-
- }
- $("status").style.display="none";
- }
- }
- );
-}
-function remove(s, t) {
- /*
- ** Remove all occurrences of a token in a string
- ** s string to be processed
- ** t token to be removed
- ** returns new string
- */
- i = s.indexOf(t);
- r = "";
- if (i == -1) return s;
- r += s.substring(0,i) + remove(s.substring(i + t.length), t);
- return r;
-}
-function changeMbox(box) {
- location.href = "index.php?module=Webmails&action=index&parenttab=My%20Home%20Page&mailbox="+box+"&start=<?php echo $start;?>";
-}
-function show_addfolder() {
- var fldr = $("folderOpts");
- if(fldr.style.display == 'none')
- $("folderOpts").style.display="";
- else
- $("folderOpts").style.display="none";
-}
-function show_remfolder(mb) {
- var fldr = $("remove_"+mb);
- if(fldr.style.display == 'none')
- fldr.style.display="";
- else
- fldr.style.display="none";
-}
+
+
+addOnloadEvent(function() {
+ timer = window.setTimeout("periodic_event()",box_refresh);
+ }
+);
</script>
<?
-// END MASSIVE AMOUNTS OF JAVASCRIPT
-
-
global $mbox,$displayed_msgs;
$mbox = getImapMbox($mailbox,$temprow);
More information about the vtigercrm-commits
mailing list