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 else
ctr.removeClass 'text-danger' ctr.removeClass 'text-danger'
ctr.addClass 'text-muted' 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 end
def destroy_comment 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
end end

View File

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