-
Notifications
You must be signed in to change notification settings - Fork 2
/
preferences.html
103 lines (79 loc) · 3 KB
/
preferences.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
<!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. -->
</head>
<body>
<div class="sidebar branding-below">
<div id="before-error"></div>
<form>
<div class="block form-group">
<label for="prefs-accountList"><b>Process only the following accounts</b><br />(comma separated list: XX,YY,...)</label>
<input id="prefs-accountList" type="text" value="Loading..." />
</div>
<div class="block">
<hr />
</div>
<div class="block">
<button class="grey" id="prefs-cancel">Cancel</button>
<button class="blue" id="prefs-apply" disabled="true">Apply</button>
</div>
</form>
</div>
<div class="sidebar bottom">
<span class="gray branding-text">© 2018-2019 3WhiteHats</span>
</div>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js">
</script>
<script>
// Run initial scripts onLoad.
$(function() {
console.log("preferences.html: displayed") ;
google.script.run.withSuccessHandler(initializePrefsValues).withFailureHandler(showError).getPreferences();
$('#prefs-cancel').click(closePreferences);
$('#prefs-apply').click(applyPreferences);
});
// Helpers
function initializePrefsValues(prefs) {
$('#prefs-accountList').val(prefs['accountList'].join(', ')) ;
$("#prefs-apply").prop("disabled", false);
}
// Callbacks
function closePreferences() {
google.script.host.close();
}
function applyPreferences(e) {
e.preventDefault();
$("#prefs-apply").prop("disabled", true);
// accountList
accountList = $('#prefs-accountList').val() ;
if ( (/^\s*\d+(?:\s*,\s*\d+\s*)*$/.exec(accountList) === null) && (/^\s*$/.exec(accountList) === null) ) {
showError("Invalid accountList format", $('div#before-error'));
$("#prefs-apply").prop("disabled", false);
return;
}
accountList = accountList.split(/,/) ;
for (var loop=0; loop<accountList.length; ++loop) {
accountList[loop] = accountList[loop].replace(/\s*/g, '') ;
}
// update on UserProperties
google.script.run.withSuccessHandler( function(){ google.script.host.close(); } ).withFailureHandler(showError).savePreferences({
accountList: accountList
});
}
/**
* Inserts/replaces a div that contains an error message after a given element.
*
* @param msg The error message to display.
* @param element The element after which to display the error.
*/
function showError(msg, element) {
$('div#error').remove() ;
var div = $('<div id="error" class="error">' + msg + '</div>');
$(element).after(div);
}
</script>
</body>
</html>