[CHANGE] JS updated to ES8+ standard where ever possible

This commit is contained in:
Peter Pfeufer 2023-12-10 14:56:15 +01:00
parent 021b7b2edb
commit de12b49527
No known key found for this signature in database
GPG Key ID: 6051D2C6AD4EBC27
13 changed files with 231 additions and 208 deletions

View File

@ -34,32 +34,36 @@
{% block extra_javascript %} {% block extra_javascript %}
{% include "bundles/datatables-js-bs5.html" %} {% include "bundles/datatables-js-bs5.html" %}
<script>
$(document).ready(() => {
let grp = 2;
const table = $('#table_tokens').DataTable({
'columnDefs': [{orderable: false, targets: [0, 1]}, {
'visible': false,
'targets': grp
}],
'order': [[grp, 'asc']],
'drawCallback': function (settings) {
var api = this.api();
var rows = api.rows({page: 'current'}).nodes();
var last = null;
api.column(grp, {page: 'current'})
.data()
.each(function (group, i) {
if (last !== group) {
$(rows).eq(i).before(`<tr class="info"><td colspan="3">${group}</td></tr>`);
last = group;
}
});
},
'stateSave': true
});
});
</script>
{% endblock extra_javascript %} {% endblock extra_javascript %}
{% block extra_css %} {% block extra_css %}
{% include "bundles/datatables-css-bs5.html" %} {% include "bundles/datatables-css-bs5.html" %}
{% endblock extra_css %} {% endblock extra_css %}
{% block extra_script %}
$(document).ready(function(){
let grp = 2;
var table = $('#table_tokens').DataTable({
"columnDefs": [{ orderable: false, targets: [0,1] },{ "visible": false, "targets": grp }],
"order": [[grp, 'asc']],
"drawCallback": function (settings) {
var api = this.api();
var rows = api.rows({ page: 'current' }).nodes();
var last = null;
api.column(grp, { page: 'current' })
.data()
.each(function (group, i) {
if (last !== group) {
$(rows).eq(i).before('<tr class="info"><td colspan="3">' + group + '</td></tr>');
last = group;
}
});
},
"stateSave": true,
});
});
{% endblock extra_script %}

View File

