mirror of
https://gitlab.com/allianceauth/allianceauth.git
synced 2025-12-06 04:41:41 +01:00
[CHANGE] Move inline JS into $(document).ready(()) block
This commit is contained in:
parent
464016ac05
commit
b1f5aad9f9
@ -65,83 +65,85 @@
|
||||
{% include 'bundles/timers-js.html' %}
|
||||
|
||||
<script>
|
||||
// Data
|
||||
const timers = [
|
||||
{% for op in optimer %}
|
||||
{
|
||||
'id': {{ op.id }},
|
||||
'start': moment("{{ op.start | date:"c" }}"),
|
||||
'expired': false
|
||||
},
|
||||
{% endfor %}
|
||||
];
|
||||
$(document).ready(() => {
|
||||
// Data
|
||||
const timers = [
|
||||
{% for op in optimer %}
|
||||
{
|
||||
'id': {{ op.id }},
|
||||
'start': moment("{{ op.start | date:"c" }}"),
|
||||
'expired': false
|
||||
},
|
||||
{% endfor %}
|
||||
];
|
||||
|
||||
/**
|
||||
* Update a timer
|
||||
* @param timer Timer information
|
||||
*/
|
||||
const updateTimer = (timer) => {
|
||||
if (timer.start.isAfter(Date.now())) {
|
||||
const duration = moment.duration(timer.start - moment(), 'milliseconds');
|
||||
/**
|
||||
* Update a timer
|
||||
* @param timer Timer information
|
||||
*/
|
||||
const updateTimer = (timer) => {
|
||||
if (timer.start.isAfter(Date.now())) {
|
||||
const duration = moment.duration(timer.start - moment(), 'milliseconds');
|
||||
|
||||
document.getElementById("countdown" + timer.id).innerHTML = getDurationString(duration);
|
||||
} else {
|
||||
timer.expired = true;
|
||||
document.getElementById("countdown" + timer.id).innerHTML = getDurationString(duration);
|
||||
} else {
|
||||
timer.expired = true;
|
||||
|
||||
document.getElementById("countdown" + timer.id).innerHTML = "";
|
||||
}
|
||||
};
|
||||
document.getElementById("countdown" + timer.id).innerHTML = "";
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Update all timers
|
||||
*/
|
||||
const updateAllTimers = () => {
|
||||
const l = timers.length;
|
||||
/**
|
||||
* Update all timers
|
||||
*/
|
||||
const updateAllTimers = () => {
|
||||
const l = timers.length;
|
||||
|
||||
for (let i=0; i < l; ++i) {
|
||||
if (timers[i].expired) continue;
|
||||
for (let i=0; i < l; ++i) {
|
||||
if (timers[i].expired) continue;
|
||||
|
||||
updateTimer(timers[i]);
|
||||
}
|
||||
};
|
||||
updateTimer(timers[i]);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Set the local time info for the timer
|
||||
* @param timer Timer information
|
||||
*/
|
||||
const setLocalTime = (timer) => {
|
||||
document.getElementById("localtime" + timer.id).innerHTML = timer.start.format("ddd @ LT");
|
||||
};
|
||||
/**
|
||||
* Set the local time info for the timer
|
||||
* @param timer Timer information
|
||||
*/
|
||||
const setLocalTime = (timer) => {
|
||||
document.getElementById("localtime" + timer.id).innerHTML = timer.start.format("ddd @ LT");
|
||||
};
|
||||
|
||||
/**
|
||||
* Set all local time fields
|
||||
*/
|
||||
const setAllLocalTimes = () => {
|
||||
const l = timers.length;
|
||||
/**
|
||||
* Set all local time fields
|
||||
*/
|
||||
const setAllLocalTimes = () => {
|
||||
const l = timers.length;
|
||||
|
||||
for (let i=0; i < l; ++i) {
|
||||
setLocalTime(timers[i]);
|
||||
}
|
||||
};
|
||||
for (let i=0; i < l; ++i) {
|
||||
setLocalTime(timers[i]);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Get the current EVE time as a string
|
||||
* @returns {string} EVE time string
|
||||
*/
|
||||
const updateClock = () => {
|
||||
document.getElementById("current-time").innerHTML = getCurrentEveTimeString();
|
||||
};
|
||||
/**
|
||||
* Get the current EVE time as a string
|
||||
* @returns {string} EVE time string
|
||||
*/
|
||||
const updateClock = () => {
|
||||
document.getElementById("current-time").innerHTML = getCurrentEveTimeString();
|
||||
};
|
||||
|
||||
const timedUpdate = () => {
|
||||
updateClock();
|
||||
updateAllTimers();
|
||||
};
|
||||
const timedUpdate = () => {
|
||||
updateClock();
|
||||
updateAllTimers();
|
||||
};
|
||||
|
||||
// Set initial values
|
||||
setAllLocalTimes();
|
||||
timedUpdate();
|
||||
// Set initial values
|
||||
setAllLocalTimes();
|
||||
timedUpdate();
|
||||
|
||||
// Start timed updates
|
||||
setInterval(timedUpdate, 1000);
|
||||
// Start timed updates
|
||||
setInterval(timedUpdate, 1000);
|
||||
});
|
||||
</script>
|
||||
{% endblock content %}
|
||||
|
||||
@ -1,29 +1,32 @@
|
||||
{% load i18n %}
|
||||
|
||||
<div id="esi-alert" class="col-12 collapse">
|
||||
<div class="alert alert-warning">
|
||||
<p class="text-center ">{% translate 'Your Server received an ESI error response code of ' %}<b id="esi-code">?</b></p>
|
||||
<hr>
|
||||
<pre id="esi-data" class="text-center text-wrap"></pre>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
const elemCard = document.getElementById('esi-alert');
|
||||
const elemMessage = document.getElementById('esi-data');
|
||||
const elemCode = document.getElementById('esi-code');
|
||||
<script>
|
||||
$(document).ready(() => {
|
||||
const elements = {
|
||||
card: document.getElementById('esi-alert'),
|
||||
message: document.getElementById('esi-data'),
|
||||
code: document.getElementById('esi-code')
|
||||
};
|
||||
|
||||
fetchGet({url: '{% url "authentication:esi_check" %}'})
|
||||
.then((data) => {
|
||||
console.log('ESI Check: ', JSON.stringify(data, null, 2));
|
||||
fetchGet({url: '{% url "authentication:esi_check" %}'})
|
||||
.then(({status, data}) => {
|
||||
console.log('ESI Check:', JSON.stringify({status, data}, null, 2));
|
||||
|
||||
if (data.status !== 200) {
|
||||
elemCode.textContent = data.status;
|
||||
elemMessage.textContent = data.data.error;
|
||||
if (status !== 200) {
|
||||
elements.code.textContent = status;
|
||||
elements.message.textContent = data.error;
|
||||
|
||||
new bootstrap.Collapse(elemCard, {toggle: true});
|
||||
}
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error('Error fetching ESI check:', error);
|
||||
new bootstrap.Collapse(elements.card, {toggle: true});
|
||||
}
|
||||
})
|
||||
.catch((error) => console.error('Error fetching ESI check:', error));
|
||||
});
|
||||
</script>
|
||||
</script>
|
||||
</div>
|
||||
|
||||
@ -96,86 +96,86 @@
|
||||
{% get_datatables_language_static LANGUAGE_CODE as DT_LANG_PATH %}
|
||||
|
||||
<script>
|
||||
const timers = [
|
||||
{% for timer in timers %}
|
||||
{
|
||||
'id': {{ timer.id }},
|
||||
'targetDate': moment("{{ timer.eve_time | date:"c" }}"),
|
||||
'expired': false
|
||||
},
|
||||
{% endfor %}
|
||||
|
||||
{% for timer in corp_timers %}
|
||||
{
|
||||
'id': {{ timer.id }},
|
||||
'targetDate': moment("{{ timer.eve_time | date:"c" }}"),
|
||||
'expired': false
|
||||
},
|
||||
{% endfor %}
|
||||
];
|
||||
|
||||
/**
|
||||
* Update a timer
|
||||
* @param timer Timer information
|
||||
*/
|
||||
const updateTimer = (timer) => {
|
||||
if (timer.targetDate.isAfter(Date.now())) {
|
||||
const duration = moment.duration(timer.targetDate - moment(), 'milliseconds');
|
||||
|
||||
document.getElementById("countdown" + timer.id).innerHTML = getDurationString(duration);
|
||||
} else {
|
||||
timer.expired = true;
|
||||
|
||||
document.getElementById("countdown" + timer.id).innerHTML = "";
|
||||
}
|
||||
};
|
||||
|
||||
const updateAllTimers = () => {
|
||||
const l = timers.length;
|
||||
|
||||
for (let i=0; i < l; ++i) {
|
||||
if (timers[i].expired) continue;
|
||||
|
||||
updateTimer(timers[i]);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Set the local time info for the timer
|
||||
* @param timer Timer information
|
||||
*/
|
||||
const setLocalTime = (timer) => {
|
||||
document.getElementById("localtime" + timer.id).innerHTML = timer.targetDate.format("ddd @ LT");
|
||||
};
|
||||
|
||||
/**
|
||||
* Set all local time fields
|
||||
*/
|
||||
const setAllLocalTimes = () => {
|
||||
const l = timers.length;
|
||||
|
||||
for (let i=0; i < l; ++i) {
|
||||
setLocalTime(timers[i]);
|
||||
}
|
||||
};
|
||||
|
||||
const updateClock = () => {
|
||||
document.getElementById("current-time").innerHTML = getCurrentEveTimeString();
|
||||
};
|
||||
|
||||
const timedUpdate = () => {
|
||||
updateClock();
|
||||
updateAllTimers();
|
||||
}
|
||||
|
||||
// Set initial values
|
||||
setAllLocalTimes();
|
||||
timedUpdate();
|
||||
|
||||
// Start timed updates
|
||||
setInterval(timedUpdate, 1000);
|
||||
|
||||
$(document).ready(() => {
|
||||
const timers = [
|
||||
{% for timer in timers %}
|
||||
{
|
||||
'id': {{ timer.id }},
|
||||
'targetDate': moment("{{ timer.eve_time | date:"c" }}"),
|
||||
'expired': false
|
||||
},
|
||||
{% endfor %}
|
||||
|
||||
{% for timer in corp_timers %}
|
||||
{
|
||||
'id': {{ timer.id }},
|
||||
'targetDate': moment("{{ timer.eve_time | date:"c" }}"),
|
||||
'expired': false
|
||||
},
|
||||
{% endfor %}
|
||||
];
|
||||
|
||||
/**
|
||||
* Update a timer
|
||||
* @param timer Timer information
|
||||
*/
|
||||
const updateTimer = (timer) => {
|
||||
if (timer.targetDate.isAfter(Date.now())) {
|
||||
const duration = moment.duration(timer.targetDate - moment(), 'milliseconds');
|
||||
|
||||
document.getElementById("countdown" + timer.id).innerHTML = getDurationString(duration);
|
||||
} else {
|
||||
timer.expired = true;
|
||||
|
||||
document.getElementById("countdown" + timer.id).innerHTML = "";
|
||||
}
|
||||
};
|
||||
|
||||
const updateAllTimers = () => {
|
||||
const l = timers.length;
|
||||
|
||||
for (let i=0; i < l; ++i) {
|
||||
if (timers[i].expired) continue;
|
||||
|
||||
updateTimer(timers[i]);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Set the local time info for the timer
|
||||
* @param timer Timer information
|
||||
*/
|
||||
const setLocalTime = (timer) => {
|
||||
document.getElementById("localtime" + timer.id).innerHTML = timer.targetDate.format("ddd @ LT");
|
||||
};
|
||||
|
||||
/**
|
||||
* Set all local time fields
|
||||
*/
|
||||
const setAllLocalTimes = () => {
|
||||
const l = timers.length;
|
||||
|
||||
for (let i=0; i < l; ++i) {
|
||||
setLocalTime(timers[i]);
|
||||
}
|
||||
};
|
||||
|
||||
const updateClock = () => {
|
||||
document.getElementById("current-time").innerHTML = getCurrentEveTimeString();
|
||||
};
|
||||
|
||||
const timedUpdate = () => {
|
||||
updateClock();
|
||||
updateAllTimers();
|
||||
}
|
||||
|
||||
// Set initial values
|
||||
setAllLocalTimes();
|
||||
timedUpdate();
|
||||
|
||||
// Start timed updates
|
||||
setInterval(timedUpdate, 1000);
|
||||
|
||||
const dtOptions = {
|
||||
language: {url: '{{ DT_LANG_PATH }}'},
|
||||
order: [
|
||||
@ -185,7 +185,10 @@
|
||||
|
||||
{% if perms.auth.timer_management %}
|
||||
dtOptions['columnDefs'] = [
|
||||
{ "orderable": false, "targets": 7 }
|
||||
{
|
||||
"orderable": false,
|
||||
"targets": 7
|
||||
}
|
||||
];
|
||||
{% endif %}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user