deleting comments works now

This commit is contained in:
nilsding 2014-12-29 01:05:30 +01:00
parent a0c0d68e43
commit 34a2f3cd6b
3 changed files with 48 additions and 9 deletions

View File

@ -63,3 +63,24 @@ $(document).on "input", "input[name=mod-comment-new]", (evt) ->
else
ctr.removeClass 'text-danger'
ctr.addClass 'text-muted'
# destroy
$(document).on "click", "a[data-action=mod-comment-destroy]", (ev) ->
ev.preventDefault()
if confirm 'Are you sure?'
btn = $(this)
cid = btn[0].dataset.id
$.ajax
url: '/ajax/mod/destroy_comment'
type: 'POST'
data:
comment: cid
success: (data, status, jqxhr) ->
if data.success
$("li[data-comment-id=#{cid}]").slideUp()
showNotification data.message, data.success
error: (jqxhr, status, error) ->
console.log jqxhr, status, error
showNotification "An error occurred, a developer should check the console for details", false
complete: (jqxhr, status) ->

View File

@ -85,6 +85,23 @@ class Ajax::ModerationController < ApplicationController
end
def destroy_comment
params.require :comment
@status = :err
@success = false
comment = ModerationComment.find(params[:comment])
unless current_user == comment.user
@status = :nopriv
@message = "can't delete other people's comments"
@success = false
return
end
comment.destroy
@status = :okay
@message = "Successfully deleted comment."
@success = true
end
end

View File

@ -9,15 +9,16 @@
%img.img-rounded.answerbox--img{src: gravatar_url(comment.user)}
.media-body.comments--body
%h6.media-heading.answerbox--question-user= user_screen_name comment.user
.pull-right
.btn-group
%button.btn.btn-link.btn-sm.dropdown-toggle{data: { toggle: :dropdown }, aria: { expanded: :false }}
%span.caret
%ul.dropdown-menu.dropdown-menu-right{role: :menu}
%li.text-danger
%a{href: '#', name: 'mod-comment-destroy', data: { id: comment.id }}
%i.fa.fa-trash-o
Delete
- if comment.user == current_user
.pull-right
.btn-group
%button.btn.btn-link.btn-sm.dropdown-toggle{data: { toggle: :dropdown }, aria: { expanded: :false }}
%span.caret
%ul.dropdown-menu.dropdown-menu-right{role: :menu}
%li.text-danger
%a{href: '#', data: { action: 'mod-comment-destroy', id: comment.id }}
%i.fa.fa-trash-o
Delete
%p.comments--content= comment.content
.form-group.has-feedback{name: 'mod-comment-new-group', data: { id: report.id }}
%input.form-control.comments--box{type: :text, placeholder: 'Comment...', name: 'mod-comment-new', data: { id: report.id }}