summaryrefslogtreecommitdiff
path: root/public/static/js/travelynx-actions.js
blob: 7cec0cd5e1b0b80d92c5e95582f2ba5575526406 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
$(document).ready(function() {
	var error_icon = '<i class="material-icons">error</i>';
	$('.action-checkin').click(function() {
		var link = $(this);
		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);
			}
		});
	});
	$('.action-checkout').click(function() {
		var link = $(this);
		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);
			}
		});
	});
});