From 3af4750eaf91ffaa56a5f133ce44897a1f678c04 Mon Sep 17 00:00:00 2001 From: Jared Hancock <jared@osticket.com> Date: Fri, 17 Jul 2015 08:26:04 -0500 Subject: [PATCH] redactor: Hide image button if upload not supported --- include/ajax.draft.php | 14 +++++++------- js/redactor-osticket.js | 43 ++++++++++++++++++++++------------------- 2 files changed, 30 insertions(+), 27 deletions(-) diff --git a/include/ajax.draft.php b/include/ajax.draft.php index 9fa61635d..1b7b30d5a 100644 --- a/include/ajax.draft.php +++ b/include/ajax.draft.php @@ -344,16 +344,16 @@ class DraftAjaxAPI extends AjaxController { && ($object = $thread->getObject()) && ($thisstaff->canAccess($object)) ) { - $union = ' UNION SELECT f.id, a.`type` FROM '.THREAD_TABLE.' t + $union = ' UNION SELECT f.id, a.`type`, a.`name` FROM '.THREAD_TABLE.' t JOIN '.THREAD_ENTRY_TABLE.' th ON (th.thread_id = t.id) JOIN '.ATTACHMENT_TABLE.' a ON (a.object_id = th.id AND a.`type` = \'H\') JOIN '.FILE_TABLE.' f ON (a.file_id = f.id) - WHERE t.id='.db_input($_GET['threadId']); + WHERE a.`inline` = 1 AND t.id='.db_input($_GET['threadId']); } - $sql = 'SELECT distinct f.id, COALESCE(a.type, f.ft) FROM '.FILE_TABLE + $sql = 'SELECT distinct f.id, COALESCE(a.type, f.ft), a.`name` FROM '.FILE_TABLE .' f LEFT JOIN '.ATTACHMENT_TABLE.' a ON (a.file_id = f.id) - WHERE (a.`type` IN (\'C\', \'F\', \'T\', \'P\') OR f.ft = \'L\')' + WHERE ((a.`type` IN (\'C\', \'F\', \'T\', \'P\') AND a.`inline` = 1) OR f.ft = \'L\')' .' AND f.`type` LIKE \'image/%\''; if (!($res = db_query($sql.$union))) Http::response(500, 'Unable to lookup files'); @@ -367,15 +367,15 @@ class DraftAjaxAPI extends AjaxController { 'P' => __('Pages'), 'H' => __('This Thread'), ); - while (list($id, $type) = db_fetch_row($res)) { - $f = AttachmentFile::lookup($id); + while (list($id, $type, $name) = db_fetch_row($res)) { + $f = AttachmentFile::lookup((int) $id); $url = $f->getDownloadUrl(); $files[] = array( // Don't send special sizing for thread items 'cause they // should be cached already by the client 'thumb'=>$url.($type != 'H' ? '&s=128' : ''), 'image'=>$url, - 'title'=>$f->getName(), + 'title'=>$name ?: $f->getName(), 'folder'=>$folders[$type] ); } diff --git a/js/redactor-osticket.js b/js/redactor-osticket.js index c39352812..8c3a8d806 100644 --- a/js/redactor-osticket.js +++ b/js/redactor-osticket.js @@ -33,7 +33,7 @@ RedactorPlugins.draft = function() { this.opts.imageUpload = 'ajax.php/draft/'+this.opts.draftId+'/attach'; } - else { + else if (this.$textarea.hasClass('draft')) { // Just upload the file. A draft will be created automatically // and will be configured locally in the afterUpateDraft() this.opts.clipboardUploadUrl = @@ -43,23 +43,26 @@ RedactorPlugins.draft = function() { if (autosave_url) this.autosave.enable(); - this.$draft_saved = $('<span>') - .addClass("pull-right draft-saved") - .hide() - .append($('<span>') - .text(__('Draft Saved'))); - // Float the [Draft Saved] box with the toolbar - this.$toolbar.append(this.$draft_saved); - // Add [Delete Draft] button to the toolbar - if (this.opts.draftDelete) { - var trash = this.draft.deleteButton = - this.button.add('deleteDraft', __('Delete Draft')) - this.button.addCallback(trash, this.draft.deleteDraft); - this.button.setAwesome('deleteDraft', 'icon-trash'); - trash.parent().addClass('pull-right'); - trash.addClass('delete-draft'); - if (!this.opts.draftId) - trash.hide(); + if (this.$textarea.hasClass('draft')) { + this.$draft_saved = $('<span>') + .addClass("pull-right draft-saved") + .hide() + .append($('<span>') + .text(__('Draft Saved'))); + // Float the [Draft Saved] box with the toolbar + this.$toolbar.append(this.$draft_saved); + + // Add [Delete Draft] button to the toolbar + if (this.opts.draftDelete) { + var trash = this.draft.deleteButton = + this.button.add('deleteDraft', __('Delete Draft')) + this.button.addCallback(trash, this.draft.deleteDraft); + this.button.setAwesome('deleteDraft', 'icon-trash'); + trash.parent().addClass('pull-right'); + trash.addClass('delete-draft'); + if (!this.opts.draftId) + trash.hide(); + } } if (this.code.get()) this.$box.trigger('draft:recovered'); @@ -247,7 +250,7 @@ $(function() { var options = $.extend({ 'air': el.hasClass('no-bar'), 'buttons': el.hasClass('no-bar') - ? ['formatting', '|', 'bold', 'italic', 'underline', 'deleted', '|', 'unorderedlist', 'orderedlist', 'outdent', 'indent', '|', 'image'] + ? ['formatting', '|', 'bold', 'italic', 'underline', 'deleted', '|', 'unorderedlist', 'orderedlist', 'outdent', 'indent', '|', 'link', 'image'] : ['html', '|', 'formatting', '|', 'bold', 'italic', 'underline', 'deleted', '|', 'unorderedlist', 'orderedlist', 'outdent', 'indent', '|', 'image', 'video', @@ -261,7 +264,7 @@ $(function() { 'plugins': el.hasClass('no-bar') ? ['imagemanager','definedlinks'] : ['imagemanager','imageannotate','table','video','definedlinks','autolock'], - 'imageUpload': 'tbd', + 'imageUpload': el.hasClass('draft'), 'imageManagerJson': 'ajax.php/draft/images/browse', 'syncBeforeCallback': captureImageSizes, 'linebreaks': true, -- GitLab