-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathConnectionDetailsJavaScript.html
222 lines (196 loc) · 6.05 KB
/
ConnectionDetailsJavaScript.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
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script>
$(function() {
disableButtons();
toggleLoader();
$('#sidebar-save-button').click(onSaveClick);
$('#sidebar-check-button').click(onCheckClick);
$('#sidebar-clear-button').click(onClearClick);
$('#sidebar-host').keyup(hostChanged);
$('#sidebar-port').keyup(hostChanged);
$('#sidebar-user').keyup(hostChanged);
$('#sidebar-pass').keyup(hostChanged);
$('#sidebar-ssl').change(hostChanged);
getHostData(getInitialHostSuccess);
});
function getHostData(success_function) {
if(!success_function) {
success_function = function(msg) { };
}
google.script.run
.withSuccessHandler(success_function)
.withFailureHandler(failure)
.getHostData();
}
function getInitialHostSuccess(msg) {
$('#sidebar-host').val(msg.host);
$('#sidebar-port').val(msg.port);
$('#sidebar-user').val(msg.username);
$('#sidebar-pass').val(msg.password);
$('#sidebar-ssl').prop('checked', msg.use_ssl);
$('#was-checked').val(msg.was_checked);
enableButtons();
if(msg.was_checked === "1") {
$("#sidebar-check-button").prop('disabled', true);
addContinueButton();
onContinueClick();
} else {
$('#connection-details-sidebar').removeClass('hidden');
$('#push-data-sidebar').addClass('hidden');
}
toggleLoader();
}
function hostChanged() {
$('#was-checked').val(0);
$("#sidebar-check-button").prop('disabled', false);
disableContinueButton();
}
function onSaveClick() {
disableButtons();
toggleLoader();
var host = getHost();
// First check the connection
checkClusterConnection(host,onSaveClickCheckHostSuccess);
}
function onClearClick() {
disableButtons();
enableLoader();
google.script.run
.withSuccessHandler(function() {
clearHost();
hostChanged();
showStatus('Data cleared.');
enableButtons();
disableLoader();
} )
.withFailureHandler(failure)
.clearData();
}
function onSaveClickCheckHostSuccess(msg) {
$('#was-checked').val(1);
$("#sidebar-check-button").prop('disabled', true);
var host = getHost();
saveHostData(host);
}
function saveHostData(host) {
google.script.run
.withSuccessHandler(saveClickSuccess)
.withFailureHandler(failure)
.saveHostData(host);
}
function saveClickSuccess(msg) {
showStatus('Successfully verified and saved your cluster details.');
enableButtons();
$("#sidebar-check-button").prop('disabled', true);
addContinueButton();
toggleLoader();
}
function failure(msg) {
showStatus(msg, 'error');
enableButtons();
toggleLoader();
}
/**
* Calls the server to retrieve information from the sheet.
* Gets the value in the active cell, which is then placed in the
* sidebar text field.
*/
function onCheckClick() {
disableButtons();
toggleLoader();
var host = getHost();
checkClusterConnection(host,checkClusterSuccess);
}
function checkClusterConnection(host,success_callback) {
google.script.run
.withSuccessHandler(success_callback)
.withFailureHandler(failure)
.checkClusterConnection(host);
}
function checkClusterSuccess(msg) {
showStatus('Successfully connected to your cluster.');
$('#was-checked').val(1);
enableButtons();
toggleLoader();
$("#sidebar-check-button").prop('disabled', true);
}
function checkClusterFailure(msg) {
showStatus(msg, 'error');
enableButtons();
toggleLoader();
}
/**
* Displays the given status message in the sidebar.
*
* @param {String} msg The status message to display.
* @param {String} classId The message type (class id) that the message
* should be displayed as.
*/
function showStatus(msg, classId) {
$('#sidebar-status').removeClass().html(msg);
if (classId) {
$('#sidebar-status').addClass(classId);
}
}
function toggleLoader() {
if($('#static').hasClass('show-inline')) {
$('#static').removeClass().addClass('hidden');
$('#loader').removeClass().addClass('show-inline');
} else {
$('#loader').removeClass().addClass('hidden');
$('#static').removeClass().addClass('show-inline');
}
}
function disableButtons() {
$("#sidebar-save-button").prop('disabled', true);
$("#sidebar-check-button").prop('disabled', true);
}
function enableButtons() {
$("#sidebar-save-button").prop('disabled', false);
$("#sidebar-check-button").prop('disabled', false);
}
function getHost() {
return {
host : $('#sidebar-host').val().trim(),
port : $('#sidebar-port').val(),
username : $('#sidebar-user').val(),
password : $('#sidebar-pass').val(),
use_ssl : $('#sidebar-ssl').is(':checked'),
was_checked : $('#was-checked').val()
};
}
function clearHost() {
$('#sidebar-host').val('');
$('#sidebar-port').val('');
$('#sidebar-user').val('');
$('#sidebar-pass').val('');
$('#sidebar-ssl').attr('checked', false);
$('#was-checked').val(0);
}
function addContinueButton() {
$('#sidebar-save-button').removeClass();
if(!$('#sidebar-continue-button').length) {
var table = $('#connection-details-table tr:last');
table.after(['<td colspan="3" style="text-align:right;">',
'<button id="sidebar-continue-button" class="action">Edit Data Details</button>',
'</td>'].join(''));
$('#sidebar-continue-button').click(onContinueClick);
} else {
enableContinueButton();
}
}
function disableContinueButton() {
if($('#sidebar-continue-button').length > 0) {
$('#sidebar-continue-button').prop('disabled', true);
}
}
function enableContinueButton() {
if($('#sidebar-continue-button').length > 0) {
$('#sidebar-continue-button').prop('disabled', false);
}
}
function onContinueClick() {
$('#connection-details-sidebar').addClass('hidden');
$('#push-data-sidebar').removeClass('hidden');
}
</script>