Show inline error messages when checkin/checkout fails
This commit is contained in:
parent
2cdd176b94
commit
6afef992f1
3 changed files with 38 additions and 30 deletions
11
public/static/css/materialize.min.css
vendored
11
public/static/css/materialize.min.css
vendored
File diff suppressed because one or more lines are too long
10
public/static/js/materialize.min.js
vendored
10
public/static/js/materialize.min.js
vendored
File diff suppressed because one or more lines are too long
|
@ -1,4 +1,5 @@
|
||||||
$(document).ready(function() {
|
$(document).ready(function() {
|
||||||
|
var error_icon = '<i class="material-icons">error</i>';
|
||||||
$('.action-checkin').click(function() {
|
$('.action-checkin').click(function() {
|
||||||
var link = $(this);
|
var link = $(this);
|
||||||
req = {
|
req = {
|
||||||
|
@ -6,9 +7,16 @@ $(document).ready(function() {
|
||||||
station: link.data('station'),
|
station: link.data('station'),
|
||||||
train: link.data('train'),
|
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) {
|
$.post('/action', req, function(data) {
|
||||||
|
if (data.success) {
|
||||||
$(location).attr('href', '/');
|
$(location).attr('href', '/');
|
||||||
|
} else {
|
||||||
|
M.toast({html: error_icon + ' ' + data.error});
|
||||||
|
link.append(' ' + error_icon);
|
||||||
|
progressbar.replaceWith(link);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
$('.action-checkout').click(function() {
|
$('.action-checkout').click(function() {
|
||||||
|
@ -18,9 +26,16 @@ $(document).ready(function() {
|
||||||
station: link.data('station'),
|
station: link.data('station'),
|
||||||
force: link.data('force'),
|
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) {
|
$.post('/action', req, function(data) {
|
||||||
|
if (data.success) {
|
||||||
$(location).attr('href', '/' + req.station);
|
$(location).attr('href', '/' + req.station);
|
||||||
|
} else {
|
||||||
|
M.toast({html: error_icon + ' ' + data.error});
|
||||||
|
link.append(' ' + error_icon);
|
||||||
|
progressbar.replaceWith(link);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue