Reporting and Deleting logic

This commit is contained in:
Yuki 2015-04-26 07:06:25 +05:30
parent 3ef2c841c5
commit ee29e1f28f
9 changed files with 86 additions and 9 deletions

View File

@ -0,0 +1,30 @@
$(document).on "click", "a[data-action=ab-question-destroy]", (ev) ->
ev.preventDefault()
btn = $(this)
qid = btn[0].dataset.qId
swal
title: "Are you sure?"
text: "The question will be removed."
type: "warning"
showCancelButton: true
confirmButtonColor: "#DD6B55"
confirmButtonText: "Yes"
cancelButtonText: "No"
closeOnConfirm: true
, ->
$.ajax
url: '/ajax/destroy_question' # TODO: find a way to use rake routes instead of hardcoding them here
type: 'POST'
data:
question: qid
success: (data, status, jqxhr) ->
if data.success
if btn[0].dataset.redirect != undefined
window.location.href = btn[0].dataset.redirect
else
$("div.answerbox[data-qId=#{qid}], div.questionbox[data-id=#{qid}]").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

@ -0,0 +1,5 @@
$(document).on "click", "a[data-action=ab-question-report]", (ev) ->
ev.preventDefault()
btn = $(this)
qId = btn[0].dataset.qId
reportDialog "question", qId, -> btn.button "reset"

View File

@ -12,3 +12,9 @@
.panel-primary .answerbox--question-text {
color: #fff;
}
#questions .panel-body .media {
&, .media-body {
overflow: visible;
}
}

View File

@ -1,6 +1,24 @@
class Ajax::QuestionController < ApplicationController
include MarkdownHelper
def destroy
params.require :question
question = Question.find params[:question]
if question.nil?
@status = :not_found
@message = "Question does not exist"
@success = false
return
end
question.destroy!
@status = :okay
@message = "Successfully deleted question."
@success = true
end
def create
params.require :question
params.require :anonymousQuestion

View File

@ -0,0 +1 @@
json.partial! 'ajax/shared/status'

View File

@ -11,11 +11,11 @@
%button.btn.btn-link.btn-sm.dropdown-toggle{data: { toggle: :dropdown }, aria: { expanded: :false }}
%span.caret
%ul.dropdown-menu.dropdown-menu-right{role: :menu}
- if current_user.mod?
- if current_user.mod? or @question.user == current_user
%li.text-danger
%a{href: '#', data: { action: 'ab-question-destroy', q_id: @question.id }}
%a{href: '#', data: { action: 'ab-question-destroy', q_id: @question.id, redirect: show_user_questions_path(@question.user.screen_name) }}
%i.fa.fa-trash-o
Delete
Delete Question
- unless @question.user == current_user
%li
%a{href: '#', data: { action: 'ab-question-report', q_id: @question.id }}

View File

@ -1,4 +1,4 @@
.panel.panel-default.answerbox{data: { id: a.id }}
.panel.panel-default.answerbox{data: { id: a.id, q_id: a.question.id }}
- if @question.nil?
.panel-heading
.media.question-media
@ -12,11 +12,11 @@
%button.btn.btn-link.btn-sm.dropdown-toggle{data: { toggle: :dropdown }, aria: { expanded: :false }}
%span.caret
%ul.dropdown-menu.dropdown-menu-right{role: :menu}
- if current_user.mod?
- if current_user.mod? or a.question.user == current_user
%li.text-danger
%a{href: '#', data: { action: 'ab-question-destroy', q_id: a.question.id }}
%i.fa.fa-trash-o
Delete
Delete Question
- unless a.question.user == current_user
%li
%a{href: '#', data: { action: 'ab-question-report', q_id: a.question.id }}

View File

@ -1,7 +1,23 @@
.panel.panel-default
.panel.panel-default.questionbox{data: { id: q.id }}
.panel-body
.media
.media-body
- if user_signed_in?
.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}
- if current_user.mod? or q.user == current_user
%li.text-danger
%a{href: '#', data: { action: 'ab-question-destroy', q_id: q.id }}
%i.fa.fa-trash-o
Delete Question
- unless q.user == current_user
%li
%a{href: '#', data: { action: 'ab-question-report', q_id: q.id }}
%i.fa.fa-exclamation-triangle
Report
%h6.media-heading.text-muted.answerbox--question-user
= user_screen_name q.user
asked

View File

@ -66,6 +66,7 @@ Rails.application.routes.draw do
namespace :ajax do
match '/ask', to: 'question#create', via: :post, as: :ask
match '/destroy_question', to: 'question#destroy', via: :post, as: :destroy_question
match '/generate_question', to: 'inbox#create', via: :post, as: :generate_question
match '/delete_inbox', to: 'inbox#remove', via: :post, as: :delete_inbox
match '/delete_all_inbox', to: 'inbox#remove_all', via: :post, as: :delete_all_inbox