diff --git a/app/assets/javascripts/moderation/destroy.coffee b/app/assets/javascripts/moderation/destroy.coffee new file mode 100644 index 00000000..728b36f3 --- /dev/null +++ b/app/assets/javascripts/moderation/destroy.coffee @@ -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) -> \ No newline at end of file diff --git a/app/controllers/ajax/moderation_controller.rb b/app/controllers/ajax/moderation_controller.rb index 94496a8c..d4516d33 100644 --- a/app/controllers/ajax/moderation_controller.rb +++ b/app/controllers/ajax/moderation_controller.rb @@ -40,4 +40,24 @@ class Ajax::ModerationController < ApplicationController @message = "Successfully removed vote from report." @success = true 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 diff --git a/app/views/ajax/moderation/destroy_report.json.jbuilder b/app/views/ajax/moderation/destroy_report.json.jbuilder new file mode 100644 index 00000000..2c193af4 --- /dev/null +++ b/app/views/ajax/moderation/destroy_report.json.jbuilder @@ -0,0 +1 @@ +json.partial! 'ajax/shared/status' \ No newline at end of file diff --git a/app/views/moderation/_moderationbox.html.haml b/app/views/moderation/_moderationbox.html.haml index caa66757..6764eedb 100644 --- a/app/views/moderation/_moderationbox.html.haml +++ b/app/views/moderation/_moderationbox.html.haml @@ -1,4 +1,4 @@ -.panel.panel-default.moderationbox +.panel.panel-default.moderationbox{data: { id: report.id }} .panel-heading %img.img-rounded.answerbox--img{src: gravatar_url(report.user)} = user_screen_name report.user @@ -21,14 +21,14 @@ %span.mod-count{id: "mod-count-#{report.id}"} = report.votes .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 - %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 - %button.btn.btn-primary.btn-sm + %button.btn.btn-primary.btn-sm{type: :button} %i.fa.fa-comments %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 .panel-footer = render 'moderation/discussion', report: report \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index 1fd6908e..946fb125 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -17,6 +17,7 @@ Rails.application.routes.draw do namespace :ajax do 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_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/destroy_vote', to: 'moderation#destroy_vote', via: :post, as: :mod_destroy_vote end