From b23960e8d7139338a253f23ae9ba1ed8499d3618 Mon Sep 17 00:00:00 2001 From: Baris Soner Usakli Date: Fri, 24 Jan 2014 23:05:59 -0500 Subject: [PATCH] fixes to category pagination --- public/src/forum/category.js | 6 ++++++ public/src/forum/pagination.js | 14 ++++++++++---- public/src/forum/topic.js | 2 +- public/templates/category.tpl | 1 + src/socket.io/categories.js | 7 ++++--- 5 files changed, 22 insertions(+), 8 deletions(-) diff --git a/public/src/forum/category.js b/public/src/forum/category.js index d995aaf8d9..aa6b25dd79 100644 --- a/public/src/forum/category.js +++ b/public/src/forum/category.js @@ -104,7 +104,12 @@ define(['composer', 'forum/pagination'], function(composer, pagination) { addActiveUser(data); + socket.emit('categories.getPageCount', templates.get('category_id'), function(err, newPageCount) { + pagination.recreatePaginationLinks('category', newPageCount); + }); + $('#topics-container span.timeago').timeago(); + app.createUserTooltips(); }); } @@ -143,6 +148,7 @@ define(['composer', 'forum/pagination'], function(composer, pagination) { } $('#topics-container span.timeago').timeago(); + app.createUserTooltips(); app.makeNumbersHumanReadable(html.find('.human-readable-number')); }); } diff --git a/public/src/forum/pagination.js b/public/src/forum/pagination.js index 4ebc89e313..d7e9abc965 100644 --- a/public/src/forum/pagination.js +++ b/public/src/forum/pagination.js @@ -27,15 +27,15 @@ define(function() { }); } - pagination.recreatePaginationLinks = function(newPageCount) { - pagination.pageCount = parseInt(newPageCount); + pagination.recreatePaginationLinks = function(template, newPageCount) { + pagination.pageCount = parseInt(newPageCount, 10); var pages = []; - for(var i=1; i<=pagination.page; ++i) { + for(var i=1; i<=pagination.pageCount; ++i) { pages.push({pageNumber: i}); } - var html = templates.prepare(templates['topic'].blocks['pages']).parse({pages:pages}); + var html = templates.prepare(templates[template].blocks['pages']).parse({pages:pages}); html = $(html); $('.pagination li.page').remove(); html.insertAfter($('.pagination li.previous')); @@ -60,6 +60,12 @@ define(function() { function updatePageLinks() { + if(pagination.pageCount === 0) { + $('.pagination').addClass('hide'); + } else { + $('.pagination').removeClass('hide'); + } + $('.pagination .next').removeClass('disabled'); $('.pagination .previous').removeClass('disabled'); diff --git a/public/src/forum/topic.js b/public/src/forum/topic.js index 9f18bd247e..60ab01ce92 100644 --- a/public/src/forum/topic.js +++ b/public/src/forum/topic.js @@ -387,7 +387,7 @@ define(['composer', 'forum/pagination'], function(composer, pagination) { var posts = data.posts; socket.emit('topics.getPageCount', tid, function(err, newPageCount) { - pagination.recreatePaginationLinks(newPageCount); + pagination.recreatePaginationLinks('topic', newPageCount); if(pagination.currentPage === pagination.newPageCount) { createNewPosts(data); diff --git a/public/templates/category.tpl b/public/templates/category.tpl index 6bbd2a5ae7..81727bd042 100644 --- a/public/templates/category.tpl +++ b/public/templates/category.tpl @@ -96,6 +96,7 @@ +
[[category:sidebar.recent_replies]]
diff --git a/src/socket.io/categories.js b/src/socket.io/categories.js index b664114cdc..ec663ee8e6 100644 --- a/src/socket.io/categories.js +++ b/src/socket.io/categories.js @@ -38,14 +38,15 @@ SocketCategories.loadPage = function(socket, data, callback) { var start = (data.page - 1) * topicsPerPage, end = start + topicsPerPage - 1; - console.log('start to end' ,start, end); - categories.getCategoryTopics(data.cid, start, end, socket.uid, function(err, topics) { - console.log('getting topics', topics.length); callback(err, { topics: topics }); }); } +SocketCategories.getPageCount = function(socket, cid, callback) { + categories.getPageCount(cid, callback); +} + module.exports = SocketCategories; \ No newline at end of file