From 392d642927788042811bb3f83f222333528c5a8c Mon Sep 17 00:00:00 2001
From: Jared Hancock <jared@osticket.com>
Date: Wed, 13 Aug 2014 14:40:29 -0500
Subject: [PATCH] draft: Fix creation of client drafts

---
 include/ajax.draft.php  | 9 +++++----
 js/redactor-osticket.js | 3 ++-
 2 files changed, 7 insertions(+), 5 deletions(-)

diff --git a/include/ajax.draft.php b/include/ajax.draft.php
index 3b8fba5b5..6743b3280 100644
--- a/include/ajax.draft.php
+++ b/include/ajax.draft.php
@@ -7,7 +7,7 @@ require_once(INCLUDE_DIR.'class.draft.php');
 class DraftAjaxAPI extends AjaxController {
 
     function _createDraft($vars) {
-        if (!($vars['body'] = self::_findDraftBody($_POST)))
+        if (false === ($vars['body'] = self::_findDraftBody($_POST)))
             return JsonDataEncoder::encode(array(
                 'error' => __("Draft body not found in request"),
                 'code' => 422,
@@ -34,7 +34,7 @@ class DraftAjaxAPI extends AjaxController {
     }
 
     function _updateDraft($draft) {
-        if (!($body = self::_findDraftBody($_POST)))
+        if (false === ($body = self::_findDraftBody($_POST)))
             return JsonDataEncoder::encode(array(
                 'error' => array(
                     'message' => "Draft body not found in request",
@@ -127,8 +127,7 @@ class DraftAjaxAPI extends AjaxController {
             'namespace' => $namespace,
         );
 
-        $info = self::_createDraft($vars);
-        $info['draft_id'] = $namespace;
+        return self::_createDraft($vars);
     }
 
     function getDraftClient($namespace) {
@@ -320,6 +319,8 @@ class DraftAjaxAPI extends AjaxController {
                 return urldecode($vars[$field]);
             }
         }
+
+        return false;
     }
 
 }
diff --git a/js/redactor-osticket.js b/js/redactor-osticket.js
index ba85e301f..07f9eaaaf 100644
--- a/js/redactor-osticket.js
+++ b/js/redactor-osticket.js
@@ -86,7 +86,7 @@ RedactorPlugins.draft = {
             // No change yet — dont't show the button
             return;
         }
-        if (data) {
+        if (data && this.get()) {
             this.$draft_saved.show().delay(5000).fadeOut();
         }
         // Show the button if there is a draft to delete
@@ -126,6 +126,7 @@ RedactorPlugins.draft = {
                 self.set(self.opts.draftOriginal || '', false, false);
                 self.opts.autosave = self.opts.autoCreateUrl;
                 self.draftDeleteButton.hide();
+                self.firstSave = false;
             }
         });
     }
-- 
GitLab