N°2847 - Tranform old itop datatable to jquery DataTable - Fix management of button "Add" step 2

This commit is contained in:
acognet
2020-11-24 14:21:28 +01:00
parent ad19a89fc5
commit fb70026966

View File

@@ -173,78 +173,101 @@ var oTable{{ oUIBlock.GetId() }} = $('#{{ oUIBlock.GetId() }}').DataTable({
{% if oUIBlock.GetOption("select_mode") is not empty %} {% if oUIBlock.GetOption("select_mode") is not empty %}
{% if oUIBlock.GetOption("select_mode") != "single" %} {% if oUIBlock.GetOption("select_mode") != "single" %}
console.warn('aa'); oTable{{ oUIBlock.GetId() }}.off('select').on('select', function (oEvent, dt, type, indexes) {
oTable{{ oUIBlock.GetId() }}.off('select').on('select', function (oEvent, dt, type, indexes) { var aData = oTable{{ oUIBlock.GetId() }}.rows(indexes).data().toArray();
var aData = oTable{{ oUIBlock.GetId() }}.rows(indexes).data().toArray(); if( $(this).closest('.ibo-panel--body').find('[name=selectionMode]').val() === "negative")
if( $(this).closest('.ibo-panel--body').find('[name=selectionMode]').val() === "negative") {
{ // Checking input
// Checking input $('#{{ oUIBlock.GetId() }} tr[role="row"].selected td:first-child input').prop('checked', true);
$('#{{ oUIBlock.GetId() }} tr[role="row"].selected td:first-child input').prop('checked', true); // Saving values in temp array
// Saving values in temp array for (var i in aData) {
for (var i in aData) { var iItemId = aData[i].id;
var iItemId = aData[i].id; if (oSelectedItems{{ oUIBlock.GetOption('sListId') }}.indexOf(iItemId) > -1) {
if (oSelectedItems{{ oUIBlock.GetOption('sListId') }}.indexOf(iItemId) > -1) { oSelectedItems{{ oUIBlock.GetOption('sListId') }}.splice(oSelectedItems{{ oUIBlock.GetOption('sListId') }}.indexOf(iItemId), 1);
oSelectedItems{{ oUIBlock.GetOption('sListId') }}.splice(oSelectedItems{{ oUIBlock.GetOption('sListId') }}.indexOf(iItemId), 1); }
}
if (oSelectedItems{{ oUIBlock.GetOption('sListId') }}.length === oTable{{ oUIBlock.GetId() }}.page.info()["recordsTotal"] ) {
$('#btn_ok_{{ oUIBlock.GetOption('sTableId') }}').prop('disabled', true);
} else {
$('#btn_ok_{{ oUIBlock.GetOption('sTableId') }}').prop('disabled', false);
}
} }
} else {
if (oSelectedItems{{ oUIBlock.GetOption('sListId') }}.length === oTable{{ oUIBlock.GetId() }}.page.info()["recordsTotal"] ) { // Checking input
$('#btn_ok_{{ oUIBlock.GetOption('sTableId') }}').prop('disabled', true); $('#{{ oUIBlock.GetId() }} tr[role="row"].selected td:first-child input').prop('checked', true);
} else { // Saving values in temp array
$('#btn_ok_{{ oUIBlock.GetOption('sTableId') }}').prop('disabled', false); for (var i in aData) {
} var iItemId = aData[i].id;
} if (oSelectedItems{{ oUIBlock.GetOption('sListId') }}.indexOf(iItemId) === -1) {
else { oSelectedItems{{ oUIBlock.GetOption('sListId') }}.push(iItemId);
// Checking input }
$('#{{ oUIBlock.GetId() }} tr[role="row"].selected td:first-child input').prop('checked', true); }
// Saving values in temp array $('#btn_ok_{{ oUIBlock.GetOption('sTableId') }}').prop('disabled', false);
for (var i in aData) {
var iItemId = aData[i].id;
if (oSelectedItems{{ oUIBlock.GetOption('sListId') }}.indexOf(iItemId) === -1) {
oSelectedItems{{ oUIBlock.GetOption('sListId') }}.push(iItemId);
} }
} });
$('#btn_ok_{{ oUIBlock.GetOption('sTableId') }}').prop('disabled', false);
}
});
oTable{{ oUIBlock.GetId() }}.off('deselect').on('deselect', function (oEvent, dt, type, indexes) { oTable{{ oUIBlock.GetId() }}.off('deselect').on('deselect', function (oEvent, dt, type, indexes) {
var aData = oTable{{ oUIBlock.GetId() }}.rows(indexes).data().toArray(); var aData = oTable{{ oUIBlock.GetId() }}.rows(indexes).data().toArray();
// Checking input // Checking input
$('#{{ oUIBlock.GetId() }} tr[role="row"]:not(.selected) td:first-child input').prop('checked', false); $('#{{ oUIBlock.GetId() }} tr[role="row"]:not(.selected) td:first-child input').prop('checked', false);
// Saving values in temp array // Saving values in temp array
if ($(this).closest('.ibo-panel--body').find('[name=selectionMode]').val() === "negative") { if ($(this).closest('.ibo-panel--body').find('[name=selectionMode]').val() === "negative") {
for (var i in aData) { for (var i in aData) {
var iItemId = aData[i].id; var iItemId = aData[i].id;
if (oSelectedItems{{ oUIBlock.GetOption('sListId') }}.indexOf(iItemId) === -1) { if (oSelectedItems{{ oUIBlock.GetOption('sListId') }}.indexOf(iItemId) === -1) {
oSelectedItems{{ oUIBlock.GetOption('sListId') }}.push(iItemId); oSelectedItems{{ oUIBlock.GetOption('sListId') }}.push(iItemId);
}
}
if (oSelectedItems{{ oUIBlock.GetOption('sListId') }}.length === oTable{{ oUIBlock.GetId() }}.page.info()["recordsTotal"]) {
$('#btn_ok_{{ oUIBlock.GetOption('sTableId') }}').prop('disabled', true);
} else {
$('#btn_ok_{{ oUIBlock.GetOption('sTableId') }}').prop('disabled', false);
}
} else {
for (var i in aData) {
var iItemId = aData[i].id;
if (oSelectedItems{{ oUIBlock.GetOption('sListId') }}.indexOf(iItemId) > -1) {
oSelectedItems{{ oUIBlock.GetOption('sListId') }}.splice(oSelectedItems{{ oUIBlock.GetOption('sListId') }}.indexOf(iItemId), 1);
}
}
if (oSelectedItems{{ oUIBlock.GetOption('sListId') }}.length === 0) {
$('#btn_ok_{{ oUIBlock.GetOption('sTableId') }}').prop('disabled', true);
} else {
$('#btn_ok_{{ oUIBlock.GetOption('sTableId') }}').prop('disabled', false);
}
} }
} });
if (oSelectedItems{{ oUIBlock.GetOption('sListId') }}.length === oTable{{ oUIBlock.GetId() }}.page.info()["recordsTotal"]) { {% else %}
$('#btn_ok_{{ oUIBlock.GetOption('sTableId') }}').prop('disabled', true); oTable{{ oUIBlock.GetId() }}.off('select').on('select', function (oEvent, dt, type, indexes) {
} else { var aData = oTable{{ oUIBlock.GetId() }}.rows(indexes).data().toArray();
$('#btn_ok_{{ oUIBlock.GetOption('sTableId') }}').prop('disabled', false); // Checking input
} $('#{{ oUIBlock.GetId() }} tr[role="row"].selected td:first-child input').prop('checked', true);
} else { // Saving values in temp array
for (var i in aData) { for (var i in aData) {
var iItemId = aData[i].id; var iItemId = aData[i].id;
if (oSelectedItems{{ oUIBlock.GetOption('sListId') }}.indexOf(iItemId) > -1) { if (oSelectedItems{{ oUIBlock.GetOption('sListId') }}.indexOf(iItemId) === -1) {
oSelectedItems{{ oUIBlock.GetOption('sListId') }}.splice(oSelectedItems{{ oUIBlock.GetOption('sListId') }}.indexOf(iItemId), 1); oSelectedItems{{ oUIBlock.GetOption('sListId') }}.push(iItemId);
}
} }
} $('#btn_ok_{{ oUIBlock.GetOption('sListId') }}').prop('disabled', false);
if (oSelectedItems{{ oUIBlock.GetOption('sListId') }}.length === 0) { });
$('#btn_ok_{{ oUIBlock.GetOption('sTableId') }}').prop('disabled', true);
} else { oTable{{ oUIBlock.GetId() }}.off('deselect').on('deselect', function (oEvent, dt, type, indexes) {
$('#btn_ok_{{ oUIBlock.GetOption('sTableId') }}').prop('disabled', false); var aData = oTable{{ oUIBlock.GetId() }}.rows(indexes).data().toArray();
}
} // Checking input
}); $('#{{ oUIBlock.GetId() }} tr[role="row"]:not(.selected) td:first-child input').prop('checked', false);
{% else %} // Saving values in temp array
oTable{{ oUIBlock.GetId() }}.off('select').on('select', function (oEvent, dt, type, indexes) { for (var i in aData) {
$('#btn_ok_{{ oUIBlock.GetOption('sListId') }}').prop('disabled', false); var iItemId = aData[i].id;
}); if (oSelectedItems{{ oUIBlock.GetOption('sListId') }}.indexOf(iItemId) > -1) {
{% endif %} oSelectedItems{{ oUIBlock.GetOption('sListId') }}.splice(oSelectedItems{{ oUIBlock.GetOption('sListId') }}.indexOf(iItemId), 1);
}
}
});
{% endif %}
{% endif %} {% endif %}
$('#datatable_dlg_{{ oUIBlock.GetId() }}').dialog( $('#datatable_dlg_{{ oUIBlock.GetId() }}').dialog(