lots of pagination work, query params, ajaxify to pids

This commit is contained in:
Baris Soner Usakli
2014-01-25 19:19:25 -05:00
parent 8744013013
commit 1084523c92
13 changed files with 144 additions and 164 deletions

View File

@@ -468,4 +468,28 @@ var db = require('./database'),
});
}
Posts.getPidPage = function(pid, callback) {
Posts.getPostField(pid, 'tid', function(err, tid) {
if(err) {
return callback(err);
}
topics.getPids(tid, function(err, pids) {
if(err) {
return callback(err);
}
var index = pids.indexOf(pid);
if(index === -1) {
return callback(new Error('pid not found'));
}
var postsPerPage = parseInt(meta.config.postsPerPage, 10);
postsPerPage = postsPerPage ? postsPerPage : 20;
var page = Math.ceil((index + 1) / postsPerPage);
callback(null, page);
});
});
}
}(exports));