diff --git a/include/ajax.content.php b/include/ajax.content.php index d4846823987fa3ac66f289cb1ff3dc57cb420310..acc238c34e828c414d3be133c836bb82d3f311b7 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 7449197a12b02c09961373d12703935d3d53d16b..b1c5bc978fab79cdfa02e5efcf234cc06530b56c 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 09629a041ad1e60d9a4f5988210aa56564aea6c2..fc84b1a16b079e875d7434027f0fced738276868 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 766e173e3550e00af002baffe47f4d9c445f4168..5bc266064fda0a468c766d093371efffa411d3c5 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 81c0e176375bed89111cf0c39dc9db5752c71be0..a3dca364f9a547ba4be98ea2d86f9e39a8ab1063 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; +}