From fb70026966e015864c4ed6d7946b879356d78eee Mon Sep 17 00:00:00 2001 From: acognet Date: Tue, 24 Nov 2020 14:21:28 +0100 Subject: [PATCH] =?UTF-8?q?N=C2=B02847=20-=20Tranform=20old=20itop=20datat?= =?UTF-8?q?able=20to=20jquery=20DataTable=20-=20Fix=20management=20of=20bu?= =?UTF-8?q?tton=20"Add"=20step=202?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- templates/components/datatable/layout.js.twig | 155 ++++++++++-------- 1 file changed, 89 insertions(+), 66 deletions(-) diff --git a/templates/components/datatable/layout.js.twig b/templates/components/datatable/layout.js.twig index c88fa2cec5..225e6becf3 100644 --- a/templates/components/datatable/layout.js.twig +++ b/templates/components/datatable/layout.js.twig @@ -173,78 +173,101 @@ var oTable{{ oUIBlock.GetId() }} = $('#{{ oUIBlock.GetId() }}').DataTable({ {% if oUIBlock.GetOption("select_mode") is not empty %} -{% if oUIBlock.GetOption("select_mode") != "single" %} -console.warn('aa'); -oTable{{ oUIBlock.GetId() }}.off('select').on('select', function (oEvent, dt, type, indexes) { - var aData = oTable{{ oUIBlock.GetId() }}.rows(indexes).data().toArray(); - if( $(this).closest('.ibo-panel--body').find('[name=selectionMode]').val() === "negative") - { - // Checking input - $('#{{ oUIBlock.GetId() }} tr[role="row"].selected td:first-child input').prop('checked', true); - // Saving values in temp array - 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 oUIBlock.GetOption("select_mode") != "single" %} + oTable{{ oUIBlock.GetId() }}.off('select').on('select', function (oEvent, dt, type, indexes) { + var aData = oTable{{ oUIBlock.GetId() }}.rows(indexes).data().toArray(); + if( $(this).closest('.ibo-panel--body').find('[name=selectionMode]').val() === "negative") + { + // Checking input + $('#{{ oUIBlock.GetId() }} tr[role="row"].selected td:first-child input').prop('checked', true); + // Saving values in temp array + 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 === oTable{{ oUIBlock.GetId() }}.page.info()["recordsTotal"] ) { + $('#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"] ) { - $('#btn_ok_{{ oUIBlock.GetOption('sTableId') }}').prop('disabled', true); - } else { - $('#btn_ok_{{ oUIBlock.GetOption('sTableId') }}').prop('disabled', false); - } - } - else { - // Checking input - $('#{{ oUIBlock.GetId() }} tr[role="row"].selected td:first-child input').prop('checked', true); - // Saving values in temp array - for (var i in aData) { - var iItemId = aData[i].id; - if (oSelectedItems{{ oUIBlock.GetOption('sListId') }}.indexOf(iItemId) === -1) { - oSelectedItems{{ oUIBlock.GetOption('sListId') }}.push(iItemId); + else { + // Checking input + $('#{{ oUIBlock.GetId() }} tr[role="row"].selected td:first-child input').prop('checked', true); + // Saving values in temp array + 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); } - } - $('#btn_ok_{{ oUIBlock.GetOption('sTableId') }}').prop('disabled', false); - } -}); + }); -oTable{{ oUIBlock.GetId() }}.off('deselect').on('deselect', function (oEvent, dt, type, indexes) { - var aData = oTable{{ oUIBlock.GetId() }}.rows(indexes).data().toArray(); + oTable{{ oUIBlock.GetId() }}.off('deselect').on('deselect', function (oEvent, dt, type, indexes) { + 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); - // Saving values in temp array - if ($(this).closest('.ibo-panel--body').find('[name=selectionMode]').val() === "negative") { - for (var i in aData) { - var iItemId = aData[i].id; - if (oSelectedItems{{ oUIBlock.GetOption('sListId') }}.indexOf(iItemId) === -1) { - oSelectedItems{{ oUIBlock.GetOption('sListId') }}.push(iItemId); + // Checking input + $('#{{ oUIBlock.GetId() }} tr[role="row"]:not(.selected) td:first-child input').prop('checked', false); + // Saving values in temp array + if ($(this).closest('.ibo-panel--body').find('[name=selectionMode]').val() === "negative") { + for (var i in aData) { + var iItemId = aData[i].id; + if (oSelectedItems{{ oUIBlock.GetOption('sListId') }}.indexOf(iItemId) === -1) { + 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"]) { - $('#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); + }); + {% else %} + oTable{{ oUIBlock.GetId() }}.off('select').on('select', function (oEvent, dt, type, indexes) { + var aData = oTable{{ oUIBlock.GetId() }}.rows(indexes).data().toArray(); + // Checking input + $('#{{ oUIBlock.GetId() }} tr[role="row"].selected td:first-child input').prop('checked', true); + // Saving values in temp array + for (var i in aData) { + var iItemId = aData[i].id; + if (oSelectedItems{{ oUIBlock.GetOption('sListId') }}.indexOf(iItemId) === -1) { + oSelectedItems{{ oUIBlock.GetOption('sListId') }}.push(iItemId); + } } - } - if (oSelectedItems{{ oUIBlock.GetOption('sListId') }}.length === 0) { - $('#btn_ok_{{ oUIBlock.GetOption('sTableId') }}').prop('disabled', true); - } else { - $('#btn_ok_{{ oUIBlock.GetOption('sTableId') }}').prop('disabled', false); - } - } -}); -{% else %} - oTable{{ oUIBlock.GetId() }}.off('select').on('select', function (oEvent, dt, type, indexes) { - $('#btn_ok_{{ oUIBlock.GetOption('sListId') }}').prop('disabled', false); - }); -{% endif %} + $('#btn_ok_{{ oUIBlock.GetOption('sListId') }}').prop('disabled', false); + }); + + oTable{{ oUIBlock.GetId() }}.off('deselect').on('deselect', function (oEvent, dt, type, indexes) { + 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); + // Saving values in temp array + 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); + } + } + }); + {% endif %} {% endif %} $('#datatable_dlg_{{ oUIBlock.GetId() }}').dialog(