diff --git a/modules/core/js_modules/actions/pagination.js b/modules/core/js_modules/actions/pagination.js index 9789079c3..33288ab5e 100644 --- a/modules/core/js_modules/actions/pagination.js +++ b/modules/core/js_modules/actions/pagination.js @@ -1,6 +1,6 @@ function refreshNextButton(current) { const totalPages = $(".pagination .total").text(); - if (current >= totalPages) { + if (parseInt(current) >= parseInt(totalPages)) { $(".pagination .next").prop('disabled', true); } else { $(".pagination .next").prop('disabled', false); @@ -8,7 +8,7 @@ function refreshNextButton(current) { } function refreshPreviousButton(current) { - if (current <= 1) { + if (parseInt(current) <= 1) { $(".pagination .prev").prop('disabled', true); } else { $(".pagination .prev").prop('disabled', false); diff --git a/modules/core/message_list_functions.php b/modules/core/message_list_functions.php index 6a4362790..95b5586b2 100644 --- a/modules/core/message_list_functions.php +++ b/modules/core/message_list_functions.php @@ -602,79 +602,3 @@ function search_field_selection($current, $output_mod) { $res .= '</select>'; return $res; }} - -/** - * Build pagination links for a list of messages - * @subpackage core/functions - * @param int $page_size number of messages per page - * @param int $current current page number - * @param int $total number of messages total - * @param string $path list path - * @param string $filter list filter - * @param string $sort list sort - * @return string - */ -if (!hm_exists('build_page_links')) { -function build_page_links($page_size, $current_page, $total, $path, $filter=false, $sort=false, $keyword=false) { - $links = ''; - $first = ''; - $last = ''; - $display_links = 10; - if ($filter) { - $filter_str = '&filter='.$filter; - } - else { - $filter_str = ''; - } - if ($sort) { - $sort_str = '&sort='.$sort; - } - else { - $sort_str = ''; - } - if ($keyword) { - $keyword_str = '&keyword='.$keyword; - } - else { - $keyword_str = ''; - } - - $max_pages = ceil($total/$page_size); - if ($max_pages == 1) { - return ''; - } - $floor = ($current_page - 1) - intval($display_links/2); - if ($floor < 0) { - $floor = 1; - } - $ceil = $floor + $display_links; - if ($ceil > $max_pages) { - $floor -= ($ceil - $max_pages); - } - $prev = '<a class="disabled_link"><i class="bi bi-caret-left-fill"></i></a>'; - $next = '<a class="disabled_link"><i class="bi bi-caret-right-fill"></i></a>'; - - if ($floor > 1 ) { - $first = '<a href="?page=message_list&list_path='.urlencode($path).'&list_page=1'.$keyword_str.$filter_str.$sort_str.'">1</a> ... '; - } - if ($ceil < $max_pages) { - $last = ' ... <a href="?page=message_list&list_path='.urlencode($path).'&list_page='.$max_pages.$keyword_str.$filter_str.$sort_str.'">'.$max_pages.'</a>'; - } - if ($current_page > 1) { - $prev = '<a href="?page=message_list&list_path='.urlencode($path).'&list_page='.($current_page - 1).$keyword_str.$filter_str.$sort_str.'"><i class="bi bi-caret-left-fill"></i></a>'; - } - if ($max_pages > 1 && $current_page < $max_pages) { - $next = '<a href="?page=message_list&list_path='.urlencode($path).'&list_page='.($current_page + 1).$keyword_str.$filter_str.$sort_str.'"><i class="bi bi-caret-right-fill"></i></a>'; - } - for ($i=1;$i<=$max_pages;$i++) { - if ($i < $floor || $i > $ceil) { - continue; - } - $links .= ' <a '; - if ($i == $current_page) { - $links .= 'class="current_page fw-bolder" '; - } - $links .= 'href="?page=message_list&list_path='.urlencode($path).'&list_page='.$i.$keyword_str.$filter_str.$sort_str.'">'.$i.'</a>'; - } - return $prev.' '.$first.$links.$last.' '.$next; -}} diff --git a/modules/core/output_modules.php b/modules/core/output_modules.php index 12bedb23a..95799220f 100644 --- a/modules/core/output_modules.php +++ b/modules/core/output_modules.php @@ -1996,7 +1996,7 @@ class Hm_Output_message_list_end extends Hm_Output_Module { * Close the table opened in Hm_Output_message_list_start */ protected function output() { - $res = '</tbody></table></div><div class="mb-5 page_links d-flex justify-content-center gap-3 align-content-center"></div></div>'; + $res = '</tbody></table></div></div>'; return $res; } } @@ -2444,6 +2444,5 @@ protected function output() { $messageList = array_merge($messageList, $this->get('feed_list_data'), Hm_Output_filter_feed_list_data::formatMessageList($this)); } $this->out('formatted_message_list', $messageList); - $this->out('page_links', 'There is no pagination in this view, please visit the individual mail boxes.'); } } diff --git a/modules/core/setup.php b/modules/core/setup.php index 957aa405d..2c5648447 100644 --- a/modules/core/setup.php +++ b/modules/core/setup.php @@ -227,7 +227,6 @@ 'msg_text' => array(FILTER_UNSAFE_RAW, false), 'msg_source' => array(FILTER_UNSAFE_RAW, false), 'msg_parts' => array(FILTER_UNSAFE_RAW, false), - 'page_links' => array(FILTER_UNSAFE_RAW, false), 'pages' => array(FILTER_VALIDATE_INT, false), 'folder_status' => array(FILTER_DEFAULT, FILTER_REQUIRE_ARRAY), 'imap_server_id' => array(FILTER_DEFAULT, false), diff --git a/modules/core/site.js b/modules/core/site.js index a1d27ebd9..682cdb045 100644 --- a/modules/core/site.js +++ b/modules/core/site.js @@ -243,7 +243,7 @@ var Hm_Ajax_Request = function() { return { messages.load().then(() => { if (messages.count != res.folder_status[name].messages) { messages.load(true).then(() => { - display_imap_mailbox(messages.rows, messages.links); + display_imap_mailbox(messages.rows, messages.list); }) } }); @@ -889,7 +889,6 @@ function Message_List() { else { $('.message_list').append('<div class="empty_list">'+hm_empty_folder()+'</div>'); } - $(".page_links").css("display", "none");// Hide page links as message list is empty } } else { diff --git a/modules/imap/output_modules.php b/modules/imap/output_modules.php index ee07b6365..0294edab3 100644 --- a/modules/imap/output_modules.php +++ b/modules/imap/output_modules.php @@ -976,7 +976,6 @@ class Hm_Output_filter_combined_inbox extends Hm_Output_Module { protected function output() { if ($this->get('imap_combined_inbox_data')) { prepare_imap_message_list($this->get('imap_combined_inbox_data'), $this, 'combined_inbox'); - $this->out('page_links', 'There is no pagination in this view, please visit the individual mail boxes.'); } else { $this->out('formatted_message_list', array()); @@ -1006,8 +1005,6 @@ protected function output() { } $max_pages = ceil($details['detail']['exists']/$details['limit']); $this->out('pages', $max_pages); - $this->out('page_links', build_page_links($details['limit'], $page_num, $details['detail']['exists'], - $this->get('imap_mailbox_page_path'), $this->html_safe($this->get('list_filter')), $this->html_safe($this->get('list_sort')), $this->html_safe($this->get('list_keyword')))); } elseif (!$this->get('formatted_message_list')) { $this->out('formatted_message_list', array()); diff --git a/tests/phpunit/modules/core/message_list_functions.php b/tests/phpunit/modules/core/message_list_functions.php index 4da49bec6..6c67482c7 100644 --- a/tests/phpunit/modules/core/message_list_functions.php +++ b/tests/phpunit/modules/core/message_list_functions.php @@ -163,15 +163,4 @@ public function test_search_field_selection() { $this->assertEquals('<select class="form-select form-select-sm w-auto" id="search_fld" name="search_fld"><option selected="selected" value="TEXT">Entire message</option><option value="BODY">Message body</option><option value="SUBJECT">Subject</option><option value="FROM">From</option><option value="TO">To</option><option value="CC">Cc</option></select>', search_field_selection('TEXT', $mod)); $this->assertEquals('<select class="form-select form-select-sm w-auto" id="search_fld" name="search_fld"><option value="TEXT">Entire message</option><option value="BODY">Message body</option><option value="SUBJECT">Subject</option><option value="FROM">From</option><option value="TO">To</option><option value="CC">Cc</option></select>', search_field_selection('foo', $mod)); } - /** - * @preserveGlobalState disabled - * @runInSeparateProcess - */ - public function test_build_page_links() { - $this->assertEquals('<a href="?page=message_list&list_path=%2F&list_page=4"><i class="bi bi-caret-left-fill"></i></a> <a href="?page=message_list&list_path=%2F&list_page=1">1</a> <a href="?page=message_list&list_path=%2F&list_page=2">2</a> <a href="?page=message_list&list_path=%2F&list_page=3">3</a> <a href="?page=message_list&list_path=%2F&list_page=4">4</a> <a class="current_page fw-bolder" href="?page=message_list&list_path=%2F&list_page=5">5</a> <a href="?page=message_list&list_path=%2F&list_page=6">6</a> <a href="?page=message_list&list_path=%2F&list_page=7">7</a> <a href="?page=message_list&list_path=%2F&list_page=8">8</a> <a href="?page=message_list&list_path=%2F&list_page=9">9</a> <a href="?page=message_list&list_path=%2F&list_page=10">10</a> <a href="?page=message_list&list_path=%2F&list_page=11">11</a> ... <a href="?page=message_list&list_path=%2F&list_page=100">100</a> <a href="?page=message_list&list_path=%2F&list_page=6"><i class="bi bi-caret-right-fill"></i></a>', build_page_links(10, 5, 1000, '/')); - $this->assertEquals('<a href="?page=message_list&list_path=%2F&list_page=9"><i class="bi bi-caret-left-fill"></i></a> <a href="?page=message_list&list_path=%2F&list_page=1">1</a> ... <a href="?page=message_list&list_path=%2F&list_page=4">4</a> <a href="?page=message_list&list_path=%2F&list_page=5">5</a> <a href="?page=message_list&list_path=%2F&list_page=6">6</a> <a href="?page=message_list&list_path=%2F&list_page=7">7</a> <a href="?page=message_list&list_path=%2F&list_page=8">8</a> <a href="?page=message_list&list_path=%2F&list_page=9">9</a> <a class="current_page fw-bolder" href="?page=message_list&list_path=%2F&list_page=10">10</a> <a href="?page=message_list&list_path=%2F&list_page=11">11</a> <a href="?page=message_list&list_path=%2F&list_page=12">12</a> <a href="?page=message_list&list_path=%2F&list_page=13">13</a> <a href="?page=message_list&list_path=%2F&list_page=14">14</a> ... <a href="?page=message_list&list_path=%2F&list_page=100">100</a> <a href="?page=message_list&list_path=%2F&list_page=11"><i class="bi bi-caret-right-fill"></i></a>', build_page_links(10, 10, 1000, '/')); - $this->assertEquals('', build_page_links(10, 1, 10, '/')); - $this->assertEquals('<a class="disabled_link"><i class="bi bi-caret-left-fill"></i></a> <a class="current_page fw-bolder" href="?page=message_list&list_path=%2F&list_page=1&filter=1&sort=1">1</a> <a href="?page=message_list&list_path=%2F&list_page=2&filter=1&sort=1">2</a> <a href="?page=message_list&list_path=%2F&list_page=3&filter=1&sort=1">3</a> <a href="?page=message_list&list_path=%2F&list_page=4&filter=1&sort=1">4</a> <a href="?page=message_list&list_path=%2F&list_page=5&filter=1&sort=1">5</a> <a href="?page=message_list&list_path=%2F&list_page=6&filter=1&sort=1">6</a> <a href="?page=message_list&list_path=%2F&list_page=7&filter=1&sort=1">7</a> <a href="?page=message_list&list_path=%2F&list_page=8&filter=1&sort=1">8</a> <a href="?page=message_list&list_path=%2F&list_page=9&filter=1&sort=1">9</a> <a href="?page=message_list&list_path=%2F&list_page=10&filter=1&sort=1">10</a> <a href="?page=message_list&list_path=%2F&list_page=2&filter=1&sort=1"><i class="bi bi-caret-right-fill"></i></a>', build_page_links(10, 1, 100, '/', true, true)); - $this->assertEquals('<a class="disabled_link"><i class="bi bi-caret-left-fill"></i></a> <a class="current_page fw-bolder" href="?page=message_list&list_path=%2F&list_page=1&keyword=cypht&filter=1&sort=1">1</a> <a href="?page=message_list&list_path=%2F&list_page=2&keyword=cypht&filter=1&sort=1">2</a> <a href="?page=message_list&list_path=%2F&list_page=3&keyword=cypht&filter=1&sort=1">3</a> <a href="?page=message_list&list_path=%2F&list_page=2&keyword=cypht&filter=1&sort=1"><i class="bi bi-caret-right-fill"></i></a>', build_page_links(10, 1, 30, '/', true, true, "cypht")); - } } diff --git a/tests/phpunit/modules/core/output_modules.php b/tests/phpunit/modules/core/output_modules.php index 9b953753d..370bcc2f2 100644 --- a/tests/phpunit/modules/core/output_modules.php +++ b/tests/phpunit/modules/core/output_modules.php @@ -1139,6 +1139,6 @@ public function test_message_list_heading() { public function test_message_list_end() { $test = new Output_Test('message_list_end', 'core'); $res = $test->run(); - $this->assertEquals(array('</tbody></table></div><div class="mb-5 page_links d-flex justify-content-center gap-3 align-content-center"></div></div>'), $res->output_response); + $this->assertEquals(array('</tbody></table></div></div>'), $res->output_response); } }