Skip to content

Instantly share code, notes, and snippets.

@josephrexme
Created December 26, 2014 10:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save josephrexme/fc495bae88ca4811e446 to your computer and use it in GitHub Desktop.
Save josephrexme/fc495bae88ca4811e446 to your computer and use it in GitHub Desktop.
UJS: Continue execution of ajax request in a callback after altering with ajax:beforeSend
$(document).ready ->
$('[id^="edit_department"').on("ajax:success", (e, data, status, xhr) ->
$(this).append "<p class='fr'>Updated Succesfully</p>"
$(this).children('.fr').delay(2000).fadeOut()
).on "ajax:error", (e, data, status, error) ->
$(this).append "<p class='fr'>Failed to update</p>"
$('.content>.fr span:last-of-type>a').on "ajax:beforeSend", (xhr, settings) ->
swal
title: "Are you sure?"
text: "You will not be able to undo this!"
type: "warning"
showCancelButton: true
confirmButtonColor: "#DD6B55"
confirmButtonText: "Yes, delete it!"
closeOnConfirm: false
, ->
# should send the request here
swal "Deleted!", "Department has been deleted.", "success"
return
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment