From 3262ad702931e1b46abb60986e32d702e1ad369a Mon Sep 17 00:00:00 2001 From: acognet Date: Wed, 7 Apr 2021 12:22:02 +0200 Subject: [PATCH] =?UTF-8?q?N=C2=B03868=20-=20"Error:=20Invalid=20filter=20?= =?UTF-8?q?parameter"=20on=20mass=20update?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- css/backoffice/components/input/_input.scss | 4 + js/dataTables.main.js | 88 +++---- js/dataTables.settings.js | 22 +- js/utils.js | 11 +- .../components/datatable/layout.live.js.twig | 11 +- .../components/datatable/layout.ready.js.twig | 233 ++++++++++-------- 6 files changed, 204 insertions(+), 165 deletions(-) diff --git a/css/backoffice/components/input/_input.scss b/css/backoffice/components/input/_input.scss index 9e1e1d5ce..89ce68cef 100644 --- a/css/backoffice/components/input/_input.scss +++ b/css/backoffice/components/input/_input.scss @@ -74,3 +74,7 @@ $ibo-input--margin-x: 5px !default; margin-leftt: $ibo-input--margin-x; display: inline; } + +.disabled { + background-color: $ibo-input--disabled--background-color; +} diff --git a/js/dataTables.main.js b/js/dataTables.main.js index 2318873ec..6f3761002 100644 --- a/js/dataTables.main.js +++ b/js/dataTables.main.js @@ -1,54 +1,59 @@ +/* + * @copyright Copyright (C) 2010-2021 Combodo SARL + * @license http://opensource.org/licenses/AGPL-3.0 + */ + function checkAllDataTable(tableId, value, listId) { - let tableSelector = $('#'+tableId); - // Set the 'selectionMode' for the future objects to load - let selectionMode = 'positive'; - if (value) { - selectionMode = 'negative'; - } - window['oSelectedItems' + listId] = []; - // Mark all the displayed items as check or unchecked depending on the value - tableSelector.find(':checkbox[name^=selectObj]:not([disabled])').each(function () { - let currentCheckbox = $(this); - currentCheckbox.prop('checked', value); - let currentLine = currentCheckbox.closest("tr"); - (value) ? currentLine.addClass("selected") : currentLine.removeClass("selected"); - }); + let tableSelector = $('#'+tableId); + // Set the 'selectionMode' for the future objects to load + let selectionMode = 'positive'; + if (value) { + selectionMode = 'negative'; + } + window['oSelectedItems'+listId] = []; + // Mark all the displayed items as check or unchecked depending on the value + tableSelector.find(':checkbox[name^=selectObj]:not([disabled])').each(function () { + let currentCheckbox = $(this); + currentCheckbox.prop('checked', value); + let currentLine = currentCheckbox.closest("tr"); + (value) ? currentLine.addClass("selected") : currentLine.removeClass("selected"); + }); - tableSelector.parent().parent().find(':input[name=selectionMode]').val(selectionMode); - // Reset the list of saved selection... - $(':input[name^=storedSelection]').remove(); - tableSelector.parent().find(':checkbox[name^=selectObj]').trigger("change"); + tableSelector.parent().parent().find(':input[name=selectionMode]').val(selectionMode); + // Reset the list of saved selection... + $(':input[name^=storedSelection]').remove(); + tableSelector.parent().find(':checkbox[name^=selectObj]').trigger("change"); - if (value) { - tableSelector.DataTable().rows().select(); - } else { - tableSelector.DataTable().rows({page: 'current'}).deselect(); - } + if (value) { + tableSelector.DataTable().rows().select(); + } else { + tableSelector.DataTable().rows({page: 'current'}).deselect(); + } updateDataTableSelection(listId); - return true; + return true; } function updateDataTableSelection(listId) { - let selectionContainer = $('#'+listId+' [data-target="ibo-datatable--selection"]'); - let selectionCount = $('#'+listId+' [name="selectionCount"]'); - let selectionMode = $('#'+listId+' [name=selectionMode]').val(); + let selectionContainer = $('#'+listId+' [data-target="ibo-datatable--selection"]'); + let selectionCount = $('#'+listId+' [name="selectionCount"]'); + let selectionMode = $('#'+listId+' [name=selectionMode]').val(); - selectionContainer.html(''); - let currentSelection = window['oSelectedItems'+listId]; - for(let i in currentSelection) { - let value = currentSelection[i]; - selectionContainer.append(''); - } + selectionContainer.html(''); + let currentSelection = window['oSelectedItems'+listId]; + for(let i in currentSelection) { + let value = currentSelection[i]; + selectionContainer.append(''); + } - if (selectionMode === 'negative') { - let total = window['oTable'+listId].page.info()["recordsTotal"]; - selectionCount.val(total - currentSelection.length); - } else { - selectionCount.val(currentSelection.length); - } + if (selectionMode === 'negative') { + let total = $('#'+$aOptions.sListId).DataTable().page.info()["recordsTotal"]; + selectionCount.val(total-currentSelection.length); + } else { + selectionCount.val(currentSelection.length); + } - selectionCount.trigger('change'); + selectionCount.trigger('change'); } function getMultipleSelectionParams(listId) @@ -56,8 +61,7 @@ function getMultipleSelectionParams(listId) var oRes = {}; oRes.selectionMode = ''; - if ($('#'+listId+' [name=selectionMode]').length > 0) - { + if ($('#'+listId+' [name=selectionMode]').length > 0) { oRes.selectionMode = $('#'+listId+' [name=selectionMode]').val(); } diff --git a/js/dataTables.settings.js b/js/dataTables.settings.js index 630f7a09e..b1854a390 100644 --- a/js/dataTables.settings.js +++ b/js/dataTables.settings.js @@ -15,15 +15,16 @@ $(function () { sListId: '', oColumns: {}, sSelectMode: '', + sSelectedItemsName: "", sViewLink: 'true', iPageSize: -1, oClassAliases: {}, - sTableId : null, + sTableId: null, oData: {}, sRenderUrl: 'index.php', oRenderParameters: {}, oDefaultSettings: {}, - oLabels: { moveup: 'Move Up', movedown: 'Move Down' } + oLabels: {moveup: 'Move Up', movedown: 'Move Down'} }, // the constructor @@ -80,12 +81,14 @@ $(function () { } var parentElt = $('#'+me.options.sListId).closest('.dataTables_wrapper').parent(); + var aOptions = $('#'+me.options.sListId).DataTable().context[0].oInit; + window['bSelectAllowed'+me.options.sListId] = false; $('#'+me.options.sListId).DataTable().destroy(true); var sThead = ""; if (me.options.sSelectMode != "") { sThead += ""; } - var aOptions = JSON.parse(data); + aOptions = $.extend(aOptions, JSON.parse(data)); $.each(aOptions['allColumns'], function (i, item) { $.each(item, function (j, champs) { if (champs.checked == 'true') { @@ -93,14 +96,15 @@ $(function () { } }); }); - $.each(aOptions['columns'], function(i, item) { - aOptions["columns"][i]["render"]["display"] = new Function ( "data, type, row" , aOptions["columns"][i]["render"]["display"]); + $.each(aOptions['columns'], function (i, item) { + aOptions["columns"][i]["render"]["display"] = new Function("data, type, row", aOptions["columns"][i]["render"]["display"]); }); - parentElt.append( "" + - ""+sThead+"
" ); - aOptions["lengthMenu"]= [[oParams.end, oParams.end*2, oParams.end*3, oParams.end*4, -1], [oParams.end, oParams.end*2, oParams.end*3, oParams.end*4, aOptions["lengthMenu"]]]; - aOptions["ajax"]=eval(aOptions["ajax"]); + parentElt.append(""+ + ""+sThead+"
"); + aOptions["lengthMenu"] = [[oParams.end, oParams.end * 2, oParams.end * 3, oParams.end * 4, -1], [oParams.end, oParams.end * 2, oParams.end * 3, oParams.end * 4, aOptions["lengthMenu"]]]; + aOptions["ajax"] = eval(aOptions["ajax"]); + $('#'+me.options.sListId).DataTable(aOptions); me.element.unblock(); diff --git a/js/utils.js b/js/utils.js index 790e6b7a5..ed2229231 100644 --- a/js/utils.js +++ b/js/utils.js @@ -281,8 +281,15 @@ function ToggleField(value, field_id) { $('#'+field_id+' :input').prop('disabled', false); } else { $('#'+field_id).prop('disabled', true); - // In case the field is rendered as a div containing several inputs (e.g. RedundancySettings) - $('#'+field_id+' :input').prop('disabled', true); + if ($('#'+field_id).hasClass('selectized')) { + $('#'+field_id)[0].selectize.disable(); + } else if ($('#'+field_id).parent().find('.ibo-input-select-autocomplete').length > 0) { + $('#'+field_id).parent().find('.ibo-input-select-autocomplete').prop('disabled', true); + $('#'+field_id).parent().find('.ibo-input-select--action-buttons').addClass('ibo-is-hidden'); + } else { + // In case the field is rendered as a div containing several inputs (e.g. RedundancySettings) + $('#'+field_id+' :input').prop('disabled', true); + } } $('#'+field_id).trigger('update'); $('#'+field_id).trigger('validate'); diff --git a/templates/base/components/datatable/layout.live.js.twig b/templates/base/components/datatable/layout.live.js.twig index 853cf8f9f..171b6da4a 100644 --- a/templates/base/components/datatable/layout.live.js.twig +++ b/templates/base/components/datatable/layout.live.js.twig @@ -1,8 +1,9 @@ - {% if oUIBlock.GetOption("select_mode") is not empty %} - var oSelectedItems{{ oUIBlock.GetOption('sListId') }} = []; - {% if oUIBlock.GetOption("sSelectedRows") is not empty %} - oSelectedItems{{ oUIBlock.GetOption('sListId') }} = {{ oUIBlock.GetOption('sSelectedRows')|raw }}; - {% endif %} +var oSelectedItems{{ oUIBlock.GetOption('sListId') }} = []; +{% if oUIBlock.GetOption("sSelectedRows") is not empty %} +oSelectedItems{{ oUIBlock.GetOption('sListId') }} = {{ oUIBlock.GetOption('sSelectedRows')|raw }}; +{% endif %} {% endif %} +var bSelectAllowed{{ oUIBlock.GetId() }} = false; + diff --git a/templates/base/components/datatable/layout.ready.js.twig b/templates/base/components/datatable/layout.ready.js.twig index 9eb941d73..6241c7986 100644 --- a/templates/base/components/datatable/layout.ready.js.twig +++ b/templates/base/components/datatable/layout.ready.js.twig @@ -48,7 +48,6 @@ else maxHeight{{ sListIDForVarSuffix }} = maxHeight{{ sListIDForVarSuffix }} -50; } - var oTable{{ sListIfForVarSuffix }} = $('#{{ oUIBlock.GetId() }}').DataTable({ language: { processing: "{{ 'UI:Datatables:Language:Processing'|dict_s }}", @@ -91,7 +90,8 @@ var oTable{{ sListIfForVarSuffix }} = $('#{{ oUIBlock.GetId() }}').DataTable({ { if (oSelectedItems{{ sListId }}.indexOf(oData.id) === -1) { - $(oRow).select(); + this.api().row($(oRow)).select(); + // $(oRow).addClass('selected'); $(oRow).find('td:first-child input').prop('checked', true); } } @@ -99,7 +99,7 @@ var oTable{{ sListIfForVarSuffix }} = $('#{{ oUIBlock.GetId() }}').DataTable({ { if (oSelectedItems{{ sListId }}.indexOf(oData.id) > -1) { - $(oRow).select(); + this.api().row($(oRow)).select(); $(oRow).find('td:first-child input').prop('checked', true); } } @@ -108,12 +108,12 @@ var oTable{{ sListIfForVarSuffix }} = $('#{{ oUIBlock.GetId() }}').DataTable({ if ($(this).closest('.ibo-panel--body').find('[name=selectionMode]').val() === "negative") { $(this).closest('.dataTables_wrapper').find('.checkAll')[0].checked = true; - $(this).DataTable().rows({page: 'current'}).select(); } else { $(this).closest('.dataTables_wrapper').find('.dataTables_paginate, .dataTables_info').show(); } + bSelectAllowed{{ oUIBlock.GetId() }} = true; $("#{{ oUIBlock.GetId() }} a").on('click', function (e) { //disable select action when there is a link @@ -197,113 +197,133 @@ var oTable{{ sListIfForVarSuffix }} = $('#{{ oUIBlock.GetId() }}').DataTable({ this.find('.ibo-dataTables--processing').remove(); this.find('tbody').unblock(); this.find('thead').unblock(); + + {% if oUIBlock.GetOption("select_mode") is not empty %} + updateDataTableSelection('{{ sListId }}'); + console.warn(this.api().rows('.selected').data().length); + {% if oUIBlock.GetOption("select_mode") != "single" %} + this.api().on('select', function (oEvent, dt, type, indexes) { + if (bSelectAllowed{{ oUIBlock.GetId() }}) + { + console.warn('select'); + let aData = oTable{{ sListIfForVarSuffix }}.rows(indexes).data().toArray(); + if ($(this).closest('.ibo-panel--body').find('[name=selectionMode]').val() === "negative") + { + // Checking input + $('#{{ oUIBlock.GetId() }} tbody tr.selected td:first-child input').prop('checked', true); + // Saving values in temp array + for (let i in aData) + { + let iItemId = aData[i].id; + if (oSelectedItems{{ sListId }}.indexOf(iItemId) > -1) + { + oSelectedItems{{ sListId }}.splice(oSelectedItems{{ sListId }}.indexOf(iItemId), 1); + updateDataTableSelection('{{ sListId }}'); + } + } + } + else + { + // Checking input + $('#{{ oUIBlock.GetId() }} tbody tr.selected td:first-child input').prop('checked', true); + // Saving values in temp array + for (let i in aData) + { + let iItemId = aData[i].id; + if (oSelectedItems{{ sListId }}.indexOf(iItemId) === -1) + { + oSelectedItems{{ sListId }}.push(iItemId); + updateDataTableSelection('{{ sListId }}'); + } + } + } + } + }); + + this.api().off('deselect').on('deselect', function (oEvent, dt, type, indexes) { + if (bSelectAllowed{{ oUIBlock.GetId() }} ) + { + let aData = oTable{{ sListIfForVarSuffix }}.rows(indexes).data().toArray(); + console.warn('deselect'); + // Checking input + $('#{{ oUIBlock.GetId() }} tbody tr: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 (let i in aData) + { + let iItemId = aData[i].id; + if (oSelectedItems{{ sListId }}.indexOf(iItemId) === -1) + { + oSelectedItems{{ sListId }}.push(iItemId); + updateDataTableSelection('{{ sListId }}'); + } + } + } + else + { + for (let i in aData) + { + let iItemId = aData[i].id; + if (oSelectedItems{{ sListId }}.indexOf(iItemId) > -1) + { + oSelectedItems{{ sListId }}.splice(oSelectedItems{{ sListId }}.indexOf(iItemId), 1); + updateDataTableSelection('{{ sListId }}'); + } + } + } + } + }); + {% else %} + this.api().off('select').on('select', function (oEvent, dt, type, indexes) { + if (bSelectAllowed{{ oUIBlock.GetId() }} ) + { + let aData = oTable{{ sListIfForVarSuffix }}.rows(indexes).data().toArray(); + // Checking input + $('#{{ oUIBlock.GetId() }} tbody tr.selected td:first-child input').prop('checked', true); + // Saving values in temp array + for (let i in aData) + { + let iItemId = aData[i].id; + if (oSelectedItems{{ sListId }}.indexOf(iItemId) === -1) + { + oSelectedItems{{ sListId }}.push(iItemId); + updateDataTableSelection('{{ sListId }}'); + } + } + } + }); + + this.api().off('deselect').on('deselect', function (oEvent, dt, type, indexes) { + if (bSelectAllowed{{ oUIBlock.GetId() }} ) + { + let aData = oTable{{ sListIfForVarSuffix }}.rows(indexes).data().toArray(); + + // Checking input + $('#{{ oUIBlock.GetId() }} tr tbody tr:not(.selected) td:first-child input').prop('checked', false); + // Saving values in temp array + for (let i in aData) + { + let iItemId = aData[i].id; + if (oSelectedItems{{ sListId }}.indexOf(iItemId) > -1) + { + oSelectedItems{{ sListId }}.splice(oSelectedItems{{ sListId }}.indexOf(iItemId), 1); + updateDataTableSelection('{{ sListId }}'); + } + } + } + }); + {% endif %} + + + {% endif %} } }); +oTable{{ sListIfForVarSuffix }}.select(); $('#{{ oUIBlock.GetId() }}').closest(".dataTables_scrollBody").css('max-height', maxHeight{{ sListIDForVarSuffix }}-100); -{% if oUIBlock.GetOption("select_mode") is not empty %} -{% if oUIBlock.GetOption("select_mode") != "single" %} -oTable{{ sListIfForVarSuffix }}.off('select').on('select', function (oEvent, dt, type, indexes) { - let aData = oTable{{ sListIfForVarSuffix }}.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 (let i in aData) - { - let iItemId = aData[i].id; - if (oSelectedItems{{ sListId }}.indexOf(iItemId) > -1) - { - oSelectedItems{{ sListId }}.splice(oSelectedItems{{ sListId }}.indexOf(iItemId), 1); - updateDataTableSelection('{{ sListId }}'); - } - } - } - else - { - // Checking input - $('#{{ oUIBlock.GetId() }} tr[role="row"].selected td:first-child input').prop('checked', true); - // Saving values in temp array - for (let i in aData) - { - let iItemId = aData[i].id; - if (oSelectedItems{{ sListId }}.indexOf(iItemId) === -1) - { - oSelectedItems{{ sListId }}.push(iItemId); - updateDataTableSelection('{{ sListId }}'); - } - } - } -}); - -oTable{{ sListIfForVarSuffix }}.off('deselect').on('deselect', function (oEvent, dt, type, indexes) { - let aData = oTable{{ sListIfForVarSuffix }}.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 (let i in aData) - { - let iItemId = aData[i].id; - if (oSelectedItems{{ sListId }}.indexOf(iItemId) === -1) - { - oSelectedItems{{ sListId }}.push(iItemId); - updateDataTableSelection('{{ sListId }}'); - } - } - } - else - { - for (let i in aData) - { - let iItemId = aData[i].id; - if (oSelectedItems{{ sListId }}.indexOf(iItemId) > -1) - { - oSelectedItems{{ sListId }}.splice(oSelectedItems{{ sListId }}.indexOf(iItemId), 1); - updateDataTableSelection('{{ sListId }}'); - } - } - } -}); -{% else %} -oTable{{ sListIfForVarSuffix }}.off('select').on('select', function (oEvent, dt, type, indexes) { - let aData = oTable{{ sListIfForVarSuffix }}.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 (let i in aData) - { - let iItemId = aData[i].id; - if (oSelectedItems{{ sListId }}.indexOf(iItemId) === -1) - { - oSelectedItems{{ sListId }}.push(iItemId); - updateDataTableSelection('{{ sListId }}'); - } - } -}); - -oTable{{ sListIfForVarSuffix }}.off('deselect').on('deselect', function (oEvent, dt, type, indexes) { - let aData = oTable{{ sListIfForVarSuffix }}.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 (let i in aData) - { - let iItemId = aData[i].id; - if (oSelectedItems{{ sListId }}.indexOf(iItemId) > -1) - { - oSelectedItems{{ sListId }}.splice(oSelectedItems{{ sListId }}.indexOf(iItemId), 1); - updateDataTableSelection('{{ sListId }}'); - } - } -}); -{% endif %} {% if oUIBlock.GetOption('sCountSelector') is not empty %} $('#{{ sListId }} [name="selectionCount"]').bind('change', function () { @@ -312,8 +332,6 @@ $('#{{ sListId }} [name="selectionCount"]').bind('change', function () { }); {% endif %} -{% endif %} - $('#datatable_dlg_{{ oUIBlock.GetId() }}').dialog( { autoOpen: false, @@ -334,6 +352,7 @@ $aOptions = { sListId: '{{ oUIBlock.GetId() }}', oColumns: {{ oUIBlock.GetResultColumnsAsJson()|raw }}, sSelectMode: "{{ oUIBlock.GetOption("select_mode") }}", + sSelectedItemsName: "oSelectedItems{{ sListId }}", sViewLink: '{{ oUIBlock.GetOption("bViewLink") }}', iPageSize: '{{ oUIBlock.GetOption("iPageSize") }}', oClassAliases: JSON.parse('{{ oUIBlock.GetOption("oClassAliases") |raw }}'),