mirror of
https://github.com/Combodo/iTop.git
synced 2026-02-13 07:24:13 +01:00
N°2847 - Datatables Fix external keys search
This commit is contained in:
@@ -25,6 +25,7 @@
|
||||
*/
|
||||
|
||||
use Combodo\iTop\Application\UI\Component\DataTable\DataTableFactory;
|
||||
use Combodo\iTop\Application\UI\Component\DataTable\StaticTable\FormTableRow\FormTableRow;
|
||||
use Combodo\iTop\Renderer\BlockRenderer;
|
||||
|
||||
require_once(APPROOT.'application/displayblock.class.inc.php');
|
||||
@@ -353,7 +354,13 @@ JS
|
||||
*/
|
||||
protected function DisplayFormTable(WebPage $oP, $aConfig, $aData)
|
||||
{
|
||||
$oTable = DataTableFactory::MakeForForm("{$this->m_sAttCode}{$this->m_sNameSuffix}", $aConfig, $aData);
|
||||
$oTable = DataTableFactory::MakeForForm("{$this->m_sAttCode}{$this->m_sNameSuffix}", $aConfig);
|
||||
|
||||
foreach ($aData as $iRowId => $aRow)
|
||||
{
|
||||
$oRow = new FormTableRow("{$this->m_sAttCode}{$this->m_sNameSuffix}", $aConfig, $aRow, $iRowId);
|
||||
$oTable->AddRow($oRow);
|
||||
}
|
||||
|
||||
$sHtml = BlockRenderer::RenderBlockTemplates($oTable);
|
||||
|
||||
@@ -600,7 +607,9 @@ HTML
|
||||
if (is_object($oLinkedObj))
|
||||
{
|
||||
$aRow = $this->GetFormRow($oP, $oLinkedObj, $iObjectId, array(), $oCurrentObj, $iAdditionId); // Not yet created link get negative Ids
|
||||
$oP->add($this->DisplayFormRow($oP, $this->m_aTableConfig, $aRow, -$iAdditionId));
|
||||
//$oP->add($this->DisplayFormRow($oP, $this->m_aTableConfig, $aRow, -$iAdditionId));
|
||||
$oRow = new FormTableRow("{$this->m_sAttCode}{$this->m_sNameSuffix}", $this->m_aTableConfig, $aRow, -$iAdditionId);
|
||||
$oP->AddUiBlock($oRow);
|
||||
$iAdditionId++;
|
||||
}
|
||||
else
|
||||
|
||||
@@ -603,11 +603,11 @@ abstract class DBSearch
|
||||
elseif (($iPos = strpos($sParam, '->')) !== false)
|
||||
{
|
||||
$sParamName = substr($sParam, 0, $iPos);
|
||||
if (isset($aContextParams[$sParamName.'->object()']))
|
||||
if (isset($aContextParams[$sParamName.'->object()']) || isset($aContextParams[$sParamName]))
|
||||
{
|
||||
$sAttCode = substr($sParam, $iPos + 2);
|
||||
/** @var \DBObject $oObj */
|
||||
$oObj = $aContextParams[$sParamName.'->object()'];
|
||||
$oObj = isset($aContextParams[$sParamName.'->object()']) ? $aContextParams[$sParamName.'->object()'] : $aContextParams[$sParamName];
|
||||
if ($oObj->IsModified())
|
||||
{
|
||||
if ($sAttCode == 'id')
|
||||
|
||||
@@ -24,4 +24,5 @@
|
||||
@import "field";
|
||||
@import "toolbar";
|
||||
@import "richtext";
|
||||
@import "formtable";
|
||||
@import "formtable";
|
||||
@import "formtablerow";
|
||||
4
css/backoffice/components/_formtablerow.scss
Normal file
4
css/backoffice/components/_formtablerow.scss
Normal file
@@ -0,0 +1,4 @@
|
||||
/*!
|
||||
* copyright Copyright (C) 2010-2020 Combodo SARL
|
||||
* license http://opensource.org/licenses/AGPL-3.0
|
||||
*/
|
||||
@@ -164,6 +164,7 @@ return array(
|
||||
'Combodo\\iTop\\Application\\UI\\Component\\DataTable\\DataTableBlock' => $baseDir . '/sources/application/UI/Component/DataTable/DataTable.php',
|
||||
'Combodo\\iTop\\Application\\UI\\Component\\DataTable\\DataTableFactory' => $baseDir . '/sources/application/UI/Component/DataTable/DataTableFactory.php',
|
||||
'Combodo\\iTop\\Application\\UI\\Component\\DataTable\\DataTableSettings' => $baseDir . '/sources/application/UI/Component/DataTable/DataTableSettings.php',
|
||||
'Combodo\\iTop\\Application\\UI\\Component\\DataTable\\StaticTable\\FormTableRow\\FormTableRow' => $baseDir . '/sources/application/UI/Component/DataTable/StaticTable/FormTableRow/FormTableRow.php',
|
||||
'Combodo\\iTop\\Application\\UI\\Component\\DataTable\\StaticTable\\FormTable\\FormTable' => $baseDir . '/sources/application/UI/Component/DataTable/StaticTable/FormTable/FormTable.php',
|
||||
'Combodo\\iTop\\Application\\UI\\Component\\DataTable\\StaticTable\\StaticTable' => $baseDir . '/sources/application/UI/Component/DataTable/StaticTable/StaticTable.php',
|
||||
'Combodo\\iTop\\Application\\UI\\Component\\FieldSet\\FieldSet' => $baseDir . '/sources/application/UI/Component/FieldSet/FieldSet.php',
|
||||
|
||||
@@ -394,6 +394,7 @@ class ComposerStaticInit0018331147de7601e7552f7da8e3bb8b
|
||||
'Combodo\\iTop\\Application\\UI\\Component\\DataTable\\DataTableBlock' => __DIR__ . '/../..' . '/sources/application/UI/Component/DataTable/DataTable.php',
|
||||
'Combodo\\iTop\\Application\\UI\\Component\\DataTable\\DataTableFactory' => __DIR__ . '/../..' . '/sources/application/UI/Component/DataTable/DataTableFactory.php',
|
||||
'Combodo\\iTop\\Application\\UI\\Component\\DataTable\\DataTableSettings' => __DIR__ . '/../..' . '/sources/application/UI/Component/DataTable/DataTableSettings.php',
|
||||
'Combodo\\iTop\\Application\\UI\\Component\\DataTable\\StaticTable\\FormTableRow\\FormTableRow' => __DIR__ . '/../..' . '/sources/application/UI/Component/DataTable/StaticTable/FormTableRow/FormTableRow.php',
|
||||
'Combodo\\iTop\\Application\\UI\\Component\\DataTable\\StaticTable\\FormTable\\FormTable' => __DIR__ . '/../..' . '/sources/application/UI/Component/DataTable/StaticTable/FormTable/FormTable.php',
|
||||
'Combodo\\iTop\\Application\\UI\\Component\\DataTable\\StaticTable\\StaticTable' => __DIR__ . '/../..' . '/sources/application/UI/Component/DataTable/StaticTable/StaticTable.php',
|
||||
'Combodo\\iTop\\Application\\UI\\Component\\FieldSet\\FieldSet' => __DIR__ . '/../..' . '/sources/application/UI/Component/FieldSet/FieldSet.php',
|
||||
|
||||
@@ -261,7 +261,7 @@ try
|
||||
|
||||
case 'search':
|
||||
$oPage->SetContentType('application/json');
|
||||
$extraParams = utils::ReadParam('extra_param', '', false, 'raw_data');
|
||||
$extraParams = utils::ReadParam('extra_params', '', false, 'raw_data');
|
||||
$aExtraParams = array();
|
||||
if (is_array($extraParams))
|
||||
{
|
||||
@@ -385,9 +385,10 @@ try
|
||||
}
|
||||
|
||||
}
|
||||
$aQueryParams = isset($aExtraParams['query_params']) ? $aExtraParams['query_params'] : [];
|
||||
|
||||
// Load only the requested columns
|
||||
$oSet = new DBObjectSet($oFilter, $aOrderBy, $aExtraParams, null, $iEnd - $iStart, $iStart);
|
||||
$oSet = new DBObjectSet($oFilter, $aOrderBy, $aQueryParams, null, $iEnd - $iStart, $iStart);
|
||||
$oSet->OptimizeColumnLoad($aColumnsLoad);
|
||||
|
||||
if (isset($aExtraParams['show_obsolete_data'])) {
|
||||
|
||||
@@ -106,6 +106,15 @@ class DataTableBlock extends UIContentBlock
|
||||
{
|
||||
$this->aResultColumns = $aColumns;
|
||||
}
|
||||
|
||||
public function GetOption(string $sOption)
|
||||
{
|
||||
if (isset($this->aOptions[$sOption])) {
|
||||
return $this->aOptions[$sOption];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
|
||||
@@ -706,11 +706,10 @@ class DataTableFactory
|
||||
return $oBlock;
|
||||
}
|
||||
|
||||
public Static function MakeForForm(string $sRef, array $aColumns, array $aData)
|
||||
public Static function MakeForForm(string $sRef, array $aColumns): FormTable
|
||||
{
|
||||
$oTable = new FormTable($sRef);
|
||||
$oTable->SetColumns($aColumns);
|
||||
$oTable->SetData($aData);
|
||||
|
||||
return $oTable;
|
||||
}
|
||||
|
||||
@@ -7,7 +7,9 @@
|
||||
namespace Combodo\iTop\Application\UI\Component\DataTable\StaticTable\FormTable;
|
||||
|
||||
|
||||
use Combodo\iTop\Application\UI\Component\DataTable\StaticTable\FormTableRow\FormTableRow;
|
||||
use Combodo\iTop\Application\UI\Component\DataTable\StaticTable\StaticTable;
|
||||
use Combodo\iTop\Application\UI\iUIBlock;
|
||||
|
||||
/**
|
||||
* Class FormTable
|
||||
@@ -24,10 +26,14 @@ class FormTable extends StaticTable
|
||||
/** @var string */
|
||||
private $sRef;
|
||||
|
||||
/** @var iUIBlock[] */
|
||||
private $aRows;
|
||||
|
||||
public function __construct(string $sRef, string $sContainerCSSClass = '')
|
||||
{
|
||||
parent::__construct("dt_{$sRef}", $sContainerCSSClass);
|
||||
$this->SetRef($sRef);
|
||||
$this->aRows = [];
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -45,4 +51,15 @@ class FormTable extends StaticTable
|
||||
{
|
||||
$this->sRef = $sRef;
|
||||
}
|
||||
|
||||
public function GetRows(): array
|
||||
{
|
||||
return $this->aRows;
|
||||
}
|
||||
|
||||
public function AddRow(FormTableRow $oRow): self
|
||||
{
|
||||
$this->aRows[] = $oRow;
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,124 @@
|
||||
<?php
|
||||
/**
|
||||
* @copyright Copyright (C) 2010-2020 Combodo SARL
|
||||
* @license http://opensource.org/licenses/AGPL-3.0
|
||||
*/
|
||||
|
||||
namespace Combodo\iTop\Application\UI\Component\DataTable\StaticTable\FormTableRow;
|
||||
|
||||
|
||||
use Combodo\iTop\Application\UI\UIBlock;
|
||||
|
||||
/**
|
||||
* Class FormTableRow
|
||||
*
|
||||
* @package Combodo\iTop\Application\UI\Component\FormTableRow
|
||||
*/
|
||||
class FormTableRow extends UIBlock
|
||||
{
|
||||
// Overloaded constants
|
||||
public const BLOCK_CODE = 'ibo-formtablerow';
|
||||
public const HTML_TEMPLATE_REL_PATH = 'components/datatable/static/formtablerow/layout';
|
||||
public const JS_TEMPLATE_REL_PATH = 'components/datatable/static/formtablerow/layout';
|
||||
|
||||
/** @var string */
|
||||
private $sRef;
|
||||
/** @var int */
|
||||
private $iRowId;
|
||||
/**
|
||||
* @var array
|
||||
* [
|
||||
* 'entry name' => [
|
||||
* 'description' => tooltip,
|
||||
* 'label' => label to display,
|
||||
* 'class' => cell CSS class,
|
||||
* 'metadata' => [key => value] transformed into data-key="value"
|
||||
* ], ...
|
||||
* ]
|
||||
*/
|
||||
private $aColumns;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
* [
|
||||
* 'entry name' => [
|
||||
* 'value_html' => value to display in the cell,
|
||||
* 'value_raw' => real value put into data-value-raw
|
||||
* ], ...
|
||||
* ]
|
||||
*/
|
||||
private $aData;
|
||||
|
||||
public function __construct(string $sRef, array $aColumns, array $aData, int $iRowId)
|
||||
{
|
||||
parent::__construct();
|
||||
$this->SetRef($sRef);
|
||||
$this->SetColumns($aColumns);
|
||||
$this->SetData($aData);
|
||||
$this->SetRowId($iRowId);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function GetRef(): string
|
||||
{
|
||||
return $this->sRef;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sRef
|
||||
*/
|
||||
public function SetRef(string $sRef): void
|
||||
{
|
||||
$this->sRef = $sRef;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function GetColumns(): array
|
||||
{
|
||||
return $this->aColumns;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $aColumns
|
||||
*/
|
||||
public function SetColumns(array $aColumns): void
|
||||
{
|
||||
$this->aColumns = $aColumns;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function GetData(): array
|
||||
{
|
||||
return $this->aData;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $aData
|
||||
*/
|
||||
public function SetData(array $aData): void
|
||||
{
|
||||
$this->aData = $aData;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function GetRowId(): int
|
||||
{
|
||||
return $this->iRowId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $iRowId
|
||||
*/
|
||||
public function SetRowId(int $iRowId): void
|
||||
{
|
||||
$this->iRowId = $iRowId;
|
||||
}
|
||||
}
|
||||
@@ -99,16 +99,26 @@ var oTable{{ oUIBlock.GetId() }} = $('#{{ oUIBlock.GetId() }}').DataTable({
|
||||
"processing": true,
|
||||
"serverSide": true,
|
||||
"columns": [
|
||||
{% if oUIBlock.GetOptions()["select_mode"] is defined %}
|
||||
{% if oUIBlock.GetOption("select") is not empty %}
|
||||
{
|
||||
"width": "auto",
|
||||
"searchable": false,
|
||||
"sortable": false,
|
||||
"title": '<span class="row_input"><input type="checkbox" onclick="checkAllDataTable(\'#{{ oUIBlock.GetId() }}\',this.checked);" class="checkAll" id="field_{{ oUIBlock.GetId() }}_check_all" name="field_{{ oUIBlock.GetId() }}_check_all" title="{{ 'UI:SearchValue:CheckAll'|dict_s }} / {{ 'UI:SearchValue:UncheckAll'|dict_s }}" /></span>',
|
||||
title:
|
||||
{% if oUIBlock.GetOption("select") == "multi" %}
|
||||
'<span class="row_input"><input type="checkbox" onclick="checkAllDataTable(\'#{{ oUIBlock.GetId() }}\',this.checked);" class="checkAll" id="field_{{ oUIBlock.GetId() }}_check_all" name="field_{{ oUIBlock.GetId() }}_check_all" title="{{ 'UI:SearchValue:CheckAll'|dict_s }} / {{ 'UI:SearchValue:UncheckAll'|dict_s }}" /></span>'
|
||||
{% else %}
|
||||
'<span class="row_input"><input type="checkbox" style="display: none;" onclick="checkAllDataTable(\'#{{ oUIBlock.GetId() }}\',this.checked);" class="checkAll" id="field_{{ oUIBlock.GetId() }}_check_all" name="field_{{ oUIBlock.GetId() }}_check_all" title="{{ 'UI:SearchValue:CheckAll'|dict_s }} / {{ 'UI:SearchValue:UncheckAll'|dict_s }}" /></span>'
|
||||
{% endif %},
|
||||
"type": "html",
|
||||
"data": "",
|
||||
"render": function (data, type, row) {
|
||||
var oCheckboxElem = $('<span class="row_input"><input type="checkbox" class="selectList{{ oUIBlock.GetId() }}" name="selectObject[]" /></span>');
|
||||
var oCheckboxElem =
|
||||
{% if oUIBlock.GetOption("select") == "multi" %}
|
||||
$('<span class="row_input"><input type="checkbox" class="selectList{{ oUIBlock.GetId() }}" name="selectObject[]" /></span>');
|
||||
{% else %}
|
||||
$('<span class="row_input"><input type="radio" class="selectList{{ oUIBlock.GetId() }}" name="selectObject[]" /></span>');
|
||||
{% endif %}
|
||||
if (row.limited_access) {
|
||||
oCheckboxElem.html('-');
|
||||
} else {
|
||||
|
||||
@@ -13,23 +13,8 @@
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for rowId,data in oUIBlock.GetData() %}
|
||||
<tr role="row" id="{{ oUIBlock.GetRef() }}_row_{{ rowId }}">
|
||||
{% for name,column in columns %}
|
||||
<td>
|
||||
{% set cellValueHtml = '' %}
|
||||
{% for cellName,cellValue in data %}
|
||||
{% if cellName == name %}
|
||||
{% set cellValueHtml = cellValue %}
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
{% if cellValueHtml is empty %}
|
||||
{% set cellValueHtml = ' ' %}
|
||||
{% endif %}
|
||||
{{ cellValueHtml|raw }}
|
||||
</td>
|
||||
{% endfor %}
|
||||
</tr>
|
||||
{% for oSubBlock in oUIBlock.GetRows() %}
|
||||
{{ render_block(oSubBlock, {aPage: aPage}) }}
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
@@ -0,0 +1,19 @@
|
||||
{# @copyright Copyright (C) 2010-2020 Combodo SARL #}
|
||||
{# @license http://opensource.org/licenses/AGPL-3.0 #}
|
||||
|
||||
<tr role="row" id="{{ oUIBlock.GetRef() }}_row_{{ oUIBlock.GetRowId() }}">
|
||||
{% for colName,column in oUIBlock.GetColumns() %}
|
||||
<td>
|
||||
{% set cellValueHtml = '' %}
|
||||
{% for cellName,cellValue in oUIBlock.GetData() %}
|
||||
{% if cellName == colName %}
|
||||
{% set cellValueHtml = cellValue %}
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
{% if cellValueHtml is empty %}
|
||||
{% set cellValueHtml = ' ' %}
|
||||
{% endif %}
|
||||
{{ cellValueHtml|raw }}
|
||||
</td>
|
||||
{% endfor %}
|
||||
</tr>
|
||||
Reference in New Issue
Block a user