2015-04-25 18:36:25 -07:00
|
|
|
$(document).on "click", "a[data-action=ab-question-destroy]", (ev) ->
|
|
|
|
ev.preventDefault()
|
|
|
|
btn = $(this)
|
|
|
|
qid = btn[0].dataset.qId
|
|
|
|
swal
|
2015-06-08 11:35:16 -07:00
|
|
|
title: translate('frontend.delete_own.confirm.title')
|
|
|
|
text: translate('frontend.delete_own.confirm.text')
|
2015-04-25 18:36:25 -07:00
|
|
|
type: "warning"
|
|
|
|
showCancelButton: true
|
|
|
|
confirmButtonColor: "#DD6B55"
|
2015-06-08 12:01:37 -07:00
|
|
|
confirmButtonText: translate('views.actions.y')
|
|
|
|
cancelButtonText: translate('views.actions.n')
|
2015-04-25 18:36:25 -07:00
|
|
|
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
|
2015-04-26 18:21:29 -07:00
|
|
|
window.location.pathname = btn[0].dataset.redirect
|
2015-04-25 18:36:25 -07:00
|
|
|
else
|
2015-04-26 03:21:47 -07:00
|
|
|
$("div.answerbox[data-q-id=#{qid}], div.questionbox[data-id=#{qid}]").slideUp()
|
2015-04-25 18:36:25 -07:00
|
|
|
showNotification data.message, data.success
|
|
|
|
error: (jqxhr, status, error) ->
|
|
|
|
console.log jqxhr, status, error
|
2015-06-08 11:35:16 -07:00
|
|
|
showNotification translate('frontend.error.message'), false
|
2015-04-25 18:36:25 -07:00
|
|
|
complete: (jqxhr, status) ->
|