[CHANGE] JS corrections

This commit is contained in:
Peter Pfeufer 2023-12-09 17:20:07 +01:00
parent 6f0b853a60
commit 11a32c90a8
No known key found for this signature in database
GPG Key ID: 6051D2C6AD4EBC27
2 changed files with 71 additions and 67 deletions

View File

@ -34,6 +34,7 @@
{% if srpfleetrequests %}
<form method="POST">
{% csrf_token %}
<div class="alert alert-info" role="alert">
<div class="text-end">
<b><span style="padding-right:2.5em">{% translate "Total Losses:" %} {{ srpfleetrequests.count }}</span></b>
@ -43,9 +44,11 @@
<button type="submit" title="Approve" class="btn btn-success btn-sm m-1" formaction="{% url 'srp:request_approve' %}">
<i class="fa-solid fa-thumbs-up"></i>
</button>
<button type="submit" title="Reject" class="btn btn-warning btn-sm m-1" formaction="{% url 'srp:request_reject' %}">
<i class="fa-solid fa-thumbs-down"></i>
</button>
<button type="submit" title="Remove" onclick="return confirm('{% translate "Are you sure you want to delete SRP requests?" %}')" class="btn btn-danger btn-sm m-1" formaction="{% url 'srp:request_remove' %}">
<i class="fa-solid fa-trash-alt"></i>
</button>
@ -172,41 +175,41 @@ ESC to cancel{% endblocktranslate %}" id="blah"></i></th>
console.error('Action:', e.action);
console.error('Trigger:', e.trigger);
});
</script>
{% endblock extra_javascript %}
{% block extra_script %}
$(document).ready(function() {
const elementEditableSrpAmount = $('.srp');
const elementTableSrpList = $('table.srplist');
$.fn.editable.defaults.mode = 'inline';
$.fn.editable.defaults.showbuttons = false;
$.fn.editable.defaults.highlight = "#AAFF80";
$.fn.dataTable.moment = function(format, locale) {
let types = $.fn.dataTable.ext.type;
$.fn.dataTable.moment = (format, locale) => {
const types = $.fn.dataTable.ext.type;
// Add type detection
types.detect.unshift(function(d) {
types.detect.unshift((d) => {
return moment(d, format, locale, true).isValid() ?
'moment-' + format :
null;
});
// 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();
};
};
$.fn.dataTable.moment('YYYY-MMM-D, HH:mm');
$('.srp').editable({
elementEditableSrpAmount.editable({
display: function(value, response) {
return false;
},
success: function(response, newValue) {
newValue = parseInt(newValue);
let newValueOutput = newValue.toLocaleString() + " ISK";
const newValueOutput = newValue.toLocaleString() + " ISK";
$(this).html(newValueOutput.bold());
$(this).html(`<b>${newValueOutput}</b>`);
},
validate: function(value) {
if (value === null || value === '') {
@ -215,17 +218,17 @@ ESC to cancel{% endblocktranslate %}" id="blah"></i></th>
}
});
$('.srp').on('hidden', function(e, reason){
elementEditableSrpAmount.on('hidden', function(e, reason){
if(reason === 'save' || reason === 'nochange') {
let $next = $(this).closest('tr').next().find('.editable');
const next_editable_element = $(this).closest('tr').next().find('.editable');
setTimeout(function() {
$next.editable('show');
next_editable_element.editable('show');
}, 400);
}
});
$('table.srplist').DataTable({
elementTableSrpList.DataTable({
"order": [[ 6, "asc" ]],
"paging": false,
"columnDefs": [
@ -245,7 +248,8 @@ ESC to cancel{% endblocktranslate %}" id="blah"></i></th>
// tooltip
$("[rel=tooltip]").tooltip({ placement: 'top'});
});
{% endblock extra_script %}
</script>
{% endblock extra_javascript %}
{% block extra_css %}
{% include "bundles/datatables-css-bs5.html" %}

View File

@ -106,6 +106,7 @@
<a href="{% url 'srp:remove' srpfleet.id %}" onclick="return confirm('{% translate "Are you sure you want to delete this SRP code and its contents?" %}')" class="btn btn-danger btn-sm m-1" title="Remove">
<i class="fa-solid fa-trash fa-fw"></i>
</a>
{% if srpfleet.fleet_srp_code %}
<a href="{% url 'srp:disable' srpfleet.id %}" class="btn btn-warning btn-sm m-1" title="Disable">
<i class="fa-solid fa-ban fa-fw"></i>
@ -115,7 +116,6 @@
<i class="fa-solid fa-check fa-fw"></i>
</a>
{% endif %}
{% endif %}
</td>
</tr>