Verified Commit 045ee6e4 authored by ynerant's avatar ynerant
Browse files

Don't prevent printing everytime

parent c709336f
Pipeline #10050 passed with stages
in 1 minute and 44 seconds
......@@ -3,18 +3,12 @@ window.addEventListener('load', function() {
let forms = document.getElementsByTagName('form')
let modal_node = document.getElementById('night_modal')
let modal = new bootstrap.Modal(modal_node)
let opening_hours = JSON.parse(document.getElementById('opening_hours').textContent)
for (let i = 0; i < forms.length; ++i) {
let form = forms[i]
form.addEventListener('submit', function(event) {
let date = new Date()
let open_hours = opening_hours['open']
open_hours = [("0" + open_hours[0]).slice(-2), ("0" + open_hours[1]).slice(-2)]
let current_hours = [("0" + date.getHours()).slice(-2), ("0" + date.getMinutes()).slice(-2)]
let close_hours = opening_hours['close']
close_hours = [("0" + close_hours[0]).slice(-2), ("0" + close_hours[1]).slice(-2)]
if (!(open_hours <= current_hours && current_hours <= close_hours)) {
if (!checkDate()) {
event.preventDefault()
modal.show()
}
......@@ -26,9 +20,25 @@ window.addEventListener('load', function() {
for (let i = 0; i < modals.length; ++i) {
let modal = modals[i]
modal.addEventListener('show.bs.modal', function(event) {
if (modal.id !== 'night_modal') {
if (modal.id !== 'night_modal' && !checkDate()) {
event.preventDefault()
}
})
}
})
function checkDate() {
/*
* Ensure that the university library is currently open.
*/
let opening_hours = JSON.parse(document.getElementById('opening_hours').textContent)
let date = new Date()
let open_hours = opening_hours['open']
open_hours = [("0" + open_hours[0]).slice(-2), ("0" + open_hours[1]).slice(-2)]
let current_hours = [("0" + date.getHours()).slice(-2), ("0" + date.getMinutes()).slice(-2)]
let close_hours = opening_hours['close']
close_hours = [("0" + close_hours[0]).slice(-2), ("0" + close_hours[1]).slice(-2)]
return open_hours <= current_hours && current_hours <= close_hours;
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment