summaryrefslogtreecommitdiff
path: root/public/static/js/travelynx-actions.js
diff options
context:
space:
mode:
authorDaniel Friesel <derf@finalrewind.org>2018-10-05 19:12:49 +0200
committerDaniel Friesel <derf@finalrewind.org>2018-10-05 19:12:49 +0200
commit6afef992f1840d29a4277f6063bdcd5c2e13ed89 (patch)
tree705a7c6a26bdcb6e716fc0e1f91406a994f423fe /public/static/js/travelynx-actions.js
parent2cdd176b9489331e8ec6894ed8ad9fac90e355a8 (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.js23
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);
+ }
});
});
});