-
Notifications
You must be signed in to change notification settings - Fork 0
/
sideJavaScript.html
77 lines (74 loc) · 2.4 KB
/
sideJavaScript.html
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
<!DOCTYPE html>
<script>
google.script.run.withSuccessHandler(loadRental)
.withFailureHandler(function(msg,element){window.alert("failed"); }).getNextRentals();
function performAction() {
var select = document.getElementById('select')
window.alert(select.selectedIndex)
switch(select.selectedIndex) {
case 0:
enterRental();
break;
case 1:
splitRental();
break;
case 2:
deleteRental();
break;
case 3:
google.script.run.withSuccessHandler(loadRental)
.withFailureHandler(function(msg,element){window.alert("failed"); }).getNextRentals();
default:
window.alert("Selection doesn't exist");
}
}
function loadRental(rentals) {
var main = document.getElementById('main');
var divs = document.getElementsByName('check');
var labels = document.getElementsByName('checktext')
for(var i = 0; i < divs.length; i++) {
if(rentals[i] != null ) {
labels[i].setAttribute('rentalid', rentals[i].id);
labels[i].innerHTML = rentals[i].bikes;
}
else {
divs[i].style.display = 'none';
}
}
main.style.display = 'block';
}
function enterRental() {
var checks = document.getElementsByName('checkbox');
var labels = document.getElementsByName('checktext');
var date = document.getElementById('dateinput').value
var name = document.getElementById('nameinput').value
var ids = [];
for(var i = 0; i < checks.length; i++) {
if (checks[i].checked) {
ids[ids.length] = labels[i].getAttribute('rentalid');
}
}
google.script.run.withSuccessHandler(onSuccess).finishRental(name, date, ids);
function onSuccess(finished) {
if(finished)
google.script.run.withSuccessHandler(loadRental)
.withFailureHandler(function(msg,element){window.alert("failed"); }).getNextRentals();
}
}
function deleteRental() {
var checks = document.getElementsByName('checkbox');
var labels = document.getElementsByName('checktext');
var ids = [];
for(var i = 0; i < checks.length; i++) {
if (checks[i].checked) {
ids[ids.length] = labels[i].getAttribute('rentalid');
}
}
google.script.run.withSuccessHandler(onSuccess).deleteRental(ids)
function onSuccess(completed) {
if (completed)
google.script.run.withSuccessHandler(loadRental)
.withFailureHandler(function(msg,element){window.alert("failed"); }).getNextRentals();
}
}
</script>