From 443ede10e35923e8c4fe22b94847804a31991291 Mon Sep 17 00:00:00 2001 From: Jared Hancock <jared@osticket.com> Date: Tue, 25 Feb 2014 14:52:15 -0600 Subject: [PATCH] Show selected signature in the rich text editor --- include/ajax.content.php | 23 +++++++++++++++++++++++ include/staff/ticket-view.inc.php | 15 ++++++++++++++- js/redactor-osticket.js | 29 ++++++++++++++++++++++++++++- scp/ajax.php | 3 ++- scp/css/scp.css | 11 +++++++++++ 5 files changed, 78 insertions(+), 3 deletions(-) diff --git a/include/ajax.content.php b/include/ajax.content.php index d48468239..acc238c34 100644 --- a/include/ajax.content.php +++ b/include/ajax.content.php @@ -102,5 +102,28 @@ class ContentAjaxAPI extends AjaxController { return $content; } + + function getSignature($type, $id) { + global $thisstaff; + + if (!$thisstaff) + Http::response(403, 'Login Required'); + + switch ($type) { + case 'none': + break; + case 'mine': + echo Format::viewableImages($thisstaff->getSignature()); + break; + case 'dept': + if (!($dept = Dept::lookup($id))) + Http::response(404, 'No such department'); + echo Format::viewableImages($dept->getSignature()); + break; + default: + Http::response(400, 'Unknown signature type'); + break; + } + } } ?> diff --git a/include/staff/ticket-view.inc.php b/include/staff/ticket-view.inc.php index 7449197a1..b1c5bc978 100644 --- a/include/staff/ticket-view.inc.php +++ b/include/staff/ticket-view.inc.php @@ -494,10 +494,23 @@ $tcount+= $ticket->getNumNotes(); <label><input type='checkbox' value='1' name="append" id="append" checked="checked"> Append</label> <br> <?php - }?> + } + $signature = ''; + switch ($thisstaff->getDefaultSignatureType()) { + case 'dept': + if ($dept && $dept->canAppendSignature()) + $signature = $dept->getSignature(); + break; + case 'mine': + $signature = $thisstaff->getSignature(); + break; + } ?> <input type="hidden" name="draft_id" value=""/> <textarea name="response" id="response" cols="50" data-draft-namespace="ticket.response" + data-signature-field="signature" data-dept-id="<?php echo $dept->getId(); ?>" + data-signature="<?php + echo Format::htmlchars(Format::viewableImages($signature)); ?>" placeholder="Start writing your response here. Use canned responses from the drop-down above" data-draft-object-id="<?php echo $ticket->getId(); ?>" rows="9" wrap="soft" diff --git a/js/redactor-osticket.js b/js/redactor-osticket.js index 09629a041..fc84b1a16 100644 --- a/js/redactor-osticket.js +++ b/js/redactor-osticket.js @@ -119,6 +119,33 @@ RedactorPlugins.draft = { } }; +RedactorPlugins.signature = { + init: function() { + var $el = $(this.$element.get(0)); + if ($el.data('signatureField')) { + var $sig = $('input[name='+$el.data('signatureField')+']', $el.closest('form')) + .on('change', false, false, $.proxy(this.updateSignature, this)), + sel = $('input:checked[name='+$el.data('signatureField')+']', $el.closest('form')); + this.$signatureBox = $('<div class="redactor_editor selected-signature"></div>') + .html($el.data('signature')) + .appendTo(this.$box); + } + }, + updateSignature: function(e) { + var $el = $(this.$element.get(0)); + selected = e.target, + type = $(selected).val(), + url = 'ajax.php/content/signature/' + type; + e.preventDefault && e.preventDefault(); + if (type == 'dept' && $el.data('deptId')) + url += '/' + $el.data('deptId'); + else if (type == 'none') + return this.$signatureBox.empty().hide(); + + this.$signatureBox.load(url).show(); + } +}; + /* Redactor richtext init */ $(function() { var captureImageSizes = function(html) { @@ -150,7 +177,7 @@ $(function() { 'autoresize': !el.hasClass('no-bar'), 'minHeight': el.hasClass('small') ? 75 : 150, 'focus': false, - 'plugins': ['fontcolor','fontfamily'], + 'plugins': ['fontcolor','fontfamily', 'signature'], 'imageGetJson': 'ajax.php/draft/images/browse', 'syncBeforeCallback': captureImageSizes, 'linebreaks': true, diff --git a/scp/ajax.php b/scp/ajax.php index 766e173e3..5bc266064 100644 --- a/scp/ajax.php +++ b/scp/ajax.php @@ -41,7 +41,8 @@ $dispatcher = patterns('', )), url('^/content/', patterns('ajax.content.php:ContentAjaxAPI', url_get('^log/(?P<id>\d+)', 'log'), - url_get('^ticket_variables', 'ticket_variables') + url_get('^ticket_variables', 'ticket_variables'), + url_get('^signature/(?P<type>\w+)(?:/(?P<id>\d+))?$', 'getSignature') )), url('^/config/', patterns('ajax.config.php:ConfigAjaxAPI', url_get('^scp', 'scp') diff --git a/scp/css/scp.css b/scp/css/scp.css index 81c0e1763..a3dca364f 100644 --- a/scp/css/scp.css +++ b/scp/css/scp.css @@ -1534,3 +1534,14 @@ div.patch { .patch-title { color: #555; } + +div.redactor_editor.selected-signature { + opacity: 0.5; + border-top: 1px dotted #aaa; + padding-top: 0.1em !important; + background-color: #f9f9f9 !important; +} +.selected-signature:empty { + border-top: none; + display: none; +} -- GitLab