summaryrefslogtreecommitdiff
path: root/program/js/app.js
diff options
context:
space:
mode:
Diffstat (limited to 'program/js/app.js')
-rw-r--r--program/js/app.js43
1 files changed, 41 insertions, 2 deletions
diff --git a/program/js/app.js b/program/js/app.js
index f4f4fc475..d42b8ede8 100644
--- a/program/js/app.js
+++ b/program/js/app.js
@@ -3648,13 +3648,21 @@ function rcube_webmail()
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 @@ function rcube_webmail()
/********************************************************/
+ /********* 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 *********/
/********************************************************/