-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSumValues.html
213 lines (194 loc) · 7.12 KB
/
SumValues.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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
<!--
* Copyright 2015 Google Inc. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* This work has been modified and redistributed by Miles Catlett, http://milescatlett.com
-->
<!DOCTYPE html>
<html>
<head>
<base target="_top">
<link rel="stylesheet" href="https://ssl.gstatic.com/docs/script/css/add-ons1.css">
<!-- The CSS package above applies Google styling to buttons and other elements. -->
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<!-- jQuery library -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<!-- Latest compiled JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="https://ssl.gstatic.com/docs/script/css/add-ons1.css">
<!-- The CSS package above applies Google styling to buttons and other elements. -->
<style>
.branding-below {
bottom: 54px;
top: 0;
}
.branding-text {
left: 7px;
position: relative;
top: 3px;
}
.logo {
vertical-align: middle;
}
.width-100 {
width: 100%;
box-sizing: border-box;
-webkit-box-sizing : border-box;
-moz-box-sizing : border-box;
}
label {
font-weight: bold;
}
#multiple-options {
background-color: #eee;
border-color: #eee;
border-width: 5px;
border-style: solid;
display: none;
}
#multiple-save,
{
margin-bottom: 10px;
}
</style>
</head>
<body>
<div style="margin: 20px 20px 20px 20px;">
<p class="lead">Sum values submitted through the form by configuring settings.</p><p>Check the box to add responses together.
Then select the fields you would like to add together by holding down the <kbd>CTRL</kbd> key. The values you have
previously saved are shown in the blue box below.</p>
<form>
<!-- Block #1 -->
<div class="block">
<input type="checkbox" id="multiple-save">
<label for="multiple-save">Add responses together</label>
</div>
<div class="block form-group" id="multiple-options">
<label for="multiple-select">
Select the items you would like to add together.
</label>
<select multiple class="width-100" id="multiple-select"></select>
</div>
<!-- End of Blocks.... -->
<div class="block" id="button-bar">
<button class="action" id="save-settings">Save</button>
</div>
</form>
<div style="margin-top:20px;" class="alert alert-info"><strong>Selected values:</strong>
<div id="result" style="margin-top:10px;"></div></div>
</div>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js">
</script>
<script>
/**
* On document load, assign required handlers to each element,
* and attempt to load any saved settings.
*/
$(function() {
$('#save-settings').click(saveSettingsToServer);
$('#multiple-save').click(toggleMultiple);
google.script.run
.withSuccessHandler(loadSettings)
.withFailureHandler(showStatus)
.withUserObject($('#button-bar').get())
.getSettings();
});
/**
* Callback function that populates the notification options using
* previously saved values.
*
* @param {Object} settings The saved settings from the client.
*/
function loadSettings(settings) {
// creating settings
if (settings.multipleSave === 'true') {
$('#multiple-save').prop('checked', true);
$('#multiple-options').show();
}
// Fill the respondent email select box with the
// titles given to the form's text Items. Also include
// the form Item IDs as values so that they can be
// easily recovered during the Save operation.
for (var i = 0; i < settings.formItems.length; i++) {
var option = $('<option>').attr('value', settings.formItems[i]['id'])
.text(settings.formItems[i]['title']);
$('#multiple-select').append(option);
}
if (settings.multipleSave == 'true') {
document.getElementById('result').innerHTML = settings.multipleSelect;
} else if (settings.multipleSave == 'false') {
document.getElementById('result').innerHTML = 'No values selected.';
}
}
/**
* Toggles the visibility of the form creator notification options.
*/
function toggleMultiple() {
$('#status').remove();
if ($('#multiple-save').is(':checked')) {
$('#multiple-options').show();
} else {
$('#multiple-options').hide();
}
}
/**
* Collects the options specified in the add-on sidebar and sends them to
* be saved as Properties on the server.
*/
function saveSettingsToServer() {
this.disabled = true;
$('#status').remove();
var multipleSave = $('#multiple-save').is(':checked');
var settings = {
'multipleSave': multipleSave,
};
// Only save creator options if notify is turned on
if (multipleSave) {
settings.multipleSelect = $("select option:selected").map(function(){ return this.value }).get().join(", ");
} else {
settings.multipleSelect = 'No values selected.';
}
// Save the settings on the server
google.script.run
.withSuccessHandler(
function(msg, element) {
showStatus('Saved settings', $('#button-bar'));
element.disabled = false;
})
.withFailureHandler(
function(msg, element) {
showStatus(msg, $('#button-bar'));
element.disabled = false;
})
.withUserObject(this)
.saveSettings(settings);
document.getElementById('result').innerHTML = settings.multipleSelect;
}
/**
* Inserts a div that contains an status message after a given element.
*
* @param {String} msg The status message to display.
* @param {Object} element The element after which to display the Status.
*/
function showStatus(msg, element) {
var div = $('<div>')
.attr('id', 'status')
.attr('class','error')
.text(msg);
$(element).after(div);
}
</script>
</body>
</html>