From 79af0bb1ba370bd5f194afb692e7ed59a26b02af Mon Sep 17 00:00:00 2001
From: alecpl <alec@alec.pl>
Date: Mon, 03 Nov 2008 09:26:23 -0500
Subject: [PATCH] - Add warning when switching editor mode from html to plain (#1485488) - Unified editor switching functions

---
 CHANGELOG                                |    5 ++
 program/steps/mail/compose.inc           |   10 ++++-
 program/js/editor.js                     |   37 ------------------
 program/localization/en_US/messages.inc  |    1 
 program/localization/pl_PL/messages.inc  |    1 
 skins/default/templates/compose.html     |    2 
 program/js/app.js                        |   18 +++++++--
 program/steps/settings/edit_identity.inc |    4 +-
 8 files changed, 32 insertions(+), 46 deletions(-)

diff --git a/CHANGELOG b/CHANGELOG
index fe8bb5c..1e5d087 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -1,6 +1,11 @@
 CHANGELOG RoundCube Webmail
 ---------------------------
 
+2008/11/03 (alec)
+----------
+- Add warning when switching editor mode from html to plain (#1485488)
+- Unified editor switching functions
+
 2008/10/29 (alec)
 ----------
 - Fix problem with numeric folder names (#1485527)
diff --git a/program/js/app.js b/program/js/app.js
index d8a7eed..5c258f9 100644
--- a/program/js/app.js
+++ b/program/js/app.js
@@ -3622,24 +3622,34 @@
     this.enable_command('export', (this.contact_list.rowcount > 0));
     };
 
-  this.toggle_editor = function(checkbox, textAreaId)
+  this.toggle_editor = function(ishtml, textAreaId, flagElement)
     {
-    var ischecked = checkbox.checked;
     var composeElement = document.getElementById(textAreaId);
-    
-    if (ischecked)
+    var flag;
+
+    if (ishtml)
       {
       var existingPlainText = composeElement.value;
       var htmlText = "<pre>" + existingPlainText + "</pre>";
+
+      this.display_spellcheck_controls(false);
       composeElement.value = htmlText;
       tinyMCE.execCommand('mceAddControl', true, textAreaId);
+      if (flagElement && (flag = rcube_find_object(flagElement)))
+        flag.value = '1';
       }
     else
       {
+      if (!confirm(rcmail.get_label('editorwarning')))
+        return false;
+
       var thisMCE = tinyMCE.get(textAreaId);
       var existingHtml = thisMCE.getContent();
       this.html2plain(existingHtml, textAreaId);
       tinyMCE.execCommand('mceRemoveControl', true, textAreaId);
+      this.display_spellcheck_controls(true);
+      if (flagElement && (flag = rcube_find_object(flagElement)))
+        flag.value = '0';
       }
     };
 
diff --git a/program/js/editor.js b/program/js/editor.js
index a9aec62..179d089 100644
--- a/program/js/editor.js
+++ b/program/js/editor.js
@@ -38,40 +38,3 @@
     rc_client: rcube_webmail_client
   });
 }
-
-// Toggle between the HTML and Plain Text editors
-
-function rcmail_toggle_editor(toggler)
-  {
-  var selectedEditor = toggler.value;
-
-  // determine the currently displayed editor
-  var htmlFlag = document.getElementsByName('_is_html')[0];
-  var isHtml = htmlFlag.value;
-
-  if (((selectedEditor == 'plain') && (isHtml == "0")) ||
-      ((selectedEditor == 'html') && (isHtml == "1")))
-    {
-    return;
-    }
-
-  // do the appropriate conversion
-  if (selectedEditor == 'html')
-    {
-    rcmail.display_spellcheck_controls(false);
-    var composeElement = document.getElementById('compose-body');
-    var htmlText = "<pre>" + composeElement.value + "</pre>";
-    composeElement.value = htmlText;
-    tinyMCE.execCommand('mceAddControl', true, 'compose-body');
-    htmlFlag.value = "1";
-    }
-  else
-    {
-    var thisMCE = tinyMCE.get('compose-body');
-    var existingHtml = thisMCE.getContent();
-    rcmail.html2plain(existingHtml, 'compose-body');
-    tinyMCE.execCommand('mceRemoveControl', true, 'compose-body');
-    htmlFlag.value = "0";
-    rcmail.display_spellcheck_controls(true);
-    }
-  }
diff --git a/program/localization/en_US/messages.inc b/program/localization/en_US/messages.inc
index 568decc..2eea16e 100644
--- a/program/localization/en_US/messages.inc
+++ b/program/localization/en_US/messages.inc
@@ -93,5 +93,6 @@
 $messages['importconfirm'] = '<b>Successfully imported $inserted contacts, $skipped existing entries skipped</b>:<p><em>$names</em></p>';
 $messages['opnotpermitted'] = 'Operation not permitted!';
 $messages['nofromaddress'] = 'Missing e-mail address in selected identity';
