-
Notifications
You must be signed in to change notification settings - Fork 2
/
sidebar.html
139 lines (118 loc) · 3.67 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
<!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: 56px;
top: 0;
}
.branding-text {
left: 7px;
position: relative;
top: 3px;
}
.col-contain {
overflow: hidden;
}
.col-one {
float: left;
width: 50%;
}
.logo {
vertical-align: middle;
}
.radio-spacer {
height: 20px;
}
.width-100 {
width: 100%;
}
</style>
</head>
<body>
<div class="sidebar branding-below">
<form>
<div class="block form-group">
<label for="selectAccount"><b>1. Import Google Analytics Views from your account</b></label>
<select id="selectAccount">
<option selected>Loading...</option>
</select>
</div>
<div class="block">
<button class="blue" id="run-get-views">Get views</button>
</div>
<div class="block">
<hr />
</div>
<div class="block form-group">
<p><b>2. Publish changes to Google Analytics</b></p>
<p style="color:red;">Warning: This is not reversible</p>
<button class="blue" id="executeApp">Publish changes</button>
<p id="runningFeedback"> </p>
</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() {
google.script.run.withSuccessHandler(showAccounts).withFailureHandler(showError)
.getAccounts();
$('#run-get-views').click(runGetViews);
$('#executeApp').click(executeApplication);
});
// Callback that updates the accounts list.
function showAccounts(accounts) {
var select = $('#selectAccount');
select.empty();
for (var i = 0; i < accounts.length; i++) {
select.append('<option value="' + accounts[i].id + '">' + accounts[i].name + '</option>');
}
}
// Request to print properties to the sheet.
function runGetViews(e) {
e.preventDefault();
$(this).prop("disabled",true);
google.script.run.withSuccessHandler(function(msg, element){
$(element).prop("disabled", false);
})
.withFailureHandler(showError)
.withUserObject(this).printViewList($("#selectAccount").val());
}
// Execute the update
function executeApplication(e) {
e.preventDefault();
startRunning();
google.script.run.withFailureHandler(showError).withUserObject(this).withSuccessHandler(stopRunning).executeApp();
}
function startRunning() {
$("#error").remove();
$("#executeApp").prop("disabled", true);
$("#runningFeedback").text("Running...").show();
}
function stopRunning() {
$("#executeApp").prop("disabled", false);
$("#runningFeedback").text("Success!").delay(5000).fadeOut(1000);
}
/**
* Inserts 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) {
var div = $('<div id="error" class="error">' + msg + '</div>');
$(element).after(div);
$("#executeApp").prop("disabled", false);
$("#runningFeedback").hide();
}
</script>
</body>
</html>