Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Comments removing

  • Loading branch information...
commit 5048a88c230232a97d1f400336cd350e62fab1bd 1 parent 5c2310d
Anatoliy Chakkaev authored
View
15 app/controllers/comments_controller.js
@@ -28,3 +28,18 @@ action('create', function () {
redirect(path);
}
});
+
+action('destroy', function () {
+ Comment.findById(req.param('id'), function (err, comment) {
+ if (comment && req.session.twitter && req.session.twitter.id == comment.twid) {
+ var page = Page.index[comment.path];
+ comment.remove(function () {
+ page.loadComments(function () {
+ send('location.href = location.href');
+ });
+ });
+ } else {
+ send('');
+ }
+ });
+});
View
5 app/views/cms/page.ejs
@@ -9,7 +9,7 @@
<% if (request.session.twitter && request.session.twitter.profile_image_url) { %>
<img src="<%= request.session.twitter.profile_image_url %>" class="avatar" />
<% } %>
- Leave comment as <%- request.session.twitter.screen_name %><br />
+ Leave comment as <%- request.session.twitter.name || request.session.twitter.screen_name %><br />
</div>
<%- form.input('path', {type: 'hidden', value: page.path}) %>
<%- form.textarea('text') %><br />
@@ -27,6 +27,9 @@
<% } %>
<%- comment.author %>
<%- comment.timeAgo() %>
+ <% if (request.session.twitter && comment.twid == request.session.twitter.id) { %>
+ <%- link_to('Delete comment', path_to.comment(comment), {remote: true, confirm: 'Are you sure want to delete comment?', method: 'DELETE', jsonp: '(function(){})'}) %>
+ <% } %>
</div>
<div class="comment-body">
<%- sanitize(comment.text) %>
View
2  config/routes.js
@@ -5,5 +5,5 @@ exports.routes = function (map) {
map.post('/pages/reorder', 'pages#reorder');
map.get(/^(.*)$/, 'cms#page');
- map.resources('comments', {only: 'create'});
+ map.resources('comments', {only: ['create', 'destroy']});
};
View
2  server.js
@@ -2,6 +2,6 @@ var app = module.exports = require('express').createServer();
require("./.railway/lib/onrailway").init(app);
if (!module.parent) {
- app.listen(1602);
+ app.listen(app.settings.env == 'development' ? 1602 : 8808);
console.log("Express server listening on port %d", app.address().port)
}
Please sign in to comment.
Something went wrong with that request. Please try again.