Show inline error messages when checkin/checkout fails

This commit is contained in:
Daniel Friesel 2018-10-05 19:12:49 +02:00
parent 2cdd176b94
commit 6afef992f1
3 changed files with 38 additions and 30 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View file

@ -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) {
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) {
if (data.success) {
$(location).attr('href', '/' + req.station);
} else {
M.toast({html: error_icon + ' ' + data.error});
link.append(' ' + error_icon);
progressbar.replaceWith(link);
}
});
});
});