deleting reports works now
This commit is contained in:
parent
486d5d18f2
commit
b7b5ee960e
|
@ -0,0 +1,17 @@
|
||||||
|
$(document).on "click", "button[name=mod-delete-report]", ->
|
||||||
|
if confirm 'Are you sure?'
|
||||||
|
btn = $(this)
|
||||||
|
id = btn[0].dataset.id
|
||||||
|
$.ajax
|
||||||
|
url: '/ajax/mod/destroy_report'
|
||||||
|
type: 'POST'
|
||||||
|
data:
|
||||||
|
id: id
|
||||||
|
success: (data, status, jqxhr) ->
|
||||||
|
if data.success
|
||||||
|
$("div.moderationbox[data-id=#{id}]").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) ->
|
|
@ -40,4 +40,24 @@ class Ajax::ModerationController < ApplicationController
|
||||||
@message = "Successfully removed vote from report."
|
@message = "Successfully removed vote from report."
|
||||||
@success = true
|
@success = true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def destroy_report
|
||||||
|
params.require :id
|
||||||
|
|
||||||
|
report = Report.find(params[:id])
|
||||||
|
|
||||||
|
begin
|
||||||
|
report.deleted = true
|
||||||
|
report.save
|
||||||
|
rescue
|
||||||
|
@status = :fail
|
||||||
|
@message = "Something bad happened!"
|
||||||
|
@success = false
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
@status = :okay
|
||||||
|
@message = "WHERE DID IT GO??? OH NO!!!"
|
||||||
|
@success = true
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
json.partial! 'ajax/shared/status'
|
|
@ -1,4 +1,4 @@
|
||||||
.panel.panel-default.moderationbox
|
.panel.panel-default.moderationbox{data: { id: report.id }}
|
||||||
.panel-heading
|
.panel-heading
|
||||||
%img.img-rounded.answerbox--img{src: gravatar_url(report.user)}
|
%img.img-rounded.answerbox--img{src: gravatar_url(report.user)}
|
||||||
= user_screen_name report.user
|
= user_screen_name report.user
|
||||||
|
@ -21,14 +21,14 @@
|
||||||
%span.mod-count{id: "mod-count-#{report.id}"}
|
%span.mod-count{id: "mod-count-#{report.id}"}
|
||||||
= report.votes
|
= report.votes
|
||||||
.btn-group
|
.btn-group
|
||||||
%button.btn.btn-success.btn-sm{name: "mod-vote", disabled: current_user.report_x_voted?(report, true) ? 'disabled' : nil, data: { id: report.id, action: current_user.report_voted?(report) ? 'unvote' : 'vote', vote_type: 'upvote' }}
|
%button.btn.btn-success.btn-sm{type: :button, name: "mod-vote", disabled: current_user.report_x_voted?(report, true) ? 'disabled' : nil, data: { id: report.id, action: current_user.report_voted?(report) ? 'unvote' : 'vote', vote_type: 'upvote' }}
|
||||||
%i.fa.fa-thumbs-up
|
%i.fa.fa-thumbs-up
|
||||||
%button.btn.btn-danger.btn-sm{name: "mod-vote", disabled: current_user.report_x_voted?(report, false) ? 'disabled' : nil, data: { id: report.id, action: current_user.report_voted?(report) ? 'unvote' : 'vote', vote_type: 'downvote' }}
|
%button.btn.btn-danger.btn-sm{type: :button, name: "mod-vote", disabled: current_user.report_x_voted?(report, false) ? 'disabled' : nil, data: { id: report.id, action: current_user.report_voted?(report) ? 'unvote' : 'vote', vote_type: 'downvote' }}
|
||||||
%i.fa.fa-thumbs-down
|
%i.fa.fa-thumbs-down
|
||||||
%button.btn.btn-primary.btn-sm
|
%button.btn.btn-primary.btn-sm{type: :button}
|
||||||
%i.fa.fa-comments
|
%i.fa.fa-comments
|
||||||
%span 0
|
%span 0
|
||||||
%button.btn.btn-default.btn-sm
|
%button.btn.btn-default.btn-sm{type: :button, name: "mod-delete-report", data: { id: report.id }}
|
||||||
%i.fa.fa-trash-o
|
%i.fa.fa-trash-o
|
||||||
.panel-footer
|
.panel-footer
|
||||||
= render 'moderation/discussion', report: report
|
= render 'moderation/discussion', report: report
|
|
@ -17,6 +17,7 @@ Rails.application.routes.draw do
|
||||||
namespace :ajax do
|
namespace :ajax do
|
||||||
match '/mod/create_comment', to: 'moderation#comment', via: :post, as: :mod_comment
|
match '/mod/create_comment', to: 'moderation#comment', via: :post, as: :mod_comment
|
||||||
match '/mod/destroy_comment', to: 'moderation#destroy_comment', via: :post, as: :mod_destroy_comment
|
match '/mod/destroy_comment', to: 'moderation#destroy_comment', via: :post, as: :mod_destroy_comment
|
||||||
|
match '/mod/destroy_report', to: 'moderation#destroy_report', via: :post, as: :mod_destroy_report
|
||||||
match '/mod/create_vote', to: 'moderation#vote', via: :post, as: :mod_vote
|
match '/mod/create_vote', to: 'moderation#vote', via: :post, as: :mod_vote
|
||||||
match '/mod/destroy_vote', to: 'moderation#destroy_vote', via: :post, as: :mod_destroy_vote
|
match '/mod/destroy_vote', to: 'moderation#destroy_vote', via: :post, as: :mod_destroy_vote
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue