comment and post deletion now works on the backbone stream
This commit is contained in:
parent
46b1567622
commit
f5172fa977
8 changed files with 72 additions and 28 deletions
|
|
@ -44,12 +44,14 @@ class CommentsController < ApplicationController
|
||||||
current_user.retract(@comment)
|
current_user.retract(@comment)
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
format.js { render :nothing => true, :status => 204 }
|
format.js { render :nothing => true, :status => 204 }
|
||||||
|
format.json { render :nothing => true, :status => 204 }
|
||||||
format.mobile{ redirect_to @comment.post }
|
format.mobile{ redirect_to @comment.post }
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
format.mobile {redirect_to :back}
|
format.mobile {redirect_to :back}
|
||||||
format.js {render :nothing => true, :status => 403}
|
format.js {render :nothing => true, :status => 403}
|
||||||
|
format.json { render :nothing => true, :status => 403 }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -52,6 +52,7 @@ class PostsController < ApplicationController
|
||||||
current_user.retract(@post)
|
current_user.retract(@post)
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
format.js {render 'destroy'}
|
format.js {render 'destroy'}
|
||||||
|
format.json { render :nothing => true, :status => 204 }
|
||||||
format.all {redirect_to multi_path}
|
format.all {redirect_to multi_path}
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,7 @@
|
||||||
<div class="reshare">
|
<div class="reshare">
|
||||||
|
|
||||||
|
<% if(root) { %>
|
||||||
|
|
||||||
<a href="/people/<%= root.author.id %>">
|
<a href="/people/<%= root.author.id %>">
|
||||||
<img src="<%= root.author.avatar.small %>" class="avatar" data-person-id="<%= root.author.id %>"/>
|
<img src="<%= root.author.avatar.small %>" class="avatar" data-person-id="<%= root.author.id %>"/>
|
||||||
</a>
|
</a>
|
||||||
|
|
@ -25,4 +27,10 @@
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<% } else { %>
|
||||||
|
<p>
|
||||||
|
Original post deleted by author.
|
||||||
|
</p>
|
||||||
|
<% } %>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
|
|
@ -75,7 +75,7 @@
|
||||||
</span>
|
</span>
|
||||||
·
|
·
|
||||||
|
|
||||||
<% if(public) { %>
|
<% if(public && author.id != current_user.id) { %>
|
||||||
<span class="reshare_action">
|
<span class="reshare_action">
|
||||||
<% if(root) {
|
<% if(root) {
|
||||||
var rootGuid = root.guid;
|
var rootGuid = root.guid;
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,3 @@
|
||||||
App.Models.Comment = Backbone.Model.extend({
|
App.Models.Comment = Backbone.Model.extend({
|
||||||
url: function() {
|
urlRoot: "/comments"
|
||||||
return "/posts/" + this.get("post_id") + "/comments";
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,7 @@
|
||||||
App.Models.Post = Backbone.Model.extend({
|
App.Models.Post = Backbone.Model.extend({
|
||||||
url: "/posts",
|
url: function(){
|
||||||
|
return "/posts/" + this.get("id");
|
||||||
|
},
|
||||||
|
|
||||||
initialize: function() {
|
initialize: function() {
|
||||||
this.comments = new App.Collections.Comments(this.get("last_three_comments"));
|
this.comments = new App.Collections.Comments(this.get("last_three_comments"));
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,8 @@
|
||||||
App.Views.Comment = Backbone.View.extend({
|
App.Views.Comment = Backbone.View.extend({
|
||||||
|
events : {
|
||||||
|
"click .delete": "destroyComment"
|
||||||
|
},
|
||||||
|
|
||||||
initialize: function(options) {
|
initialize: function(options) {
|
||||||
this.model = options.model;
|
this.model = options.model;
|
||||||
this.template = _.template($("#comment-template").html());
|
this.template = _.template($("#comment-template").html());
|
||||||
|
|
@ -10,6 +14,21 @@ App.Views.Comment = Backbone.View.extend({
|
||||||
App.user()
|
App.user()
|
||||||
)));
|
)));
|
||||||
|
|
||||||
|
this.delegateEvents(); //we need this because we are explicitly setting this.el in this.render()
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
|
},
|
||||||
|
|
||||||
|
// NOTE: pull this out into a base class
|
||||||
|
destroyComment: function(evt) {
|
||||||
|
if(evt) { evt.preventDefault() }
|
||||||
|
|
||||||
|
var domElement = this.el;
|
||||||
|
|
||||||
|
this.model.destroy({
|
||||||
|
success: function(){
|
||||||
|
$(domElement).remove();
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,8 @@ App.Views.Post = Backbone.View.extend({
|
||||||
|
|
||||||
events: {
|
events: {
|
||||||
"click .focus_comment_textarea": "focusCommentTextarea",
|
"click .focus_comment_textarea": "focusCommentTextarea",
|
||||||
"focus .comment_box": "commentTextareaFocused"
|
"focus .comment_box": "commentTextareaFocused",
|
||||||
|
"click .delete:first": "destroyPost"
|
||||||
},
|
},
|
||||||
|
|
||||||
initialize: function(options) {
|
initialize: function(options) {
|
||||||
|
|
@ -51,6 +52,19 @@ App.Views.Post = Backbone.View.extend({
|
||||||
|
|
||||||
commentTextareaFocused: function(evt){
|
commentTextareaFocused: function(evt){
|
||||||
this.$("form").removeClass('hidden').addClass("open");
|
this.$("form").removeClass('hidden').addClass("open");
|
||||||
|
},
|
||||||
|
|
||||||
|
// NOTE: pull this out into a base class
|
||||||
|
destroyPost: function(evt){
|
||||||
|
if(evt){ evt.preventDefault(); }
|
||||||
|
|
||||||
|
var domElement = this.el;
|
||||||
|
|
||||||
|
this.model.destroy({
|
||||||
|
success: function(){
|
||||||
|
$(domElement).remove();
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue