N°3123 - Fix table counts on search results

This commit is contained in:
Eric
2020-12-14 18:31:32 +01:00
parent c106caf924
commit 9df80b9f79
7 changed files with 94 additions and 89 deletions

View File

@@ -663,7 +663,7 @@ JS
'table_inner_id' => "{$this->iId}_results",
'selection_mode' => true,
'selection_type' => 'single',
'cssCount' => '#count_'.$this->iId,
'cssCount' => '#count_'.$this->iId.'_results',
)
));
$sCancel = Dict::S('UI:Button:Cancel');
@@ -719,7 +719,7 @@ JS
$iCurrentExtKeyId = (is_null($oObj)) ? 0 : $oObj->Get($this->sAttCode);
$oBlock = new DisplayBlock($oFilter, 'list_search', false, array('query_params' => array('this' => $oObj, 'current_extkey_id' => $iCurrentExtKeyId)));
$oBlock->Display($oP, $this->iId.'_results', array('this' => $oObj, 'cssCount'=> '#count_'.$this->iId, 'menu' => false, 'selection_mode' => true, 'selection_type' => 'single', 'table_id' => 'select_'.$this->sAttCode)); // Don't display the 'Actions' menu on the results
$oBlock->Display($oP, $this->iId.'_results', array('this' => $oObj, 'cssCount'=> '#count_'.$this->iId.'_results', 'menu' => false, 'selection_mode' => true, 'selection_type' => 'single', 'table_id' => 'select_'.$this->sAttCode)); // Don't display the 'Actions' menu on the results
}
/**

View File

@@ -524,7 +524,7 @@ JS
</div>
<input type="hidden" id="count_{$this->m_sAttCode}{$this->m_sNameSuffix}" value="0"/>
<input type="button" value="{$sCancel}" onClick="$('#dlg_{$this->m_sAttCode}{$this->m_sNameSuffix}').dialog('close');">&nbsp;&nbsp;
<input id="btn_ok_add_{$this->m_sAttCode}{$this->m_sNameSuffix}" disabled="disabled" type="button" onclick="return oWidget{$this->m_iInputId}.DoAddObjects(this.id);" value="{$sAdd}">
<input id="btn_ok_{$this->m_sAttCode}{$this->m_sNameSuffix}" disabled="disabled" type="button" onclick="return oWidget{$this->m_iInputId}.DoAddObjects(this.id);" value="{$sAdd}">
</form>
HTML
);

View File

@@ -34,15 +34,25 @@ function checkAllDataTable(tableId, value, listId) {
function updateDataTableSelection(listId) {
let selectionContainer = $('#'+listId+' [data-target="ibo-datatable--selection"]');
let selectionCount = $('#'+listId+' [name="selectionCount"]');
let selectionMode = $('#'+listId+' [name=selectionMode]');
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 + '">');
}
selectionCount.val(currentSelection.length);
if (selectionMode === 'negative') {
let total = window['oTable'+listId].page.info()["recordsTotal"];
selectionCount.val(total - currentSelection.length);
} else {
selectionCount.val(currentSelection.length);
}
selectionCount.trigger('change');
}
function getMultipleSelectionParams(listId)
{
var oRes = {};

View File

@@ -234,7 +234,7 @@ function ExtKeyWidget(id, sTargetClass, sFilter, sTitle, bSelectMode, oWizHelper
me.UpdateSizes();
me.UpdateButtons();
me.ajax_request = null;
$('#count_'+me.id).change(function () {
$('#count_'+me.id+ '_results').change(function () {
me.UpdateButtons();
});
if (me.bDoSearch)

View File

@@ -31,7 +31,7 @@ function LinksWidget(id, sClass, sAttCode, iInputId, sSuffix, bDuplicates, oWizH
this.aRemoved = [];
this.aModified = {};
this.bDoSearch = bDoSearch; // false if the search is not launched
var me = this;
let me = this;
this.Init = function () {
// make sure that the form is clean
@@ -47,7 +47,7 @@ function LinksWidget(id, sClass, sAttCode, iInputId, sSuffix, bDuplicates, oWizH
me.RegisterChange();
var oInput = $('#'+this.iInputId);
let oInput = $('#'+this.iInputId);
oInput.bind('update_value', function () {
$(this).val(me.GetUpdatedValue());
});
@@ -57,10 +57,10 @@ function LinksWidget(id, sClass, sAttCode, iInputId, sSuffix, bDuplicates, oWizH
};
this.RemoveSelected = function () {
var my_id = '#'+me.id;
let my_id = '#'+me.id;
$('#linkedset_'+me.id+' .selection:checked').each(function () {
$(my_id+'_row_'+this.value).remove();
var iLink = $(this).attr('data-link-id');
let iLink = $(this).attr('data-link-id');
if (iLink > 0)
{
me.aRemoved.push(iLink);
@@ -71,7 +71,7 @@ function LinksWidget(id, sClass, sAttCode, iInputId, sSuffix, bDuplicates, oWizH
}
else
{
var iUniqueId = $(this).attr('data-unique-id');
let iUniqueId = $(this).attr('data-unique-id');
if (iUniqueId < 0)
{
iUniqueId = -iUniqueId;
@@ -92,7 +92,7 @@ function LinksWidget(id, sClass, sAttCode, iInputId, sSuffix, bDuplicates, oWizH
};
this.OnSelectChange = function () {
var nbChecked = $('#linkedset_'+me.id+' .selection:checked').length;
let nbChecked = $('#linkedset_'+me.id+' .selection:checked').length;
if (nbChecked > 0)
{
$('#'+me.id+'_btnRemove').prop('disabled', false);
@@ -104,10 +104,10 @@ function LinksWidget(id, sClass, sAttCode, iInputId, sSuffix, bDuplicates, oWizH
};
this.AddObjects = function () {
var me = this;
let me = this;
$('#'+me.id+'_indicatorAdd').html('&nbsp;<img src="../images/indicator.gif"/>');
me.oWizardHelper.UpdateWizard();
var theMap = {
let theMap = {
sAttCode: me.sAttCode,
iInputId: me.iInputId,
sSuffix: me.sSuffix,
@@ -120,7 +120,7 @@ function LinksWidget(id, sClass, sAttCode, iInputId, sSuffix, bDuplicates, oWizH
// Gather the already linked target objects
theMap.aAlreadyLinked = [];
$('#linkedset_'+me.id+' .selection:input').each(function (i) {
var iRemote = $(this).attr('data-remote-id');
let iRemote = $(this).attr('data-remote-id');
theMap.aAlreadyLinked.push(iRemote);
});
@@ -141,7 +141,7 @@ function LinksWidget(id, sClass, sAttCode, iInputId, sSuffix, bDuplicates, oWizH
else
{
$('#count_'+me.id).change(function () {
var c = this.value;
let c = this.value;
me.UpdateButtons(c);
});
}
@@ -152,7 +152,7 @@ function LinksWidget(id, sClass, sAttCode, iInputId, sSuffix, bDuplicates, oWizH
this.SearchObjectsToAdd = function () {
$('#count_'+me.id).change(function () {
var c = this.value;
let c = this.value;
me.UpdateButtons(c);
});
me.UpdateSizes(null, null);
@@ -163,7 +163,7 @@ function LinksWidget(id, sClass, sAttCode, iInputId, sSuffix, bDuplicates, oWizH
};
this.UpdateButtons = function (iCount) {
var okBtn = $('#btn_ok_'+me.id);
let okBtn = $('#btn_ok_'+me.id);
if (iCount > 0)
{
okBtn.prop('disabled', false);
@@ -175,7 +175,7 @@ function LinksWidget(id, sClass, sAttCode, iInputId, sSuffix, bDuplicates, oWizH
};
this.DoAddObjects = function () {
var theMap = {
let theMap = {
sAttCode: me.sAttCode,
iInputId: me.iInputId,
sSuffix: me.sSuffix,
@@ -184,12 +184,12 @@ function LinksWidget(id, sClass, sAttCode, iInputId, sSuffix, bDuplicates, oWizH
};
// Gather the parameters from the search form
var context = $('#SearchResultsToAdd_'+me.id);
var selectionMode = $(':input[name=selectionMode]', context);
let context = $('#SearchResultsToAdd_'+me.id);
let selectionMode = $(':input[name=selectionMode]', context);
if (selectionMode.length > 0)
{
// Paginated table retrieve the mode and the exceptions
var sMode = selectionMode.val();
let sMode = selectionMode.val();
theMap['selectionMode'] = sMode;
$('#fs_SearchFormToAdd_'+me.id+' :input').each(
function (i) {
@@ -278,7 +278,7 @@ function LinksWidget(id, sClass, sAttCode, iInputId, sSuffix, bDuplicates, oWizH
this.AddLink = function (iAddedId, iRemote) {
// Assumption: this identifier will be higher than the previous one
me.iMaxAddedId = iAddedId;
var sFormPrefix = me.iInputId;
let sFormPrefix = me.iInputId;
oAdded = {};
oAdded['formPrefix'] = sFormPrefix;
oAdded['attr_'+sFormPrefix+this.sExtKeyToRemote] = iRemote;
@@ -291,25 +291,25 @@ function LinksWidget(id, sClass, sAttCode, iInputId, sSuffix, bDuplicates, oWizH
};
this.UpdateSizes = function (event, ui) {
var dlg = $('#dlg_'+me.id);
var searchForm = $('#SearchFormToAdd_'+me.id);
var results = $('#SearchResultsToAdd_'+me.id);
var padding_right = 0;
let dlg = $('#dlg_'+me.id);
let searchForm = $('#SearchFormToAdd_'+me.id);
let results = $('#SearchResultsToAdd_'+me.id);
let padding_right = 0;
if (dlg.css('padding-right'))
{
padding_right = parseInt(dlg.css('padding-right').replace('px', ''));
}
var padding_left = 0;
let padding_left = 0;
if (dlg.css('padding-left'))
{
padding_left = parseInt(dlg.css('padding-left').replace('px', ''));
}
var padding_top = 0;
let padding_top = 0;
if (dlg.css('padding-top'))
{
padding_top = parseInt(dlg.css('padding-top').replace('px', ''));
}
var padding_bottom = 0;
let padding_bottom = 0;
if (dlg.css('padding-bottom'))
{
padding_bottom = parseInt(dlg.css('padding-bottom').replace('px', ''));
@@ -324,26 +324,26 @@ function LinksWidget(id, sClass, sAttCode, iInputId, sSuffix, bDuplicates, oWizH
};
this.GetUpdatedValue = function () {
var sSelector = '#linkedset_'+me.id+' :input[name^=attr_'+me.id+']';
var aIndexes = [];
var aValues = [];
let sSelector = '#linkedset_'+me.id+' :input[name^=attr_'+me.id+']';
let aIndexes = [];
let aValues = [];
$(sSelector).each(function () {
var re = /\[([^\[]+)\]\[(.+)\]/;
var aMatches = [];
let re = /\[([^\[]+)\]\[(.+)\]/;
let aMatches = [];
if (aMatches = this.name.match(re))
{
var idx = aMatches[1];
var index = jQuery.inArray(idx, aIndexes);
let idx = aMatches[1];
let index = jQuery.inArray(idx, aIndexes);
if (index == -1)
{
aIndexes.push(idx);
index = jQuery.inArray(idx, aIndexes);
aValues[index] = {};
}
var value = $(this).val();
let value = $(this).val();
if (aMatches[2] == "id")
{
var iId = parseInt(aMatches[1], 10);
let iId = parseInt(aMatches[1], 10);
if (iId < 0)
{
aValues[index][me.sExtKeyToRemote] = -iId;
@@ -367,11 +367,11 @@ function LinksWidget(id, sClass, sAttCode, iInputId, sSuffix, bDuplicates, oWizH
$('#linkedset_'+me.id+' :input[name^="attr_'+me.sAttCode+'["]').off('change').on('change', function () {
if (!($(this).hasClass('selection')))
{
var oCheckbox = $(this).closest('tr').find('.selection');
var iLink = oCheckbox.attr('data-link-id');
var iUniqueId = oCheckbox.attr('data-unique-id');
var sAttCode = $(this).closest('.attribute-edit').attr('data-attcode');
var value = $(this).val();
let oCheckbox = $(this).closest('tr').find('.selection');
let iLink = oCheckbox.attr('data-link-id');
let iUniqueId = oCheckbox.attr('data-unique-id');
let sAttCode = $(this).closest('.attribute-edit').attr('data-attcode');
let value = $(this).val();
return me.OnValueChange(iLink, iUniqueId, sAttCode, value, this);
}
return true;
@@ -386,11 +386,11 @@ function LinksWidget(id, sClass, sAttCode, iInputId, sSuffix, bDuplicates, oWizH
* @param jQuery $oSourceObject object which fires the event
*/
this.OnValueChange = function (iLink, iUniqueId, sAttCode, value, $oSourceObject) {
var sFormPrefix = me.iInputId;
let sFormPrefix = me.iInputId;
if (iLink > 0)
{
// Modifying an existing link
var oModified = me.aModified[iLink];
let oModified = me.aModified[iLink];
if (oModified == undefined)
{
// Still not marked as modified
@@ -413,23 +413,23 @@ function LinksWidget(id, sClass, sAttCode, iInputId, sSuffix, bDuplicates, oWizH
};
this.OnFormSubmit = function () {
var oDiv = $('#linkedset_'+me.id);
let oDiv = $('#linkedset_'+me.id);
var sToBeDeleted = JSON.stringify(me.aRemoved);
let sToBeDeleted = JSON.stringify(me.aRemoved);
$('<input type="hidden" name="attr_'+me.sAttCode+'_tbd">').val(sToBeDeleted).appendTo(oDiv);
var sToBeModified = JSON.stringify(me.aModified);
let sToBeModified = JSON.stringify(me.aModified);
$('<input type="hidden" name="attr_'+me.sAttCode+'_tbm">').val(sToBeModified).appendTo(oDiv);
var aToBeCreated = [];
let aToBeCreated = [];
me.aAdded.forEach(function (oAdded) {
if (oAdded != null)
{
aToBeCreated.push(oAdded);
}
});
var sToBeCreated = JSON.stringify(aToBeCreated);
let sToBeCreated = JSON.stringify(aToBeCreated);
$('<input type="hidden" name="attr_'+me.sAttCode+'_tbc">').val(sToBeCreated).appendTo(oDiv);
// Remove unused inputs

View File

@@ -347,6 +347,10 @@ class DataTableFactory
}
}
if (isset($aExtraParams['cssCount'])) {
$aOptions['sCountSelector'] = $aExtraParams['cssCount'];
}
$aOptions['iPageSize'] = 10;
if ($oCustomSettings->iDefaultPageSize > 0) {
$aOptions['iPageSize'] = $oCustomSettings->iDefaultPageSize;

View File

@@ -17,7 +17,7 @@ if ($.fn.dataTable.isDataTable('#{{ oUIBlock.GetId() }}')) {
$('#{{ oUIBlock.GetId() }}').DataTable().destroy(false);
}
var oTable{{ oUIBlock.GetId() }} = $('#{{ oUIBlock.GetId() }}').DataTable({
var oTable{{ sListId }} = $('#{{ oUIBlock.GetId() }}').DataTable({
language: {
processing: "{{ 'UI:Datatables:Language:Processing'|dict_s }}",
search: "{{ 'UI:Datatables:Language:Search'|dict_s }}",
@@ -93,7 +93,7 @@ var oTable{{ oUIBlock.GetId() }} = $('#{{ oUIBlock.GetId() }}').DataTable({
type: "html",
data: "",
render: function (data, type, row) {
var oCheckboxElem =
let oCheckboxElem =
{% if oUIBlock.GetOption("select_mode") != "single" %}
$('<span class="row_input"><input type="checkbox" class="selectList{{ oUIBlock.GetId() }}" name="selectObject[]" value="'+row.id+'"></span>');
{% else %}
@@ -148,99 +148,82 @@ var oTable{{ oUIBlock.GetId() }} = $('#{{ oUIBlock.GetId() }}').DataTable({
{% if oUIBlock.GetOption("select_mode") is not empty %}
{% 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();
oTable{{ sListId }}.off('select').on('select', function (oEvent, dt, type, indexes) {
let aData = oTable{{ sListId }}.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;
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 }}');
}
}
if (oSelectedItems{{ 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;
for (let i in aData) {
let iItemId = aData[i].id;
if (oSelectedItems{{ sListId }}.indexOf(iItemId) === -1) {
oSelectedItems{{ sListId }}.push(iItemId);
updateDataTableSelection('{{ sListId }}');
}
}
$('#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{{ sListId }}.off('deselect').on('deselect', function (oEvent, dt, type, indexes) {
let aData = oTable{{ sListId }}.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;
for (let i in aData) {
let iItemId = aData[i].id;
if (oSelectedItems{{ sListId }}.indexOf(iItemId) === -1) {
oSelectedItems{{ sListId }}.push(iItemId);
updateDataTableSelection('{{ sListId }}');
}
}
if (oSelectedItems{{ 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;
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 }}');
}
}
if (oSelectedItems{{ 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) {
var aData = oTable{{ oUIBlock.GetId() }}.rows(indexes).data().toArray();
oTable{{ sListId }}.off('select').on('select', function (oEvent, dt, type, indexes) {
let aData = oTable{{ sListId }}.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;
for (let i in aData) {
let iItemId = aData[i].id;
if (oSelectedItems{{ sListId }}.indexOf(iItemId) === -1) {
oSelectedItems{{ sListId }}.push(iItemId);
updateDataTableSelection('{{ sListId }}');
}
}
$('#btn_ok_{{ 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();
oTable{{ sListId }}.off('deselect').on('deselect', function (oEvent, dt, type, indexes) {
let aData = oTable{{ sListId }}.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;
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 }}');
@@ -248,6 +231,14 @@ var oTable{{ oUIBlock.GetId() }} = $('#{{ oUIBlock.GetId() }}').DataTable({
}
});
{% endif %}
{% if oUIBlock.GetOption('sCountSelector') is not empty %}
$('#{{ sListId }} [name="selectionCount"]').bind('change', function() {
$('{{ oUIBlock.GetOption('sCountSelector') }}').val($('#{{ sListId }} [name="selectionCount"]').val());
$('{{ oUIBlock.GetOption('sCountSelector') }}').trigger('change');
});
{% endif %}
{% endif %}
$('#datatable_dlg_{{ oUIBlock.GetId() }}').dialog(