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

thread: Make thread view template generic

This will allow for any threadable object to render the thread.
parent 8e67a014
No related branches found
No related tags found
No related merge requests found
...@@ -89,6 +89,15 @@ class Thread extends VerySimpleModel { ...@@ -89,6 +89,15 @@ class Thread extends VerySimpleModel {
return $base; 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) { function getEntry($id) {
return ThreadEntry::lookup($id, $this->getId()); return ThreadEntry::lookup($id, $this->getId());
} }
......
<?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;?>&nbsp;
<?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>';
}?>
...@@ -396,102 +396,8 @@ $tcount = $ticket->getThreadEntries($types)->count(); ...@@ -396,102 +396,8 @@ $tcount = $ticket->getThreadEntries($types)->count();
<div id="ticket_tabs_container"> <div id="ticket_tabs_container">
<div id="ticket_thread" data-thread-id="<?php echo $ticket->getThread()->getId(); ?>" class="tab_content"> <div id="ticket_thread" data-thread-id="<?php echo $ticket->getThread()->getId(); ?>" class="tab_content">
<?php <?php
$threadTypes=array('M'=>'message','R'=>'response', 'N'=>'note'); $ticket->getThread()->render(array('M', 'R', 'N'));
/* -------- 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;?>&nbsp;
<?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>';
}?>
<div class="clear" style="padding-bottom:10px;"></div> <div class="clear" style="padding-bottom:10px;"></div>
<?php if($errors['err']) { ?> <?php if($errors['err']) { ?>
<div id="msg_error"><?php echo $errors['err']; ?></div> <div id="msg_error"><?php echo $errors['err']; ?></div>
......
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