From 9f4ad94d35bb914e73236b4eee8f3281a32e125e Mon Sep 17 00:00:00 2001 From: Peter Rotich <peter@osticket.com> Date: Mon, 3 Feb 2014 23:01:29 +0000 Subject: [PATCH] Move ticket preview to a template Show ticket prview when a ticket number is clicked as opposed to ticket view. Add collaborator preview tab on ticket preview tool tip. --- include/ajax.tickets.php | 117 +----------- .../staff/templates/ticket-preview.tmpl.php | 172 ++++++++++++++++++ scp/js/tips.js | 11 +- 3 files changed, 179 insertions(+), 121 deletions(-) create mode 100644 include/staff/templates/ticket-preview.tmpl.php diff --git a/include/ajax.tickets.php b/include/ajax.tickets.php index b96531951..4e87d0866 100644 --- a/include/ajax.tickets.php +++ b/include/ajax.tickets.php @@ -335,123 +335,8 @@ class TicketsAjaxAPI extends AjaxController { if(!$thisstaff || !($ticket=Ticket::lookup($tid)) || !$ticket->checkStaffAccess($thisstaff)) Http::response(404, 'No such ticket'); - $staff=$ticket->getStaff(); - $lock=$ticket->getLock(); - $error=$msg=$warn=null; - - if($lock && $lock->getStaffId()==$thisstaff->getId()) - $warn.=' <span class="Icon lockedTicket">Ticket is locked by '.$lock->getStaffName().'</span>'; - elseif($ticket->isOverdue()) - $warn.=' <span class="Icon overdueTicket">Marked overdue!</span>'; - ob_start(); - echo sprintf( - '<div style="width:500px; padding: 2px 2px 0 5px;"> - <h2>%s</h2><br>',Format::htmlchars($ticket->getSubject())); - - if($error) - echo sprintf('<div id="msg_error">%s</div>',$error); - elseif($msg) - echo sprintf('<div id="msg_notice">%s</div>',$msg); - elseif($warn) - echo sprintf('<div id="msg_warning">%s</div>',$warn); - - echo '<table border="0" cellspacing="" cellpadding="1" width="100%" class="ticket_info">'; - - $ticket_state=sprintf('<span>%s</span>',ucfirst($ticket->getStatus())); - if($ticket->isOpen()) { - if($ticket->isOverdue()) - $ticket_state.=' — <span>Overdue</span>'; - else - $ticket_state.=sprintf(' — <span>%s</span>',$ticket->getPriority()); - } - - echo sprintf(' - <tr> - <th width="100">Ticket State:</th> - <td>%s</td> - </tr> - <tr> - <th>Create Date:</th> - <td>%s</td> - </tr>',$ticket_state, - Format::db_datetime($ticket->getCreateDate())); - if($ticket->isClosed()) { - echo sprintf(' - <tr> - <th>Close Date:</th> - <td>%s <span class="faded">by %s</span></td> - </tr>', - Format::db_datetime($ticket->getCloseDate()), - ($staff?$staff->getName():'staff') - ); - } elseif($ticket->getEstDueDate()) { - echo sprintf(' - <tr> - <th>Due Date:</th> - <td>%s</td> - </tr>', - Format::db_datetime($ticket->getEstDueDate())); - } - echo '</table>'; - - - echo '<hr> - <table border="0" cellspacing="" cellpadding="1" width="100%" class="ticket_info">'; - if($ticket->isOpen()) { - echo sprintf(' - <tr> - <th width="100">Assigned To:</th> - <td>%s</td> - </tr>',$ticket->isAssigned()?implode('/', $ticket->getAssignees()):' <span class="faded">— Unassigned —</span>'); - } - echo sprintf( - ' <tr> - <th width="100">Department:</th> - <td>%s</td> - </tr> - <tr> - <th>Help Topic:</th> - <td>%s</td> - </tr> - <tr> - <th>From:</th> - <td>%s <span class="faded">%s</span></td> - </tr>', - Format::htmlchars($ticket->getDeptName()), - Format::htmlchars($ticket->getHelpTopic()), - Format::htmlchars($ticket->getName()), - $ticket->getEmail()); - echo ' - </table>'; - - $options = array(); - $options[]=array('action'=>'Thread ('.$ticket->getThreadCount().')','url'=>"tickets.php?id=$tid"); - if($ticket->getNumNotes()) - $options[]=array('action'=>'Notes ('.$ticket->getNumNotes().')','url'=>"tickets.php?id=$tid#notes"); - - if($ticket->isOpen()) - $options[]=array('action'=>'Reply','url'=>"tickets.php?id=$tid#reply"); - - if($thisstaff->canAssignTickets()) - $options[]=array('action'=>($ticket->isAssigned()?'Reassign':'Assign'),'url'=>"tickets.php?id=$tid#assign"); - - if($thisstaff->canTransferTickets()) - $options[]=array('action'=>'Transfer','url'=>"tickets.php?id=$tid#transfer"); - - $options[]=array('action'=>'Post Note','url'=>"tickets.php?id=$tid#note"); - - if($thisstaff->canEditTickets()) - $options[]=array('action'=>'Edit Ticket','url'=>"tickets.php?id=$tid&a=edit"); - - if($options) { - echo '<ul class="tip_menu">'; - foreach($options as $option) - echo sprintf('<li><a href="%s">%s</a></li>',$option['url'],$option['action']); - echo '</ul>'; - } - - echo '</div>'; + include STAFFINC_DIR . 'templates/ticket-preview.tmpl.php'; $resp = ob_get_contents(); ob_end_clean(); diff --git a/include/staff/templates/ticket-preview.tmpl.php b/include/staff/templates/ticket-preview.tmpl.php new file mode 100644 index 000000000..4b5b540cd --- /dev/null +++ b/include/staff/templates/ticket-preview.tmpl.php @@ -0,0 +1,172 @@ +<?php +/* + * Ticket Preview popup template + * + */ + +$staff=$ticket->getStaff(); +$lock=$ticket->getLock(); +$error=$msg=$warn=null; + +if($lock && $lock->getStaffId()==$thisstaff->getId()) + $warn.=' <span class="Icon lockedTicket">Ticket is locked by '.$lock->getStaffName().'</span>'; +elseif($ticket->isOverdue()) + $warn.=' <span class="Icon overdueTicket">Marked overdue!</span>'; + +echo sprintf( + '<div style="width:600px; padding: 2px 2px 0 5px;" id="t%s"> + <h2>Ticket #%s: %s</h2><br>', + $ticket->getNumber(), + $ticket->getNumber(), + Format::htmlchars($ticket->getSubject())); + +if($error) + echo sprintf('<div id="msg_error">%s</div>',$error); +elseif($msg) + echo sprintf('<div id="msg_notice">%s</div>',$msg); +elseif($warn) + echo sprintf('<div id="msg_warning">%s</div>',$warn); + +echo '<ul class="tabs">'; + +echo ' + <li><a id="preview_tab" href="#preview" class="active" + ><i class="icon-list-alt"></i> Ticket Preview</a></li>'; +if ($ticket->getNumCollaborators()) { +echo sprintf(' + <li><a id="collab_tab" href="#collab" + ><i class="icon-fixed-width icon-group + faded"></i> Collaborators (%d)</a></li>', + $ticket->getNumCollaborators()); +} +echo '</ul>'; + +echo '<div class="tab_content" id="preview">'; +echo '<table border="0" cellspacing="" cellpadding="1" width="100%" class="ticket_info">'; + +$ticket_state=sprintf('<span>%s</span>',ucfirst($ticket->getStatus())); +if($ticket->isOpen()) { + if($ticket->isOverdue()) + $ticket_state.=' — <span>Overdue</span>'; + else + $ticket_state.=sprintf(' — <span>%s</span>',$ticket->getPriority()); +} + +echo sprintf(' + <tr> + <th width="100">Ticket State:</th> + <td>%s</td> + </tr> + <tr> + <th>Create Date:</th> + <td>%s</td> + </tr>',$ticket_state, + Format::db_datetime($ticket->getCreateDate())); +if($ticket->isClosed()) { + echo sprintf(' + <tr> + <th>Close Date:</th> + <td>%s <span class="faded">by %s</span></td> + </tr>', + Format::db_datetime($ticket->getCloseDate()), + ($staff?$staff->getName():'staff') + ); +} elseif($ticket->getEstDueDate()) { + echo sprintf(' + <tr> + <th>Due Date:</th> + <td>%s</td> + </tr>', + Format::db_datetime($ticket->getEstDueDate())); +} +echo '</table>'; + + +echo '<hr> + <table border="0" cellspacing="" cellpadding="1" width="100%" class="ticket_info">'; +if($ticket->isOpen()) { + echo sprintf(' + <tr> + <th width="100">Assigned To:</th> + <td>%s</td> + </tr>',$ticket->isAssigned()?implode('/', $ticket->getAssignees()):' <span class="faded">— Unassigned —</span>'); +} +echo sprintf( + ' + <tr> + <th>From:</th> + <td>%s <span class="faded">%s</span></td> + </tr> + <tr> + <th width="100">Department:</th> + <td>%s</td> + </tr> + <tr> + <th>Help Topic:</th> + <td>%s</td> + </tr>', + Format::htmlchars($ticket->getName()), + $ticket->getEmail(), + Format::htmlchars($ticket->getDeptName()), + Format::htmlchars($ticket->getHelpTopic())); + +echo ' + </table>'; +echo '</div>'; // ticket preview content. +?> +<div class="tab_content" id="collab" style="display:none;"> + <table border="0" cellspacing="" cellpadding="1"> + <colgroup><col style="min-width: 250px;"></col></colgroup> + <?php + if (($users=$ticket->getCollaborators())) {?> + <?php + foreach($users as $user) { + echo sprintf('<tr><td %s><i class="icon-%s"></i> %s <em><%s></em></td></tr>', + ($user->isActive()? '' : 'class="faded"'), + ($user->isActive()? 'comments' : 'comment-alt'), + $user->getName(), + $user->getEmail()); + } + } else { + echo "Ticket doesn't have collaborators."; + }?> + </table> + <br> + <?php + echo sprintf('<span><a class="collaborators" + href="#tickets/%d/collaborators">%s</a></span>', + $ticket->getId(), + $ticket->getNumCollaborators() + ? 'Manage Collaborators' : 'Add Collaborator' + ); + ?> +</div> +<?php +$options = array(); +$options[]=array('action'=>'Thread ('.$ticket->getThreadCount().')','url'=>"tickets.php?id=$tid"); +if($ticket->getNumNotes()) + $options[]=array('action'=>'Notes ('.$ticket->getNumNotes().')','url'=>"tickets.php?id=$tid#notes"); + +if($ticket->isOpen()) + $options[]=array('action'=>'Reply','url'=>"tickets.php?id=$tid#reply"); + +if($thisstaff->canAssignTickets()) + $options[]=array('action'=>($ticket->isAssigned()?'Reassign':'Assign'),'url'=>"tickets.php?id=$tid#assign"); + +if($thisstaff->canTransferTickets()) + $options[]=array('action'=>'Transfer','url'=>"tickets.php?id=$tid#transfer"); + +$options[]=array('action'=>'Post Note','url'=>"tickets.php?id=$tid#note"); + +if($thisstaff->canEditTickets()) + $options[]=array('action'=>'Edit Ticket','url'=>"tickets.php?id=$tid&a=edit"); + +if($options) { + echo '<ul class="tip_menu">'; + foreach($options as $option) + echo sprintf('<li><a href="%s">%s</a></li>',$option['url'],$option['action']); + echo '</ul>'; +} + +echo '</div>'; +?> diff --git a/scp/js/tips.js b/scp/js/tips.js index db94a1acb..6a801a18b 100644 --- a/scp/js/tips.js +++ b/scp/js/tips.js @@ -183,7 +183,7 @@ jQuery(function() { //Ticket preview - $('.ticketPreview').live('mouseover', function(e) { + $('.ticketPreview').live('mouseover click', function(e) { e.preventDefault(); var elem = $(this); @@ -192,18 +192,19 @@ jQuery(function() { var id='t'+vars[1]; var xoffset = 80; - - elem.data('id',id); - elem.data('timer',0); - if($('.' + id).length == 0) { + elem.data('timer', 0); + if(!elem.data('id')) { + elem.data('id', id); if(e.type=='mouseover') { /* wait about 1 sec - before showing the tip - mouseout kills the timeout*/ elem.data('timer',setTimeout(function() { showtip(url,elem,xoffset);},750)) }else{ + clearTimeout(elem.data('timer')); showtip(url,elem,xoffset); } } }).live('mouseout', function(e) { + $(this).data('id', 0); clearTimeout($(this).data('timer')); }); -- GitLab