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

Thread View Sort Order

Add a preference option to set the sort order of the thread entries in DESC or
ASC order.

 * System Default order is ASC
 * Auto-scroll is disabled when sort order is set to DESC.
parent 8235ffbb
No related branches found
No related tags found
No related merge requests found
......@@ -86,7 +86,8 @@ implements AuthenticatedUser, EmailContact, TemplateVariable {
// Defaults
array(
'default_from_name' => '',
'datetime_format' => '',
'datetime_format' => '',
'thread_view_order' => '',
));
$this->_config = $_config->getInfo();
}
......@@ -675,6 +676,7 @@ implements AuthenticatedUser, EmailContact, TemplateVariable {
$_config->updateAll(array(
'datetime_format' => $vars['datetime_format'],
'default_from_name' => $vars['default_from_name'],
'thread_view_order' => $vars['thread_view_order'],
)
);
$this->_config = $_config->getInfo();
......
......@@ -244,6 +244,9 @@ class Thread extends VerySimpleModel {
if ($type && is_array($type))
$entries->filter(array('type__in' => $type));
if ($options['sort'] && !strcasecmp($options['sort'], 'DESC'))
$entries->order_by('-id');
// Precache all the attachments on this thread
AttachmentFile::objects()->filter(array(
'attachments__thread_entry__thread__id' => $this->id
......
......@@ -223,7 +223,29 @@ if ($avatar->isChangeable()) { ?>
<div class="error"><?php echo $errors['default_from_name']; ?></div>
</td>
</tr>
<tr>
<td><?php echo __('Thread View Order');?>:
<div class="faded"><?php echo __('The order of thread entries');?></div>
</td>
<td>
<select name="thread_view_order">
<?php
$options=array(
'desc' => __('Descending'),
'asc' => __('Ascending'),
'' => '— '.__('System Default').' —',
);
foreach($options as $k=>$v) {
echo sprintf('<option value="%s" %s>%s</option>',
$k
,($staff->thread_view_order == $k) ? 'selected="selected"' : ''
,$v);
}
?>
</select>
<div class="error"><?php echo $errors['thread_view_order']; ?></div>
</td>
</tr>
<tr>
<td><?php echo __('Default Signature');?>:
<div class="faded"><?php echo __('This can be selected when replying to a thread');?></div>
......
......@@ -311,7 +311,8 @@ if (!$ticket) { ?>
$task->getThread()->render(array('M', 'R', 'N'),
array(
'mode' => Thread::MODE_STAFF,
'container' => 'taskThread'
'container' => 'taskThread',
'sort' => $thisstaff->thread_view_order
)
);
?>
......
<?php
$events = $events->order_by('id');
$sort = 'id';
if ($options['sort'] && !strcasecmp($options['sort'], 'DESC'))
$sort = '-id';
$cmp = function ($a, $b) use ($sort) {
return ($sort == 'id')
? ($a < $b) : $a > $b;
};
$events = $events->order_by($sort);
$events = $events->getIterator();
$events->rewind();
$event = $events->current();
......@@ -33,7 +43,7 @@ foreach (Attachment::objects()->filter(array(
// changes in dates between thread items.
foreach ($entries as $entry) {
// Emit all events prior to this entry
while ($event && $event->timestamp < $entry->created) {
while ($event && $cmp($event->timestamp, $entry->created)) {
$event->render(ThreadEvent::MODE_STAFF);
$events->next();
$event = $events->current();
......@@ -79,6 +89,7 @@ foreach (Attachment::objects()->filter(array(
$('#'+container).data('imageUrls', <?php echo JsonDataEncoder::encode($urls); ?>);
// Trigger thread processing.
if ($.thread)
$.thread.onLoad(container);
$.thread.onLoad(container,
{autoScroll: <?php echo $sort == 'id' ? 'true' : 'false'; ?>});
});
</script>
......@@ -497,8 +497,10 @@ $tcount = $ticket->getThreadEntries($types)->count();
$ticket->getThread()->render(
array('M', 'R', 'N'),
array(
'html-id' => 'ticketThread',
'mode' => Thread::MODE_STAFF)
'html-id' => 'ticketThread',
'mode' => Thread::MODE_STAFF,
'sort' => $thisstaff->thread_view_order
)
);
?>
<div class="clear"></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