Guest User

Untitled

a guest
Dec 18th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.26 KB | None | 0 0
  1. function bindSweetAlertButtonDemo() {
  2. const swalButton = document.querySelectorAll('.sweet-alert-demo');
  3.  
  4. swalButton.forEach((dom) => {
  5. let form = $(dom).closest('form')
  6. console.log('HELLO FROM FORM');
  7. console.log(form);
  8. let cryptocurrency_id = window.location.search.split("?crypto_id=")[1]
  9. console.log('HELLO FROM CRYPTOCURRENCY ID');
  10. console.log(cryptocurrency_id);
  11. let url = `/cryptocurrencies/${cryptocurrency_id}/trades`;
  12. console.log('HELLO FROM URL');
  13. console.log(url);
  14. // url = /cryptocurrencies/3/trades
  15.  
  16. form.on('submit', (e) => {
  17. e.preventDefault()
  18. e.stopPropagation()
  19.  
  20. swal({
  21. title: "Are you sure?",
  22. text: "Is this the cryptocurrency you wanna buy?",
  23. icon: "warning",
  24. buttons: true,
  25. dangerMode: true,
  26. }).then((willSave) => {
  27. if (willSave) {
  28. $.ajax({
  29. headers: {
  30. 'X-CSRF-Token': $(form).find('[name="authenticity_token"]').val()
  31. },
  32. url: `${url}.json`,
  33. type: "POST"
  34. }).done(function() {
  35. swal("Booking canceled!", {
  36. icon: "success",
  37. }).then(() => {
  38. location.reload()
  39. });
  40. })
  41. }
  42. });
  43. })
  44. })
  45. };
Add Comment
Please, Sign In to add comment