-
Notifications
You must be signed in to change notification settings - Fork 0
/
UI.html
309 lines (256 loc) · 15.6 KB
/
UI.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
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
<html>
<head>
<script>
var remoteServer = null;
</script>
<title>BetterHyperplanning</title>
<link rel="stylesheet" href="https://www.w3schools.com/w3css/4/w3.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<script>
var calendarInfos = {};
// Add "/" to remoteServer to prevent further errors.
if (remoteServer != null && !remoteServer.endsWith("/")) {
remoteServer += "/"
}
function encodeHTMLEntities(text) {
return text.replace(/[\u00A0-\u9999<>\&]/gim, function(i) {
return '&#'+i.charCodeAt(0)+';';
});
}
// Tabs handling
var idCounter = 1;
function changeTab(id) {
// Hide every tab
let tabs = document.getElementById("tab").childNodes;
for (tab of tabs) {
if (tab.style) {
tab.style.display = "none";
}
}
// Uncolor every tab button
let buttons = document.getElementById("tab.buttons").childNodes;
// Hide every tab
for (button of buttons) {
if (button.style) {
button.style.backgroundColor = null;
}
}
let selectedTab = document.getElementById(`calendar.${id}`);
selectedTab.style.display = "block";
document.getElementById(`tab.button.${id}`).style.backgroundColor = "#d1d1d1";
}
function newTab() {
let tabButtonTemplate = document.getElementById("tab.button.template").cloneNode(true);
let calendarTemplate = document.getElementById("calendar.template").cloneNode(true);
tabButtonTemplate.style.display = "block";
tabButtonTemplate.setAttribute('onclick', `changeTab(${idCounter})`);
tabButtonTemplate.id = `tab.button.${idCounter}`;
tabButtonTemplate.innerHTML = `Calendrier ${idCounter}`;
calendarTemplate.id = `calendar.${idCounter}`;
let calendarTemplateOuterHTML = calendarTemplate.outerHTML.replace("url", `url.${idCounter}`)
.replace("spinner", `spinner.${idCounter}`)
.replace("error", `error.${idCounter}`)
.replace("container.subjects", `container.subjects.${idCounter}`)
.replace("container.subjects.name", `container.subjects.name.${idCounter}`)
.replace("id=\"subjects", `id=\"subjects.${idCounter}`)
.replace("id=\"subjects.name", `id=\"subjects.name.${idCounter}`)
.replace("updateSubjects()", `updateSubjects(${idCounter})`);
document.getElementById("tab.buttons").innerHTML += tabButtonTemplate.outerHTML;
document.getElementById("tab").innerHTML += calendarTemplateOuterHTML;
calendarInfos[idCounter] = {};
changeTab(idCounter++);
}
document.addEventListener("DOMContentLoaded", function(){
// Create first tab
newTab();
// Warn user if the remoteServer variable is null.
if (remoteServer == null) {
document.getElementById("remoteServer.missing").style.display = "block"
}
});
function updateSubjects(id) {
if (remoteServer == null) {
return;
}
let calendarInfo = calendarInfos[id];
document.getElementById(`container.subjects.${id}`).style.display = "none";
document.getElementById(`container.subjects.name.${id}`).style.display = "none";
document.getElementById(`error.${id}`).style.display = "none";
document.getElementById("generate.button").disabled = true;
calendarInfo.url = document.getElementById(`url.${id}`).value
if (calendarInfo.url == "") {
return
}
document.getElementById(`spinner.${id}`).style.display = "block";
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function() {
// Check if the request is done.
if (this.readyState == 4) {
if (this.status == 200) {
calendarInfo.subjects = JSON.parse(this.responseText);
document.getElementById(`subjects.${id}`).innerHTML = "";
document.getElementById(`subjects.name.${id}`).innerHTML = "";
for (var code in calendarInfo.subjects) {
document.getElementById(`subjects.${id}`).innerHTML += "<li class=\"w3-display-container\"><input id=\"" + code + ".checkbox." + id + "\" class=\"w3-check\" type=\"checkbox\" checked=\"checked\" onclick=\"toggleSubjectName(event.srcElement.id);\"><label>" + calendarInfo.subjects[code] + "</label></li>";
document.getElementById(`subjects.name.${id}`).innerHTML += "<li id=\"" + code + ".subject." + id + "\" class=\"w3-display-container\"><label>" + calendarInfo.subjects[code] + "</label><input id=\"" + code + ".name." + id + "\" class=\"w3-input\" type=\"text\" placeholder=\"Nouveau nom\"></li>";
}
document.getElementById(`container.subjects.${id}`).style.display = "block";
document.getElementById(`container.subjects.name.${id}`).style.display = "block";
document.getElementById("generate.button").disabled = false;
} else {
document.getElementById(`error.${id}`).innerHTML = "Erreur " + this.status + ((this.responseText != "") ? ": " + this.responseText : "");
document.getElementById(`error.${id}`).style.display = "block";
}
document.getElementById(`spinner.${id}`).style.display = "none";
}
};
xmlhttp.open("GET", remoteServer + "subjects/?url=" + escape(calendarInfo.url));
xmlhttp.send();
}
function generateURL() {
document.getElementById("modal").style.display = "block";
document.getElementById(`modal.spinner`).style.display = "block";
document.getElementById(`modal.error`).style.display = "none";
document.getElementById(`modal.output`).style.display = "none";
let preference = [];
for (id in calendarInfos) {
let calendarInfo = calendarInfos[id];
let ignore = []
var subjects = {};
for (var code in calendarInfo.subjects) {
if (!document.getElementById(`${code}.checkbox.${id}`).checked) {
ignore.push(code);
}
if (document.getElementById(`${code}.name.${id}`).value != "") {
subjects[code] = encodeHTMLEntities(document.getElementById(`${code}.name.${id}`).value);
}
}
preference.push({"url": calendarInfo.url, "ignore": ignore, "subjects": subjects});
}
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function() {
// Check if the request is done.
if (this.readyState == 4) {
if (this.status == 200) {
document.getElementById("modal.output.url").value = `${remoteServer}v2/?preferenceID=${this.responseText}`;
document.getElementById(`modal.output`).style.display = "block";
} else {
document.getElementById(`modal.error`).innerHTML = "Erreur " + this.status + ((this.responseText != "") ? ": " + this.responseText : "");
document.getElementById(`modal.error`).style.display = "block";
}
document.getElementById(`modal.spinner`).style.display = "none";
}
};
xmlhttp.open("POST", remoteServer + "register/");
xmlhttp.send(JSON.stringify(preference));
}
function toggleSubjectName(id) {
let subjectID = id.replace(".checkbox", ".subject")
document.getElementById(subjectID).hidden = !document.getElementById(id).checked
}
function toggleIgnoreDuplicates() {
var output = document.getElementById("modal.output.url").value
console.log(output)
console.log(document.getElementById("ignoreDuplicates.checkbox").checked)
if (document.getElementById("ignoreDuplicates.checkbox").checked) {
document.getElementById("modal.output.url").value = `${output}&ignoreDuplicates`
} else {
document.getElementById("modal.output.url").value = output.replace("&ignoreDuplicates", "")
}
}
</script>
</head>
<body>
<!-- Navigation bar -->
<div class="w3-bar w3-light-grey w3-large">
<a class="w3-bar-item">BetterHyperplanning</a>
<button id="generate.button" class="w3-bar-item w3-button w3-green w3-right" onclick="generateURL()" disabled>Générer l'URL</button>
</div>
<!-- Tabs bar -->
<div class="w3-bar w3-light-gray w3-border-bottom">
<div id="tab.buttons">
<button id="tab.button.template" class="w3-bar-item w3-button" style="display: none;">Calendrier Template</button>
</div>
<button class="w3-bar-item w3-button w3-green" onclick="newTab()">Ajouter un calendrier</button>
</div>
<!-- Tabs div -->
<div id="tab">
<div id="calendar.template" style="display: none;">
<!-- Urls input -->
<div class="w3-container w3-animate-opacity">
<p>Placez ici l'URL iCal trouvable sur l'<a href="https://hplanning2019.umons.ac.be/invite">hyperplanning de l'UMONS (2019-2020)</a>. L'interface web d'hyperplanning 2020-2021 ne propose plus de générer l'URL iCal, cependant vous pouvez aller chercher celle de votre année et option d'étude sur l'<a href="https://hplanning2019.umons.ac.be/invite">hyperplanning 2019-2020</a> et modifier "https://hplanning2019.umons.ac.be/" par "https://hplanning2020.umons.ac.be/". Vous obtiendrez ainsi l'URL iCal 2020-2021.</p>
<div class="w3-container w3-card-4 w3-padding-16">
<label>URL</label>
<input id="url" class="w3-input" type="text" onchange="updateSubjects();" onkeyup="if (event.keyCode == 13) {this.onchange();}" onpaste="this.onchange();">
</div>
<p class="w3-small">Appuyez sur "Entrer" pour charger.</p>
</div>
<!-- Spinner div -->
<div id="spinner" class="w3-container w3-center w3-padding-64" style="display: none;">
<i class="fa fa-spinner w3-spin" style="font-size:32px"></i>
</div>
<!-- Error div -->
<div id="error" class="w3-container w3-center w3-padding-64" style="color: red; display: none;">
Erreur
</div>
<div id="container.subjects" class="w3-container w3-animate-opacity" style="display: none;">
<h2>Cours</h2>
<p>Séléctionnez les cours auxquels vous participez.</p>
<ul id="subjects" class="w3-ul w3-card-4">
<li class="w3-display-container">
<input class="w3-check" type="checkbox" checked="checked">
<label>Subject</label>
</li>
</ul>
</div>
<div id="container.subjects.name" class="w3-container w3-animate-opacity w3-margin-bottom" style="display: none;">
<h2>Nom des cours</h2>
<p>Modfiez le nom des cours que vous souhaitez.</p>
<ul id="subjects.name" class="w3-ul w3-card-4">
<li class="w3-display-container">
<label>Subject name</label>
<input class="w3-input" type="text" placeholder="Nouveau nom">
</li>
</ul>
</div>
</div>
</div>
<!-- remoteServer missing warning -->
<div id="remoteServer.missing" class="w3-modal">
<div class="w3-modal-content">
<header class="w3-container w3-teal">
<span onclick="document.getElementById('remoteServer.missing').style.display='none'" class="w3-button w3-display-topright" style="font-size:30px">×</span>
<h2>L'adresse du serveur est manquante</h2>
</header>
<div class="w3-container w3-padding-16">
Veuillez renseigner l'adresse du serveur, pour cela suivez les instructions de la section "Générer l'URL" du README.md.
</div>
</div>
</div>
<!-- Generated url popup -->
<div id="modal" class="w3-modal">
<div class="w3-modal-content">
<header class="w3-container w3-teal">
<span onclick="document.getElementById('modal').style.display='none'" class="w3-button w3-display-topright" style="font-size:30px">×</span>
<h2>Copiez l'URL et ajoutez-la dans vos calendriers souscrits</h2>
</header>
<!-- Body -->
<div class="w3-container w3-margin-top" style="display: block;">
<input id="ignoreDuplicates.checkbox" class="w3-check" type="checkbox" onclick="toggleIgnoreDuplicates();">
<label>Ingorer les doublons</label>
</div>
<!-- Spinner div -->
<div id="modal.spinner" class="w3-container w3-center w3-padding-64" style="display: block;">
<i class="fa fa-spinner w3-spin" style="font-size:32px"></i>
</div>
<!-- Error div -->
<div id="modal.error" class="w3-container w3-center w3-padding-64" style="color: red; display: block;">
Erreur
</div>
<div id="modal.output" class="w3-container w3-padding-16" style="display: none;">
<textarea id="modal.output.url" class="w3-input w3-border" type="text" style="height:40%"></textarea>
</div>
</div>
</div>
</body>
</html>