-
Notifications
You must be signed in to change notification settings - Fork 0
/
round.html
166 lines (144 loc) · 5.49 KB
/
round.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
<!DOCTYPE html>
<html>
<head>
<base target="_top">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css">
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script>
function handleFormSubmit() {
btnLoading();
// Retrieve form values
var formObject = {"newName": $('#new-round').val(), "newType": $('input[name="newType"]:checked').val(), "currentName": $('#current-round').val(), "protect": $('#protections-check').is(':checked')};
// Set gameName property
google.script.run.withSuccessHandler(setGameName).withUserObject(formObject).getGameName();
}
function setGameName(name, formObject) {
formObject.gameName = name;
google.script.run.withSuccessHandler(handleValidateForm).withUserObject(formObject).validateForm(formObject);
}
function handleValidateForm(errors, formObject) {
// Modify CSS depending on validity of entries
if (errors.newName) {
$('#new-round').removeClass('is-invalid');
}
else {
$('#new-round').addClass('is-invalid');
btnNotLoading();
}
if (errors.currentName) {
$('#current-round').removeClass('is-invalid');
}
else {
$('#current-round').addClass('is-invalid');
btnNotLoading();
}
if (errors.newName && errors.currentName) {
submitForm(formObject);
}
}
function closeDialog() {
google.script.host.close();
}
function submitForm(formObject) {
google.script.run.withSuccessHandler(closeDialog).createNewRoundWrapper(formObject);
}
// Detect if the given sheet is a stock round or operating round
function detect(name) {
// First clear out currently detected round
$('#detected').html(" ");
google.script.run.withSuccessHandler(updateDetect).detectRound(name);
}
function btnLoading() {
$('#submit').prop('disabled', true);
$('#submit').html('<span class="spinner-border spinner-border-sm" role="status" aria-hidden="true"></span> Creating...');
}
function btnNotLoading() {
$('#submit').prop('disabled', false);
$('#submit').html("Create!");
}
// Update "detected" tag
function updateDetect(round) {
if (round) {
$('#detected').text("Detected: " + round);
$('#detected').attr('class', 'mt-2 ml-1 text-muted');
$('#current-round').removeClass('is-invalid');
if (round == "SR") {
// If a stock round was detected, the next round has to be an OR
$('#radios-sr').prop('disabled', true);
$('#radios-sr').prop('checked', false);
$('#radios-or').prop('checked', true);
}
else {
$('#radios-sr').prop('disabled', false);
}
}
else {
$('#detected').text("No round detected");
$('#detected').attr('class', 'mt-2 ml-1 text-danger');
$('#current-round').addClass('is-invalid');
btnNotLoading();
}
}
</script>
</head>
<body>
<form id="roundForm">
<div class="container">
<div class="row">
<!-- Text -->
<div class="col-sm-6 mr-auto">
<label for="text">Name of new round:</label>
<input class="form-control" id="new-round" name="newName">
</div>
<div class="col-sm-4 mr-auto">
<label for="newType">New round is a(n):</label>
<div class="form-check">
<input class=form-check-input type="radio" name="newType" id="radios-or" value="OR" checked="checked">
<label class=form-check-label for="radios-or">Operating round</label>
</div>
<div class="form-check">
<input class=form-check-input type="radio" name="newType" id="radios-sr" value="SR">
<label class=form-check-label for="radios-sr">Stock round</label>
</div>
</div>
</div>
<div class="row">
<div class="col-sm-6 mt-3 mr-auto">
<label class="form-check-label">Current round:</label>
<select class="form-control" id="current-round" name="currentName" onchange="detect(this.options[this.selectedIndex].innerHTML)">
</select>
<h6><small id="detected"> </small></h6>
<script>
(function() {
google.script.run.withSuccessHandler(populateNames).getSheetNames();
})();
// Populate dropdown list with sheet names
function populateNames(names) {
var dropdown = $('#current-round');
dropdown.empty();
for (var i=0; i<names.length; i++) {
dropdown.append("<option value=\"" + names[i] + "\">" + names[i] + '</option>');
}
// After populating, update the detected round
if (names.length > 0) {
detect(names[0]);
}
}
</script>
</div>
<div class="col-sm-5 mt-3 ml-auto">
<input class="form-check-input" type="checkbox" id="protections-check" checked>
<label class="form-check-label">Copy cell protections (may take longer)</label>
</div>
</div>
<div class="row mt-3">
<div class="col-sm-4 offset-sm-4">
<div class="form-group">
<button name="button-submit" type="button" id="submit" class="btn btn-success btn-block" onclick="handleFormSubmit()">Create!</button>
</div>
</div>
</div>
</div>
</form>
</body>
</html>