Skip to content

Node.js based forum software built for the modern web

some pagination work

Baris Soner Usaklicf39c660173a
diff --git a/public/src/app.js b/public/src/app.js
index bc583e2b17..c6ad9c7305 100644
--- a/public/src/app.js
+++ b/public/src/app.js
@@ -528,6 +528,10 @@ var socket,
});
templates.setGlobal('relative_path', RELATIVE_PATH);
+ templates.setGlobal('usePagination', config.usePagination);
+ templates.setGlobal('topicsPerPage', config.topicsPerPage);
+ templates.setGlobal('postsPerPage', config.postsPerPage);
+ console.log(templates.globals);
});
showWelcomeMessage = location.href.indexOf('loggedin') !== -1;
diff --git a/public/src/forum/topic.js b/public/src/forum/topic.js
index a48d8c82cf..62ded4c4ce 100644
--- a/public/src/forum/topic.js
+++ b/public/src/forum/topic.js
@@ -355,15 +355,27 @@ define(['composer'], function(composer) {
});
function enableInfiniteLoading() {
- $(window).off('scroll').on('scroll', function() {
- var bottom = ($(document).height() - $(window).height()) * 0.9;
+ if(!config.usePagination) {
+ $(window).off('scroll').on('scroll', function() {
+ var bottom = ($(document).height() - $(window).height()) * 0.9;
- if ($(window).scrollTop() > bottom && !infiniteLoaderActive && $('#post-container').children().length) {
- loadMorePosts(tid, function(posts) {
- fixDeleteStateForPosts();
- });
- }
- });
+ if ($(window).scrollTop() > bottom && !infiniteLoaderActive && $('#post-container').children().length) {
+ loadMorePosts(tid, function(posts) {
+ fixDeleteStateForPosts();
+ });
+ }
+ });
+ } else {
+ $('.pagination .previous').on('click', function() {
+
+ return false;
+ });
+
+ $('.pagination .next').on('click', function() {
+
+ return false;
+ });
+ }
}
$('.topic').on('click', '.post_reply', function() {
diff --git a/public/templates/admin/settings.tpl b/public/templates/admin/settings.tpl
index 8ddd896da9..3601f7c2ca 100644
--- a/public/templates/admin/settings.tpl
+++ b/public/templates/admin/settings.tpl
@@ -7,6 +7,7 @@
<li><a href="#email" data-toggle="tab">Email</a></li>
<li><a href="#user" data-toggle="tab">User</a></li>
<li><a href="#post" data-toggle="tab">Post</a></li>
+ <li><a href="#pagination" data-toggle="tab">Pagination</a></li>
<li><a href="#web-crawler" data-toggle="tab">Web Crawler</a></li>
</ul>
@@ -133,6 +134,21 @@
</form>
</div>
+ <div class="tab-pane" id="pagination">
+ <form>
+ <div class="alert alert-warning">
+ <div class="checkbox">
+ <label>
+ <input type="checkbox" data-field="usePagination"> <strong>Paginate topics and posts instead of using infinite scroll.</strong>
+ </label>
+ </div>
+
+ <strong>Topics per Page</strong><br /> <input type="text" class="form-control" value="20" data-field="topicsPerPage"><br />
+ <strong>Posts per Page</strong><br /> <input type="text" class="form-control" value="20" data-field="postsPerPage"><br />
+ </div>
+ </form>
+ </div>
+
<div class="tab-pane" id="web-crawler">
<form>
<div class="alert alert-warning">
diff --git a/public/templates/topic.tpl b/public/templates/topic.tpl
index ec72ff958b..1aabe3c8c0 100644
--- a/public/templates/topic.tpl
+++ b/public/templates/topic.tpl
@@ -201,6 +201,13 @@
<div style="clear:both;"></div>
</div>
+ <!-- {usePagination} -->
+ <ul class="pager">
+ <li class="previous"><a href="#">&larr; Older</a></li>
+ <li class="next"><a href="#">Newer &rarr;</a></li>
+ </ul>
+ <!-- {usePagination} -->
+
<div id="move_thread_modal" class="modal" tabindex="-1" role="dialog" aria-labelledby="Move Topic" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
diff --git a/src/routes/api.js b/src/routes/api.js
index 78c7e6f8ac..3d1fb270df 100644
--- a/src/routes/api.js
+++ b/src/routes/api.js
@@ -42,6 +42,9 @@ var path = require('path'),
config.useOutgoingLinksPage = parseInt(meta.config.useOutgoingLinksPage, 10) === 1;
config.allowGuestPosting = parseInt(meta.config.allowGuestPosting, 10) === 1;
config.allowFileUploads = parseInt(meta.config.allowFileUploads, 10) === 1;
+ config.usePagination = parseInt(meta.config.usePagination, 10) === 1;
+ config.topicsPerPage = meta.config.topicsPerPage || 20;
+ config.postsPerPage = meta.config.postsPerPage || 20;
config.maximumFileSize = meta.config.maximumFileSize;
config.emailSetup = !!meta.config['email:from'];
config.defaultLang = meta.config.defaultLang || 'en';
@@ -161,20 +164,23 @@ var path = require('path'),
});
app.get('/topic/:id/:slug?', function (req, res, next) {
+ console.log(req.query);
var uid = (req.user) ? req.user.uid : 0;
ThreadTools.privileges(req.params.id, uid, function(err, privileges) {
if (privileges.read) {
- topics.getTopicWithPosts(req.params.id, uid, 0, 10, false, function (err, data) {
- if (!err) {
- // Send in privilege data as well
- data.privileges = privileges;
+ var postsPerPage = meta.config.postsPerPage ? (meta.config.postsPerPage - 1) : 20;
+ topics.getTopicWithPosts(req.params.id, uid, 0, postsPerPage, false, function (err, data) {
+ if(err) {
+ return next(err);
+ }
- if (parseInt(data.deleted, 10) === 1 && parseInt(data.expose_tools, 10) === 0) {
- return res.json(404, {});
- }
+ data.privileges = privileges;
- res.json(data);
- } else next();
+ if (parseInt(data.deleted, 10) === 1 && parseInt(data.expose_tools, 10) === 0) {
+ return res.json(404, {});
+ }
+
+ res.json(data);
});
} else {
res.send(403);