From f0bf96edef27319b7be646e6b3282f1207bfaee8 Mon Sep 17 00:00:00 2001
From: Jared Hancock <jared@osticket.com>
Date: Wed, 29 Jul 2015 11:25:36 -0500
Subject: [PATCH] redactor: Fixup trashing of draft saving

---
 js/redactor-osticket.js | 21 +++++++++++++++------
 1 file changed, 15 insertions(+), 6 deletions(-)

diff --git a/js/redactor-osticket.js b/js/redactor-osticket.js
index 1463093cf..8754c6371 100644
--- a/js/redactor-osticket.js
+++ b/js/redactor-osticket.js
@@ -40,6 +40,14 @@ RedactorPlugins.draft = function() {
             this.opts.imageUpload = this.opts.autoCreateUrl + '/attach';
             this.opts.imageUploadCallback = this.afterUpdateDraft;
         }
+
+        // FIXME: Monkey patch Redactor's autosave enable method to disable first
+        var oldAse = this.autosave.enable;
+        this.autosave.enable = function() {
+            this.autosave.disable();
+            oldAse.call(this);
+        }.bind(this);
+
         if (autosave_url)
             this.autosave.enable();
 
@@ -99,15 +107,16 @@ RedactorPlugins.draft = function() {
             // Unprocessable request (Empty message)
             return;
 
-        this.displayError(error);
+        this.draft.displayError(error);
         // Cancel autosave
-        clearInterval(this.autosaveInterval);
+        this.autosave.disable();
         this.hideDraftSaved();
         this.$box.trigger('draft:failed');
     },
 
     displayError: function(json) {
-        alert(json.error);
+        $.sysAlert(json.error,
+            __('Unable to save draft. Refresh the current page to restore and continue your draft.'));
     },
 
     hideDraftSaved: function() {
@@ -360,11 +369,11 @@ $(document).ajaxError(function(event, request, settings) {
         $('.richtext').each(function() {
             var redactor = $(this).data('redactor');
             if (redactor) {
+                redactor.autosave.disable();
                 clearInterval(redactor.autosaveInterval);
             }
         });
-        $('#overlay').show();
-        alert(__('Unable to save draft. Refresh the current page to restore and continue your draft.'));
-        $('#overlay').hide();
+        $.sysAlert(__('Unable to save draft.'),
+            __('Refresh the current page to restore and continue your draft.'));
     }
 });
-- 
GitLab