diff options
author | Daniel Friesel <derf@finalrewind.org> | 2018-10-05 19:12:49 +0200 |
---|---|---|
committer | Daniel Friesel <derf@finalrewind.org> | 2018-10-05 19:12:49 +0200 |
commit | 6afef992f1840d29a4277f6063bdcd5c2e13ed89 (patch) | |
tree | 705a7c6a26bdcb6e716fc0e1f91406a994f423fe /public/static/js/travelynx-actions.js | |
parent | 2cdd176b9489331e8ec6894ed8ad9fac90e355a8 (diff) |
Show inline error messages when checkin/checkout fails
Diffstat (limited to 'public/static/js/travelynx-actions.js')
-rw-r--r-- | public/static/js/travelynx-actions.js | 23 |
1 files changed, 19 insertions, 4 deletions
diff --git a/public/static/js/travelynx-actions.js b/public/static/js/travelynx-actions.js index 3fbbdea..7cec0cd 100644 --- a/public/static/js/travelynx-actions.js +++ b/public/static/js/travelynx-actions.js @@ -1,4 +1,5 @@ $(document).ready(function() { + var error_icon = '<i class="material-icons">error</i>'; $('.action-checkin').click(function() { var link = $(this); req = { @@ -6,9 +7,16 @@ $(document).ready(function() { station: link.data('station'), train: link.data('train'), }; - link.replaceWith('<div class="progress"><div class="indeterminate"></div></div>'); + progressbar = $('<div class="progress"><div class="indeterminate"></div></div>'); + link.replaceWith(progressbar); $.post('/action', req, function(data) { - $(location).attr('href', '/'); + if (data.success) { + $(location).attr('href', '/'); + } else { + M.toast({html: error_icon + ' ' + data.error}); + link.append(' ' + error_icon); + progressbar.replaceWith(link); + } }); }); $('.action-checkout').click(function() { @@ -18,9 +26,16 @@ $(document).ready(function() { station: link.data('station'), force: link.data('force'), }; - link.replaceWith('<div class="progress"><div class="indeterminate"></div></div>'); + progressbar = $('<div class="progress"><div class="indeterminate"></div></div>'); + link.replaceWith(progressbar); $.post('/action', req, function(data) { - $(location).attr('href', '/' + req.station); + if (data.success) { + $(location).attr('href', '/' + req.station); + } else { + M.toast({html: error_icon + ' ' + data.error}); + link.append(' ' + error_icon); + progressbar.replaceWith(link); + } }); }); }); |