Web Interfaces of PROSUME

transfer.ctp 3.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <script>
  2. (function($) {
  3. var overlay = $("#eprosume_overlay");
  4. var errors = $("#transferErrors");
  5. var outcome = $("#transferOutcome");
  6. var prosumerSelect = $("#prosumerSelect");
  7. var amountInput = $("#amountInput");
  8. var assetSelect = $("#assetSelect");
  9. var memoInput = $("#memoInput");
  10. var submitButton = $("#submitButton");
  11. if(submitButton) {
  12. submitButton.click(function(e) {
  13. var amount = parseFloat(amountInput.val());
  14. outcome.html("");
  15. outcome.addClass("hidden");
  16. e.preventDefault();
  17. if(prosumerSelect.val() == 0) {
  18. errors.html("Select a Meter");
  19. errors.removeClass("hidden");
  20. return;
  21. }
  22. if(amount == null || isNaN(amount) || amount <= 0) {
  23. errors.html("Set an amount");
  24. errors.removeClass("hidden");
  25. return;
  26. }
  27. if(assetSelect.val() <= 0) {
  28. errors.html("Choose an asset type");
  29. errors.removeClass("hidden");
  30. return;
  31. }
  32. if(memoInput.val().length <= 0) {
  33. errors.html("Please. insert a transfer memo");
  34. errors.removeClass("hidden");
  35. return;
  36. }
  37. errors.html("");
  38. errors.addClass("hidden");
  39. overlay.show();
  40. $.ajax({
  41. url : "/xhr/transfer",
  42. type: "POST",
  43. contentType: "application/json",
  44. headers: {
  45. "X-CSRF-Token": <?= json_encode($this->request->getParam('_csrfToken')) ?>
  46. },
  47. data: JSON.stringify({
  48. amount: amount,
  49. asset: assetSelect.val(),
  50. memo: memoInput.val(),
  51. prosumer: prosumerSelect.val(),
  52. }),
  53. complete:function(xhr) {
  54. if(xhr.status == 200) {
  55. outcome.html("The transfer has been successfully processed. The registration of this may take some time. Reloading...");
  56. outcome.removeClass("hidden");
  57. $('#submitButton').addClass("hidden");
  58. setTimeout(
  59. () => { window.location.reload(); },
  60. 5000
  61. );
  62. } else {
  63. outcome.html("Sorry, an error occured while processing you transaction");
  64. }
  65. outcome.removeClass("hidden");
  66. overlay.hide();
  67. }
  68. });
  69. });
  70. }
  71. })(jQuery);
  72. </script>