-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathSidebar.html
102 lines (93 loc) · 2.9 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
<!DOCTYPE html>
<html>
<head>
<base target="_top">
<link rel="stylesheet" href="https://ssl.gstatic.com/docs/script/css/add-ons1.css">
<style>
.width-100 {
width: 100%;
box-sizing: border-box;
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
}
label {
font-weight: bold;
}
#options {
background-color: #eee;
border-color: #eee;
border-width: 5px;
border-style: solid;
}
#bot-api-token,
#chat-id {
margin-bottom: 10px;
}
</style>
</head>
<body>
<div class="sidebar branding-below">
<form>
<div class="block form-group" id="options">
<label for="bot-api-token">Bot API key</label>
<input type="text" class="width-100" id="bot-api-token">
<label for="chat-id">Chat ID</label>
<input type="text" class="width-100" id="chat-id">
<label for="message">Message (allows {name} placeholders):</label>
<textarea rows="8" cols="40" id="message" class="width-100"></textarea>
</div>
<div class="block" id="button-bar">
<button class="action" id="save-settings">Save</button>
</div>
</form>
</div>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js">
</script>
<script>
$(function() {
$('#save-settings').click(saveSettingsToServer);
google.script.run
.withSuccessHandler(loadSettings)
.withFailureHandler(showStatus)
.withUserObject($('#button-bar').get())
.getSettings();
});
function loadSettings(settings) {
$('#bot-api-token').val(settings.botApiToken);
$('#chat-id').val(settings.chatId);
$('#message').val(settings.message);
}
function saveSettingsToServer() {
this.disabled = true;
$('#status').remove();
var creatorNotify = $('#creator-notify').is(':checked');
var respondentNotify = $('#respondent-notify').is(':checked');
var settings = {
'botApiToken': $('#bot-api-token').val(),
'chatId': $('#chat-id').val(),
'message': $('#message').val(),
};
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);
}
function showStatus(msg, element) {
var div = $('<div>')
.attr('id', 'status')
.attr('class','error')
.text(msg);
$(element).after(div);
}
</script>
</body>
</html>