-
Notifications
You must be signed in to change notification settings - Fork 0
/
Sidebar.html
89 lines (82 loc) · 2.98 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
<!DOCTYPE html>
<html>
<head>
<base target="_top">
<meta charset="utf-8">
<link href="//cdn.muicss.com/mui-0.10.3/css/mui.min.css" rel="stylesheet" type="text/css" />
<script src="//cdn.muicss.com/mui-0.10.3/js/mui.min.js"></script>
<style>
#content { margin: 1rem; }
legend { padding: 0 2px; }
label { padding-right: 4px; }
fieldset { border-radius: 6px; }
#cover { position: absolute; left: 0; top: 0; width: 100%; height: 100%; background-color: rgba(255, 255, 255, 0.75); }
</style>
</head>
<body>
<div id="content">
<div id="loading">Loading...</div>
<div id="ui" style="display: none;">
<h3>Process Sheet Data</h3>
<fieldset id="inputs">
<legend>Options</legend>
</fieldset>
<input type="checkbox" name="header" id="header">
<label for="header">Contains header row?</label>
<input type="button" value="Write" onclick="writeColumnCombos()">
</div>
</div>
<div id="cover" style="display: none;"><div style="align-self: center; margin: auto;">Running script...</div></div>
<script>
function buildUi(data) {
var sheetNames = data;
document.querySelector('#loading').style.display = 'none';
createMenu(sheetNames, 'source-sheet', 'Source sheet', '#inputs');
createMenu(sheetNames, 'destination-sheet', 'Destination sheet', '#inputs');
document.querySelector('#ui').style.display = 'unset';
}
function createMenu(items, id, label, target) {
var frag = new DocumentFragment();
var sel = document.createElement('select');
var lab = document.createElement('label');
sel.id = lab.htmlFor = id;
lab.textContent = label;
items.forEach(item => {
var opt = document.createElement('option');
opt.value = item;
opt.text = item;
sel.add(opt);
});
frag.appendChild(lab);
frag.appendChild(sel);
document.querySelector(target).appendChild(frag);
}
function getOptions() {
var src = document.querySelector('#source-sheet').value;
var dest = document.querySelector('#destination-sheet').value;
var header = document.querySelector('#header').checked;
document.querySelector('#cover').style.display = 'flex';
return { src: src, dest: dest, header: header };
}
function getSheetNames() {
google.script.run
.withSuccessHandler(buildUi)
.withFailureHandler(logError)
.getSheetNames();
}
function writeColumnCombos() {
google.script.run
.withSuccessHandler(writeSuccess)
.withFailureHandler(logError)
.writeColumnCombos(getOptions());
}
function writeSuccess(msg) {
document.querySelector('#cover').style.display = 'none';
}
function logError(msg) {
console.log(msg);
}
window.onload = getSheetNames;
</script>
</body>
</html>