make sure the user really wants to delete something…

This commit is contained in:
nilsding 2014-12-08 15:45:15 +01:00
parent c486c293ef
commit 2d8305095b
2 changed files with 38 additions and 36 deletions

View File

@ -1,18 +1,19 @@
$(document).on "click", "button[name=ab-destroy]", -> $(document).on "click", "button[name=ab-destroy]", ->
btn = $(this) if confirm 'Are you sure?'
btn.button "loading" btn = $(this)
aid = btn[0].dataset.aId btn.button "loading"
$.ajax aid = btn[0].dataset.aId
url: '/ajax/destroy_answer' # TODO: find a way to use rake routes instead of hardcoding them here $.ajax
type: 'POST' url: '/ajax/destroy_answer' # TODO: find a way to use rake routes instead of hardcoding them here
data: type: 'POST'
answer: aid data:
success: (data, status, jqxhr) -> answer: aid
if data.success success: (data, status, jqxhr) ->
$("div.answer-box[data-id=#{aid}]").slideUp() if data.success
showNotification data.message, data.success $("div.answer-box[data-id=#{aid}]").slideUp()
error: (jqxhr, status, error) -> showNotification data.message, data.success
console.log jqxhr, status, error error: (jqxhr, status, error) ->
showNotification "An error occurred, a developer should check the console for details", false console.log jqxhr, status, error
complete: (jqxhr, status) -> showNotification "An error occurred, a developer should check the console for details", false
btn.button "reset" complete: (jqxhr, status) ->
btn.button "reset"

View File

@ -27,22 +27,23 @@ $(document).on "click", "button[name=ib-answer]", ->
$("textarea[name=ib-answer][data-id=#{iid}]").removeAttr "readonly" $("textarea[name=ib-answer][data-id=#{iid}]").removeAttr "readonly"
$(document).on "click", "button[name=ib-destroy]", -> $(document).on "click", "button[name=ib-destroy]", ->
btn = $(this) if confirm 'Are you sure?'
btn.button "loading" btn = $(this)
iid = btn[0].dataset.ibId btn.button "loading"
$("textarea[name=ib-answer][data-id=#{iid}]").attr "readonly", "readonly" iid = btn[0].dataset.ibId
$.ajax $("textarea[name=ib-answer][data-id=#{iid}]").attr "readonly", "readonly"
url: '/ajax/delete_inbox' $.ajax
type: 'POST' url: '/ajax/delete_inbox'
data: type: 'POST'
id: iid data:
success: (data, status, jqxhr) -> id: iid
if data.success success: (data, status, jqxhr) ->
$("div.inbox-box[data-id=#{iid}]").slideUp() if data.success
showNotification data.message, data.success $("div.inbox-box[data-id=#{iid}]").slideUp()
error: (jqxhr, status, error) -> showNotification data.message, data.success
console.log jqxhr, status, error error: (jqxhr, status, error) ->
showNotification "An error occurred, a developer should check the console for details", false console.log jqxhr, status, error
complete: (jqxhr, status) -> showNotification "An error occurred, a developer should check the console for details", false
btn.button "reset" complete: (jqxhr, status) ->
$("textarea[name=ib-answer][data-id=#{iid}]").removeAttr "readonly" btn.button "reset"
$("textarea[name=ib-answer][data-id=#{iid}]").removeAttr "readonly"