bde-liste/static/js/main.js

96 lines
2.2 KiB
JavaScript
Raw Normal View History

2022-12-19 22:26:51 +00:00
const base_url = "https://oss110metz.rezo-rm.fr/"
2022-12-21 21:58:48 +00:00
var page = ['#main-page', '#admin-page', '#login-page', '#demande-page'];
2022-12-21 21:57:49 +00:00
var historyHandler = [];
window.onpopstate = history.onpushstate = function(e) {
2022-12-21 22:22:56 +00:00
if (e.state) {
show_page(e.state, true);
} else {
history.back();
}
2022-12-21 21:57:49 +00:00
};
history.pushState("#main-page", "", "")
2022-12-19 22:26:51 +00:00
function show_page(id) {
2022-12-21 21:58:48 +00:00
for(i in page) {
$(page[i]).hide();
}
2022-12-19 22:26:51 +00:00
$(id).show();
2022-12-21 22:22:56 +00:00
if (!historyPush) {
history.pushState(id, "", "")
}
2022-12-19 22:26:51 +00:00
}
2022-12-21 21:20:48 +00:00
$("#login-button").click(function (e) {
var data = JSON.stringify({
user: $("#login").val(),
password: $("#password").val()
});
$("#password").val('');
$.ajax({
type: "POST",
url: base_url + "login",
data: data,
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (data) {
if(data.success) {
localStorage.setItem("token", data.token);
localStorage.setItem("user", data.user);
show_page('#demande-page');
} else {
2022-12-21 21:57:49 +00:00
2022-12-21 21:20:48 +00:00
}
}
});
});
$("#prank-button").click(function () {
if(localStorage.getItem('token')) {
show_page('#demande-page');
}
else {
show_page('#login-page');
}
});
2022-12-15 13:30:34 +00:00
$(window).on("load", function() {
2022-12-20 20:23:31 +00:00
/* Register the Service Worker */
if ('serviceWorker' in navigator) {
2022-12-21 21:20:48 +00:00
navigator.serviceWorker.register('./js/sw.js');
2022-12-20 20:23:31 +00:00
}
2022-12-21 21:58:48 +00:00
for(i in page) {
$(page[i]).css('z-index', i);
}
2022-12-15 13:30:34 +00:00
/* load timer */
window.setInterval(function() {
var time = $("#timer").text();
var t = time.split(":").map(t => parseInt(t));
t[2] -= 1;
if (t[2] < 0) {
t[2] = 59;
t[1] -= 1;
}
if (t[1] < 0) {
t[1] = 59;
t[0] -= 1;
}
if (t[0] < 0) {
t[0] = 0;
t[1] = 0;
t[2] = 0;
}
2022-12-15 16:14:41 +00:00
$("#timer").text((new Date('December 17, 1995 ' + t.join(':'))).toLocaleTimeString('default', {
hour: '2-digit',
minute: '2-digit',
second: '2-digit'
}));
2022-12-15 13:30:34 +00:00
}, 1000);
2022-12-19 22:26:51 +00:00
});