From 18d312189c1fb8214ce88ee95847d6857e4e7722 Mon Sep 17 00:00:00 2001 From: tomoya Date: Wed, 15 Jun 2016 15:38:51 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AF=9D=E9=A2=98=E8=AF=A6=E6=83=85=E5=9B=9E?= =?UTF-8?q?=E5=A4=8D=E5=88=97=E8=A1=A8=E5=A2=9E=E5=8A=A0=E5=88=86=E9=A1=B5?= =?UTF-8?q?=20=E9=BB=98=E8=AE=A4=E8=BF=9B=E5=85=A5=E6=9F=A5=E8=AF=A2?= =?UTF-8?q?=E5=9B=9E=E5=A4=8D=E5=88=97=E8=A1=A8=E6=9C=80=E5=90=8E=E4=B8=80?= =?UTF-8?q?=E9=A1=B5=E7=9A=84=E5=86=85=E5=AE=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config.default.js | 2 + controllers/topic.js | 284 ++++++++++++++++++++------------- proxy/reply.js | 95 +++++++---- proxy/topic.js | 10 +- views/index.html | 9 +- views/topic/index.html | 162 ++++++++++--------- views/topic/list.html | 55 +------ views/topic/paginate.html | 53 ++++++ views/user/collect_topics.html | 9 +- views/user/replies.html | 9 +- views/user/topics.html | 9 +- 11 files changed, 412 insertions(+), 285 deletions(-) create mode 100644 views/topic/paginate.html diff --git a/config.default.js b/config.default.js index ac403fbd3e..1fcb4a98e2 100644 --- a/config.default.js +++ b/config.default.js @@ -50,6 +50,8 @@ var config = { // 话题列表显示的话题数量 list_topic_count: 20, + // 话题详情里的回复每页显示条数 + list_reply_count: 20, // RSS配置 rss: { diff --git a/controllers/topic.js b/controllers/topic.js index cb28a2d422..1b09e3a029 100644 --- a/controllers/topic.js +++ b/controllers/topic.js @@ -8,16 +8,17 @@ var validator = require('validator'); -var at = require('../common/at'); -var User = require('../proxy').User; -var Topic = require('../proxy').Topic; +var at = require('../common/at'); +var User = require('../proxy').User; +var Topic = require('../proxy').Topic; +var Reply = require('../proxy').Reply; var TopicCollect = require('../proxy').TopicCollect; -var EventProxy = require('eventproxy'); -var tools = require('../common/tools'); -var store = require('../common/store'); -var config = require('../config'); -var _ = require('lodash'); -var cache = require('../common/cache'); +var EventProxy = require('eventproxy'); +var tools = require('../common/tools'); +var store = require('../common/store'); +var config = require('../config'); +var _ = require('lodash'); +var cache = require('../common/cache'); var logger = require('../common/logger') /** @@ -27,7 +28,7 @@ var logger = require('../common/logger') * @param {HttpResponse} res * @param {Function} next */ -exports.index = function (req, res, next) { +exports.index = function(req, res, next) { function isUped(user, reply) { if (!reply.ups) { return false; @@ -37,39 +38,43 @@ exports.index = function (req, res, next) { var topic_id = req.params.tid; var currentUser = req.session.user; + var page = req.query.page; if (topic_id.length !== 24) { return res.render404('此话题不存在或已被删除。'); } - var events = ['topic', 'other_topics', 'no_reply_topics', 'is_collect']; + var events = ['topic', 'other_topics', 'no_reply_topics', 'is_collect', 'pages']; var ep = EventProxy.create(events, - function (topic, other_topics, no_reply_topics, is_collect) { - res.render('topic/index', { - topic: topic, - author_other_topics: other_topics, - no_reply_topics: no_reply_topics, - is_uped: isUped, - is_collect: is_collect, + function(topic, other_topics, no_reply_topics, is_collect, pages) { + console.log(1, pages, page); + res.render('topic/index', { + topic: topic, + author_other_topics: other_topics, + no_reply_topics: no_reply_topics, + is_uped: isUped, + is_collect: is_collect, + pages: pages, + current_page: page ? page : pages + }); }); - }); ep.fail(next); - Topic.getFullTopic(topic_id, ep.done(function (message, topic, author, replies) { + Topic.getFullTopic(topic_id, page, ep.done(function(message, topic, author, replies) { if (message) { - logger.error('getFullTopic error topic_id: ' + topic_id) + logger.error('getFullTopic error topic_id: ' + topic_id); return res.renderError(message); } topic.visit_count += 1; topic.save(); - topic.author = author; + topic.author = author; topic.replies = replies; // 点赞数排名第三的回答,它的点赞数就是阈值 - topic.reply_up_threshold = (function () { - var allUpCount = replies.map(function (reply) { + topic.reply_up_threshold = (function() { + var allUpCount = replies.map(function(reply) { return reply.ups && reply.ups.length || 0; }); allUpCount = _.sortBy(allUpCount, Number).reverse(); @@ -84,24 +89,43 @@ exports.index = function (req, res, next) { ep.emit('topic', topic); // get other_topics - var options = { limit: 5, sort: '-last_reply_at'}; - var query = { author_id: topic.author_id, _id: { '$nin': [ topic._id ] } }; + var options = { + limit: 5, + sort: '-last_reply_at' + }; + var query = { + author_id: topic.author_id, + _id: { + '$nin': [topic._id] + } + }; Topic.getTopicsByQuery(query, options, ep.done('other_topics')); // get no_reply_topics - cache.get('no_reply_topics', ep.done(function (no_reply_topics) { + cache.get('no_reply_topics', ep.done(function(no_reply_topics) { if (no_reply_topics) { ep.emit('no_reply_topics', no_reply_topics); } else { - Topic.getTopicsByQuery( - { reply_count: 0, tab: {$ne: 'job'}}, - { limit: 5, sort: '-create_at'}, - ep.done('no_reply_topics', function (no_reply_topics) { + Topic.getTopicsByQuery({ + reply_count: 0, + tab: { + $ne: 'job' + } + }, { + limit: 5, + sort: '-create_at' + }, + ep.done('no_reply_topics', function(no_reply_topics) { cache.set('no_reply_topics', no_reply_topics, 60 * 1); return no_reply_topics; })); } })); + + Reply.getCountByTopicId(topic_id, ep.done('pages', function (count) { + var pages = Math.ceil(count / config.list_reply_count); + return pages; + })); })); if (!currentUser) { @@ -111,20 +135,20 @@ exports.index = function (req, res, next) { } }; -exports.create = function (req, res, next) { +exports.create = function(req, res, next) { res.render('topic/edit', { tabs: config.tabs }); }; -exports.put = function (req, res, next) { - var title = validator.trim(req.body.title); - var tab = validator.trim(req.body.tab); +exports.put = function(req, res, next) { + var title = validator.trim(req.body.title); + var tab = validator.trim(req.body.tab); var content = validator.trim(req.body.t_content); // 得到所有的 tab, e.g. ['ask', 'share', ..] - var allTabs = config.tabs.map(function (tPair) { + var allTabs = config.tabs.map(function(tPair) { return tPair[0]; }); @@ -151,18 +175,18 @@ exports.put = function (req, res, next) { }); } - Topic.newAndSave(title, content, tab, req.session.user._id, function (err, topic) { + Topic.newAndSave(title, content, tab, req.session.user._id, function(err, topic) { if (err) { return next(err); } var proxy = new EventProxy(); - proxy.all('score_saved', function () { + proxy.all('score_saved', function() { res.redirect('/topic/' + topic._id); }); proxy.fail(next); - User.getUserById(req.session.user._id, proxy.done(function (user) { + User.getUserById(req.session.user._id, proxy.done(function(user) { user.score += 5; user.topic_count += 1; user.save(); @@ -175,10 +199,10 @@ exports.put = function (req, res, next) { }); }; -exports.showEdit = function (req, res, next) { +exports.showEdit = function(req, res, next) { var topic_id = req.params.tid; - Topic.getTopicById(topic_id, function (err, topic, tags) { + Topic.getTopicById(topic_id, function(err, topic, tags) { if (!topic) { res.render404('此话题不存在或已被删除。'); return; @@ -199,21 +223,21 @@ exports.showEdit = function (req, res, next) { }); }; -exports.update = function (req, res, next) { +exports.update = function(req, res, next) { var topic_id = req.params.tid; - var title = req.body.title; - var tab = req.body.tab; - var content = req.body.t_content; + var title = req.body.title; + var tab = req.body.tab; + var content = req.body.t_content; - Topic.getTopicById(topic_id, function (err, topic, tags) { + Topic.getTopicById(topic_id, function(err, topic, tags) { if (!topic) { res.render404('此话题不存在或已被删除。'); return; } if (topic.author_id.equals(req.session.user._id) || req.session.user.is_admin) { - title = validator.trim(title); - tab = validator.trim(tab); + title = validator.trim(title); + tab = validator.trim(tab); content = validator.trim(content); // 验证 @@ -238,12 +262,12 @@ exports.update = function (req, res, next) { } //保存话题 - topic.title = title; - topic.content = content; - topic.tab = tab; + topic.title = title; + topic.content = content; + topic.tab = tab; topic.update_at = new Date(); - topic.save(function (err) { + topic.save(function(err) { if (err) { return next(err); } @@ -259,45 +283,60 @@ exports.update = function (req, res, next) { }); }; -exports.delete = function (req, res, next) { +exports.delete = function(req, res, next) { //删除话题, 话题作者topic_count减1 //删除回复,回复作者reply_count减1 //删除topic_collect,用户collect_topic_count减1 var topic_id = req.params.tid; - Topic.getTopic(topic_id, function (err, topic) { + Topic.getTopic(topic_id, function(err, topic) { if (err) { - return res.send({ success: false, message: err.message }); + return res.send({ + success: false, + message: err.message + }); } if (!req.session.user.is_admin && !(topic.author_id.equals(req.session.user._id))) { res.status(403); - return res.send({success: false, message: '无权限'}); + return res.send({ + success: false, + message: '无权限' + }); } if (!topic) { res.status(422); - return res.send({ success: false, message: '此话题不存在或已被删除。' }); + return res.send({ + success: false, + message: '此话题不存在或已被删除。' + }); } topic.deleted = true; - topic.save(function (err) { + topic.save(function(err) { if (err) { - return res.send({ success: false, message: err.message }); + return res.send({ + success: false, + message: err.message + }); } - res.send({ success: true, message: '话题已被删除。' }); + res.send({ + success: true, + message: '话题已被删除。' + }); }); }); }; // 设为置顶 -exports.top = function (req, res, next) { +exports.top = function(req, res, next) { var topic_id = req.params.tid; - var referer = req.get('referer'); + var referer = req.get('referer'); if (topic_id.length !== 24) { res.render404('此话题不存在或已被删除。'); return; } - Topic.getTopic(topic_id, function (err, topic) { + Topic.getTopic(topic_id, function(err, topic) { if (err) { return next(err); } @@ -306,22 +345,25 @@ exports.top = function (req, res, next) { return; } topic.top = !topic.top; - topic.save(function (err) { + topic.save(function(err) { if (err) { return next(err); } var msg = topic.top ? '此话题已置顶。' : '此话题已取消置顶。'; - res.render('notify/notify', {success: msg, referer: referer}); + res.render('notify/notify', { + success: msg, + referer: referer + }); }); }); }; // 设为精华 -exports.good = function (req, res, next) { +exports.good = function(req, res, next) { var topicId = req.params.tid; var referer = req.get('referer'); - Topic.getTopic(topicId, function (err, topic) { + Topic.getTopic(topicId, function(err, topic) { if (err) { return next(err); } @@ -330,21 +372,24 @@ exports.good = function (req, res, next) { return; } topic.good = !topic.good; - topic.save(function (err) { + topic.save(function(err) { if (err) { return next(err); } var msg = topic.good ? '此话题已加精。' : '此话题已取消加精。'; - res.render('notify/notify', {success: msg, referer: referer}); + res.render('notify/notify', { + success: msg, + referer: referer + }); }); }); }; // 锁定主题,不可再回复 -exports.lock = function (req, res, next) { +exports.lock = function(req, res, next) { var topicId = req.params.tid; var referer = req.get('referer'); - Topic.getTopic(topicId, function (err, topic) { + Topic.getTopic(topicId, function(err, topic) { if (err) { return next(err); } @@ -353,44 +398,53 @@ exports.lock = function (req, res, next) { return; } topic.lock = !topic.lock; - topic.save(function (err) { + topic.save(function(err) { if (err) { return next(err); } var msg = topic.lock ? '此话题已锁定。' : '此话题已取消锁定。'; - res.render('notify/notify', {success: msg, referer: referer}); + res.render('notify/notify', { + success: msg, + referer: referer + }); }); }); }; // 收藏主题 -exports.collect = function (req, res, next) { +exports.collect = function(req, res, next) { var topic_id = req.body.topic_id; - Topic.getTopic(topic_id, function (err, topic) { + Topic.getTopic(topic_id, function(err, topic) { if (err) { return next(err); } if (!topic) { - res.json({status: 'failed'}); + res.json({ + status: 'failed' + }); } - TopicCollect.getTopicCollect(req.session.user._id, topic._id, function (err, doc) { + TopicCollect.getTopicCollect(req.session.user._id, topic._id, function(err, doc) { if (err) { return next(err); } if (doc) { - res.json({status: 'failed'}); + res.json({ + status: 'failed' + }); return; } - TopicCollect.newAndSave(req.session.user._id, topic._id, function (err) { + TopicCollect.newAndSave(req.session.user._id, topic._id, function(err) { if (err) { return next(err); } - res.json({status: 'success'}); + res.json({ + status: 'success' + }); }); - User.getUserById(req.session.user._id, function (err, user) { + User.getUserById(req.session.user._id, function(err, user) { if (err) { return next(err); } @@ -405,24 +459,28 @@ exports.collect = function (req, res, next) { }); }; -exports.de_collect = function (req, res, next) { +exports.de_collect = function(req, res, next) { var topic_id = req.body.topic_id; - Topic.getTopic(topic_id, function (err, topic) { + Topic.getTopic(topic_id, function(err, topic) { if (err) { return next(err); } if (!topic) { - res.json({status: 'failed'}); + res.json({ + status: 'failed' + }); } - TopicCollect.remove(req.session.user._id, topic._id, function (err, removeResult) { + TopicCollect.remove(req.session.user._id, topic._id, function(err, removeResult) { if (err) { return next(err); } if (removeResult.result.n == 0) { - return res.json({status: 'failed'}) + return res.json({ + status: 'failed' + }) } - User.getUserById(req.session.user._id, function (err, user) { + User.getUserById(req.session.user._id, function(err, user) { if (err) { return next(err); } @@ -434,37 +492,41 @@ exports.de_collect = function (req, res, next) { topic.collect_count -= 1; topic.save(); - res.json({status: 'success'}); + res.json({ + status: 'success' + }); }); }); }; -exports.upload = function (req, res, next) { +exports.upload = function(req, res, next) { var isFileLimit = false; - req.busboy.on('file', function (fieldname, file, filename, encoding, mimetype) { - file.on('limit', function () { - isFileLimit = true; - - res.json({ - success: false, - msg: 'File size too large. Max is ' + config.file_limit - }) - }); + req.busboy.on('file', function(fieldname, file, filename, encoding, mimetype) { + file.on('limit', function() { + isFileLimit = true; + + res.json({ + success: false, + msg: 'File size too large. Max is ' + config.file_limit + }) + }); - store.upload(file, {filename: filename}, function (err, result) { - if (err) { - return next(err); - } - if (isFileLimit) { - return; - } - res.json({ - success: true, - url: result.url, - }); + store.upload(file, { + filename: filename + }, function(err, result) { + if (err) { + return next(err); + } + if (isFileLimit) { + return; + } + res.json({ + success: true, + url: result.url, }); - }); + }); + req.pipe(req.busboy); -}; +}; \ No newline at end of file diff --git a/proxy/reply.js b/proxy/reply.js index 5e95d45411..aec590d975 100644 --- a/proxy/reply.js +++ b/proxy/reply.js @@ -1,17 +1,20 @@ -var models = require('../models'); -var Reply = models.Reply; +var models = require('../models'); +var Reply = models.Reply; var EventProxy = require('eventproxy'); -var tools = require('../common/tools'); -var User = require('./user'); -var at = require('../common/at'); +var tools = require('../common/tools'); +var User = require('./user'); +var at = require('../common/at'); +var config = require('../config'); /** * 获取一条回复信息 * @param {String} id 回复ID * @param {Function} callback 回调函数 */ -exports.getReply = function (id, callback) { - Reply.findOne({_id: id}, callback); +exports.getReply = function(id, callback) { + Reply.findOne({ + _id: id + }, callback); }; /** @@ -22,11 +25,13 @@ exports.getReply = function (id, callback) { * @param {String} id 回复ID * @param {Function} callback 回调函数 */ -exports.getReplyById = function (id, callback) { +exports.getReplyById = function(id, callback) { if (!id) { return callback(null, null); } - Reply.findOne({_id: id}, function (err, reply) { + Reply.findOne({ + _id: id + }, function(err, reply) { if (err) { return callback(err); } @@ -35,7 +40,7 @@ exports.getReplyById = function (id, callback) { } var author_id = reply.author_id; - User.getUserById(author_id, function (err, author) { + User.getUserById(author_id, function(err, author) { if (err) { return callback(err); } @@ -44,7 +49,7 @@ exports.getReplyById = function (id, callback) { if (reply.content_is_html) { return callback(null, reply); } - at.linkUsers(reply.content, function (err, str) { + at.linkUsers(reply.content, function(err, str) { if (err) { return callback(err); } @@ -63,8 +68,15 @@ exports.getReplyById = function (id, callback) { * @param {String} id 主题ID * @param {Function} callback 回调函数 */ -exports.getRepliesByTopicId = function (id, cb) { - Reply.find({topic_id: id, deleted: false}, '', {sort: 'create_at'}, function (err, replies) { +exports.getRepliesByTopicId = function(id, page, cb) { + Reply.find({ + topic_id: id, + deleted: false + }, '', { + sort: 'create_at', + limit: config.list_reply_count, + skip: (page - 1) * config.list_reply_count + }, function(err, replies) { if (err) { return cb(err); } @@ -73,21 +85,23 @@ exports.getRepliesByTopicId = function (id, cb) { } var proxy = new EventProxy(); - proxy.after('reply_find', replies.length, function () { + proxy.after('reply_find', replies.length, function() { cb(null, replies); }); for (var j = 0; j < replies.length; j++) { - (function (i) { + (function(i) { var author_id = replies[i].author_id; - User.getUserById(author_id, function (err, author) { + User.getUserById(author_id, function(err, author) { if (err) { return cb(err); } - replies[i].author = author || { _id: '' }; + replies[i].author = author || { + _id: '' + }; if (replies[i].content_is_html) { return proxy.emit('reply_find'); } - at.linkUsers(replies[i].content, function (err, str) { + at.linkUsers(replies[i].content, function(err, str) { if (err) { return cb(err); } @@ -108,20 +122,20 @@ exports.getRepliesByTopicId = function (id, cb) { * @param {String} [replyId] 回复ID,当二级回复时设定该值 * @param {Function} callback 回调函数 */ -exports.newAndSave = function (content, topicId, authorId, replyId, callback) { +exports.newAndSave = function(content, topicId, authorId, replyId, callback) { if (typeof replyId === 'function') { callback = replyId; - replyId = null; + replyId = null; } - var reply = new Reply(); - reply.content = content; - reply.topic_id = topicId; + var reply = new Reply(); + reply.content = content; + reply.topic_id = topicId; reply.author_id = authorId; if (replyId) { reply.reply_id = replyId; } - reply.save(function (err) { + reply.save(function(err) { callback(err, reply); }); }; @@ -131,19 +145,38 @@ exports.newAndSave = function (content, topicId, authorId, replyId, callback) { * @param topicId 主题ID * @param callback 回调函数 */ -exports.getLastReplyByTopId = function (topicId, callback) { - Reply.find({topic_id: topicId, deleted: false}, '_id', {sort: {create_at : -1}, limit : 1}, callback); +exports.getLastReplyByTopId = function(topicId, callback) { + Reply.find({ + topic_id: topicId, + deleted: false + }, '_id', { + sort: { + create_at: -1 + }, + limit: 1 + }, callback); }; -exports.getRepliesByAuthorId = function (authorId, opt, callback) { +exports.getRepliesByAuthorId = function(authorId, opt, callback) { if (!callback) { callback = opt; - opt = null; + opt = null; } - Reply.find({author_id: authorId}, {}, opt, callback); + Reply.find({ + author_id: authorId + }, {}, opt, callback); }; // 通过 author_id 获取回复总数 -exports.getCountByAuthorId = function (authorId, callback) { - Reply.count({author_id: authorId}, callback); +exports.getCountByAuthorId = function(authorId, callback) { + Reply.count({ + author_id: authorId + }, callback); }; + +// 通过 author_id 获取回复总数 +exports.getCountByTopicId = function(topicId, callback) { + Reply.count({ + topic_id: topicId + }, callback); +}; \ No newline at end of file diff --git a/proxy/topic.js b/proxy/topic.js index bdcad967d1..b37eb4e553 100644 --- a/proxy/topic.js +++ b/proxy/topic.js @@ -6,6 +6,7 @@ var Reply = require('./reply'); var tools = require('../common/tools'); var at = require('../common/at'); var _ = require('lodash'); +var config = require('../config.js'); /** @@ -124,7 +125,7 @@ exports.getLimit5w = function (callback) { * @param {String} id 主题ID * @param {Function} callback 回调函数 */ -exports.getFullTopic = function (id, callback) { +exports.getFullTopic = function (id, page, callback) { var proxy = new EventProxy(); var events = ['topic', 'author', 'replies']; proxy @@ -150,8 +151,11 @@ exports.getFullTopic = function (id, callback) { } proxy.emit('author', author); })); - - Reply.getRepliesByTopicId(topic._id, proxy.done('replies')); + Reply.getCountByTopicId(id, function (err, count) { + var _page = page ? page : Math.ceil(count / config.list_reply_count); + _page = _page == 0 ? 1 : _page; + Reply.getRepliesByTopicId(id, _page, proxy.done('replies')); + }); })); }; diff --git a/views/index.html b/views/index.html index 9178562501..5a4b6558bf 100644 --- a/views/index.html +++ b/views/index.html @@ -13,10 +13,11 @@ <% if (typeof(topics) !== 'undefined' && topics.length > 0) { %>
<%- partial('topic/list', { - topics: topics, - pages: pages, - current_page: current_page, - base: '/' + topics: topics, + pages: pages, + current_page: current_page, + base: '/', + param: 'tab=' + tab !== 'undefined' ? tab : '' }) %>
<% } else { %> diff --git a/views/topic/index.html b/views/topic/index.html index 860d2cd562..5ee610550e 100644 --- a/views/topic/index.html +++ b/views/topic/index.html @@ -9,7 +9,7 @@ <% if (!current_user || !current_user.isAdvanced) { %> - <%- partial('../_ads') %> + <%- partial('../_ads') %> <% } %>
@@ -68,58 +68,59 @@ <% } %> <% if (topic.tab) { %> - 来自 <%= topic.tabName %> + 来自 <%= topic.tabName %> <%}%> <% if (current_user) { %> - + <%}%>
<% if (current_user) { %>
<% if (current_user.is_admin) { %> - - <% if (topic.top) { %> - - <% } else { %> - - <% } %> - - - - - <% if (topic.good) { %> - - <% } else { %> - - <% } %> - - - - <% if (topic.lock) { %> - - <% } else { %> - - <% } %> - - - - - - - + + <% if (topic.top) { %> + <% } else { %> - <% if (current_user._id.equals(topic.author_id)) { %> - - - - + <% } %> + + + + + <% if (topic.good) { %> + + <% } else { %> + + <% } %> + + + + <% if (topic.lock) { %> + + <% } else { %> + + <% } %> + + + + + + + + <% } else { %> + <% if (current_user._id.equals(topic.author_id)) { %> + + + + + <% } %> <% } %> @@ -138,7 +139,15 @@
<%= topic.replies.length %> 回复
- <%- partial('../reply/reply', topic.replies) %> +
+ <%- partial('../reply/reply', topic.replies) %> + <%- partial('./paginate', { + pages: pages, + current_page: current_page, + base: '/topic/' + topic._id, + param: '' + }) %> +
<% } %> <% if (current_user && typeof(topic) !== 'undefined') { %> @@ -154,7 +163,8 @@
- > + >
@@ -194,7 +204,7 @@ // END 获取所有回复者name // 编辑器相关 - $('textarea.editor').each(function(){ + $('textarea.editor').each(function () { var editor = new Editor({ status: [] }); @@ -205,7 +215,7 @@ $(this).data('editor', editor); var $input = $(editor.codemirror.display.input); - $input.keydown(function(event){ + $input.keydown(function (event) { if (event.keyCode === 13 && (event.ctrlKey || event.metaKey)) { event.preventDefault(); $el.closest('form').submit(); @@ -217,19 +227,19 @@ var codeMirrorGoLineDown = CodeMirror.commands.goLineDown; var codeMirrorNewlineAndIndent = CodeMirror.commands.newlineAndIndent; $input.atwho({ - at: '@', - data: allNames - }) - .on('shown.atwho', function () { - CodeMirror.commands.goLineUp = _.noop; - CodeMirror.commands.goLineDown = _.noop; - CodeMirror.commands.newlineAndIndent = _.noop; - }) - .on('hidden.atwho', function () { - CodeMirror.commands.goLineUp = codeMirrorGoLineUp; - CodeMirror.commands.goLineDown = codeMirrorGoLineDown; - CodeMirror.commands.newlineAndIndent = codeMirrorNewlineAndIndent; - }); + at: '@', + data: allNames + }) + .on('shown.atwho', function () { + CodeMirror.commands.goLineUp = _.noop; + CodeMirror.commands.goLineDown = _.noop; + CodeMirror.commands.newlineAndIndent = _.noop; + }) + .on('hidden.atwho', function () { + CodeMirror.commands.goLineUp = codeMirrorGoLineUp; + CodeMirror.commands.goLineDown = codeMirrorGoLineDown; + CodeMirror.commands.newlineAndIndent = codeMirrorNewlineAndIndent; + }); // END at.js 配置 }); @@ -247,7 +257,7 @@ editorWrap.show('fast', function () { var cm = editor.codemirror; cm.focus(); - if(cm.getValue().indexOf('@' + user) < 0){ + if (cm.getValue().indexOf('@' + user) < 0) { editor.push('@' + user + ' '); } }); @@ -263,7 +273,7 @@ editorWrap.show('fast', function () { var cm = editor.codemirror; cm.focus(); - if(cm.getValue().indexOf('@' + user) < 0){ + if (cm.getValue().indexOf('@' + user) < 0) { editor.push('@' + user + ' '); } }); @@ -328,7 +338,7 @@ $('.delete_topic_btn').click(function () { var topicId = $(this).data('id'); if (topicId && confirm('确定要删除此话题吗?')) { - $.post('/topic/' + topicId + '/delete', { _csrf: $('#_csrf').val() }, function (result) { + $.post('/topic/' + topicId + '/delete', {_csrf: $('#_csrf').val()}, function (result) { if (!result.success) { alert(result.message); } else { @@ -360,7 +370,7 @@ <% } %> +<%- partial('../topic/paginate') %> diff --git a/views/topic/paginate.html b/views/topic/paginate.html new file mode 100644 index 0000000000..3fd67bed36 --- /dev/null +++ b/views/topic/paginate.html @@ -0,0 +1,53 @@ + + \ No newline at end of file diff --git a/views/user/collect_topics.html b/views/user/collect_topics.html index 6496c3f0b5..c6143a612c 100644 --- a/views/user/collect_topics.html +++ b/views/user/collect_topics.html @@ -10,8 +10,13 @@
<% if (topics.length > 0) { %> - <%- partial('../topic/list', { topics: topics, pages: pages, current_pages: current_page, base: '/user/' + - user.loginname + '/collections' }) %> + <%- partial('../topic/list', { + topics: topics, + pages: pages, + current_pages: current_page, + base: '/user/' + user.loginname + '/collections', + param: '' + }) %> <% } else { %>

找不到话题 (T_T)

<% } %> diff --git a/views/user/replies.html b/views/user/replies.html index 833632016c..04b452ce58 100644 --- a/views/user/replies.html +++ b/views/user/replies.html @@ -13,8 +13,13 @@
<%= user.loginname %> 参与的话题
<% if(typeof(topics) !== 'undefined' && topics.length > 0){ %> - <%- partial('../topic/list', - {topics:topics,pages:pages,current_pages:current_page,base:'/user/'+user.loginname+'/replies'}) %> + <%- partial('../topic/list', { + topics:topics, + pages:pages, + current_pages:current_page, + base:'/user/'+user.loginname+'/replies', + param: '' + }) %> <% }else{ %>

无话题

diff --git a/views/user/topics.html b/views/user/topics.html index 3ac41fba26..1d740220c8 100644 --- a/views/user/topics.html +++ b/views/user/topics.html @@ -13,8 +13,13 @@
<%=user.loginname%> 创建的话题
<% if(typeof(topics) !== 'undefined' && topics.length > 0 ){ %> - <%- partial('../topic/list', - {topics:topics,pages:pages,current_pages:current_page,base:'/user/'+user.loginname+'/topics'}) %> + <%- partial('../topic/list', { + topics:topics, + pages:pages, + current_pages:current_page, + base:'/user/'+user.loginname+'/topics', + param: '' + }) %> <% }else{ %>

无话题