From b716d9fb29c3ad6fdac96bf774020b74f1d8b0d0 Mon Sep 17 00:00:00 2001 From: emanuele Date: Wed, 19 Feb 2014 14:48:48 +0100 Subject: [PATCH] AJAX mark as read was stuck due to missing return from the controller - thanks scripple for reporting Signed-off-by: emanuele --- sources/controllers/Markasread.controller.php | 35 +++++++++++++++++-- themes/default/scripts/script_elk.js | 16 ++++++--- 2 files changed, 45 insertions(+), 6 deletions(-) diff --git a/sources/controllers/Markasread.controller.php b/sources/controllers/Markasread.controller.php index 7d2b20e443..acc8a017c9 100644 --- a/sources/controllers/Markasread.controller.php +++ b/sources/controllers/Markasread.controller.php @@ -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. * @@ -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 @@ -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 diff --git a/themes/default/scripts/script_elk.js b/themes/default/scripts/script_elk.js index a1ada7b92d..43be3096d9 100644 --- a/themes/default/scripts/script_elk.js +++ b/themes/default/scripts/script_elk.js @@ -101,7 +101,7 @@ function toggleHeaderAJAX(btn, container_id) { // Show ajax is in progress ajax_indicator(true); - var text_template = '

{text}

'; + var body_template = '
{body}
'; $.ajax({ type: 'GET', @@ -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() { @@ -215,6 +222,7 @@ function markallreadButton(btn) function markunreadButton(btn) { toggleHeaderAJAX(btn, 'main_content_section'); + return false; }