diff --git a/core/dbobject.class.php b/core/dbobject.class.php index c00c9ccf86..fd3f913dda 100644 --- a/core/dbobject.class.php +++ b/core/dbobject.class.php @@ -1315,7 +1315,7 @@ abstract class DBObject implements iDisplay * @throws \CoreException * @throws \DictExceptionMissingString */ - public static function MakeHyperLink($sObjClass, $sObjKey, $sHtmlLabel = '', $sUrlMakerClass = null, $bWithNavigationContext = true, $bArchived = false, $bObsolete = false, $bIgnorePreview = false, $sFilter = null) + public static function MakeHyperLink($sObjClass, $sObjKey, $sHtmlLabel = '', $sUrlMakerClass = null, $bWithNavigationContext = true, $bArchived = false, $bObsolete = false, $bIgnorePreview = false, $bInBasket = false) { if ($sObjKey <= 0) { return ''.Dict::S('UI:UndefinedObject').''; @@ -1377,10 +1377,11 @@ abstract class DBObject implements iDisplay } if ($bClickable && (strlen($sUrl) > 0)) { - if ($sFilter != null) { - $sUrl = $sUrl.'&filter='.$sFilter; + if ($bInBasket) { + $sHLink = "$sIcon$sHtmlLabel"; + } else { + $sHLink = "$sIcon$sHtmlLabel"; } - $sHLink = "$sIcon$sHtmlLabel"; } else { $sHLink = $sIcon.$sHtmlLabel; } @@ -1408,7 +1409,7 @@ abstract class DBObject implements iDisplay * @throws CoreException * @throws DictExceptionMissingString */ - public function GetHyperlink($sUrlMakerClass = null, $bWithNavigationContext = true, $sLabel = null, $bIgnorePreview = false, $sFilter = null) + public function GetHyperlink($sUrlMakerClass = null, $bWithNavigationContext = true, $sLabel = null, $bIgnorePreview = false, $bInBasket = false) { if ($sLabel === null) { $sLabel = $this->GetName(); @@ -1416,7 +1417,7 @@ abstract class DBObject implements iDisplay $bArchived = $this->IsArchived(); $bObsolete = $this->IsObsolete(); - return self::MakeHyperLink(get_class($this), $this->GetKey(), $sLabel, $sUrlMakerClass, $bWithNavigationContext, $bArchived, $bObsolete, $bIgnorePreview, $sFilter); + return self::MakeHyperLink(get_class($this), $this->GetKey(), $sLabel, $sUrlMakerClass, $bWithNavigationContext, $bArchived, $bObsolete, $bIgnorePreview, $bInBasket); } /** diff --git a/pages/UI.php b/pages/UI.php index bd2d990892..a9f6ef8b27 100644 --- a/pages/UI.php +++ b/pages/UI.php @@ -436,7 +436,8 @@ try } //N°1386 - Advanced Search: Navigation in list - Browse this list - $sFilter = utils::ReadParam('filter', null, false, 'raw'); + $sBackUrl = utils::ReadPostedParam('back_url', '', false, 'raw'); + $sFilter = utils::ReadPostedParam('filter', null, false, 'raw'); $sList = utils::ReadPostedParam('listNavigation', null, false, 'string'); $aList = []; if ($sList != null) { @@ -445,7 +446,7 @@ try $sClassLabel = MetaModel::GetName($sClass); $oP->set_title(Dict::Format('UI:DetailsPageTitle', $oObj->GetRawName(), $sClassLabel)); // Set title will take care of the encoding - $oP->SetContentLayout(PageContentFactory::MakeForObjectDetails($oObj, $oP->IsPrintableVersion() ? cmdbAbstractObject::ENUM_DISPLAY_MODE_PRINT : cmdbAbstractObject::ENUM_DISPLAY_MODE_VIEW, $sFilter, $aList)); + $oP->SetContentLayout(PageContentFactory::MakeForObjectDetails($oObj, $oP->IsPrintableVersion() ? cmdbAbstractObject::ENUM_DISPLAY_MODE_PRINT : cmdbAbstractObject::ENUM_DISPLAY_MODE_VIEW, $sFilter, $aList, $sBackUrl)); $oObj->DisplayDetails($oP); } } diff --git a/sources/Application/UI/Base/Component/DataTable/DataTable.php b/sources/Application/UI/Base/Component/DataTable/DataTable.php index baf99544c2..038d98917d 100644 --- a/sources/Application/UI/Base/Component/DataTable/DataTable.php +++ b/sources/Application/UI/Base/Component/DataTable/DataTable.php @@ -48,6 +48,7 @@ class DataTable extends UIContentBlock protected $aAjaxData; protected $aDisplayColumns; protected $aResultColumns; + protected $sFilter; /** * @var string */ @@ -221,8 +222,25 @@ class DataTable extends UIContentBlock return json_encode($this->aInitDisplayData); } + /** + * @return string + */ + public function GetFilter() + { + return $this->sFilter; + } + + /** + * @param string $sFilter + */ + public function setFilter($sFilter): void + { + $this->sFilter = $sFilter; + } + /** * Get $aInitDisplayData + * * @return array */ public function GetInitDisplayData(): array diff --git a/sources/Application/UI/Base/Component/DataTable/DataTableUIBlockFactory.php b/sources/Application/UI/Base/Component/DataTable/DataTableUIBlockFactory.php index de8737d43f..93a9f4e3e7 100644 --- a/sources/Application/UI/Base/Component/DataTable/DataTableUIBlockFactory.php +++ b/sources/Application/UI/Base/Component/DataTable/DataTableUIBlockFactory.php @@ -585,17 +585,18 @@ class DataTableUIBlockFactory extends AbstractUIBlockFactory ]); $oDataTable->SetDisplayColumns($aColumnDefinition); $oDataTable->SetResultColumns($oCustomSettings->aColumns); - $oDataTable->SetInitDisplayData(AjaxRenderController::GetDataForTable($oSet, $aClassAliases, $aColumnsToLoad, $sIdName, $aExtraParams)); + $oDataTable->SetFilter($oSet->GetFilter()->ToOQL(true)); + $oDataTable->SetInitDisplayData(AjaxRenderController::GetDataForTable($oSet, $aClassAliases, $aColumnsToLoad, $sIdName, $aExtraParams, 1, true)); // row actions if (isset($aExtraParams['row_actions'])) { $oDataTable->SetRowActions($aExtraParams['row_actions']); } - if (isset($aExtraParams['creation_in_modal_js_handler'])){ + if (isset($aExtraParams['creation_in_modal_js_handler'])) { $oDataTable->SetModalCreationHandler($aExtraParams['creation_in_modal_js_handler']); } - + return $oDataTable; } diff --git a/sources/Application/UI/Base/Component/Navigation/Navigation.php b/sources/Application/UI/Base/Component/Navigation/Navigation.php index 670b115737..d419611510 100644 --- a/sources/Application/UI/Base/Component/Navigation/Navigation.php +++ b/sources/Application/UI/Base/Component/Navigation/Navigation.php @@ -51,6 +51,7 @@ class Navigation extends UIContentBlock protected $iIdLast = 0; protected $aList = []; protected $sFilter; + protected $sBackUrl; protected $sClass; /** @@ -61,16 +62,17 @@ class Navigation extends UIContentBlock * @param string $sColorScheme Color scheme code such as "success", "failure", "active", ... {@see css/backoffice/components/_panel.scss} * @param string|null $sId */ - public function __construct(string $sClass, int $iIdx, array $aList, string $sFilter = '', ?string $sId = null) + public function __construct(string $sClass, int $iIdx, array $aList, string $sFilter, string $sBackUrl, ?string $sId = null) { parent::__construct($sId); $this->iCount = count($aList); - if ( $this->iCount == 0) { + if ($this->iCount == 0) { return new UIContentBlock(); } $this->sClass = $sClass; $this->aList = $aList; $this->sFilter = $sFilter; + $this->sBackUrl = $sBackUrl; $this->iIdx = $iIdx; if ($this->iIdx>0) { $this->iIdFirst = $aList[0]; @@ -100,39 +102,56 @@ class Navigation extends UIContentBlock private function GetUrlFromId($iId) { - $sUrl = iTopStandardURLMaker::MakeObjectURL($this->sClass, $iId).'&filter='.urlencode($this->sFilter); + $sUrl = iTopStandardURLMaker::MakeObjectURL($this->sClass, $iId); return $sUrl; } + /** - * @return int|mixed + * @return string */ - public function GetUrlFirst() + public function GetUrlFirst(): string { - return $this->GetUrlFromId( $this->iIdFirst); + return $this->GetUrlFromId($this->iIdFirst); + } + + /** + * @return string + */ + public function GetUrlPrev(): string + { + return $this->GetUrlFromId($this->iIdPrev); + } + + /** + * @return string + */ + public function GetUrlNext(): string + { + return $this->GetUrlFromId($this->iIdNext); } /** * @return int|mixed */ - public function GetUrlPrev() + public function GetUrlLast(): string { - return $this->GetUrlFromId( $this->iIdPrev); + return $this->GetUrlFromId($this->iIdLast); } /** - * @return int|mixed + * @return string */ - public function GetUrlNext() + public function GetBackUrl(): string { - return $this->GetUrlFromId( $this->iIdNext); + return $this->sBackUrl; } /** - * @return int|mixed + * @return string */ - public function GetUrlLast() + public function GetFilter(): string { - return $this->GetUrlFromId( $this->iIdLast); + return $this->sFilter; } /** @@ -143,11 +162,6 @@ class Navigation extends UIContentBlock return json_encode($this->aList); } - public function GetUrlSearch(){ - $sAbsoluteUrl = utils::GetAbsoluteUrlAppRoot(); - return "{$sAbsoluteUrl}pages/UI.php?operation=search&filter=".urlencode(urlencode('["'.$this->sFilter.'",[],[]]')); - } - /** * @return bool */ diff --git a/sources/Application/UI/Base/Component/Navigation/NavigationUIBlockFactory.php b/sources/Application/UI/Base/Component/Navigation/NavigationUIBlockFactory.php index 6acb2881e7..60f502be7c 100644 --- a/sources/Application/UI/Base/Component/Navigation/NavigationUIBlockFactory.php +++ b/sources/Application/UI/Base/Component/Navigation/NavigationUIBlockFactory.php @@ -48,20 +48,19 @@ class NavigationUIBlockFactory extends AbstractUIBlockFactory * * @return \Combodo\iTop\Application\UI\Base\Component\Panel\Panel */ - public static function MakeStandard( $oObject, string $sFilter, array $aList = []) + public static function MakeStandard($oObject, string $sFilter, array $aList = [], string $sBackUrl = '') { - \IssueLog::Error('MakeStandard'.count($aList)); if ($sFilter != null && count($aList) === 0) { $oFilter = DBObjectSearch::FromOQL($sFilter); $oSet = new DBObjectSet($oFilter); $aList = $oSet->GetColumnAsArray('id', false); } - if(count($aList) === 0) { + if (count($aList) === 0) { return null; } $iIdx = array_search($oObject->GetKey(), $aList); - $oNavigationBlock = new Navigation(get_class($oObject), $iIdx, $aList, $sFilter); + $oNavigationBlock = new Navigation(get_class($oObject), $iIdx, $aList, $sFilter, $sBackUrl); return $oNavigationBlock; } diff --git a/sources/Application/UI/Base/Layout/PageContent/PageContentFactory.php b/sources/Application/UI/Base/Layout/PageContent/PageContentFactory.php index dccb17f5f5..4b91590ac9 100644 --- a/sources/Application/UI/Base/Layout/PageContent/PageContentFactory.php +++ b/sources/Application/UI/Base/Layout/PageContent/PageContentFactory.php @@ -49,21 +49,22 @@ class PageContentFactory /** * Make a standard object details page with the form in the middle and the logs / activity in the side panel * - * @param \DBObject $oObject - * @param string $sMode Mode the object is being displayed (view, edit, create, ...), default is view. - * * @see cmdbAbstractObject::ENUM_DISPLAY_MODE_XXX * + * @param string $sMode Mode the object is being displayed (view, edit, create, ...), default is view. + * + * @param \DBObject $oObject + * * @return \Combodo\iTop\Application\UI\Base\Layout\PageContent\PageContentWithSideContent * @throws \CoreException */ - public static function MakeForObjectDetails(DBObject $oObject, string $sMode = cmdbAbstractObject::DEFAULT_DISPLAY_MODE, $sFilter = null, $aList = []) + public static function MakeForObjectDetails(DBObject $oObject, string $sMode = cmdbAbstractObject::DEFAULT_DISPLAY_MODE, $sFilter = null, $aList = [], $sBackUrl = null) { $oLayout = new PageContentWithSideContent(); if ($sFilter != null) { - $oNavigationBlock = NavigationUIBlockFactory::MakeStandard($oObject, $sFilter, $aList); + $oNavigationBlock = NavigationUIBlockFactory::MakeStandard($oObject, $sFilter, $aList, $sBackUrl); if ($oNavigationBlock != null) { $oLayout->AddSubBlock($oNavigationBlock); } diff --git a/sources/Controller/AjaxRenderController.php b/sources/Controller/AjaxRenderController.php index fa7a7566d8..06f0ac5434 100644 --- a/sources/Controller/AjaxRenderController.php +++ b/sources/Controller/AjaxRenderController.php @@ -62,7 +62,7 @@ class AjaxRenderController * @throws \MySQLException * @throws \MySQLHasGoneAwayException */ - public static function GetDataForTable(DBObjectSet $oSet, array $aClassAliases, array $aColumnsLoad, string $sIdName = "", array $aExtraParams = [], int $iDrawNumber = 1) + public static function GetDataForTable(DBObjectSet $oSet, array $aClassAliases, array $aColumnsLoad, string $sIdName = "", array $aExtraParams = [], int $iDrawNumber = 1, bool $bInBasket = false) { if (isset($aExtraParams['show_obsolete_data'])) { $bShowObsoleteData = $aExtraParams['show_obsolete_data']; @@ -72,7 +72,7 @@ class AjaxRenderController $oSet->SetShowObsoleteData($bShowObsoleteData); $aResult["draw"] = $iDrawNumber; $aResult["recordsTotal"] = $oSet->Count(); - $aResult["recordsFiltered"] = $aResult["recordsTotal"] ; + $aResult["recordsFiltered"] = $aResult["recordsTotal"]; $aResult["data"] = []; while ($aObject = $oSet->FetchAssoc()) { $aObj = []; @@ -80,7 +80,7 @@ class AjaxRenderController if (isset($aObject[$sAlias]) && !is_null($aObject[$sAlias])) { $aObj[$sAlias."/_key_"] = $aObject[$sAlias]->GetKey(); $aObj[$sAlias."/_key_/raw"] = $aObject[$sAlias]->GetKey(); - $aObj[$sAlias."/hyperlink"] = $aObject[$sAlias]->GetHyperlink(null, true, null, false, $oSet->GetFilter()->ToOQL(true)); + $aObj[$sAlias."/hyperlink"] = $aObject[$sAlias]->GetHyperlink(null, true, null, false, $bInBasket); $aObj[$sAlias."/friendlyname"] = $aObject[$sAlias]->Get('friendlyname'); // N°5943 Protection against $aColumnsLoad having less class aliases than $aClassAliases, this is in case the method's consumer isn't passing data correctly @@ -490,7 +490,7 @@ class AjaxRenderController $oSet = new DBObjectSet($oFilter, $aOrderBy, $aQueryParams, null, $iEnd - $iStart, $iStart); $oSet->OptimizeColumnLoad($aColumnsLoad); - return self::GetDataForTable($oSet, $aClassAliases, $aColumnsLoad, $sIdName, $aExtraParams, $iDrawNumber); + return self::GetDataForTable($oSet, $aClassAliases, $aColumnsLoad, $sIdName, $aExtraParams, $iDrawNumber, true); } /** diff --git a/templates/base/components/datatable/layout.live.js.twig b/templates/base/components/datatable/layout.live.js.twig index 87d1a52b5d..2931795db2 100644 --- a/templates/base/components/datatable/layout.live.js.twig +++ b/templates/base/components/datatable/layout.live.js.twig @@ -1,9 +1,18 @@ {% if oUIBlock.GetOption("select_mode") is not empty %} - var oSelectedItems{{ oUIBlock.GetOption('sListId')|sanitize(constant('utils::ENUM_SANITIZATION_FILTER_VARIABLE_NAME')) }} = []; - {% if oUIBlock.GetOption("sSelectedRows") is not empty %} - oSelectedItems{{ oUIBlock.GetOption('sListId')|sanitize(constant('utils::ENUM_SANITIZATION_FILTER_VARIABLE_NAME')) }} = {{ oUIBlock.GetOption('sSelectedRows')|raw }}; - {% endif %} +var oSelectedItems{{ oUIBlock.GetOption('sListId')|sanitize(constant('utils::ENUM_SANITIZATION_FILTER_VARIABLE_NAME')) }} = []; +{% if oUIBlock.GetOption("sSelectedRows") is not empty %} +oSelectedItems{{ oUIBlock.GetOption('sListId')|sanitize(constant('utils::ENUM_SANITIZATION_FILTER_VARIABLE_NAME')) }} = {{ oUIBlock.GetOption('sSelectedRows')|raw }}; +{% endif %} {% endif %} var bSelectAllowed{{ oUIBlock.GetId()|sanitize(constant('utils::ENUM_SANITIZATION_FILTER_VARIABLE_NAME')) }} = false; +$('body').append($('
') + .attr({'method': 'post', 'id': 'basket{{ oUIBlock.GetId() }}'}) + .append($('') + .attr({'type': 'hidden', 'name': 'filter', 'value': "{{ oUIBlock.GetFilter()|raw }}"}) + ) + .append($('') + .attr({'type': 'hidden', 'name': 'back_url', 'value': window.location.href}) + ) +); \ No newline at end of file diff --git a/templates/base/components/datatable/layout.ready.js.twig b/templates/base/components/datatable/layout.ready.js.twig index ae2a6afbb1..5381572189 100644 --- a/templates/base/components/datatable/layout.ready.js.twig +++ b/templates/base/components/datatable/layout.ready.js.twig @@ -108,14 +108,25 @@ var oTable{{ sListIDForVarSuffix }} = $('#{{ oUIBlock.GetId() }}').DataTable({ // Disable hyperlinks if necessary {% if oUIBlock.GetOption("disable_hyperlinks") is not same as false %} $("#{{ oUIBlock.GetId() }} a").on('click', function (e) { - e.preventDefault(); - }); + e.preventDefault(); + }); + {% else %} + + $('#{{ oUIBlock.GetId() }}_wrapper').find('.object-in-basket').on('click', + function () { + console.warn('ici'); + sUrl = $(this).attr('data-href'); + $('#basket{{ oUIBlock.GetId() }}').attr('action', sUrl); + $('#basket{{ oUIBlock.GetId() }}').submit(); + + + } + ); {% endif %} - }, {% else %} drawCallback: function (settings) { - if(settings.json) + if (settings.json) { $(this).closest('.ibo-panel').find('.ibo-datatable--result-count').html(settings.json.recordsTotal); } @@ -129,12 +140,25 @@ var oTable{{ sListIDForVarSuffix }} = $('#{{ oUIBlock.GetId() }}').DataTable({ { $(this).closest('.dataTables_wrapper').find('.dataTables_paginate, .dataTables_info').show(); } - + // Disable hyperlinks if necessary {% if oUIBlock.GetOption("disable_hyperlinks") is same as true %} $("#{{ oUIBlock.GetId() }} a").on('click', function (e) { e.preventDefault(); }); + {% else %} + + $('#{{ oUIBlock.GetId() }}_wrapper').find('.object-in-basket').on('click', + function () { + console.warn('ici'); + sUrl = $(this).attr('data-href'); + $('#basket{{ oUIBlock.GetId() }}').attr('action', sUrl); + $('#basket{{ oUIBlock.GetId() }}').submit(); + + + } + ); + {% endif %} }, {% endif %} @@ -435,17 +459,19 @@ if ($('#datatable_dlg_{{ oUIBlock.GetId() }}').hasClass('itop-datatable')) } $('#datatable_dlg_{{ oUIBlock.GetId() }}').DataTableSettings(aOptions{{ sListIDForVarSuffix }}); -if(window.ResizeObserver){ - let oTable{{ sListIDForVarSuffix }}ResizeTimeout = null; - const oTable{{ sListIDForVarSuffix }}Resize = new ResizeObserver(function(){ - clearTimeout(oTable{{ sListIDForVarSuffix }}ResizeTimeout); - oTable{{ sListIDForVarSuffix }}ResizeTimeout = setTimeout(function(){ - $('#{{ oUIBlock.GetId() }}').DataTable().columns.adjust(); - }, 120); - }); - oTable{{ sListIDForVarSuffix }}Resize.observe($('#{{ oUIBlock.GetId() }}')[0]); +if (window.ResizeObserver) +{ + let oTable{{ sListIDForVarSuffix }}ResizeTimeout = null; + const oTable{{ sListIDForVarSuffix }}Resize = new ResizeObserver(function () { + clearTimeout(oTable{{ sListIDForVarSuffix }}ResizeTimeout); + oTable{{ sListIDForVarSuffix }}ResizeTimeout = setTimeout(function () { + $('#{{ oUIBlock.GetId() }}').DataTable().columns.adjust(); + }, 120); + }); + oTable{{ sListIDForVarSuffix }}Resize.observe($('#{{ oUIBlock.GetId() }}')[0]); } {% if oUIBlock.HasRowActions() %} - {% include 'base/components/datatable/row-actions/handler.js.twig' %} -{% endif %} \ No newline at end of file +{% include 'base/components/datatable/row-actions/handler.js.twig' %} +{% endif %} +console.warn('ici-lala'); \ No newline at end of file diff --git a/templates/base/components/navigation/layout.html.twig b/templates/base/components/navigation/layout.html.twig index e40b4f3a93..b0ad887008 100644 --- a/templates/base/components/navigation/layout.html.twig +++ b/templates/base/components/navigation/layout.html.twig @@ -5,10 +5,12 @@ {% block iboNavigation %}