From 4fb1e8582baa5e6b746f31206cb42bd4dadc18be Mon Sep 17 00:00:00 2001
From: alecpl <alec@alec.pl>
Date: Mon, 15 Dec 2008 03:22:20 -0500
Subject: [PATCH] - allow cc, bcc, replyto fields hidding

---
 skins/default/functions.js           |   68 ++++++++++++++++++++++++----------
 skins/default/images/icons/minus.gif |    0 
 skins/default/templates/compose.html |   29 ++++++++------
 3 files changed, 64 insertions(+), 33 deletions(-)

diff --git a/skins/default/functions.js b/skins/default/functions.js
index e232ac7..53519d1 100644
--- a/skins/default/functions.js
+++ b/skins/default/functions.js
@@ -32,30 +32,57 @@
  * Mail Composing
  */
 
-function rcmail_show_header_form(id, link)
+function rcmail_show_header_form(id)
 {
-  var row, parent, ns, ps, links;
+  var link, row, parent, ns, ps;
+  
+  link = document.getElementById(id + '-link');
+  parent = link.parentNode;
 
-  if (link)
-  {
-    var parent = link.parentNode;
-
-    if ((ns = rcmail_next_sibling(link)))
-      parent.removeChild(ns);
-    else if ((ps = rcmail_prev_sibling(link)))
-      parent.removeChild(ps);
+  if ((ns = rcmail_next_sibling(link)))
+    ns.style.display = 'none';
+  else if ((ps = rcmail_prev_sibling(link)))
+    ps.style.display = 'none';
     
-    parent.removeChild(link);
+  link.style.display = 'none';
 
-    if(!parent.getElementsByTagName('A').length)
-      document.getElementById('compose-links').style.display = 'none';
-  }
-
-  if (row = document.getElementById(id))
+  if (row = document.getElementById('compose-' + id))
     {
     var div = document.getElementById('compose-div');
     var headers_div = document.getElementById('compose-headers-div');
     row.style.display = (document.all && !window.opera) ? 'block' : 'table-row';
+    div.style.top = (parseInt(headers_div.offsetHeight)) + 'px';
+    }
+
+  return false;
+}
+
+function rcmail_hide_header_form(id)
+{
+  var row, parent, ns, ps, link, links;
+
+  link = document.getElementById(id + '-link');
+  link.style.display = '';
+  
+  parent = link.parentNode;
+  links = parent.getElementsByTagName('A');
+
+  for (var i=0; i<links.length; i++)
+    if (links[i].style.display != 'none')
+      for (var j=i+1; j<links.length; j++)
+	if (links[j].style.display != 'none')
+          if ((ns = rcmail_next_sibling(links[i]))) {
+	    ns.style.display = '';
+	    break;
+	  }
+
+  document.getElementById('_' + id).value = '';
+
+  if (row = document.getElementById('compose-' + id))
+    {
+    var div = document.getElementById('compose-div');
+    var headers_div = document.getElementById('compose-headers-div');
+    row.style.display = 'none';
     div.style.top = (parseInt(headers_div.offsetHeight)) + 'px';
     }
 
@@ -80,12 +107,13 @@
 
 function rcmail_init_compose_form()
 {
-  var cc_field = document.getElementById('rcmcomposecc');
+  var cc_field = document.getElementById('_cc');
   if (cc_field && cc_field.value!='')
-    rcmail_show_header_form('compose-cc', document.getElementById('addcclink'));
-  var bcc_field = document.getElementById('rcmcomposebcc');
+    rcmail_show_header_form('cc');
+
+  var bcc_field = document.getElementById('_bcc');
   if (bcc_field && bcc_field.value!='')
-    rcmail_show_header_form('compose-bcc', document.getElementById('addbcclink'));
+    rcmail_show_header_form('bcc');
 
   // prevent from form data loss when pressing ESC key in IE
   if (bw.ie) {
diff --git a/skins/default/images/icons/minus.gif b/skins/default/images/icons/minus.gif
new file mode 100644
index 0000000..4ec02c8
--- /dev/null
+++ b/skins/default/images/icons/minus.gif
Binary files differ
diff --git a/skins/default/templates/compose.html b/skins/default/templates/compose.html
index aa45ef0..712db66 100644
--- a/skins/default/templates/compose.html
+++ b/skins/default/templates/compose.html
@@ -37,28 +37,31 @@
 	<table border="0" cellspacing="0" cellpadding="1" id="compose-headers" summary="">
 	<tbody>
 	    <tr>
-		<td class="title"><label for="rcmcomposefrom"><roundcube:label name="from" /></label></td>
-		<td><roundcube:object name="composeHeaders" part="from" form="form" id="rcmcomposefrom" tabindex="1" /></td>
+		<td class="title"><label for="_from"><roundcube:label name="from" /></label></td>
+		<td><roundcube:object name="composeHeaders" part="from" form="form" id="_from" tabindex="1" /></td>
 	    </tr><tr>
-		<td class="title top"><label for="rcmcomposeto"><roundcube:label name="to" /></label></td>
-		<td><roundcube:object name="composeHeaders" part="to" form="form" id="rcmcomposeto" cols="70" rows="2" tabindex="2" /></td>
+		<td class="title top"><label for="_to"><roundcube:label name="to" /></label></td>
+		<td><roundcube:object name="composeHeaders" part="to" form="form" id="_to" cols="70" rows="2" tabindex="2" /></td>
 	    </tr><tr id="compose-cc">
-		<td class="title top"><label for="rcmcomposecc"><roundcube:label name="cc" /></label></td>
-		<td><roundcube:object name="composeHeaders" part="cc" form="form" id="rcmcomposecc" cols="70" rows="2" tabindex="3" /></td>
+		<td class="title top"><a href="#cc" onclick="return rcmail_hide_header_form('cc');" /><img src="/images/icons/minus.gif" alt="" title="<roundcube:label name="delete" />" /></a>
+		<label for="_cc"><roundcube:label name="cc" /></label></td>
+		<td><roundcube:object name="composeHeaders" part="cc" form="form" id="_cc" cols="70" rows="2" tabindex="3" /></td>
 	    </tr><tr id="compose-bcc">
-		<td class="title top"><label for="rcmcomposebcc"><roundcube:label name="bcc" /></label></td>
-		<td><roundcube:object name="composeHeaders" part="bcc" form="form" id="rcmcomposebcc" cols="70" rows="2" tabindex="4" /></td>
+		<td class="title top"><a href="#bcc" onclick="return rcmail_hide_header_form('bcc');" /><img src="/images/icons/minus.gif" alt="" title="<roundcube:label name="delete" />" /></a>
+		<label for="_bcc"><roundcube:label name="bcc" /></label></td>
+		<td><roundcube:object name="composeHeaders" part="bcc" form="form" id="_bcc" cols="70" rows="2" tabindex="4" /></td>
 	    </tr><tr id="compose-replyto">
-		<td class="title top"><label for="rcmcomposereplyto"><roundcube:label name="replyto" /></label></td>
-		<td><roundcube:object name="composeHeaders" part="replyto" form="form" id="rcmcomposereplyto" size="70" tabindex="5" /></td>
+		<td class="title top"><a href="#replyto" onclick="return rcmail_hide_header_form('replyto');" /><img src="/images/icons/minus.gif" alt="" title="<roundcube:label name="delete" />" /></a>
+		<label for="_replyto"><roundcube:label name="replyto" /></label></td>
+		<td><roundcube:object name="composeHeaders" part="replyto" form="form" id="_replyto" size="70" tabindex="5" /></td>
 	    </tr><tr id="compose-links">
 		<td></td>
 		<td class="formlinks">
-		    <a href="#cc" onclick="return rcmail_show_header_form('compose-cc', this);" id="addcclink"><roundcube:label name="addcc" /></a>
+		    <a href="#cc" onclick="return rcmail_show_header_form('cc')" id="cc-link"><roundcube:label name="addcc" /></a>
 		    <span class="separator">|</span>
-		    <a href="#bcc" onclick="return rcmail_show_header_form('compose-bcc', this);" id="addbcclink"><roundcube:label name="addbcc" /></a>
+		    <a href="#bcc" onclick="return rcmail_show_header_form('bcc')" id="bcc-link"><roundcube:label name="addbcc" /></a>
 		    <span class="separator">|</span>
-		    <a href="#reply-to" onclick="return rcmail_show_header_form('compose-replyto', this);" id="addreplytolink"><roundcube:label name="addreplyto" /></a>
+		    <a href="#reply-to" onclick="return rcmail_show_header_form('replyto')" id="replyto-link"><roundcube:label name="addreplyto" /></a>
 		</td>
 	    </tr><tr>
 		<td class="title"><label for="compose-subject"><roundcube:label name="subject" /></label></td>

--
Gitblit v1.9.1