N°3868 - "Error: Invalid filter parameter" on mass update

This commit is contained in:
acognet
2021-04-07 12:22:02 +02:00
parent a5bb6a0c55
commit 3262ad7029
6 changed files with 204 additions and 165 deletions

View File

@@ -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;
}

View File

@@ -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('<input type="hidden" name="storedSelection[]" value="' + value + '">');
}
selectionContainer.html('');
let currentSelection = window['oSelectedItems'+listId];
for(let i in currentSelection) {
let value = currentSelection[i];
selectionContainer.append('<input type="hidden" name="storedSelection[]" value="' + value + '">');
}
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();
}

View File

@@ -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 += "<th></th>";
}
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( "<table id=\""+me.options.sListId+"\" width=\"100%\" class=\"ibo-datatable\">" +
"<thead><tr>"+sThead+"</tr></thead></table>" );
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("<table id=\""+me.options.sListId+"\" width=\"100%\" class=\"ibo-datatable\">"+
"<thead><tr>"+sThead+"</tr></thead></table>");
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();

View File

@@ -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');

View File

@@ -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;

View File

@@ -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 }}'),