@ -234,13 +234,8 @@
{% block extra_javascript %} {% block extra_javascript %}
{% include 'bundles/datatables-js-bs5.html' %} {% include 'bundles/datatables-js-bs5.html' %}
{% endblock %}
{% block extra_css %} <script>
{% include 'bundles/datatables-css-bs5.html' %}
{% endblock %}
{% block extra_script %}
$(document).ready(() => { $(document).ready(() => {
$('#table-mains').DataTable({ $('#table-mains').DataTable({
"columnDefs": [ "columnDefs": [
@ -270,4 +265,9 @@
"stateDuration": 0 "stateDuration": 0
}); });
}); });
</script>
{% endblock %}
{% block extra_css %}
{% include 'bundles/datatables-css-bs5.html' %}
{% endblock %} {% endblock %}

View File

@ -41,17 +41,17 @@
{% block extra_javascript %} {% block extra_javascript %}
{% include 'bundles/datatables-js-bs5.html' %} {% include 'bundles/datatables-js-bs5.html' %}
{% endblock %}
{% block extra_css %} <script>
{% include 'bundles/datatables-css-bs5.html' %}
{% endblock %}
{% block extra_script %}
$(document).ready(() => { $(document).ready(() => {
$('#table-search').DataTable({ $('#table-search').DataTable({
"stateSave": true, "stateSave": true,
"stateDuration": 0 "stateDuration": 0
}); });
}); });
</script>
{% endblock %}
{% block extra_css %}
{% include 'bundles/datatables-css-bs5.html' %}
{% endblock %} {% endblock %}

View File

@ -54,8 +54,10 @@
</div> </div>
{% endblock content %} {% endblock content %}
{% block extra_script %} {% block extra_javascript %}
<script>
$(document).ready(() => { $(document).ready(() => {
$("[rel=tooltip]").tooltip(); $("[rel=tooltip]").tooltip();
}); });
{% endblock extra_script %} </script>
{% endblock extra_javascript %}

View File

@ -58,8 +58,10 @@
</div> </div>
{% endblock content %} {% endblock content %}
{% block extra_script %} {% block extra_javascript %}
<script>
$(document).ready(() => { $(document).ready(() => {
$("[rel=tooltip]").tooltip(); $("[rel=tooltip]").tooltip();
}); });
{% endblock extra_script %} </script>
{% endblock extra_javascript %}

View File

@ -66,30 +66,25 @@
{% include 'bundles/datatables-js-bs5.html' %} {% include 'bundles/datatables-js-bs5.html' %}
{% include 'bundles/moment-js.html' with locale=True %} {% include 'bundles/moment-js.html' with locale=True %}
{% include 'bundles/filterdropdown-js.html' %} {% include 'bundles/filterdropdown-js.html' %}
{% endblock %}
{% block extra_css %} <script>
{% include 'bundles/datatables-css-bs5.html' %} $.fn.dataTable.moment = (format, locale) => {
{% endblock %} const types = $.fn.dataTable.ext.type;
{% block extra_script %}
$.fn.dataTable.moment = function(format, locale) {
let types = $.fn.dataTable.ext.type;
// Add type detection // Add type detection
types.detect.unshift(function(d) { types.detect.unshift((d) => {
return moment(d, format, locale, true).isValid() ? return moment(d, format, locale, true).isValid() ?
'moment-'+format : 'moment-'+format :
null; null;
}); });
// Add sorting method - use an integer for the sorting // Add sorting method - use an integer for the sorting
types.order[ 'moment-'+format+'-pre' ] = function(d) { types.order[ 'moment-'+format+'-pre' ] = (d) => {
return moment(d, format, locale, true).unix(); return moment(d, format, locale, true).unix();
}; };
}; };
$(document).ready(function(){ $(document).ready(() => {
$.fn.dataTable.moment('YYYY-MMM-D, HH:mm'); $.fn.dataTable.moment('YYYY-MMM-D, HH:mm');
$('#log-entries').DataTable({ $('#log-entries').DataTable({
@ -122,4 +117,9 @@
"stateDuration": 0 "stateDuration": 0
}); });
}); });
</script>
{% endblock %}
{% block extra_css %}
{% include 'bundles/datatables-css-bs5.html' %}
{% endblock %} {% endblock %}

View File

@ -77,14 +77,9 @@
{% block extra_javascript %} {% block extra_javascript %}
{% include 'bundles/datatables-js-bs5.html' %} {% include 'bundles/datatables-js-bs5.html' %}
{% endblock %}
{% block extra_css %} <script>
{% include 'bundles/datatables-css-bs5.html' %} $(document).ready(() => {
{% endblock %}
{% block extra_script %}
$(document).ready(function(){
$('#tab_group_members').DataTable({ $('#tab_group_members').DataTable({
order: [[0, "asc"]], order: [[0, "asc"]],
columnDefs: [ columnDefs: [
@ -97,4 +92,9 @@
"stateDuration": 0 "stateDuration": 0
}); });
}); });
</script>
{% endblock %}
{% block extra_css %}
{% include 'bundles/datatables-css-bs5.html' %}
{% endblock %} {% endblock %}

View File

@ -78,16 +78,17 @@
</div> </div>
{% endif %} {% endif %}
{% endblock content %} {% endblock content %}
{% block extra_javascript %} {% block extra_javascript %}
{% include 'bundles/datatables-js-bs5.html' %} {% include 'bundles/datatables-js-bs5.html' %}
<script>
$(document).ready(() => {
$('#groupsTable').DataTable();
});
</script>
{% endblock %} {% endblock %}
{% block extra_css %} {% block extra_css %}
{% include 'bundles/datatables-css-bs5.html' %} {% include 'bundles/datatables-css-bs5.html' %}
{% endblock %} {% endblock %}
{% block extra_script %}
$(document).ready(function () {
$('#groupsTable').DataTable();
});
{% endblock extra_script %}

View File

@ -163,7 +163,8 @@ ESC to cancel{% endblocktranslate %}" id="blah"></i></th>
<script> <script>
const clipboard = new ClipboardJS('.copy-text-fa-icon'); const clipboard = new ClipboardJS('.copy-text-fa-icon');
clipboard.on('success', function (e) {
clipboard.on('success', (e) => {
console.info('Action:', e.action); console.info('Action:', e.action);
console.info('Text:', e.text); console.info('Text:', e.text);
console.info('Trigger:', e.trigger); console.info('Trigger:', e.trigger);
@ -171,12 +172,12 @@ ESC to cancel{% endblocktranslate %}" id="blah"></i></th>
e.clearSelection(); e.clearSelection();
}); });
clipboard.on('error', function (e) { clipboard.on('error', (e) => {
console.error('Action:', e.action); console.error('Action:', e.action);
console.error('Trigger:', e.trigger); console.error('Trigger:', e.trigger);
}); });
$(document).ready(function() { $(document).ready(() => {
const elementEditableSrpAmount = $('.srp'); const elementEditableSrpAmount = $('.srp');
const elementTableSrpList = $('table.srplist'); const elementTableSrpList = $('table.srplist');
@ -202,12 +203,12 @@ ESC to cancel{% endblocktranslate %}" id="blah"></i></th>
$.fn.dataTable.moment('YYYY-MMM-D, HH:mm'); $.fn.dataTable.moment('YYYY-MMM-D, HH:mm');
elementEditableSrpAmount.editable({ elementEditableSrpAmount.editable({
display: function(value, response) { display: (value, response) => {
return false; return false;
}, },
success: function(response, newValue) { success: function(response, newValue) {
newValue = parseInt(newValue); newValue = parseInt(newValue);
const newValueOutput = newValue.toLocaleString() + " ISK"; const newValueOutput = `${newValue.toLocaleString()} ISK`;
$(this).html(`<b>${newValueOutput}</b>`); $(this).html(`<b>${newValueOutput}</b>`);
}, },
@ -218,11 +219,11 @@ ESC to cancel{% endblocktranslate %}" id="blah"></i></th>
} }
}); });
elementEditableSrpAmount.on('hidden', function(e, reason){ elementEditableSrpAmount.on('hidden', function(e, reason) {
if(reason === 'save' || reason === 'nochange') { if (reason === 'save' || reason === 'nochange') {
const next_editable_element = $(this).closest('tr').next().find('.editable'); const next_editable_element = $(this).closest('tr').next().find('.editable');
setTimeout(function() { setTimeout(() => {
next_editable_element.editable('show'); next_editable_element.editable('show');
}, 400); }, 400);
} }

View File

@ -1,20 +1,22 @@
$(document).ready(function () { $(document).ready(() => {
'use strict'; 'use strict';
/** /**
* render a JS clock for Eve Time * Render the current EVE time in the top menu bar
* @param element * @param element
*/ */
const renderClock = function (element) { const renderClock = (element) => {
const datetimeNow = new Date(); const datetimeNow = new Date();
const h = String(datetimeNow.getUTCHours()).padStart(2, '0'); const h = String(datetimeNow.getUTCHours()).padStart(2, '0');
const m = String(datetimeNow.getUTCMinutes()).padStart(2, '0'); const m = String(datetimeNow.getUTCMinutes()).padStart(2, '0');
element.html(h + ':' + m); element.html(`${h}:${m}`);
}; };
// Start the Eve time clock in the top menu bar /**
setInterval(function () { * Start the Eve time clock in the top menu bar
*/
setInterval(() => {
renderClock($('.eve-time-wrapper .eve-time-clock')); renderClock($('.eve-time-wrapper .eve-time-clock'));
}, 500); }, 500);
}); });

View File

@ -5,21 +5,21 @@
* on a regular basis so to keep the user apprised about newly arrived * on a regular basis so to keep the user apprised about newly arrived
* notifications without having to reload the page. * notifications without having to reload the page.
* *
* The refresh rate can be changes via the Django setting NOTIFICATIONS_REFRESH_TIME. * The refresh rate can be changed via the Django setting NOTIFICATIONS_REFRESH_TIME.
* See documentation for details. * See documentation for details.
*/ */
$(() => { $(() => {
'use strict'; 'use strict';
const notificationsRefreshTime = notificationUpdateSettings.refreshTime; const notificationRefreshTime = notificationUpdateSettings.refreshTime;
const userNotificationsCountViewUrl = notificationUpdateSettings.userNotificationsCountViewUrl; const userNotificationCountViewUrl = notificationUpdateSettings.userNotificationsCountViewUrl;
const elementNotificationIcon = $('#menu_item_notifications .fa-bell'); const elementNotificationIcon = $('#menu_item_notifications .fa-bell');
/** /**
* Update the notification icon in the top menu * Update the notification icon in the top menu
*/ */
const updateNotificationIcon = () => { const updateNotificationIcon = () => {
fetch(userNotificationsCountViewUrl) fetch(userNotificationCountViewUrl)
.then((response) => { .then((response) => {
if (response.ok) { if (response.ok) {
return response.json(); return response.json();
@ -47,9 +47,9 @@ $(() => {
* Activate automatic refresh every x seconds * Activate automatic refresh every x seconds
*/ */
const activateIconUpdate = () => { const activateIconUpdate = () => {
if (notificationsRefreshTime > 0) { if (notificationRefreshTime > 0) {
myInterval = setInterval( myInterval = setInterval(
updateNotificationIcon, notificationsRefreshTime * 1000 updateNotificationIcon, notificationRefreshTime * 1000
); );
} }
}; };
@ -58,7 +58,7 @@ $(() => {
* Deactivate automatic refresh * Deactivate automatic refresh
*/ */
const deactivateIconUpdate = () => { const deactivateIconUpdate = () => {
if ((notificationsRefreshTime > 0) && (typeof myInterval !== 'undefined')) { if ((notificationRefreshTime > 0) && (typeof myInterval !== 'undefined')) {
clearInterval(myInterval); clearInterval(myInterval);
} }
}; };

View File

@ -1,26 +1,28 @@
/* global notificationUPdateSettings */ /* global notificationUPdateSettings, xhr */
/* /**
This script refreshed the unread notification count in the top menu * This script refreshed the unread notification count in the top menu
on a regular basis so to keep the user apprised about newly arrived * on a regular basis so to keep the user apprized about newly arrived
notifications without having to reload the page. * notifications without having to reload the page.
*
The refresh rate can be changes via the Django setting NOTIFICATIONS_REFRESH_TIME. * The refresh rate can be changed via the Django setting NOTIFICATIONS_REFRESH_TIME.
See documentation for details. * See documentation for details.
*/ */
$(function () { $(document).ready(() => {
'use strict'; 'use strict';
let notificationsListViewUrl = notificationUPdateSettings.notificationsListViewUrl; const notificationListViewUrl = notificationUPdateSettings.notificationsListViewUrl;
let notificationsRefreshTime = notificationUPdateSettings.notificationsRefreshTime; const notificationRefreshTime = notificationUPdateSettings.notificationsRefreshTime;
let userNotificationsCountViewUrl = notificationUPdateSettings.userNotificationsCountViewUrl; const userNotificationCountViewUrl = notificationUPdateSettings.userNotificationsCountViewUrl;
// update the notification unread count in the top menu /**
let updateNotifications = function () { * Update the notification item in the top menu with the current unread count
$.getJSON(userNotificationsCountViewUrl, function (data, status) { */
const updateNotifications = () => {
$.getJSON(userNotificationCountViewUrl, (data, status) => {
if (status === 'success') { if (status === 'success') {
let innerHtml = ''; let innerHtml;
let unreadCount = data.unread_count; const unreadCount = data.unread_count;
if (unreadCount > 0) { if (unreadCount > 0) {
innerHtml = ( innerHtml = (
@ -31,7 +33,7 @@ $(function () {
} }
$('#menu_item_notifications').html( $('#menu_item_notifications').html(
`<a href="${notificationsListViewUrl}">${innerHtml}</a>` `<a href="${notificationListViewUrl}">${innerHtml}</a>`
); );
} else { } else {
console.error( console.error(
@ -43,32 +45,41 @@ $(function () {
let myInterval; let myInterval;
// activate automatic refreshing every x seconds /**
let activateRefreshing = function () { * Activate automatic refreshing of notifications
if (notificationsRefreshTime > 0) { */
const activateRefreshing = () => {
if (notificationRefreshTime > 0) {
myInterval = setInterval( myInterval = setInterval(
updateNotifications, notificationsRefreshTime * 1000 updateNotifications, notificationRefreshTime * 1000
); );
} }
}; };
// deactivate automatic refreshing /**
let deactivateRefreshing = function () { * Deactivate automatic refreshing of notifications
if ((notificationsRefreshTime > 0) && (typeof myInterval !== 'undefined')) { */
const deactivateRefreshing = () => {
if ((notificationRefreshTime > 0) && (typeof myInterval !== 'undefined')) {
clearInterval(myInterval); clearInterval(myInterval);
} }
}; };
// refreshing only happens on active browser tab /**
* Activate refreshing when the browser tab is active
* and deactivate it when it is not
*/
$(document).on({ $(document).on({
'show': function () { 'show': () => {
activateRefreshing(); activateRefreshing();
}, },
'hide': function () { 'hide': () => {
deactivateRefreshing(); deactivateRefreshing();
} }
}); });
// Initial start of refreshing on script loading /**
* Initial start of refreshing on script loading
*/
activateRefreshing(); activateRefreshing();
}); });

View File

@ -7,24 +7,24 @@
* @param duration * @param duration
* @returns {string} * @returns {string}
*/ */
let getDurationString = function (duration) { const getDurationString = (duration) => { // eslint-disable-line no-unused-vars
'use strict'; 'use strict';
let out = ''; let out = '';
if (duration.years()) { if (duration.years()) {
out += duration.years() + 'y '; out += `${duration.years()}y `;
} }
if (duration.months()) { if (duration.months()) {
out += duration.months() + 'm '; out += `${duration.months()}m `;
} }
if (duration.days()) { if (duration.days()) {
out += duration.days() + 'd '; out += `${duration.days()}d `;
} }
return out + duration.hours() + 'h ' + duration.minutes() + 'm ' + duration.seconds() + 's'; return `${out + duration.hours()}h ${duration.minutes()}m ${duration.seconds()}s`;
}; };
/** /**
@ -32,11 +32,11 @@ let getDurationString = function (duration) {
* *
* condition: * condition:
* only if moment.js is loaded before, * only if moment.js is loaded before,
* if not this function returns an empty string to avoid JS errors from happening. * if not, this function returns an empty string to avoid JS errors from happening.
* *
* @returns {string} * @returns {string}
*/ */
let getCurrentEveTimeString = function () { const getCurrentEveTimeString = () => { // eslint-disable-line no-unused-vars
'use strict'; 'use strict';
let returnValue = ''; let returnValue = '';