Skip to content
Snippets Groups Projects
Commit d3d65585 authored by Peter Rotich's avatar Peter Rotich
Browse files

Merge pull request #609 from greezybacon/feature/display-signature


Show selected signature in the rich text editor

Reviewed-By: default avatarPeter Rotich <peter@osticket.com>
parents 705a611c e608ff53
No related branches found
No related tags found
No related merge requests found
......@@ -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;
}
}
}
?>
......@@ -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>
......
......@@ -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"
......
......@@ -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,
......
......@@ -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')
......
......@@ -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;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment