mirror of
https://gitlab.com/allianceauth/allianceauth.git
synced 2025-07-12 22:10:16 +02:00
Cleanup and modernize JS
This commit is contained in:
parent
630400fee4
commit
bd2d19f867
@ -42,6 +42,7 @@
|
|||||||
</div>
|
</div>
|
||||||
{% endblock content %}
|
{% endblock content %}
|
||||||
{% block extra_script %}
|
{% block extra_script %}
|
||||||
$(document).ready(function(){
|
$(document).ready(function () {
|
||||||
$("[rel=tooltip]").tooltip();
|
$("[rel=tooltip]").tooltip();
|
||||||
|
});
|
||||||
{% endblock extra_script %}
|
{% endblock extra_script %}
|
||||||
|
@ -44,6 +44,7 @@
|
|||||||
</div>
|
</div>
|
||||||
{% endblock content %}
|
{% endblock content %}
|
||||||
{% block extra_script %}
|
{% block extra_script %}
|
||||||
$(document).ready(function(){
|
$(document).ready(function () {
|
||||||
$("[rel=tooltip]").tooltip();
|
$("[rel=tooltip]").tooltip();
|
||||||
|
});
|
||||||
{% endblock extra_script %}
|
{% endblock extra_script %}
|
||||||
|
@ -83,7 +83,7 @@
|
|||||||
|
|
||||||
{% block extra_script %}
|
{% block extra_script %}
|
||||||
$.fn.dataTable.moment = function(format, locale) {
|
$.fn.dataTable.moment = function(format, locale) {
|
||||||
var types = $.fn.dataTable.ext.type;
|
let types = $.fn.dataTable.ext.type;
|
||||||
|
|
||||||
// Add type detection
|
// Add type detection
|
||||||
types.detect.unshift(function(d) {
|
types.detect.unshift(function(d) {
|
||||||
|
@ -34,17 +34,15 @@
|
|||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{% block extra_script %}
|
{% block extra_script %}
|
||||||
|
|
||||||
$('#id_start').datetimepicker({
|
$('#id_start').datetimepicker({
|
||||||
setlocale: '{{ LANGUAGE_CODE }}',
|
setlocale: '{{ LANGUAGE_CODE }}',
|
||||||
{% if NIGHT_MODE %}
|
{% if NIGHT_MODE %}
|
||||||
theme: 'dark',
|
theme: 'dark',
|
||||||
{% else %}
|
{% else %}
|
||||||
theme: 'default',
|
theme: 'default',
|
||||||
{% endif %}
|
{% endif %}
|
||||||
mask: true,
|
mask: true,
|
||||||
format: 'Y-m-d H:i',
|
format: 'Y-m-d H:i',
|
||||||
minDate: 0
|
minDate: 0
|
||||||
});
|
});
|
||||||
|
|
||||||
{% endblock extra_script %}
|
{% endblock extra_script %}
|
||||||
|
@ -41,9 +41,10 @@
|
|||||||
|
|
||||||
{% include 'bundles/moment-js.html' with locale=True %}
|
{% include 'bundles/moment-js.html' with locale=True %}
|
||||||
<script src="{% static 'js/timers.js' %}"></script>
|
<script src="{% static 'js/timers.js' %}"></script>
|
||||||
|
|
||||||
<script type="application/javascript">
|
<script type="application/javascript">
|
||||||
// Data
|
// Data
|
||||||
var timers = [
|
let timers = [
|
||||||
{% for op in optimer %}
|
{% for op in optimer %}
|
||||||
{
|
{
|
||||||
'id': {{ op.id }},
|
'id': {{ op.id }},
|
||||||
@ -52,67 +53,66 @@
|
|||||||
},
|
},
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
];
|
];
|
||||||
</script>
|
|
||||||
<script type="application/javascript">
|
|
||||||
|
|
||||||
timedUpdate();
|
|
||||||
setAllLocalTimes();
|
|
||||||
|
|
||||||
// Start timed updates
|
|
||||||
setInterval(timedUpdate, 1000);
|
|
||||||
|
|
||||||
function timedUpdate() {
|
|
||||||
updateClock();
|
|
||||||
updateAllTimers();
|
|
||||||
}
|
|
||||||
|
|
||||||
function updateAllTimers () {
|
|
||||||
var l = timers.length;
|
|
||||||
for (var i=0; i < l; ++i) {
|
|
||||||
if (timers[i].expired) continue;
|
|
||||||
updateTimer(timers[i]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Update a timer
|
* Update a timer
|
||||||
* @param timer Timer information
|
* @param timer Timer information
|
||||||
* @param timer.start Date of the timer
|
|
||||||
* @param timer.id Id number of the timer
|
|
||||||
* @param timer.expired
|
|
||||||
*/
|
*/
|
||||||
function updateTimer(timer) {
|
let updateTimer = function (timer) {
|
||||||
if (timer.start.isAfter(Date.now())) {
|
if (timer.start.isAfter(Date.now())) {
|
||||||
var duration = moment.duration(timer.start - moment(), 'milliseconds');
|
let 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 = "";
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
|
let updateAllTimers = function () {
|
||||||
|
let l = timers.length;
|
||||||
|
|
||||||
/**
|
|
||||||
* Set all local time fields
|
|
||||||
*/
|
|
||||||
function setAllLocalTimes() {
|
|
||||||
var l = timers.length;
|
|
||||||
for (var i=0; i < l; ++i) {
|
for (var i=0; i < l; ++i) {
|
||||||
setLocalTime(timers[i]);
|
if (timers[i].expired) continue;
|
||||||
|
|
||||||
|
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
|
||||||
* @param timer.start Date of the timer
|
|
||||||
* @param timer.id Id number of the timer
|
|
||||||
*/
|
*/
|
||||||
function setLocalTime(timer) {
|
let setLocalTime = function (timer) {
|
||||||
document.getElementById("localtime" + timer.id).innerHTML = timer.start.format("ddd @ LT");
|
document.getElementById("localtime" + timer.id).innerHTML = timer.start.format("ddd @ LT");
|
||||||
}
|
};
|
||||||
|
|
||||||
function updateClock() {
|
/**
|
||||||
|
* Set all local time fields
|
||||||
|
*/
|
||||||
|
let setAllLocalTimes = function () {
|
||||||
|
let l = timers.length;
|
||||||
|
|
||||||
|
for (var i=0; i < l; ++i) {
|
||||||
|
setLocalTime(timers[i]);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
let updateClock = function () {
|
||||||
document.getElementById("current-time").innerHTML = getCurrentEveTimeString();
|
document.getElementById("current-time").innerHTML = getCurrentEveTimeString();
|
||||||
}
|
};
|
||||||
|
|
||||||
|
let timedUpdate = function () {
|
||||||
|
updateClock();
|
||||||
|
updateAllTimers();
|
||||||
|
};
|
||||||
|
|
||||||
|
// Set initial values
|
||||||
|
setAllLocalTimes();
|
||||||
|
timedUpdate();
|
||||||
|
|
||||||
|
// Start timed updates
|
||||||
|
setInterval(timedUpdate, 1000);
|
||||||
</script>
|
</script>
|
||||||
{% endblock content %}
|
{% endblock content %}
|
||||||
|
@ -24,7 +24,7 @@
|
|||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
{% for user in permission.users %}
|
{% for user in permission.users %}
|
||||||
{% include 'permissions_tool/audit_row.html' with type="User" name="Permission granted directlty" %}
|
{% include 'permissions_tool/audit_row.html' with type="User" name="Permission granted directlty" %}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
{% for group in permission.groups %}
|
{% for group in permission.groups %}
|
||||||
@ -35,13 +35,13 @@
|
|||||||
{% for state in permission.states %}
|
{% for state in permission.states %}
|
||||||
{% for profile in state.userprofile_set.all %}
|
{% for profile in state.userprofile_set.all %}
|
||||||
{% with profile.user as user %}
|
{% with profile.user as user %}
|
||||||
{% include 'permissions_tool/audit_row.html' with type="State" name=state%}
|
{% include 'permissions_tool/audit_row.html' with type="State" name=state%}
|
||||||
{% endwith %}
|
{% endwith %}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{% endblock content %}
|
{% endblock content %}
|
||||||
|
|
||||||
@ -56,15 +56,16 @@
|
|||||||
|
|
||||||
{% block extra_script %}
|
{% block extra_script %}
|
||||||
$(document).ready(function() {
|
$(document).ready(function() {
|
||||||
var groupColumn = 0;
|
let groupColumn = 0;
|
||||||
var table = $('#tab_permissions_audit').DataTable({
|
|
||||||
|
$('#tab_permissions_audit').DataTable({
|
||||||
columnDefs: [
|
columnDefs: [
|
||||||
{ "visible": false, "targets": groupColumn }
|
{ "visible": false, "targets": groupColumn }
|
||||||
],
|
],
|
||||||
order: [[ groupColumn, 'asc' ], [ 2, 'asc' ] ],
|
order: [[ groupColumn, 'asc' ], [ 2, 'asc' ] ],
|
||||||
filterDropDown:
|
filterDropDown:
|
||||||
{
|
{
|
||||||
columns: [
|
columns: [
|
||||||
{
|
{
|
||||||
idx: 0,
|
idx: 0,
|
||||||
title: 'Source'
|
title: 'Source'
|
||||||
@ -73,20 +74,20 @@
|
|||||||
bootstrap: true
|
bootstrap: true
|
||||||
},
|
},
|
||||||
drawCallback: function ( settings ) {
|
drawCallback: function ( settings ) {
|
||||||
var api = this.api();
|
let api = this.api();
|
||||||
var rows = api.rows( {page:'current'} ).nodes();
|
let rows = api.rows( {page:'current'} ).nodes();
|
||||||
var last=null;
|
let last = null;
|
||||||
|
|
||||||
api.column(groupColumn, {page:'current'} ).data().each( function ( group, i ) {
|
api.column(groupColumn, {page:'current'} ).data().each( function ( group, i ) {
|
||||||
if ( last !== group ) {
|
if ( last !== group ) {
|
||||||
$(rows).eq( i ).before(
|
$(rows).eq( i ).before(
|
||||||
'<tr class="tr-group"><td colspan="3">' + group + '</td></tr>'
|
'<tr class="tr-group"><td colspan="3">' + group + '</td></tr>'
|
||||||
);
|
);
|
||||||
|
|
||||||
last = group;
|
last = group;
|
||||||
}
|
}
|
||||||
} );
|
} );
|
||||||
}
|
}
|
||||||
} );
|
} );
|
||||||
} );
|
} );
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
@ -9,9 +9,9 @@
|
|||||||
<div class="col-sm-12">
|
<div class="col-sm-12">
|
||||||
<h1 class="page-header">{% trans "Permissions Overview" %}</h1>
|
<h1 class="page-header">{% trans "Permissions Overview" %}</h1>
|
||||||
<p>
|
<p>
|
||||||
{% if request.GET.all != 'yes' %}
|
{% if request.GET.all != 'yes' %}
|
||||||
{% blocktrans %}Showing only applied permissions{% endblocktrans %}
|
{% blocktrans %}Showing only applied permissions{% endblocktrans %}
|
||||||
<a href="{% url 'permissions_tool:overview' %}?all=yes" class="btn btn-primary">{% trans "Show All" %}</a>
|
<a href="{% url 'permissions_tool:overview' %}?all=yes" class="btn btn-primary">{% trans "Show All" %}</a>
|
||||||
{% else %}
|
{% else %}
|
||||||
{% blocktrans %}Showing all permissions{% endblocktrans %}
|
{% blocktrans %}Showing all permissions{% endblocktrans %}
|
||||||
<a href="{% url 'permissions_tool:overview' %}?all=no" class="btn btn-primary">{% trans "Show Applied" %}</a>
|
<a href="{% url 'permissions_tool:overview' %}?all=no" class="btn btn-primary">{% trans "Show Applied" %}</a>
|
||||||
@ -79,7 +79,7 @@
|
|||||||
{% endblock content %}
|
{% endblock content %}
|
||||||
|
|
||||||
{% block extra_javascript %}
|
{% block extra_javascript %}
|
||||||
{% include 'bundles/datatables-js.html' %}
|
{% include 'bundles/datatables-js.html' %}
|
||||||
<script type="application/javascript" src="{% static 'js/filterDropDown/filterDropDown.min.js' %}"></script>
|
<script type="application/javascript" src="{% static 'js/filterDropDown/filterDropDown.min.js' %}"></script>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
@ -89,15 +89,16 @@
|
|||||||
|
|
||||||
{% block extra_script %}
|
{% block extra_script %}
|
||||||
$(document).ready(function() {
|
$(document).ready(function() {
|
||||||
var groupColumn = 0;
|
let groupColumn = 0;
|
||||||
var table = $('#tab_permissions_overview').DataTable({
|
|
||||||
|
$('#tab_permissions_overview').DataTable({
|
||||||
columnDefs: [
|
columnDefs: [
|
||||||
{ "visible": false, "targets": groupColumn }
|
{ "visible": false, "targets": groupColumn }
|
||||||
],
|
],
|
||||||
order: [[ groupColumn, 'asc' ], [ 1, 'asc' ], [ 2, 'asc' ] ],
|
order: [[ groupColumn, 'asc' ], [ 1, 'asc' ], [ 2, 'asc' ] ],
|
||||||
filterDropDown:
|
filterDropDown:
|
||||||
{
|
{
|
||||||
columns: [
|
columns: [
|
||||||
{
|
{
|
||||||
idx: 0
|
idx: 0
|
||||||
},
|
},
|
||||||
@ -108,20 +109,20 @@
|
|||||||
bootstrap: true
|
bootstrap: true
|
||||||
},
|
},
|
||||||
drawCallback: function ( settings ) {
|
drawCallback: function ( settings ) {
|
||||||
var api = this.api();
|
let api = this.api();
|
||||||
var rows = api.rows( {page:'current'} ).nodes();
|
let rows = api.rows( {page:'current'} ).nodes();
|
||||||
var last=null;
|
let last = null;
|
||||||
|
|
||||||
api.column(groupColumn, {page:'current'} ).data().each( function ( group, i ) {
|
api.column(groupColumn, {page:'current'} ).data().each( function ( group, i ) {
|
||||||
if ( last !== group ) {
|
if ( last !== group ) {
|
||||||
$(rows).eq( i ).before(
|
$(rows).eq( i ).before(
|
||||||
'<tr class="tr-group"><td colspan="6">' + group + '</td></tr>'
|
'<tr class="tr-group"><td colspan="6">' + group + '</td></tr>'
|
||||||
);
|
);
|
||||||
|
|
||||||
last = group;
|
last = group;
|
||||||
}
|
}
|
||||||
} );
|
} );
|
||||||
}
|
}
|
||||||
} );
|
} );
|
||||||
} );
|
} );
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
@ -43,17 +43,15 @@
|
|||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{% block extra_script %}
|
{% block extra_script %}
|
||||||
|
|
||||||
$('#id_fleet_time').datetimepicker({
|
$('#id_fleet_time').datetimepicker({
|
||||||
setlocale: '{{ LANGUAGE_CODE }}',
|
setlocale: '{{ LANGUAGE_CODE }}',
|
||||||
{% if NIGHT_MODE %}
|
{% if NIGHT_MODE %}
|
||||||
theme: 'dark',
|
theme: 'dark',
|
||||||
{% else %}
|
{% else %}
|
||||||
theme: 'default',
|
theme: 'default',
|
||||||
{% endif %}
|
{% endif %}
|
||||||
mask: true,
|
mask: true,
|
||||||
format: 'Y-m-d H:i',
|
format: 'Y-m-d H:i',
|
||||||
minDate: 0
|
minDate: 0
|
||||||
});
|
});
|
||||||
|
|
||||||
{% endblock extra_script %}
|
{% endblock extra_script %}
|
||||||
|
@ -187,7 +187,7 @@ ESC to cancel{% endblocktrans %}"id="blah"></i></th>
|
|||||||
{% include 'bundles/x-editable-js.html' %}
|
{% include 'bundles/x-editable-js.html' %}
|
||||||
{% include 'bundles/moment-js.html' %}
|
{% include 'bundles/moment-js.html' %}
|
||||||
{% include 'bundles/clipboard-js.html' %}
|
{% include 'bundles/clipboard-js.html' %}
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
var clipboard = new ClipboardJS('.copy-text-fa-icon');
|
var clipboard = new ClipboardJS('.copy-text-fa-icon');
|
||||||
clipboard.on('success', function (e) {
|
clipboard.on('success', function (e) {
|
||||||
@ -206,73 +206,71 @@ ESC to cancel{% endblocktrans %}"id="blah"></i></th>
|
|||||||
{% endblock extra_javascript %}
|
{% endblock extra_javascript %}
|
||||||
|
|
||||||
{% block extra_script %}
|
{% block extra_script %}
|
||||||
$(document).ready(function() {
|
$(document).ready(function() {
|
||||||
$.fn.editable.defaults.mode = 'inline';
|
$.fn.editable.defaults.mode = 'inline';
|
||||||
$.fn.editable.defaults.showbuttons = false;
|
$.fn.editable.defaults.showbuttons = false;
|
||||||
$.fn.editable.defaults.highlight = "#AAFF80";
|
$.fn.editable.defaults.highlight = "#AAFF80";
|
||||||
|
|
||||||
|
$.fn.dataTable.moment = function(format, locale) {
|
||||||
|
let types = $.fn.dataTable.ext.type;
|
||||||
|
|
||||||
$('.srp').editable({
|
// Add type detection
|
||||||
display: function(value, response) {
|
types.detect.unshift(function(d) {
|
||||||
return false;
|
return moment(d, format, locale, true).isValid() ?
|
||||||
},
|
'moment-' + format :
|
||||||
success: function(response, newValue) {
|
null;
|
||||||
newValue = parseInt(newValue);
|
});
|
||||||
newvalue = newValue.toLocaleString() + " ISK";
|
|
||||||
$(this).html(newvalue.bold());
|
|
||||||
},
|
|
||||||
validate: function(value) {
|
|
||||||
if (value === null || value === '') {
|
|
||||||
return 'Empty values not allowed';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
$('.srp').on('hidden', function(e, reason){
|
|
||||||
if(reason === 'save' || reason === 'nochange') {
|
|
||||||
var $next = $(this).closest('tr').next().find('.editable');
|
|
||||||
setTimeout(function() {
|
|
||||||
$next.editable('show');
|
|
||||||
}, 400);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
$(document).ready(function(){
|
// Add sorting method - use an integer for the sorting
|
||||||
$("[rel=tooltip]").tooltip({ placement: 'top'});
|
types.order[ 'moment-' + format+'-pre' ] = function(d) {
|
||||||
});
|
return moment(d, format, locale, true).unix();
|
||||||
|
};
|
||||||
|
};
|
||||||
|
$.fn.dataTable.moment('YYYY-MMM-D, HH:mm');
|
||||||
|
|
||||||
$.fn.dataTable.moment = function(format, locale) {
|
$('.srp').editable({
|
||||||
var types = $.fn.dataTable.ext.type;
|
display: function(value, response) {
|
||||||
|
return false;
|
||||||
|
},
|
||||||
|
success: function(response, newValue) {
|
||||||
|
newValue = parseInt(newValue);
|
||||||
|
let newValueOutput = newValue.toLocaleString() + " ISK";
|
||||||
|
|
||||||
// Add type detection
|
$(this).html(newValueOutput.bold());
|
||||||
types.detect.unshift(function(d) {
|
},
|
||||||
return moment(d, format, locale, true).isValid() ?
|
validate: function(value) {
|
||||||
'moment-'+format :
|
if (value === null || value === '') {
|
||||||
null;
|
return 'Empty values not allowed';
|
||||||
} );
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
// Add sorting method - use an integer for the sorting
|
$('.srp').on('hidden', function(e, reason){
|
||||||
types.order[ 'moment-'+format+'-pre' ] = function(d) {
|
if(reason === 'save' || reason === 'nochange') {
|
||||||
return moment(d, format, locale, true).unix();
|
let $next = $(this).closest('tr').next().find('.editable');
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
$(document).ready( function(){
|
setTimeout(function() {
|
||||||
$.fn.dataTable.moment('YYYY-MMM-D, HH:mm');
|
$next.editable('show');
|
||||||
|
}, 400);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
$('table.srplist').DataTable({
|
$('table.srplist').DataTable({
|
||||||
"order": [[ 6, "asc" ]],
|
"order": [[ 6, "asc" ]],
|
||||||
"paging": false,
|
"paging": false,
|
||||||
"columnDefs": [{
|
"columnDefs": [
|
||||||
"targets": [1, 8],
|
{
|
||||||
"orderable": false
|
"targets": [1, 8],
|
||||||
},
|
"orderable": false
|
||||||
{
|
},
|
||||||
"targets": [4, 5],
|
{
|
||||||
"type": "num"
|
"targets": [4, 5],
|
||||||
}]
|
"type": "num"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
});
|
||||||
|
|
||||||
|
// tooltip
|
||||||
|
$("[rel=tooltip]").tooltip({ placement: 'top'});
|
||||||
});
|
});
|
||||||
});
|
|
||||||
|
|
||||||
{% endblock extra_script %}
|
{% endblock extra_script %}
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
/* global notificationUPdateSettings */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
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 apprised about newly arrived
|
||||||
@ -6,70 +8,67 @@
|
|||||||
The refresh rate can be changes via the Django setting NOTIFICATIONS_REFRESH_TIME.
|
The refresh rate can be changes via the Django setting NOTIFICATIONS_REFRESH_TIME.
|
||||||
See documentation for details.
|
See documentation for details.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
$(function () {
|
$(function () {
|
||||||
var elem = document.getElementById("dataExport");
|
'use strict';
|
||||||
var notificationsListViewUrl = elem.getAttribute("data-notificationsListViewUrl");
|
|
||||||
var notificationsRefreshTime = elem.getAttribute("data-notificationsRefreshTime");
|
let notificationsListViewUrl = notificationUPdateSettings.notificationsListViewUrl;
|
||||||
var userNotificationsCountViewUrl = elem.getAttribute(
|
let notificationsRefreshTime = notificationUPdateSettings.notificationsRefreshTime;
|
||||||
"data-userNotificationsCountViewUrl"
|
let userNotificationsCountViewUrl = notificationUPdateSettings.userNotificationsCountViewUrl;
|
||||||
);
|
|
||||||
|
|
||||||
// update the notification unread count in the top menu
|
// update the notification unread count in the top menu
|
||||||
function update_notifications() {
|
let updateNotifications = function () {
|
||||||
$.getJSON(userNotificationsCountViewUrl, function (data, status) {
|
$.getJSON(userNotificationsCountViewUrl, function (data, status) {
|
||||||
if (status == 'success') {
|
if (status === 'success') {
|
||||||
var innerHtml = "";
|
let innerHtml = '';
|
||||||
var unread_count = data.unread_count;
|
let unreadCount = data.unread_count;
|
||||||
if (unread_count > 0) {
|
|
||||||
|
if (unreadCount > 0) {
|
||||||
innerHtml = (
|
innerHtml = (
|
||||||
`Notifications <span class="badge">${unread_count}</span>`
|
`Notifications <span class="badge">${unreadCount}</span>`
|
||||||
)
|
);
|
||||||
|
} else {
|
||||||
|
innerHtml = '<i class="far fa-bell"></i>';
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
innerHtml = '<i class="far fa-bell"></i>'
|
$('#menu_item_notifications').html(
|
||||||
}
|
|
||||||
$("#menu_item_notifications").html(
|
|
||||||
`<a href="${notificationsListViewUrl}">${innerHtml}</a>`
|
`<a href="${notificationsListViewUrl}">${innerHtml}</a>`
|
||||||
);
|
);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
console.error(
|
console.error(
|
||||||
`Failed to load HTMl to render notifications item. Error: `
|
`Failed to load HTMl to render notifications item. Error: ${xhr.status}': '${xhr.statusText}`
|
||||||
`${xhr.status}': '${xhr.statusText}`
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
};
|
||||||
|
|
||||||
var myInterval;
|
let myInterval;
|
||||||
|
|
||||||
// activate automatic refreshing every x seconds
|
// activate automatic refreshing every x seconds
|
||||||
function activate_refreshing() {
|
let activateRefreshing = function () {
|
||||||
if (notificationsRefreshTime > 0) {
|
if (notificationsRefreshTime > 0) {
|
||||||
myInterval = setInterval(
|
myInterval = setInterval(
|
||||||
update_notifications, notificationsRefreshTime * 1000
|
updateNotifications, notificationsRefreshTime * 1000
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
// deactivate automatic refreshing
|
// deactivate automatic refreshing
|
||||||
function deactivate_refreshing() {
|
let deactivateRefreshing = function () {
|
||||||
if ((notificationsRefreshTime > 0) && (typeof myInterval !== 'undefined')) {
|
if ((notificationsRefreshTime > 0) && (typeof myInterval !== 'undefined')) {
|
||||||
clearInterval(myInterval)
|
clearInterval(myInterval);
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
// refreshing only happens on active browser tab
|
// refreshing only happens on active browser tab
|
||||||
$(document).on({
|
$(document).on({
|
||||||
'show': function () {
|
'show': function () {
|
||||||
activate_refreshing()
|
activateRefreshing();
|
||||||
},
|
},
|
||||||
'hide': function () {
|
'hide': function () {
|
||||||
deactivate_refreshing()
|
deactivateRefreshing();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Initial start of refreshing on script loading
|
// Initial start of refreshing on script loading
|
||||||
activate_refreshing()
|
activateRefreshing();
|
||||||
});
|
});
|
||||||
|
@ -1,23 +1,49 @@
|
|||||||
|
/* global moment */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get a duration string like countdown.js
|
* Get a duration string like countdown.js
|
||||||
* e.g. "1y 2d 3h 4m 5s"
|
* e.g. "1y 2d 3h 4m 5s"
|
||||||
* @param duration moment.duration
|
*
|
||||||
*/
|
* @param duration
|
||||||
function getDurationString(duration) {
|
* @returns {string}
|
||||||
var out = "";
|
*/
|
||||||
|
let getDurationString = function (duration) {
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
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';
|
||||||
|
};
|
||||||
|
|
||||||
function getCurrentEveTimeString() {
|
/**
|
||||||
return moment().utc().format('dddd LL HH:mm:ss')
|
* returns the current eve time as a formatted string
|
||||||
}
|
*
|
||||||
|
* condition:
|
||||||
|
* only if moment.js is loaded before,
|
||||||
|
* if not this function returns an empty string to avoid JS errors from happening.
|
||||||
|
*
|
||||||
|
* @returns {string}
|
||||||
|
*/
|
||||||
|
let getCurrentEveTimeString = function () {
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
let returnValue = '';
|
||||||
|
|
||||||
|
if (window.moment) {
|
||||||
|
returnValue = moment().utc().format('dddd LL HH:mm:ss');
|
||||||
|
}
|
||||||
|
|
||||||
|
return returnValue;
|
||||||
|
};
|
||||||
|
@ -46,19 +46,20 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<!-- share data with JS part -->
|
|
||||||
<div
|
|
||||||
id="dataExport"
|
|
||||||
data-notificationsListViewUrl="{% url 'notifications:list' %}"
|
|
||||||
data-notificationsRefreshTime="{% notifications_refresh_time %}"
|
|
||||||
data-userNotificationsCountViewUrl="{% url 'notifications:user_notifications_count' request.user.pk %}"
|
|
||||||
>
|
|
||||||
</div>
|
|
||||||
{% include 'bundles/bootstrap-js.html' %}
|
{% include 'bundles/bootstrap-js.html' %}
|
||||||
{% include 'bundles/jquery-visibility-js.html' %}
|
{% include 'bundles/jquery-visibility-js.html' %}
|
||||||
|
|
||||||
|
<script type="application/javascript">
|
||||||
|
let notificationUPdateSettings = {
|
||||||
|
notificationsListViewUrl: "{% url 'notifications:list' %}",
|
||||||
|
notificationsRefreshTime: "{% notifications_refresh_time %}",
|
||||||
|
userNotificationsCountViewUrl: "{% url 'notifications:user_notifications_count' request.user.pk %}"
|
||||||
|
};
|
||||||
|
</script>
|
||||||
<script src="{% static 'js/refresh_notifications.js' %}"></script>
|
<script src="{% static 'js/refresh_notifications.js' %}"></script>
|
||||||
|
|
||||||
{% block extra_javascript %}
|
{% block extra_javascript %}
|
||||||
{% endblock extra_javascript %}
|
{% endblock extra_javascript %}
|
||||||
<script>
|
<script>
|
||||||
{% block extra_script %}
|
{% block extra_script %}
|
||||||
|
@ -526,9 +526,7 @@
|
|||||||
{% include 'bundles/moment-js.html' with locale=True %}
|
{% include 'bundles/moment-js.html' with locale=True %}
|
||||||
<script src="{% static 'js/timers.js' %}"></script>
|
<script src="{% static 'js/timers.js' %}"></script>
|
||||||
<script type="application/javascript">
|
<script type="application/javascript">
|
||||||
var locale = "{{ LANGUAGE_CODE }}";
|
let timers = [
|
||||||
|
|
||||||
var timers = [
|
|
||||||
{% for timer in timers %}
|
{% for timer in timers %}
|
||||||
{
|
{
|
||||||
'id': {{ timer.id }},
|
'id': {{ timer.id }},
|
||||||
@ -545,67 +543,64 @@
|
|||||||
{% endfor %}
|
{% endfor %}
|
||||||
];
|
];
|
||||||
|
|
||||||
moment.locale(locale);
|
/**
|
||||||
|
* Update a timer
|
||||||
|
* @param timer Timer information
|
||||||
|
*/
|
||||||
|
let updateTimer = function (timer) {
|
||||||
|
if (timer.targetDate.isAfter(Date.now())) {
|
||||||
|
let duration = moment.duration(timer.targetDate - moment(), 'milliseconds');
|
||||||
|
|
||||||
// Set initial values
|
document.getElementById("countdown" + timer.id).innerHTML = getDurationString(duration);
|
||||||
setAllLocalTimes();
|
} else {
|
||||||
timedUpdate();
|
timer.expired = true;
|
||||||
|
|
||||||
// Start timed updates
|
document.getElementById("countdown" + timer.id).innerHTML = "";
|
||||||
setInterval(timedUpdate, 1000);
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
let updateAllTimers = function () {
|
||||||
|
let l = timers.length;
|
||||||
|
|
||||||
|
for (var i=0; i < l; ++i) {
|
||||||
|
if (timers[i].expired) continue;
|
||||||
|
|
||||||
|
updateTimer(timers[i]);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
function timedUpdate() {
|
function timedUpdate() {
|
||||||
updateClock();
|
updateClock();
|
||||||
updateAllTimers();
|
updateAllTimers();
|
||||||
}
|
}
|
||||||
|
|
||||||
function updateAllTimers () {
|
|
||||||
var l = timers.length;
|
|
||||||
for (var i=0; i < l; ++i) {
|
|
||||||
if (timers[i].expired) continue;
|
|
||||||
updateTimer(timers[i]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Update a timer
|
* Set the local time info for the timer
|
||||||
* @param timer Timer information
|
* @param timer Timer information
|
||||||
* @param timer.targetDate Date of the timer
|
|
||||||
* @param timer.id Id number of the timer
|
|
||||||
* @param timer.expired
|
|
||||||
*/
|
*/
|
||||||
function updateTimer(timer) {
|
let setLocalTime = function (timer) {
|
||||||
if (timer.targetDate.isAfter(Date.now())) {
|
document.getElementById("localtime" + timer.id).innerHTML = timer.targetDate.format("ddd @ LT");
|
||||||
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 = "";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set all local time fields
|
* Set all local time fields
|
||||||
*/
|
*/
|
||||||
function setAllLocalTimes() {
|
let setAllLocalTimes = function () {
|
||||||
var l = timers.length;
|
let l = timers.length;
|
||||||
|
|
||||||
for (var i=0; i < l; ++i) {
|
for (var i=0; i < l; ++i) {
|
||||||
setLocalTime(timers[i]);
|
setLocalTime(timers[i]);
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
/**
|
let updateClock = function () {
|
||||||
* Set the local time info for the timer
|
|
||||||
* @param timer Timer information
|
|
||||||
* @param timer.targetDate Date of the timer
|
|
||||||
* @param timer.id Id number of the timer
|
|
||||||
*/
|
|
||||||
function setLocalTime(timer) {
|
|
||||||
document.getElementById("localtime" + timer.id).innerHTML = timer.targetDate.format("ddd @ LT");
|
|
||||||
}
|
|
||||||
|
|
||||||
function updateClock() {
|
|
||||||
document.getElementById("current-time").innerHTML = getCurrentEveTimeString();
|
document.getElementById("current-time").innerHTML = getCurrentEveTimeString();
|
||||||
}
|
};
|
||||||
|
// Set initial values
|
||||||
|
setAllLocalTimes();
|
||||||
|
timedUpdate();
|
||||||
|
|
||||||
|
// Start timed updates
|
||||||
|
setInterval(timedUpdate, 1000);
|
||||||
</script>
|
</script>
|
||||||
{% endblock content %}
|
{% endblock content %}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user