Request #6892: If using spellcheck on send, automatically send if no spelling errors...
authorMichael M Slusarz <slusarz@curecanti.org>
Mon, 30 Mar 2009 23:11:40 +0000 (17:11 -0600)
committerMichael M Slusarz <slusarz@curecanti.org>
Mon, 30 Mar 2009 23:12:52 +0000 (17:12 -0600)
imp/docs/CHANGES
imp/js/src/SpellChecker.js
imp/js/src/compose.js

index 61a6883..bb6857e 100644 (file)
@@ -66,6 +66,8 @@ v4.3.4-cvs
 
 [mms] SECURITY: Don't cache local PGP public keys retrieved from the
       addressbook (found by Peter Meier <peter.meier@immerda.ch>).
+[mms] If using spellcheck on send, automatically send if no spelling errors
+      exist (Request #6892).
 [jan] Show all addresses when printing messages.
 [mms] Fix cache issues in folder tree when deleting a mailbox (Bug #7745).
 [mms] Fix updating POP3 indices when deleting in mailbox view (Bug #8035).
index 1413e95..e21d908 100644 (file)
  */
 
 var SpellChecker = Class.create({
+
     // Vars used and defaulting to null:
     //   bad, choices, choicesDiv, curWord, htmlArea, htmlAreaParent, locale,
-    //   localeChoices, onAfterSpellCheck, onBeforeSpellCheck, reviewDiv,
-    //   statusButton, statusClass, suggestions, target, url
+    //   localeChoices, onAfterSpellCheck, onBeforeSpellCheck, onNoError,
+    //   reviewDiv, statusButton, statusClass, suggestions, target, url
     options: {},
     resumeOnDblClick: true,
     state: 'CheckSpelling',
@@ -94,7 +95,10 @@ var SpellChecker = Class.create({
         e.stop();
     },
 
-    spellCheck: function()
+    // noerror - (function) A callback function to run if no errors are
+    //           identified. If not specified, will remain in spell check
+    //           mode even if no errors are present.
+    spellCheck: function(noerror)
     {
         if (this.onBeforeSpellCheck) {
             this.onBeforeSpellCheck();
@@ -107,6 +111,8 @@ var SpellChecker = Class.create({
         this.status('Checking');
         this.removeChoices();
 
+        this.onNoError = noerror;
+
         p.set(this.target, this.targetValue());
         opts.parameters = p.toQueryString();
 
@@ -160,14 +166,20 @@ var SpellChecker = Class.create({
         this.removeChoices();
 
         if (Object.isUndefined(result)) {
-            this.resume();
             this.status('Error');
             return;
         }
 
-        bad = result.bad || [];
         this.suggestions = result.suggestions || [];
 
+        if (this.onNoError && !this.suggestions.size()) {
+            this.status('CheckSpelling');
+            this.onNoError();
+            return;
+        }
+
+        bad = result.bad || [];
+
         content = this.targetValue();
         if (this.htmlAreaParent) {
             content = content.replace(/\r?\n/g, '');
index 4195450..6fbb430 100644 (file)
@@ -8,7 +8,7 @@
 var ImpCompose = {
     /* Variables defined in compose.php:
      *   cancel_url, spellcheck, cursor_pos, identities, max_attachments,
-     *   popup, redirect, reloaded, rtemode, smf_check */
+     *   popup, redirect, reloaded, rtemode, smf_check, skip_spellcheck */
     display_unload_warning: true,
     textarea_ready: true,
 
@@ -172,14 +172,18 @@ var ImpCompose = {
                 return;
             }
 
-            if (this.spellcheck &&
+            if (!this.skip_spellcheck &&
+                this.spellcheck &&
                 IMP.SpellCheckerObject &&
                 !IMP.SpellCheckerObject.isActive()) {
-                IMP.SpellCheckerObject.spellCheck();
+                IMP.SpellCheckerObject.spellCheck(this.onNoSpellError.bind(this, actionID, e));
                 return;
             }
+
         }
 
+        this.skip_spellcheck = false;
+
         if (IMP.SpellCheckerObject) {
             IMP.SpellCheckerObject.resume();
         }
@@ -203,6 +207,12 @@ var ImpCompose = {
         }
     },
 
+    onNoSpellError: function(actionID, e)
+    {
+        this.skip_spellcheck = true;
+        this.uniqSubmit(actionID, e);
+    },
+
     attachmentChanged: function()
     {
         var fields = [],