travelynx/public/static/js/travelynx-actions.js
2019-03-19 18:20:05 +01:00

67 lines
1.6 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

function tvly_run(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);
var req = {
action: 'checkin',
station: link.data('station'),
train: link.data('train'),
};
tvly_run(link, req, '/');
});
$('.action-checkout').click(function() {
var link = $(this);
var req = {
action: 'checkout',
station: link.data('station'),
force: link.data('force'),
};
tvly_run(link, req, '/s/' + req.station, function() {
link.append(' Ohne Echtzeitdaten auschecken?')
link.data('force', true);
});
});
$('.action-undo').click(function() {
var link = $(this);
var req = {
action: 'undo',
};
tvly_run(link, req, '/');
});
$('.action-cancelled-from').click(function() {
var link = $(this);
var req = {
action: 'cancelled_from',
station: link.data('station'),
train: link.data('train'),
};
tvly_run(link, req, '/');
});
$('.action-cancelled-to').click(function() {
var link = $(this);
var req = {
action: 'cancelled_to',
station: link.data('station'),
force: true,
};
tvly_run(link, req, '/');
});
});