Re-add force checkout to frontend

This commit is contained in:
Daniel Friesel 2018-10-21 15:57:38 +02:00
parent 2113533713
commit 8e817e5d60
2 changed files with 64 additions and 64 deletions

View file

@ -299,13 +299,13 @@ helper 'checkout' => sub {
my $user = $self->get_user_status;
my $train_id = $user->{train_id};
if ( $status->{errstr} and not $force ) {
return $status->{errstr};
}
if ( not $user->{checked_in} ) {
return 'You are not checked into any train';
}
else {
if ( $status->{errstr} and not $force ) {
return $status->{errstr};
}
my ($train)
= first { $_->train_id eq $train_id } @{ $status->{results} };
if ( not defined $train ) {
@ -357,7 +357,6 @@ helper 'checkout' => sub {
return 'INSERT failed';
}
}
}
};
helper 'get_station_id' => sub {

View file

@ -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);
});
});
});