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-open.inc.php b/include/staff/ticket-open.inc.php index ea3c0d64b30014271d41384ba1247b6a60ea6447..b472f46764306fbe7cac85779f62c485b858e75e 100644 --- a/include/staff/ticket-open.inc.php +++ b/include/staff/ticket-open.inc.php @@ -270,9 +270,15 @@ $info=Format::htmlchars(($errors && $_POST)?$_POST:$info); <label><input type='checkbox' value='1' name="append" id="append" checked="checked">Append</label> </div> <?php - } ?> + } + $signature = ''; + if ($thisstaff->getDefaultSignatureType() == 'mine') + $signature = $thisstaff->getSignature(); ?> <textarea class="richtext ifhtml draft draft-delete" data-draft-namespace="ticket.staff.response" + data-signature="<?php + echo Format::htmlchars(Format::viewableImages($signature)); ?>" + data-signature-field="signature" data-dept-field="deptId" placeholder="Intial response for the ticket" name="response" id="response" cols="21" rows="8" style="width:80%;"><?php echo $info['response']; ?></textarea> diff --git a/include/staff/ticket-view.inc.php b/include/staff/ticket-view.inc.php index 1a17a054e22affa832c919d507d89e24a13987af..9568dbf656c5513a28980f101ee35089368643f3 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..80500a2a32b6717f37230715c9a0e6763ff1fc98 100644 --- a/js/redactor-osticket.js +++ b/js/redactor-osticket.js @@ -119,6 +119,46 @@ RedactorPlugins.draft = { } }; +RedactorPlugins.signature = { + init: function() { + var $el = $(this.$element.get(0)); + if ($el.data('signatureField')) { + this.$signatureBox = $('<div class="redactor_editor selected-signature"></div>') + .html($el.data('signature')) + .appendTo(this.$box); + $('input[name='+$el.data('signatureField')+']', $el.closest('form')) + .on('change', false, false, $.proxy(this.updateSignature, this)) + if ($el.data('deptField')) + $(':input[name='+$el.data('deptField')+']', $el.closest('form')) + .on('change', false, false, $.proxy(this.updateSignature, this)) + } + }, + updateSignature: function(e) { + var $el = $(this.$element.get(0)); + selected = e.target, + type = $(selected).val(), + dept = $(':input[name='+$el.data('deptField')+']', $el.closest('form')).val(), + url = 'ajax.php/content/signature/'; + e.preventDefault && e.preventDefault(); + if (type == 'dept' && $el.data('deptId')) + url += 'dept/' + $el.data('deptId'); + else if ((type == 'dept' || (type % 1 === 0)) && $el.data('deptField')) { + if (type && type % 1 === 0) + url += 'dept/' + type + else if (type == 'dept' && dept) + url += 'dept/' + dept + else + return this.$signatureBox.empty().hide(); + } + else if (type == 'none') + return this.$signatureBox.empty().hide(); + else + url += type + + this.$signatureBox.load(url).show(); + } +}; + /* Redactor richtext init */ $(function() { var captureImageSizes = function(html) { @@ -150,7 +190,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; +}