From 256fecd1819c42646126ebdd9d4d95c372069127 Mon Sep 17 00:00:00 2001 From: Jared Hancock <jared@osticket.com> Date: Mon, 24 Aug 2015 10:42:31 -0500 Subject: [PATCH] tickets: Fix subject display for non text fields If the subject field is something crazy, such as an HTML field, ensure that the layout of the ticket queue is preserved and properly truncated. Furthermore, ensure that the HTML is properly rendered on the client and staff ticket view pages. --- assets/default/css/theme.css | 5 ++-- include/client/tickets.inc.php | 2 +- include/client/view.inc.php | 40 ++++++++++++++++++------------- include/staff/ticket-view.inc.php | 3 ++- include/staff/tickets.inc.php | 10 ++++---- js/osticket.js | 8 +++++++ scp/css/scp.css | 5 ++-- scp/js/scp.js | 8 +++++++ 8 files changed, 54 insertions(+), 27 deletions(-) diff --git a/assets/default/css/theme.css b/assets/default/css/theme.css index 4b880e8c3..33f8d83d2 100644 --- a/assets/default/css/theme.css +++ b/assets/default/css/theme.css @@ -115,15 +115,16 @@ fieldset { padding: 0; } /* Typography */ -a { +a, .link { color: #0072bc; text-decoration: none; display: inline-block; margin-bottom: 1px; } -a:hover { +a:hover, .link:hover { border-bottom: 1px dotted #0072bc; margin-bottom: 0; + cursor: pointer; } h1 { color: #00AEEF; diff --git a/include/client/tickets.inc.php b/include/client/tickets.inc.php index dfc7673e0..4109b822c 100644 --- a/include/client/tickets.inc.php +++ b/include/client/tickets.inc.php @@ -225,7 +225,7 @@ if ($closedTickets) {?> <td> <?php echo Format::date($T['created']); ?></td> <td> <?php echo $status; ?></td> <td> - <a class="truncate" href="tickets.php?id=<?php echo $T['ticket_id']; ?>"><?php echo $subject; ?></a> + <div style="max-height: 1.2em" class="link truncate" href="tickets.php?id=<?php echo $T['ticket_id']; ?>"><?php echo $subject; ?></div> </td> <td> <span class="truncate"><?php echo $dept; ?></span></td> </tr> diff --git a/include/client/view.inc.php b/include/client/view.inc.php index ca9aa363c..05ea6f440 100644 --- a/include/client/view.inc.php +++ b/include/client/view.inc.php @@ -32,7 +32,10 @@ if ($thisclient && $thisclient->isGuest() <td colspan="2" width="100%"> <h1> <a href="tickets.php?id=<?php echo $ticket->getId(); ?>" title="<?php echo __('Reload'); ?>"><i class="refresh icon-refresh"></i></a> - <b><?php echo Format::htmlchars($ticket->getSubject()); ?></b> + <b> + <?php $subject_field = TicketForm::getInstance()->getField('subject'); + echo $subject_field->display($ticket->getSubject()); ?> + </b> <small>#<?php echo $ticket->getNumber(); ?></small> <div class="pull-right"> <a class="action-button" href="tickets.php?a=print&id=<?php @@ -95,32 +98,37 @@ if ($thisclient && $thisclient->isGuest() <td colspan="2"> <!-- Custom Data --> <?php -foreach (DynamicFormEntry::forTicket($ticket->getId()) as $form) { +$sections = array(); +foreach (DynamicFormEntry::forTicket($ticket->getId()) as $i=>$form) { // Skip core fields shown earlier in the ticket view $answers = $form->getAnswers()->exclude(Q::any(array( 'field__flags__hasbit' => DynamicFormField::FLAG_EXT_STORED, 'field__name__in' => array('subject', 'priority'), Q::not(array('field__flags__hasbit' => DynamicFormField::FLAG_CLIENT_VIEW)), ))); - if (count($answers) == 0) - continue; + // Skip display of forms without any answers + foreach ($answers as $j=>$a) { + if ($v = $a->display()) + $sections[$i][$j] = array($v, $a); + } +} +foreach ($sections as $i=>$answers) { ?> <table class="custom-data" cellspacing="0" cellpadding="4" width="100%" border="0"> <tr><td colspan="2" class="headline flush-left"><?php echo $form->getTitle(); ?></th></tr> - <?php foreach($answers as $a) { - if (!($v = $a->display())) continue; ?> - <tr> - <th><?php - echo $a->getField()->get('label'); - ?>:</th> - <td><?php - echo $v; - ?></td> - </tr> - <?php } ?> +<?php foreach ($answers as $A) { + list($v, $a) = $A; ?> + <tr> + <th><?php +echo $a->getField()->get('label'); + ?>:</th> + <td><?php +echo $v; + ?></td> + </tr> +<?php } ?> </table> <?php - $idx++; } ?> </td> </tr> diff --git a/include/staff/ticket-view.inc.php b/include/staff/ticket-view.inc.php index 9f0c7fca0..6ec03ae89 100644 --- a/include/staff/ticket-view.inc.php +++ b/include/staff/ticket-view.inc.php @@ -201,7 +201,8 @@ if($ticket->isOverdue()) </div> <div class="clear tixTitle has_bottom_border"> <h3> - <?php echo Format::htmlchars($ticket->getSubject()); ?> + <?php $subject_field = TicketForm::getInstance()->getField('subject'); + echo $subject_field->display($ticket->getSubject()); ?> </h3> </div> <table class="ticket_info" cellspacing="0" cellpadding="0" width="940" border="0"> diff --git a/include/staff/tickets.inc.php b/include/staff/tickets.inc.php index 7ec261761..171675afc 100644 --- a/include/staff/tickets.inc.php +++ b/include/staff/tickets.inc.php @@ -472,8 +472,7 @@ return false;"> data-preview="#tickets/<?php echo $T['ticket_id']; ?>/preview" ><?php echo $tid; ?></a></td> <td align="center" nowrap><?php echo Format::datetime($T[$date_col ?: 'lastupdate']) ?: $date_fallback; ?></td> - <td><a <?php if ($flag) { ?> class="Icon <?php echo $flag; ?>Ticket" title="<?php echo ucfirst($flag); ?> Ticket" <?php } ?> - style="max-width: <?php + <td><div style="max-width: <?php $base = 280; // Make room for the paperclip and some extra if ($T['attachment_count']) $base -= 18; @@ -481,9 +480,10 @@ return false;"> if ($threadcount > 1) $base -= 20 + ((int) log($threadcount, 10) + 1) * 8; // Make room for overdue flag and friends if ($flag) $base -= 20; - echo $base; ?>px;" - href="tickets.php?id=<?php echo $T['ticket_id']; ?>"><span - class="truncate"><?php echo $subject; ?></span></a> + echo $base; ?>px; max-height: 1.2em" + class="<?php if ($flag) { ?>Icon <?php echo $flag; ?>Ticket <?php } ?>link truncate" + <?php if ($flag) { ?> title="<?php echo ucfirst($flag); ?> Ticket" <?php } ?> + href="tickets.php?id=<?php echo $T['ticket_id']; ?>"><?php echo $subject; ?></div> <?php if ($T['attachment_count']) echo '<i class="small icon-paperclip icon-flip-horizontal" data-toggle="tooltip" title="' .$T['attachment_count'].'"></i>'; diff --git a/js/osticket.js b/js/osticket.js index 95077cdf8..bd2f937e6 100644 --- a/js/osticket.js +++ b/js/osticket.js @@ -220,3 +220,11 @@ $(document).on('submit', 'form', function() { $e.val(year+'-'+month+'-'+day); }); }); + +$(document).on('click', '.link:not(a):not(.button)', function(event) { + var $e = $(event.currentTarget); + $('<a>').prop({href: $e.attr('href'), 'class': $e.attr('class')}) + .hide() + .insertBefore($e) + .get(0).click(event); +}); diff --git a/scp/css/scp.css b/scp/css/scp.css index 2cec5526c..9469a63aa 100644 --- a/scp/css/scp.css +++ b/scp/css/scp.css @@ -13,15 +13,16 @@ body, html { padding:0; } -.button.link, +.link, a { color:#184E81; text-decoration:none; display: inline-block; } -a:hover, .button.link:hover { +a:hover, .link:hover { text-decoration: underline; + cursor: pointer; } #nav a:hover, diff --git a/scp/js/scp.js b/scp/js/scp.js index 8408453d0..705388edb 100644 --- a/scp/js/scp.js +++ b/scp/js/scp.js @@ -1055,6 +1055,14 @@ if ($.support.pjax) { }) } +$(document).on('click', '.link:not(a):not(.button)', function(event) { + var $e = $(event.currentTarget); + $('<a>').attr({href: $e.attr('href'), 'class': $e.attr('class')}) + .hide() + .insertBefore($e) + .get(0).click(event); +}); + // Quick-Add dialogs $(document).on('change', 'select[data-quick-add]', function() { var $select = $(this), -- GitLab