-
Notifications
You must be signed in to change notification settings - Fork 0
/
Sidebar.html
282 lines (255 loc) · 9.02 KB
/
Sidebar.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
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
<!--
* 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.
-->
<!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. -->
<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;
}
#creator-options,
#respondent-options {
background-color: #eee;
border-color: #eee;
border-width: 5px;
border-style: solid;
display: none;
}
#creator-email,
#respondent-email,
#button-bar,
#submit-subject {
margin-bottom: 10px;
}
#response-step {
display: inline;
}
</style>
</head>
<body>
<div class="sidebar branding-below">
<form>
<div class="block">
<input type="checkbox" id="creator-notify">
<label for="creator-notify">Notify me</label>
</div>
<div class="block form-group" id="creator-options">
<label for="creator-email">
My email addresses (comma-separated)
</label>
<input type="text" class="width-100" id="creator-email">
<label for="response-step">Send notifications after every</label>
<input type="number" id="response-step" value="10"
min="1" max="99999"> responses (default 10)
</div>
<div class="block">
<input type="checkbox" id="respondent-notify">
<label for="respondent-notify">Notify respondents</label>
</div>
<div class="block form-group" id="respondent-options">
<label for="respondent-email">
Which question asks for their email?
</label>
<select class="width-100" id="respondent-email"></select>
<label for="submit-subject">
Notification email subject:
</label>
<input type="text" class="width-100" id="submit-subject">
<label for="submit-notice">Notification email body:</label>
<textarea rows="8" cols="40" id="submit-notice"
class="width-100"></textarea>
</div>
<div class="block" id="button-bar">
<button class="action" id="save-settings">Save</button>
</div>
</form>
</div>
<div class="sidebar bottom">
<img alt="Add-on logo" class="logo" width="25"
src="https://googledrive.com/host/0B0G1UdyJGrY6XzdjQWF4a1JYY1k/form-notifications-logo-small.png">
<span class="gray branding-text">Form Notifications by Google</span>
</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);
$('#creator-notify').click(toggleCreatorNotify);
$('#respondent-notify').click(toggleRespondentNotify);
$('#response-step').change(validateNumber);
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) {
$('#creator-email').val(settings.creatorEmail);
$('#response-step').val(!settings.responseStep ?
10 : settings.responseStep);
$('#submit-subject').val(!settings.responseSubject ?
'Thank you for filling out our form!' :
settings.responseSubject);
$('#submit-notice').val(!settings.responseText ?
'Thank you for responding to our form!' :
settings.responseText);
if (settings.creatorNotify === 'true') {
$('#creator-notify').prop('checked', true);
$('#creator-options').show();
}
if (settings.respondentNotify === 'true') {
$('#respondent-notify').prop('checked', true);
$('#respondent-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.textItems.length; i++) {
var option = $('<option>').attr('value', settings.textItems[i]['id'])
.text(settings.textItems[i]['title']);
$('#respondent-email').append(option);
}
$('#respondent-email').val(settings.respondentEmailItemId);
}
/**
* Toggles the visibility of the form creator notification options.
*/
function toggleCreatorNotify() {
$('#status').remove();
if ($('#creator-notify').is(':checked')) {
$('#creator-options').show();
} else {
$('#creator-options').hide();
}
}
/**
* Toggles the visibility of the form sumbitter notification options.
*/
function toggleRespondentNotify() {
$('#status').remove();
if($('#respondent-notify').is(':checked')) {
$('#respondent-options').show();
} else {
$('#respondent-options').hide();
}
}
/**
* Ensures that the entered step is a number between 1
* and 99999, inclusive.
*/
function validateNumber() {
var value = $('#response-step').val();
if (!value) {
$('#response-step').val(10);
} else if (value < 1) {
$('#response-step').val(1);
} else if (value > 99999) {
$('#response-step').val(99999);
}
}
/**
* 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 creatorNotify = $('#creator-notify').is(':checked');
var respondentNotify = $('#respondent-notify').is(':checked');
var settings = {
'creatorNotify': creatorNotify,
'respondentNotify': respondentNotify
};
// Only save creator options if notify is turned on
if (creatorNotify) {
settings.responseStep = $('#response-step').val();
settings.creatorEmail = $('#creator-email').val().trim();
// Abort save if entered email is blank
if (!settings.creatorEmail) {
showStatus('Enter an owner email', $('#button-bar'));
this.disabled = false;
return;
}
}
// Only save respondent options if notify is turned on
if (respondentNotify) {
settings.respondentEmailItemId = $('#respondent-email').val();
settings.responseSubject = $('#submit-subject').val();
settings.responseText = $('#submit-notice').val();
}
// 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);
}
/**
* 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>