Skip to content

Commit

Permalink
AJAX mark as read was stuck due to missing return from the controller…
Browse files Browse the repository at this point in the history
… - thanks scripple for reporting

Signed-off-by: emanuele <emanuele45@gmail.com>
  • Loading branch information
emanuele45 committed Feb 19, 2014
1 parent c9b3608 commit b716d9f
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 6 deletions.
35 changes: 33 additions & 2 deletions sources/controllers/Markasread.controller.php
Expand Up @@ -19,6 +19,18 @@
*/
class MarkRead_Controller extends Action_Controller
{
/**
* String used to redirect user to the correct boards when marking unread
* ajax-ively
*/
private $_querystring_board_limits = '';

/**
* String used to remember user's sorting options when marking unread
* ajax-ively
*/
private $_querystring_sort_limits = '';

/**
* This is the main function for markasread file.
*
Expand Down Expand Up @@ -114,10 +126,11 @@ public function action_index_api()
$this->_dispatch();

// For the time being this is a special case, but in BoardIndex no, we don't want it
if (isset($_REQUEST['sa']) && $_REQUEST['sa'] == 'all' && !isset($_REQUEST['bi']))
if (isset($_REQUEST['sa']) && ($_REQUEST['sa'] == 'all' || $_REQUEST['sa'] == 'board') && !isset($_REQUEST['bi']))
{
$context['xml_data'] = array(
'text' => $txt['unread_topics_visit_none'],
'text' => $txt['topic_alert_none'],
'body' => strtr($txt['unread_topics_visit_none'], array('?action=unread;all' => '?action=unread;all' . sprintf($this->_querystring_board_limits, 0) . $this->_querystring_sort_limits)),
);
}
// No need to do anything, just die
Expand Down Expand Up @@ -274,6 +287,24 @@ public function action_markasread()
$_SESSION['topicseen_cache'][$b] = array();
}

$this->_querystring_board_limits = $_REQUEST['sa'] == 'board' ? ';boards=' . implode(',', $boards) . ';start=%d' : '';

$sort_methods = array(
'subject',
'starter',
'replies',
'views',
'first_post',
'last_post'
);

// The default is the most logical: newest first.
if (!isset($_REQUEST['sort']) || !in_array($_REQUEST['sort'], $sort_methods))
$this->_querystring_sort_limits = isset($_REQUEST['asc']) ? ';asc' : '';
// But, for other methods the default sort is ascending.
else
$this->_querystring_sort_limits = ';sort=' . $_REQUEST['sort'] . (isset($_REQUEST['desc']) ? ';desc' : '');

if (!isset($_REQUEST['unread']))
{
// Find all boards with the parents in the board list
Expand Down
16 changes: 12 additions & 4 deletions themes/default/scripts/script_elk.js
Expand Up @@ -101,7 +101,7 @@ function toggleHeaderAJAX(btn, container_id)
{
// Show ajax is in progress
ajax_indicator(true);
var text_template = '<h3 class="category_header centertext">{text}</h3>';
var body_template = '<div class="board_row centertext">{body}</div>';

$.ajax({
type: 'GET',
Expand All @@ -110,17 +110,24 @@ function toggleHeaderAJAX(btn, container_id)
beforeSend: ajax_indicator(true)
})
.done(function(request) {
if (request === '')
return;

var oElement = $(request).find('elk')[0];

// No errors
if (oElement.getElementsByTagName('error').length === 0)
{
var text = oElement.getElementsByTagName('text')[0].firstChild.nodeValue.removeEntities();
var text_elem = oElement.getElementsByTagName('text'),
body_elem = oElement.getElementsByTagName('body');

$('#' + container_id + ' .pagesection').remove();
$('#' + container_id + ' .category_header').remove();
$('#' + container_id + ' .topic_listing').remove();
$(text_template.replace('{text}', text)).insertBefore('#topic_icons');
$('#' + container_id + ' .topic_sorting').remove();
if (text_elem.length === 1)
$('#' + container_id + ' #unread_header').html(text_elem[0].firstChild.nodeValue.removeEntities());
if (body_elem.length === 1)
$(body_template.replace('{body}', body_elem[0].firstChild.nodeValue.removeEntities())).insertAfter('#unread_header');
}
})
.fail(function() {
Expand Down Expand Up @@ -215,6 +222,7 @@ function markallreadButton(btn)
function markunreadButton(btn)
{
toggleHeaderAJAX(btn, 'main_content_section');

return false;
}

Expand Down

0 comments on commit b716d9f

Please sign in to comment.