2019-05-10 15:58:13 +00:00
|
|
|
|
var j_duration = 0;
|
|
|
|
|
var j_arrival = 0;
|
|
|
|
|
function upd_journey_data() {
|
|
|
|
|
$('.countdown').each(function() {
|
|
|
|
|
j_duration = $(this).data('duration');
|
|
|
|
|
j_arrival = $(this).data('arrival');
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
function upd_countdown() {
|
|
|
|
|
var now = Date.now() / 1000;
|
|
|
|
|
if (j_arrival > 0) {
|
|
|
|
|
if (j_arrival > now) {
|
|
|
|
|
$('.countdown').text('Ankunft in ' + Math.round((j_arrival - now)/60) + ' Minuten');
|
|
|
|
|
} else {
|
|
|
|
|
$('.countdown').text('Ziel erreicht');
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-04-23 16:08:07 +00:00
|
|
|
|
function tvly_run(link, req, err_callback) {
|
2018-10-05 17:12:49 +00:00
|
|
|
|
var error_icon = '<i class="material-icons">error</i>';
|
2018-10-21 13:57:38 +00:00
|
|
|
|
var progressbar = $('<div class="progress"><div class="indeterminate"></div></div>');
|
|
|
|
|
link.hide();
|
|
|
|
|
link.after(progressbar);
|
|
|
|
|
$.post('/action', req, function(data) {
|
|
|
|
|
if (data.success) {
|
2019-04-23 16:08:07 +00:00
|
|
|
|
$(location).attr('href', data.redirect_to);
|
2018-10-21 13:57:38 +00:00
|
|
|
|
} else {
|
|
|
|
|
M.toast({html: error_icon + ' ' + data.error});
|
|
|
|
|
progressbar.remove();
|
|
|
|
|
if (err_callback) {
|
|
|
|
|
err_callback();
|
|
|
|
|
}
|
|
|
|
|
link.append(' ' + error_icon);
|
|
|
|
|
link.show();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
2019-04-23 20:27:13 +00:00
|
|
|
|
function tvly_update() {
|
|
|
|
|
$.get('/ajax/status_card.html', function(data) {
|
|
|
|
|
$('.statuscol').html(data);
|
|
|
|
|
tvly_reg_handlers();
|
2019-05-10 15:58:13 +00:00
|
|
|
|
upd_journey_data();
|
|
|
|
|
setTimeout(tvly_update, 40000);
|
2019-04-23 20:27:13 +00:00
|
|
|
|
}).fail(function() {
|
2019-04-26 20:27:07 +00:00
|
|
|
|
$('.sync-failed-marker').css('display', 'block');
|
2019-05-10 15:58:13 +00:00
|
|
|
|
upd_countdown();
|
2019-05-07 16:01:49 +00:00
|
|
|
|
setTimeout(tvly_update, 5000);
|
2019-05-02 08:05:15 +00:00
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
function tvly_update_public() {
|
|
|
|
|
var user_name;
|
|
|
|
|
$('.publicstatuscol').each(function() {
|
|
|
|
|
user_name = $(this).data('user');
|
|
|
|
|
});
|
|
|
|
|
$.get('/ajax/status/' + user_name + '.html', function(data) {
|
|
|
|
|
$('.publicstatuscol').html(data);
|
2019-05-10 15:58:13 +00:00
|
|
|
|
upd_journey_data();
|
|
|
|
|
setTimeout(tvly_update_public, 40000);
|
2019-05-02 08:05:15 +00:00
|
|
|
|
}).fail(function() {
|
|
|
|
|
$('.sync-failed-marker').css('display', 'block');
|
2019-05-10 15:58:13 +00:00
|
|
|
|
upd_countdown();
|
2019-05-07 16:01:49 +00:00
|
|
|
|
setTimeout(tvly_update_public, 5000);
|
2019-04-23 20:27:13 +00:00
|
|
|
|
});
|
|
|
|
|
}
|
2019-05-10 15:58:13 +00:00
|
|
|
|
function tvly_journey_progress() {
|
|
|
|
|
var now = Date.now() / 1000;
|
|
|
|
|
var progress = 0;
|
|
|
|
|
if (j_duration > 0) {
|
|
|
|
|
progress = 1 - ((j_arrival - now) / j_duration);
|
|
|
|
|
if (progress < 0) {
|
|
|
|
|
progress = 0;
|
|
|
|
|
}
|
|
|
|
|
if (progress > 1) {
|
|
|
|
|
progress = 1;
|
|
|
|
|
}
|
|
|
|
|
$('.progress .determinate').css('width', (progress * 100) + '%');
|
|
|
|
|
setTimeout(tvly_journey_progress, 5000);
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-04-23 20:27:13 +00:00
|
|
|
|
function tvly_reg_handlers() {
|
2018-10-05 14:33:59 +00:00
|
|
|
|
$('.action-checkin').click(function() {
|
|
|
|
|
var link = $(this);
|
2018-10-21 13:57:38 +00:00
|
|
|
|
var req = {
|
2018-10-05 14:33:59 +00:00
|
|
|
|
action: 'checkin',
|
|
|
|
|
station: link.data('station'),
|
|
|
|
|
train: link.data('train'),
|
|
|
|
|
};
|
2019-04-23 16:08:07 +00:00
|
|
|
|
tvly_run(link, req);
|
2018-10-05 14:33:59 +00:00
|
|
|
|
});
|
|
|
|
|
$('.action-checkout').click(function() {
|
|
|
|
|
var link = $(this);
|
2018-10-21 13:57:38 +00:00
|
|
|
|
var req = {
|
2018-10-05 14:33:59 +00:00
|
|
|
|
action: 'checkout',
|
|
|
|
|
station: link.data('station'),
|
|
|
|
|
force: link.data('force'),
|
|
|
|
|
};
|
2019-04-23 16:08:07 +00:00
|
|
|
|
tvly_run(link, req, function() {
|
2019-02-14 17:04:15 +00:00
|
|
|
|
link.append(' – Ohne Echtzeitdaten auschecken?')
|
2018-10-21 13:57:38 +00:00
|
|
|
|
link.data('force', true);
|
2018-10-05 14:33:59 +00:00
|
|
|
|
});
|
|
|
|
|
});
|
2018-11-02 20:35:53 +00:00
|
|
|
|
$('.action-undo').click(function() {
|
|
|
|
|
var link = $(this);
|
|
|
|
|
var req = {
|
|
|
|
|
action: 'undo',
|
2019-03-31 06:45:51 +00:00
|
|
|
|
undo_id: link.data('id'),
|
2018-11-02 20:35:53 +00:00
|
|
|
|
};
|
2019-04-23 16:08:07 +00:00
|
|
|
|
tvly_run(link, req);
|
2019-03-19 17:20:05 +00:00
|
|
|
|
});
|
|
|
|
|
$('.action-cancelled-from').click(function() {
|
|
|
|
|
var link = $(this);
|
|
|
|
|
var req = {
|
|
|
|
|
action: 'cancelled_from',
|
|
|
|
|
station: link.data('station'),
|
|
|
|
|
train: link.data('train'),
|
|
|
|
|
};
|
2019-04-23 16:08:07 +00:00
|
|
|
|
tvly_run(link, req);
|
2019-03-19 17:20:05 +00:00
|
|
|
|
});
|
|
|
|
|
$('.action-cancelled-to').click(function() {
|
|
|
|
|
var link = $(this);
|
|
|
|
|
var req = {
|
|
|
|
|
action: 'cancelled_to',
|
|
|
|
|
station: link.data('station'),
|
|
|
|
|
force: true,
|
|
|
|
|
};
|
2019-04-23 16:08:07 +00:00
|
|
|
|
tvly_run(link, req);
|
2018-11-02 20:35:53 +00:00
|
|
|
|
});
|
2019-04-04 16:26:53 +00:00
|
|
|
|
$('.action-delete').click(function() {
|
|
|
|
|
var link = $(this);
|
|
|
|
|
var req = {
|
|
|
|
|
action: 'delete',
|
2019-04-23 16:08:07 +00:00
|
|
|
|
id: link.data('id'),
|
2019-04-04 16:26:53 +00:00
|
|
|
|
checkin: link.data('checkin'),
|
|
|
|
|
checkout: link.data('checkout'),
|
|
|
|
|
};
|
|
|
|
|
really_delete = confirm("Diese Zugfahrt wirklich löschen? Der Eintrag wird sofort aus der Datenbank entfernt und kann nicht wiederhergestellt werden.");
|
|
|
|
|
if (really_delete) {
|
2019-04-23 16:08:07 +00:00
|
|
|
|
tvly_run(link, req);
|
2019-04-04 16:26:53 +00:00
|
|
|
|
}
|
|
|
|
|
});
|
2019-04-23 20:27:13 +00:00
|
|
|
|
}
|
|
|
|
|
$(document).ready(function() {
|
|
|
|
|
tvly_reg_handlers();
|
|
|
|
|
if ($('.statuscol .autorefresh').length) {
|
2019-05-10 15:58:13 +00:00
|
|
|
|
upd_journey_data();
|
|
|
|
|
setTimeout(tvly_update, 40000);
|
|
|
|
|
setTimeout(tvly_journey_progress, 5000);
|
2019-05-02 08:05:15 +00:00
|
|
|
|
}
|
|
|
|
|
if ($('.publicstatuscol .autorefresh').length) {
|
2019-05-10 15:58:13 +00:00
|
|
|
|
upd_journey_data();
|
|
|
|
|
setTimeout(tvly_update_public, 40000);
|
|
|
|
|
setTimeout(tvly_journey_progress, 5000);
|
2019-04-23 20:27:13 +00:00
|
|
|
|
}
|
2019-05-07 15:56:40 +00:00
|
|
|
|
$('a[href]').click(function() {
|
2019-05-06 16:07:53 +00:00
|
|
|
|
$('nav .preloader-wrapper').addClass('active');
|
|
|
|
|
});
|
2018-10-05 14:33:59 +00:00
|
|
|
|
});
|