+$messages['editorwarning'] = 'All text formatting will be lost after editor change. Are you sure, you want to do that?';
 
 ?>
diff --git a/program/localization/pl_PL/messages.inc b/program/localization/pl_PL/messages.inc
index 7918b8a..74127e2 100644
--- a/program/localization/pl_PL/messages.inc
+++ b/program/localization/pl_PL/messages.inc
@@ -98,5 +98,6 @@
 $messages['importconfirm'] = '<b>Pomyślnie dodano $inserted kontaktów, pominięto $skipped istniejących wpisów</b>:<p><em>$names</em></p>'; 
 $messages['opnotpermitted'] = 'Niedozwolona operacja!';
 $messages['nofromaddress'] = 'Brak adresu e-mail w wybranej tożsamości';
+$messages['editorwarning'] = 'Zmiana edytora spowoduje utratę formatowania tekstu. Czy jesteś pewien, że chcesz to zrobić?';
 
 ?>
diff --git a/program/steps/mail/compose.inc b/program/steps/mail/compose.inc
index df6f1ff..758069a 100644
--- a/program/steps/mail/compose.inc
+++ b/program/steps/mail/compose.inc
@@ -81,7 +81,9 @@
 }
 
 // add some labels to client
-$OUTPUT->add_label('nosubject', 'nosenderwarning', 'norecipientwarning', 'nosubjectwarning', 'nobodywarning', 'notsentwarning', 'savingmessage', 'sendingmessage', 'messagesaved', 'converting');
+$OUTPUT->add_label('nosubject', 'nosenderwarning', 'norecipientwarning', 'nosubjectwarning',
+    'nobodywarning', 'notsentwarning', 'savingmessage', 'sendingmessage', 'messagesaved',
+    'converting', 'editorwarning');
 
 // add config parameters to client script
 if (!empty($CONFIG['drafts_mbox'])) {
@@ -848,9 +850,13 @@
   if ($compose_mode)
     $useHtml = ($useHtml && $MESSAGE->has_html_part());
 
+  $editorid = empty($attrib['editorid']) ? 'rcmComposeMessage' : $attrib['editorid'];
+
   $selector = '';
   $chosenvalue = $useHtml ? 'html' : 'plain';
-  $radio = new html_radiobutton(array('name' => '_editorSelect', 'onclick' => 'return rcmail_toggle_editor(this)'));
+  $radio = new html_radiobutton(array('name' => '_editorSelect',
+    'onclick' => "return rcmail.toggle_editor(this.value=='html', '$editorid', '_is_html')"));
+
   foreach ($choices as $value => $text)
   {
     $attrib['id'] = '_' . $value;
diff --git a/program/steps/settings/edit_identity.inc b/program/steps/settings/edit_identity.inc
index c8d448a..e4bb50f 100644
--- a/program/steps/settings/edit_identity.inc
+++ b/program/steps/settings/edit_identity.inc
@@ -72,7 +72,7 @@
 				    "gecko_spellcheck : true });");
 
   // add some labels to client
-  $OUTPUT->add_label('noemailwarning', 'nonamewarning', 'converting');
+  $OUTPUT->add_label('noemailwarning', 'nonamewarning', 'converting', 'editorwarning');
 
   $i_size = !empty($attrib['size']) ? $attrib['size'] : 40;
   $t_rows = !empty($attrib['textarearows']) ? $attrib['textarearows'] : 6;
@@ -89,7 +89,7 @@
                        'reply-to'     => array('type' => 'text', 'label' => 'reply-to', 'size' => $i_size),
                        'bcc'          => array('type' => 'text', 'size' => $i_size),
                        'signature'	  => array('type' => 'textarea', 'size' => $t_cols, 'rows' => $t_rows),
-                       'html_signature'=>array('type' => 'checkbox', 'label' => 'htmlsignature', 'onclick' => 'return rcmail.toggle_editor(this, \'rcmfd_signature\');'),
+                       'html_signature'=>array('type' => 'checkbox', 'label' => 'htmlsignature', 'onclick' => 'return rcmail.toggle_editor(this.checked, \'rcmfd_signature\');'),
                        'standard'     => array('type' => 'checkbox', 'label' => 'setdefault'));
 
   // disable some field according to access level
diff --git a/skins/default/templates/compose.html b/skins/default/templates/compose.html
index beabe98..aa45ef0 100644
--- a/skins/default/templates/compose.html
+++ b/skins/default/templates/compose.html
@@ -80,7 +80,7 @@
 		</td>
 		<td style="text-align:right; white-space:nowrap">
 		    <roundcube:label name="editortype" />:&nbsp;
-		    <span class="radios-left"><roundcube:object name="editorSelector" tabindex="10" /></span>
+		    <span class="radios-left"><roundcube:object name="editorSelector" editorid="compose-body" tabindex="10" /></span>
 		</td>
 	    </tr>
 	</tbody></table>

--
Gitblit v1.9.1