-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
232 lines (215 loc) · 8.45 KB
/
index.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
223
224
225
226
227
228
229
230
231
232
<!DOCTYPE html>
<html lang="en">
<head>
<title>Osmium Home</title>
<link href="style.css" rel="stylesheet" type ="text/css"/>
<link href="favicon.ico" rel="icon" type="image/png">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script src="scripts.js"></script>
<script src="https://www.gstatic.com/charts/loader.js"></script>
<script>
google.charts.load('current');
</script>
<script async defer src="https://apis.google.com/js/api.js"
onload="this.onload=loadAuth();"
onreadystatechange="if (this.readyState === 'complete') this.onload()">
</script>
<link href="https://fonts.googleapis.com/css?family=Roboto:100,300,400,500,700,900" rel="stylesheet">
<link href="https://fonts.googleapis.com/icon?family=Material+Icons|Material+Icons+Outlined|Material+Icons+Round" rel="stylesheet">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body id='auth-body' class='bigbody'>
<div id="newdb-popup" class="bigpopup pretty-scrollbar-light">
<div class="content">
<div class="title-center fullsize fullwidth">Create New Database</div>
<i class="material-icons">storage</i>
<input id="newdb" type="text" placeholder="Database Name"></input>
<button id='newdb-loading' class="material-icons big ok" onclick="throwCreateDatabase();"></button>
<button class="material-icons big cancel" onclick='showNewDB(false);'>close</button>
</div>
</div>
<div class='pretty-scrollbar-dark'>
<div class='fullsize title-center'><span class="logotext" onclick="window.open('/osmium','_self')">Osmium<span></div>
<div class='smallish-spacer'></div>
<button class='big' id="auth-button" onclick="toggleAuth()">
<svg viewBox="0 0 30 30">
<path d="M29.4 15.34c0-1.063-.095-2.085-.273-3.067H15v5.802h8.073c-.348 1.875-1.405 3.464-2.993 4.527v3.764h4.847c2.837-2.61 4.473-6.457 4.473-11.025z" fill="#4285F4"></path>
<path d="M15 30c4.05 0 7.445-1.343 9.927-3.634l-4.847-3.764c-1.344.9-3.062 1.432-5.08 1.432-3.907 0-7.214-2.64-8.393-6.184H1.595v3.886C4.065 26.64 9.135 30 15 30z" fill="#34A853"></path>
<path d="M6.607 17.85c-.3-.9-.47-1.86-.47-2.85s.17-1.95.47-2.85V8.264H1.595C.58 10.29 0 12.58 0 15s.58 4.71 1.595 6.736l5.012-3.886z" fill="#FBBC05"></path>
<path d="M15 5.966c2.202 0 4.18.757 5.734 2.243l4.302-4.303C22.44 1.487 19.043 0 15 0 9.136 0 4.064 3.36 1.595 8.264l5.012 3.886C7.787 8.605 11.093 5.966 15 5.966z" fill="#EA4335"></path>
</svg>
<img id='google-profilepic'></img>
<span class='tooltip' id='google-userinfo'>
</span>
</button>
<div class='smallish-spacer'></div>
<div class='dropdown auth-required'>
<span id="current-db">Select a database:</span>
<div id="db-list" class='dropdown-content'>
<p>Loading databases...</p>
</div>
</div>
<button class="new auth-required" onclick="showNewDB(true);">New</button>
<div class='smallish-spacer'></div>
<button class='big new-tab db-required' onclick="window.open('kiosk.html'+getDatabaseQueryString(),'_blank')">Student Kiosk</button>
<div class='smallish-spacer'></div>
<button class='big new-tab db-required' onclick="window.open('library-desk.html'+getDatabaseQueryString(),'_blank')">Library Desk</button>
<div class='smallish-spacer'></div>
</div>
<div class="half-pair infolinks">
<div class="left">
<button onclick="window.open('about.html','_blank')" class="large-text">About</button>
</div>
<div class="middle"></div>
<div class="right">
<button onclick="window.open('privacy-policy.html','_blank')" class="large-text">Privacy Policy</button>
</div>
</div>
</body>
</html>
<script>
if (new URLSearchParams(window.location.search).get('debug') == "true") {
var div = document.createElement('div');
div.style = "position: fixed; left:0;top:0;"
var btn = document.createElement('button');
btn.setAttribute('onclick',"document.getElementById('auth-body').classList.toggle('authenticated');document.getElementById('google-profilepic').src = 'favicon.ico';document.getElementById('google-userinfo').innerHTML = 'Signed in as [email protected]';");
btn.innerHTML = "toggle db";
div.appendChild(btn);
var btn = document.createElement('button');
btn.setAttribute('onclick',"document.getElementById('auth-body').classList.toggle('databased')");
btn.innerHTML = "toggle auth";
div.appendChild(btn);
document.body.appendChild(div);
}
function showError(errorname) {
switch (errorname) {
case 'no-url-database':
console.warn("CRITICAL ERROR: No database selected via url.");
break;
case 'auth-lost':
errorPopup("CRITICAL ERROR: Google authentication lost.")
break;
case 'bad-pageid':
console.warn("CRITICAL ERROR: Page ID for reference sheet not set. (Was a database selected?)");
break;
default:
errorPopup("UNDEFINED ERROR: "+errorname+" (No more context was provided)");
break;
}
}
function errorPopup(message) {
var popup = document.createElement('div');
popup.classList.add('error-popup');
var text = document.createElement('div');
text.innerHTML = message;
popup.appendChild(text);
var close = document.createElement('button');
close.innerHTML = 'close';
close.setAttribute('onclick','this.parentElement.remove()');
popup.appendChild(close);
document.body.appendChild(popup);
throw new Error(message);
}
function getDatabaseQueryString() {
if (databaseId == null) {
return "";
} else {
return "?id="+databaseId;
}
}
function showNewDB(state) {
if (state == true) {
document.getElementById('newdb-popup').classList.add('visible');
document.getElementById('newdb').focus();
} else {
document.getElementById('newdb-popup').classList.remove('visible');
document.getElementById("newdb").value = "";
document.getElementById('newdb-loading').classList.remove('loading');
createDatabaseHTMLSTATE = 0;
}
}
document.getElementById('newdb').addEventListener("keydown", function(event) {
if (event.keyCode === 13) {
event.preventDefault();
throwCreateDatabase();
}
});
/// BACKEND LINKAGE
// states for UI callbacks
// 0 - not active / user closed UI
// 1 - sending query / awaiting response
//createDatabase
var createDatabaseHTMLSTATE = 0;
function throwCreateDatabase() {
if (createDatabaseHTMLSTATE == 0) { //prevent double submission
var name = document.getElementById('newdb').value;
if (name != "") {
document.getElementById('newdb-loading').classList.add('loading');
createDatabase(name);
createDatabaseHTMLSTATE = 1;
}
}
}
function catchCreateDatabase(response){
catchSelectDatabase(selectDatabase(response));
if (createDatabaseHTMLSTATE == 1) { //don't touch UI if already closed
showNewDB(false);
}
}
//selectDatabase
function catchSelectDatabase(id) {
var dbname = getDatabaseName(id);
document.getElementById('current-db').innerText = dbname;
document.getElementById('auth-body').classList.add('databased');
setHashmark(id);
}
function catchGetDatabases(databases) {
var dblist = document.getElementById('db-list');
dblist.innerHTML = '';
var i = 0;
for (var id in databases) {
i++;
var el = document.createElement('p')
el.innerText = getDatabaseName(id);
el.setAttribute('onclick','catchSelectDatabase(selectDatabase("'+id+'"));');
dblist.appendChild(el);
}
if (i < 1) {
var el = document.createElement('p')
el.innerText = "No databases found";
el.setAttribute('onclick','showNewDB(true);');
dblist.appendChild(el);
}
if (knownDatabases != undefined && getHashmark() != undefined && knownDatabases[getHashmark()] != undefined && databaseId == undefined){
catchSelectDatabase(selectDatabase(getHashmark()));
}
else {
setHashmark("");
}
}
// Updates toggleAuth button status text
function updateAuthButton() {
var el = document.getElementById('auth-body');
if (GoogleAuth.isSignedIn.get()) {
document.cookie = "keepAuth=true";
if (!(el.classList.contains('authenticated'))) {
el.classList.add('authenticated');
document.getElementById('google-profilepic').src = GoogleAuth.currentUser.get().getBasicProfile().getImageUrl();
document.getElementById('google-userinfo').innerHTML = "Signed in as "+GoogleAuth.currentUser.get().getBasicProfile().getEmail();
document.getElementById('current-db').innerHTML = "Select a database:";
getDatabases();
}
}
else {
document.cookie = "keepAuth=null";
el.classList.remove('authenticated');
el.classList.remove('databased');
knownDatabases = {};
databaseId;
pageId = 0;
}
}
function onAuthUpdate() {
updateAuthButton();
}
</script>