From 3bd94b142eb00024eeb52c0e3f4a9f61bed4f3f9 Mon Sep 17 00:00:00 2001
From: alecpl <alec@alec.pl>
Date: Sun, 14 Sep 2008 04:34:11 -0400
Subject: [PATCH] - use html2text for signatures in Settings/Identities

---
 program/js/app.js |   43 +++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 41 insertions(+), 2 deletions(-)

diff --git a/program/js/app.js b/program/js/app.js
index f4f4fc4..d42b8ed 100644
--- a/program/js/app.js
+++ b/program/js/app.js
@@ -3648,13 +3648,21 @@
   this.toggle_editor = function(checkbox, textAreaId)
     {
     var ischecked = checkbox.checked;
+    var composeElement = document.getElementById(textAreaId);
+    
     if (ischecked)
       {
-        tinyMCE.execCommand('mceAddControl', true, textAreaId);
+      var existingPlainText = composeElement.value;
+      var htmlText = "<pre>" + existingPlainText + "</pre>";
+      composeElement.value = htmlText;
+      tinyMCE.execCommand('mceAddControl', true, textAreaId);
       }
     else
       {
-        tinyMCE.execCommand('mceRemoveControl', true, textAreaId);
+      var thisMCE = tinyMCE.get(textAreaId);
+      var existingHtml = thisMCE.getContent();
+      this.html2plain(existingHtml, textAreaId);
+      tinyMCE.execCommand('mceRemoveControl', true, textAreaId);
       }
     };
 
@@ -3718,6 +3726,37 @@
 
 
   /********************************************************/
+  /*********  html to text conversion functions   *********/
+  /********************************************************/
+
+  this.html2plain = function(htmlText, id)
+    {
+    var http_request = new rcube_http_request();
+    var url = this.env.bin_path+'html2text.php';
+    var rcmail = this;
+
+    this.set_busy(true, 'converting');
+    console.log('HTTP POST: '+url);
+
+    http_request.onerror = function(o) { rcmail.http_error(o); };
+    http_request.oncomplete = function(o) { rcmail.set_text_value(o, id); };
+    http_request.POST(url, htmlText, 'application/octet-stream');
+    }
+
+  this.set_text_value = function(httpRequest, id)
+    {
+    this.set_busy(false);
+    document.getElementById(id).value = httpRequest.get_text();
+    console.log(httpRequest.get_text());
+    }
+
+  this.handle_conv_error = function(httpRequest)
+    {
+    alert('html2text request returned with error ' + httpRequest.xmlhttp.status);
+    }
+
+
+  /********************************************************/
   /*********        remote request methods        *********/
   /********************************************************/
 

--
Gitblit v1.9.1