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