diff --git a/include/ajax.draft.php b/include/ajax.draft.php index c50817dac4598a0a4c4ce42b6585f4af61cd5566..ab68700d4c4be6d8f481c444f3cadc795103023e 100644 --- a/include/ajax.draft.php +++ b/include/ajax.draft.php @@ -17,7 +17,7 @@ class DraftAjaxAPI extends AjaxController { } } } - if (!isset($vars['body']) || !$vars['body']) + if (!isset($vars['body'])) return JsonDataEncoder::encode(array( 'error' => __("Draft body not found in request"), 'code' => 422, @@ -228,7 +228,7 @@ class DraftAjaxAPI extends AjaxController { ); if (isset($_POST['name'])) - $vars['body'] = $_POST[$_POST['name']]; + $vars['body'] = urldecode($_POST[$_POST['name']]); return self::_createDraft($vars); } diff --git a/include/class.draft.php b/include/class.draft.php index d8bbbcd3076a95652710c7fc348028f6d1f4b321..d71b89e57a22d5c1695adc7346788797e7e67056 100644 --- a/include/class.draft.php +++ b/include/class.draft.php @@ -48,9 +48,11 @@ class Draft extends VerySimpleModel { $attrs[] = sprintf('data-draft-id="%s"', $draft->getId()); $draft_body = $draft->getBody(); } - $attrs[] = sprintf('data-draft-original="%s"', Format::htmlchars($original)); + $attrs[] = sprintf('data-draft-original="%s"', + Format::htmlchars(Format::viewableImages($original))); - return array($draft_body, implode(' ', $attrs)); + return array(Format::htmlchars(Format::viewableImages($draft_body)), + implode(' ', $attrs)); } function getAttachmentIds($body=false) { @@ -105,7 +107,7 @@ class Draft extends VerySimpleModel { function isValid() { // Required fields - return $this->namespace && isset($this->body) && isset($this->staff_id); + return $this->namespace && isset($this->staff_id); } function save($refetch=false) { diff --git a/include/class.forms.php b/include/class.forms.php index fc1519a66c8f9673ab975a5b7de876ed490b8568..73afeaa0eca493abcfe50d8d415af01bbd03f89d 100644 --- a/include/class.forms.php +++ b/include/class.forms.php @@ -2032,7 +2032,7 @@ class ThreadEntryWidget extends Widget { class="<?php if ($cfg->isHtmlThreadEnabled()) echo 'richtext'; ?> draft draft-delete" <?php echo $attrs; ?> cols="21" rows="8" style="width:80%;"><?php echo - Format::htmlchars($draft ?: $this->value); ?></textarea> + $draft ?: Format::htmlchars($this->value); ?></textarea> <?php $config = $this->field->getConfiguration(); if (!$config['attachments']) diff --git a/js/redactor-osticket.js b/js/redactor-osticket.js index 9bd0e57d7f844ce3b643b6c85d8a88191effb37a..33b27ef38e9896d5e5aa8606b58e4e343e6348fc 100644 --- a/js/redactor-osticket.js +++ b/js/redactor-osticket.js @@ -25,13 +25,18 @@ RedactorPlugins.draft = { this.opts.autosaveInterval = 10; this.opts.autosaveCallback = this.afterUpdateDraft; this.opts.autosaveErrorCallback = this.autosaveFailed; + this.opts.imageUploadErrorCallback = this.displayError; if (this.opts.draftId) { this.opts.autosave = 'ajax.php/draft/'+this.opts.draftId; this.opts.clipboardUploadUrl = this.opts.imageUpload = 'ajax.php/draft/'+this.opts.draftId+'/attach'; } - this.opts.imageUploadErrorCallback = this.displayError; + else { + // Autosave quickly to and setup image upload in the + // afterUpdateDraft callback + this.opts.autosaveInterval = 1; + } this.$draft_saved = $('<span>') .addClass("pull-right draft-saved") @@ -65,11 +70,18 @@ RedactorPlugins.draft = { if (data.draft_id) { this.opts.draftId = data.draft_id; this.opts.autosave = 'ajax.php/draft/' + data.draft_id; + this.opts.clipboardUploadUrl = + this.opts.imageUpload = + 'ajax.php/draft/'+this.opts.draftId+'/attach'; + if (this.opts.autosaveInterval < 10) { + clearInterval(this.autosaveInterval); + this.opts.autosaveInterval = 10; + this.autosave(); + } } - // Only show the [Draft Saved] notice if there is content in the // field that has been touched - if (this.opts.draftOriginal && this.opts.draftOriginal == this.get()) { + if (!this.opts.draftOriginal || this.opts.draftOriginal == this.get()) { // No change yet — dont't show the button return; } @@ -108,7 +120,7 @@ RedactorPlugins.draft = { type: 'delete', async: false, success: function() { - self.draft_id = undefined; + self.draft_id = this.opts.draftId = undefined; self.hideDraftSaved(); self.set(self.opts.draftOriginal || '', false, false); self.opts.autosave = self.opts.autoCreateUrl;