mirror of
https://github.com/cnodejs/nodeclub.git
synced 2026-02-01 16:34:28 +00:00
话题收藏
This commit is contained in:
parent
5d8fbd75c3
commit
072cca971f
@ -35,16 +35,20 @@ exports.index = function (req, res, next) {
|
||||
}
|
||||
|
||||
var topic_id = req.params.tid;
|
||||
var currentUser = req.session.user;
|
||||
|
||||
if (topic_id.length !== 24) {
|
||||
return res.render404('此话题不存在或已被删除。');
|
||||
}
|
||||
var events = ['topic', 'other_topics', 'no_reply_topics'];
|
||||
var ep = EventProxy.create(events, function (topic, other_topics, no_reply_topics) {
|
||||
var events = ['topic', 'other_topics', 'no_reply_topics', 'is_collect'];
|
||||
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_uped: isUped,
|
||||
is_collect: is_collect,
|
||||
});
|
||||
});
|
||||
|
||||
@ -98,6 +102,8 @@ exports.index = function (req, res, next) {
|
||||
}
|
||||
}));
|
||||
}));
|
||||
|
||||
TopicCollect.getTopicCollect(currentUser._id, topic_id, ep.done('is_collect'))
|
||||
};
|
||||
|
||||
exports.create = function (req, res, next) {
|
||||
@ -355,6 +361,7 @@ exports.lock = function (req, res, next) {
|
||||
// 收藏主题
|
||||
exports.collect = function (req, res, next) {
|
||||
var topic_id = req.body.topic_id;
|
||||
|
||||
Topic.getTopic(topic_id, function (err, topic) {
|
||||
if (err) {
|
||||
return next(err);
|
||||
|
||||
@ -24,7 +24,7 @@ exports.adminRequired = function (req, res, next) {
|
||||
* 需要登录
|
||||
*/
|
||||
exports.userRequired = function (req, res, next) {
|
||||
if (!req.session || !req.session.user) {
|
||||
if (!req.session || !req.session.user || !req.session.user._id) {
|
||||
return res.status(403).send('forbidden!');
|
||||
}
|
||||
|
||||
|
||||
@ -10,4 +10,6 @@ var TopicCollectSchema = new Schema({
|
||||
});
|
||||
|
||||
TopicCollectSchema.plugin(BaseModel);
|
||||
TopicCollectSchema.index({user_id: 1});
|
||||
|
||||
mongoose.model('TopicCollect', TopicCollectSchema);
|
||||
|
||||
@ -673,10 +673,6 @@ img.unread {
|
||||
clear: left;
|
||||
}
|
||||
|
||||
#collect_btn {
|
||||
|
||||
}
|
||||
|
||||
#backtotop {
|
||||
width: 24px;
|
||||
color: gray;
|
||||
@ -1249,3 +1245,4 @@ textarea.editor {
|
||||
.cnode-app-download {
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
|
||||
@ -70,53 +70,57 @@
|
||||
<% if (topic.tab) { %>
|
||||
<span> 来自 <%= topic.tabName %></span>
|
||||
<%}%>
|
||||
|
||||
<input class="span-common <%= is_collect ? '' : 'span-success' %> pull-right collect_btn" type="submit" value="<%= is_collect ? '取消收藏' : '收藏' %>" action="<%= is_collect ? 'de_collect' : 'collect' %>">
|
||||
|
||||
</div>
|
||||
<% if (current_user) { %>
|
||||
<div id="manage_topic">
|
||||
<% if (current_user.is_admin) { %>
|
||||
<a href='/topic/<%= topic._id %>/top' data-method="post">
|
||||
<% if (topic.top) { %>
|
||||
<i class="fa fa-lg fa-star-o" title='取消置顶'></i>
|
||||
<% } else { %>
|
||||
<i class="fa fa-lg fa-star" title='置顶'/></i>
|
||||
<% } %>
|
||||
</a>
|
||||
|
||||
<a href='/topic/<%= topic._id %>/top' data-method="post">
|
||||
<% if (topic.top) { %>
|
||||
<i class="fa fa-lg fa-star-o" title='取消置顶'></i>
|
||||
|
||||
<a href='/topic/<%= topic._id %>/good' data-method="post">
|
||||
<% if (topic.good) { %>
|
||||
<i class="fa fa-lg fa-heart-o" title="取消精华"></i>
|
||||
<% } else { %>
|
||||
<i class="fa fa-lg fa-heart" title="加精华"></i>
|
||||
<% } %>
|
||||
</a>
|
||||
|
||||
<a href='/topic/<%= topic._id %>/lock' data-method="post">
|
||||
<% if (topic.lock) { %>
|
||||
<i class="fa fa-lg fa-unlock" title='取消锁定'></i>
|
||||
<% } else { %>
|
||||
<i class="fa fa-lg fa-lock" title='锁定(不可再回复)'/></i>
|
||||
<% } %>
|
||||
</a>
|
||||
|
||||
|
||||
<a href='/topic/<%= topic._id %>/edit'>
|
||||
<i class="fa fa-lg fa-pencil-square-o" title='编辑'></i></a>
|
||||
<a href='javascript:;'
|
||||
data-id="<%= topic._id %>"
|
||||
class='delete_topic_btn'>
|
||||
<i class="fa fa-lg fa-trash" title='删除'></i></a>
|
||||
<% } else { %>
|
||||
<i class="fa fa-lg fa-star" title='置顶'/></i>
|
||||
<% if (current_user._id.equals(topic.author_id)) { %>
|
||||
<a href='/topic/<%= topic._id %>/edit'>
|
||||
<i class="fa fa-lg fa-pencil-square-o" title='编辑'></i></a>
|
||||
<a href='javascript:;'
|
||||
data-id="<%= topic._id %>"
|
||||
class='delete_topic_btn'>
|
||||
<i class="fa fa-lg fa-trash" title='删除'></i></a>
|
||||
<% } %>
|
||||
</a>
|
||||
|
||||
|
||||
<a href='/topic/<%= topic._id %>/good' data-method="post">
|
||||
<% if (topic.good) { %>
|
||||
<i class="fa fa-lg fa-heart-o" title="取消精华"></i>
|
||||
<% } else { %>
|
||||
<i class="fa fa-lg fa-heart" title="加精华"></i>
|
||||
<% } %>
|
||||
</a>
|
||||
|
||||
<a href='/topic/<%= topic._id %>/lock' data-method="post">
|
||||
<% if (topic.lock) { %>
|
||||
<i class="fa fa-lg fa-unlock" title='取消锁定'></i>
|
||||
<% } else { %>
|
||||
<i class="fa fa-lg fa-lock" title='锁定(不可再回复)'/></i>
|
||||
<% } %>
|
||||
</a>
|
||||
|
||||
|
||||
<a href='/topic/<%= topic._id %>/edit'>
|
||||
<i class="fa fa-lg fa-pencil-square-o" title='编辑'></i></a>
|
||||
<a href='javascript:;'
|
||||
data-id="<%= topic._id %>"
|
||||
class='delete_topic_btn'>
|
||||
<i class="fa fa-lg fa-trash" title='删除'></i></a>
|
||||
<% } else { %>
|
||||
<% if (current_user._id.equals(topic.author_id)) { %>
|
||||
<a href='/topic/<%= topic._id %>/edit'>
|
||||
<i class="fa fa-lg fa-pencil-square-o" title='编辑'></i></a>
|
||||
<a href='javascript:;'
|
||||
data-id="<%= topic._id %>"
|
||||
class='delete_topic_btn'>
|
||||
<i class="fa fa-lg fa-trash" title='删除'></i></a>
|
||||
<% } %>
|
||||
<% } %>
|
||||
|
||||
|
||||
</div>
|
||||
<% } %>
|
||||
</div>
|
||||
@ -258,7 +262,7 @@
|
||||
// END 评论回复
|
||||
|
||||
// 加入收藏
|
||||
$('#collect_btn').click(function () {
|
||||
$('.collect_btn').click(function () {
|
||||
var $me = $(this);
|
||||
var action = $me.attr('action');
|
||||
var data = {
|
||||
@ -269,10 +273,10 @@
|
||||
$.post('/topic/' + action, data, function (data) {
|
||||
if (data.status === 'success') {
|
||||
if (action == 'collect') {
|
||||
$me.text('取消收藏');
|
||||
$me.val('取消收藏');
|
||||
$me.attr('action', 'de_collect');
|
||||
} else {
|
||||
$me.text('加入收藏');
|
||||
$me.val('收藏');
|
||||
$me.attr('action', 'collect');
|
||||
}
|
||||
$me.toggleClass('span-success');
|
||||
|
||||
@ -19,7 +19,7 @@
|
||||
<% if (user.collect_topic_count) {%>
|
||||
<li>
|
||||
<a class='dark' href="/user/<%= user.loginname %>/collections" target='_blank'>
|
||||
<span class='big collect-topic-count'><%= user.collect_topic_count %></span>话题收藏
|
||||
<span class='big collect-topic-count'><%= user.collect_topic_count %></span>个话题收藏
|
||||
</a>
|
||||
</li>
|
||||
<%}%>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user