summaryrefslogtreecommitdiff
path: root/public/static/js
diff options
context:
space:
mode:
authorDaniel Friesel <derf@finalrewind.org>2018-10-21 15:57:38 +0200
committerDaniel Friesel <derf@finalrewind.org>2018-10-21 15:57:38 +0200
commit8e817e5d60303e5307c3151f2b5a1a0eb62c0acd (patch)
tree260213272307da2cab8cb086e240dc6134fa07d9 /public/static/js
parent21135337130482d24a3add77d7fbb672b6881d7d (diff)
Re-add force checkout to frontend
Diffstat (limited to 'public/static/js')
-rw-r--r--public/static/js/travelynx-actions.js49
1 files changed, 25 insertions, 24 deletions
diff --git a/public/static/js/travelynx-actions.js b/public/static/js/travelynx-actions.js
index 7cec0cd..91953a6 100644
--- a/public/static/js/travelynx-actions.js
+++ b/public/static/js/travelynx-actions.js
@@ -1,41 +1,42 @@
-$(document).ready(function() {
+function travelynx_run_action(link, req, redir, err_callback) {
var error_icon = '<i class="material-icons">error</i>';
+ var progressbar = $('<div class="progress"><div class="indeterminate"></div></div>');
+ link.hide();
+ link.after(progressbar);
+ $.post('/action', req, function(data) {
+ if (data.success) {
+ $(location).attr('href', redir);
+ } else {
+ M.toast({html: error_icon + ' ' + data.error});
+ progressbar.remove();
+ if (err_callback) {
+ err_callback();
+ }
+ link.append(' ' + error_icon);
+ link.show();
+ }
+ });
+}
+$(document).ready(function() {
$('.action-checkin').click(function() {
var link = $(this);
- req = {
+ var req = {
action: 'checkin',
station: link.data('station'),
train: link.data('train'),
};
- 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);
- }
- });
+ travelynx_run_action(link, req, '/');
});
$('.action-checkout').click(function() {
var link = $(this);
- req = {
+ var req = {
action: 'checkout',
station: link.data('station'),
force: link.data('force'),
};
- 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);
- }
+ travelynx_run_action(link, req, '/' + req.station, function() {
+ link.append(' – Keine Echtzeitdaten vorhanden')
+ link.data('force', true);
});
});
});