diff --git a/include/class.thread.php b/include/class.thread.php index 4b3771e10c864cf0c611ea4d6b35d9a23b333fe9..bd50ecb20c48a8c7e3a2e935cfdf878042c07748 100644 --- a/include/class.thread.php +++ b/include/class.thread.php @@ -89,6 +89,15 @@ class Thread extends VerySimpleModel { return $base; } + function render($type=false) { + + $entries = $this->getEntries(); + if ($type && is_array($type)) + $entries->filter(array('type__in' => $type)); + + include STAFFINC_DIR . 'templates/thread-entries.tmpl.php'; + } + function getEntry($id) { return ThreadEntry::lookup($id, $this->getId()); } diff --git a/include/staff/templates/thread-entries.tmpl.php b/include/staff/templates/thread-entries.tmpl.php new file mode 100644 index 0000000000000000000000000000000000000000..821c1c50ca4416860e4350507fa730b744d6a2e9 --- /dev/null +++ b/include/staff/templates/thread-entries.tmpl.php @@ -0,0 +1,83 @@ +<?php +$entryTypes = array('M'=>'message', 'R'=>'response', 'N'=>'note'); +if ($entries) { + foreach ($entries as $entry) { ?> + <table class="thread-entry <?php echo $entryTypes[$entry->type]; ?>" cellspacing="0" cellpadding="1" width="940" border="0"> + <tr> + <th colspan="4" width="100%"> + <div> + <span class="pull-left"> + <span style="display:inline-block"><?php + echo Format::datetime($entry->created);?></span> + <span style="display:inline-block;padding:0 1em;max-width: 500px" class="faded title truncate"><?php + echo $entry->title; ?></span> + </span> + <div class="pull-right"> +<?php if ($entry->hasActions()) { + $actions = $entry->getActions(); ?> + <span class="action-button pull-right" data-dropdown="#entry-action-more-<?php echo $entry->getId(); ?>"> + <i class="icon-caret-down"></i> + <span ><i class="icon-cog"></i></span> + </span> + <div id="entry-action-more-<?php echo $entry->getId(); ?>" class="action-dropdown anchor-right"> + <ul class="title"> +<?php foreach ($actions as $group => $list) { + foreach ($list as $id => $action) { ?> + <li> + <a class="no-pjax" href="#" onclick="javascript: + <?php echo str_replace('"', '\\"', $action->getJsStub()); ?>; return false;"> + <i class="<?php echo $action->getIcon(); ?>"></i> <?php + echo $action->getName(); + ?></a></li> +<?php } + } ?> + </ul> + </div> +<?php } ?> + <span style="vertical-align:middle"> + <span style="vertical-align:middle;" class="textra"></span> + <span style="vertical-align:middle;" + class="tmeta faded title"><?php + echo Format::htmlchars($entry->getName()); ?></span> + </span> + </div> + </th> + </tr> + <tr><td colspan="4" class="thread-body" id="thread-id-<?php + echo $entry->getId(); ?>"><div><?php + echo $entry->getBody()->toHtml(); ?></div></td></tr> + <?php + $urls = null; + if ($entry->has_attachments + && ($urls = $entry->getAttachmentUrls())) { ?> + <tr> + <td class="info" colspan="4"><?php + foreach ($entry->attachments as $A) { + if ($A->inline) continue; + $size = ''; + if ($A->file->size) + $size = sprintf('<em>(%s)</em>', + Format::file_size($A->file->size)); +?> + <a class="Icon file no-pjax" href="<?php echo $A->file->getDownloadUrl(); + ?>" target="_blank"><?php echo Format::htmlchars($A->file->name); + ?></a><?php echo $size;?> +<?php } ?> + </td> + </tr> <?php + } + if ($urls) { ?> + <script type="text/javascript"> + $('#thread-id-<?php echo $entry->getId(); ?>') + .data('urls', <?php + echo JsonDataEncoder::encode($urls); ?>) + .data('id', <?php echo $entry->getId(); ?>); + </script> +<?php + } ?> + </table> + <?php + } +} else { + echo '<p><em>'.__('No entries have been posted to this thread.').'</em></p>'; +}?> diff --git a/include/staff/ticket-view.inc.php b/include/staff/ticket-view.inc.php index a0e843a0c47e46144ccc66caaf8911ddd758519f..9bc13c7aa0105d686938be9e9dba8dcfe44093c6 100644 --- a/include/staff/ticket-view.inc.php +++ b/include/staff/ticket-view.inc.php @@ -396,102 +396,8 @@ $tcount = $ticket->getThreadEntries($types)->count(); <div id="ticket_tabs_container"> <div id="ticket_thread" data-thread-id="<?php echo $ticket->getThread()->getId(); ?>" class="tab_content"> <?php - $threadTypes=array('M'=>'message','R'=>'response', 'N'=>'note'); - /* -------- Messages & Responses & Notes (if inline)-------------*/ - $types = array('M', 'R', 'N'); - if(($thread=$ticket->getThreadEntries($types))) { - foreach($thread as $entry) { ?> - <table class="thread-entry <?php echo $threadTypes[$entry->type]; ?>" cellspacing="0" cellpadding="1" width="940" border="0"> - <tr> - <th colspan="4" width="100%"> - <div> - <span class="pull-left"> - <span style="display:inline-block"><?php - echo Format::datetime($entry->created);?></span> - <span style="display:inline-block;padding:0 1em;max-width: 500px" class="faded title truncate"><?php - echo $entry->title; ?></span> - </span> - <div class="pull-right"> -<?php if ($entry->hasActions()) { - $actions = $entry->getActions(); ?> - <span class="action-button pull-right" data-dropdown="#entry-action-more-<?php echo $entry->getId(); ?>"> - <i class="icon-caret-down"></i> - <span ><i class="icon-cog"></i></span> - </span> - <div id="entry-action-more-<?php echo $entry->getId(); ?>" class="action-dropdown anchor-right"> - <ul class="title"> -<?php foreach ($actions as $group => $list) { - foreach ($list as $id => $action) { ?> - <li> - <a class="no-pjax <?php - if (!$action->isEnabled()) - echo 'disabled'; - ?>" href="#" onclick="javascript: - if ($(this).hasClass('disabled')) return false; - <?php echo str_replace('"', '\\"', $action->getJsStub()); ?>; return false;"> - <i class="icon-fixed-width <?php echo $action->getIcon(); ?>"></i> <?php - echo $action->getName(); - ?></a></li> -<?php } - } ?> - </ul> - </div> -<?php } ?> - <span style="vertical-align:middle"> - <span style="vertical-align:middle;" class="textra"> - <?php if ($entry->flags & ThreadEntry::FLAG_EDITED) { ?> - <span class="label label-bare" title="<?php - echo sprintf(__('Edited on %s by %s'), Format::datetime($entry->updated), 'You'); - ?>"><?php echo __('Edited'); ?></span> - <?php } ?> - </span> - <span style="vertical-align:middle;" - class="tmeta faded title"><?php - echo Format::htmlchars($entry->getName()); ?></span> - </span> - </div> - </th> - </tr> - <tr><td colspan="4" class="thread-body" id="thread-id-<?php - echo $entry->getId(); ?>"><div><?php - echo $entry->getBody()->toHtml(); ?></div></td></tr> - <?php - $urls = null; - if ($entry->has_attachments - && ($urls = $entry->getAttachmentUrls())) { ?> - <tr> - <td class="info" colspan="4"><?php - foreach ($entry->attachments as $A) { - if ($A->inline) continue; - $size = ''; - if ($A->file->size) - $size = sprintf('<em>(%s)</em>', - Format::file_size($A->file->size)); -?> - <a class="Icon file no-pjax" href="<?php echo $A->file->getDownloadUrl(); - ?>" target="_blank"><?php echo Format::htmlchars($A->file->name); - ?></a><?php echo $size;?> -<?php } ?> - </td> - </tr> <?php - } - if ($urls) { ?> - <script type="text/javascript"> - $('#thread-id-<?php echo $entry->getId(); ?>') - .data('urls', <?php - echo JsonDataEncoder::encode($urls); ?>) - .data('id', <?php echo $entry->getId(); ?>); - </script> -<?php - } ?> - </table> - <?php - if ($entry->type == 'M') - $msgId = $entry->getId(); - } - } else { - echo '<p><em>'.__('No entries have been posted to this ticket.').'</em></p>'; - }?> + $ticket->getThread()->render(array('M', 'R', 'N')); + ?> <div class="clear" style="padding-bottom:10px;"></div> <?php if($errors['err']) { ?> <div id="msg_error"><?php echo $errors['err']; ?></div>