deleting comments works now
This commit is contained in:
parent
a0c0d68e43
commit
34a2f3cd6b
|
@ -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) ->
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -9,13 +9,14 @@
|
|||
%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
|
||||
- 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: '#', name: 'mod-comment-destroy', data: { id: comment.id }}
|
||||
%a{href: '#', data: { action: 'mod-comment-destroy', id: comment.id }}
|
||||
%i.fa.fa-trash-o
|
||||
Delete
|
||||
%p.comments--content= comment.content
|
||||
|
|
Loading…
Reference in New Issue