mirror of
https://github.com/Combodo/iTop.git
synced 2026-02-13 15:34:12 +01:00
* Rebase onto develop * Use exit condition instead of englobing condition * Add informative modals that can be called from modal toolbox * Refactor "apply_modify" and "apply_new" into own controller, handle ajax requests with a json response and handle these responses in linkset creation/edition * Fix merge issues * Remove inverted condition * Move linkset create button to a better place, still needs to fix duplicate "New" button caused by a refactor * Handle "Cancel" button in modals * Do not display relations when editing an object in a modal * More elegant way to add "New" button to relations lists * Factorize vertical highlights in alerts and modal in a single mixin * Replace button name with dict entry code * Change route name to snake case * More elegant way to add "Create in modal" button to relations lists * Replace triple if with in_array * Move listener to body * Rename variable to match boolean rules * Rename event * Rename extra param * Add phpdoc * Revert changes * Check indirect linkset rights before allowing creation in modal
205 lines
4.6 KiB
PHP
205 lines
4.6 KiB
PHP
<?php
|
|
/**
|
|
* @copyright Copyright (C) 2010-2022 Combodo SARL
|
|
* @license http://opensource.org/licenses/AGPL-3.0
|
|
*/
|
|
|
|
namespace Combodo\iTop\Application\UI\Links;
|
|
|
|
use Combodo\iTop\Application\UI\Base\Component\MedallionIcon\MedallionIcon;
|
|
use Combodo\iTop\Application\UI\Base\Layout\UIContentBlock;
|
|
use MetaModel;
|
|
|
|
/**
|
|
* Class AbstractBlockLinksViewTable
|
|
*
|
|
* @internal
|
|
* @since 3.1.0
|
|
* @package Combodo\iTop\Application\UI\Links
|
|
*/
|
|
abstract class AbstractBlockLinksViewTable extends UIContentBlock
|
|
{
|
|
// Overloaded constants
|
|
public const BLOCK_CODE = 'ibo-abstract-block-links-view-table';
|
|
public const DEFAULT_JS_TEMPLATE_REL_PATH = 'application/links/layout';
|
|
public const DEFAULT_JS_FILES_REL_PATH = [
|
|
'js/links/link_set_worker.js',
|
|
'js/wizardhelper.js',
|
|
];
|
|
|
|
/** @var \DBObject $oDbObject db object witch link set belongs to */
|
|
protected \DBObject $oDbObject;
|
|
|
|
/** @var string $sObjectClass db object class name */
|
|
protected string $sObjectClass;
|
|
|
|
/** @var string $sAttCode db object link set attribute code */
|
|
protected string $sAttCode;
|
|
|
|
/** @var \AttributeLinkedSet $oAttDef attribute link set */
|
|
protected \AttributeLinkedSet $oAttDef;
|
|
|
|
/** @var string $sTargetClass links target classname */
|
|
protected string $sTargetClass;
|
|
|
|
protected string $sTableId;
|
|
|
|
/**
|
|
* Constructor.
|
|
*
|
|
* @param \WebPage $oPage
|
|
* @param \DBObject $oDbObject
|
|
* @param string $sObjectClass
|
|
* @param string $sAttCode
|
|
* @param \AttributeLinkedSet $oAttDef
|
|
*
|
|
* @throws \CoreException
|
|
* @throws \Exception
|
|
*/
|
|
public function __construct(\WebPage $oPage, \DBObject $oDbObject, string $sObjectClass, string $sAttCode, \AttributeLinkedSet $oAttDef)
|
|
{
|
|
parent::__construct('', ["ibo-block-links-table"]);
|
|
|
|
// retrieve parameters
|
|
$this->oAttDef = $oAttDef;
|
|
$this->sAttCode = $sAttCode;
|
|
$this->sObjectClass = $sObjectClass;
|
|
$this->oDbObject = $oDbObject;
|
|
$this->sTableId = 'rel_'.$this->sAttCode;
|
|
$this->SetDataAttributes(['role' => 'ibo-block-links-table', 'link-attcode' => $sAttCode, 'link-class' => $this->oAttDef->GetLinkedClass()]);
|
|
// Initialization
|
|
$this->Init();
|
|
|
|
// UI Initialization
|
|
$this->InitUI($oPage);
|
|
}
|
|
|
|
/**
|
|
* Init.
|
|
*
|
|
* @return void
|
|
* @throws \Exception
|
|
*/
|
|
private function Init()
|
|
{
|
|
$this->sTargetClass = $this->GetTargetClass();
|
|
}
|
|
|
|
/**
|
|
* Initialize UI.
|
|
*
|
|
* @return void
|
|
* @throws \CoreException
|
|
*/
|
|
private function InitUI(\WebPage $oPage)
|
|
{
|
|
// header
|
|
$this->InitHeader();;
|
|
|
|
// Table
|
|
$this->InitTable($oPage);
|
|
}
|
|
|
|
/**
|
|
* InitHeader.
|
|
*
|
|
* @return void
|
|
* @throws \CoreException
|
|
*/
|
|
private function InitHeader()
|
|
{
|
|
// MedallionIcon
|
|
$oClassIcon = new MedallionIcon(MetaModel::GetClassIcon($this->sTargetClass, false));
|
|
$oClassIcon->SetDescription($this->oAttDef->GetDescription())->AddCSSClass('ibo-block-list--medallion');
|
|
$this->AddSubBlock($oClassIcon);
|
|
}
|
|
|
|
/**
|
|
* InitTable.
|
|
*
|
|
* @param \WebPage $oPage
|
|
*
|
|
* @return void
|
|
* @throws \ApplicationException
|
|
* @throws \ArchivedObjectException
|
|
* @throws \CoreException
|
|
* @throws \CoreWarning
|
|
* @throws \DictExceptionMissingString
|
|
* @throws \MySQLException
|
|
*/
|
|
private function InitTable(\WebPage $oPage)
|
|
{
|
|
// retrieve db object set
|
|
$oOrmLinkSet = $this->oDbObject->Get($this->sAttCode);
|
|
$oLinkSet = $oOrmLinkSet->ToDBObjectSet(\utils::ShowObsoleteData());
|
|
|
|
// add list block
|
|
$oBlock = new \DisplayBlock($oLinkSet->GetFilter(), 'list', false);
|
|
$this->AddSubBlock($oBlock->GetRenderContent($oPage, $this->GetExtraParam(), $this->sTableId));
|
|
}
|
|
|
|
/**
|
|
* GetTableId.
|
|
*
|
|
* @return string table identifier
|
|
*/
|
|
protected function GetTableId(): string
|
|
{
|
|
return $this->sObjectClass.'_'.$this->sAttCode;
|
|
}
|
|
|
|
/**
|
|
* GetDoNotShowAgainPreferenceKey.
|
|
*
|
|
* @return string do not show again preference key
|
|
*/
|
|
protected function GetDoNotShowAgainPreferenceKey(): string
|
|
{
|
|
return "{$this->GetTableId()}.remove_link.do_not_show_again";
|
|
}
|
|
|
|
/**
|
|
* GetExtraParam.
|
|
*
|
|
* Provide parameters for display block as list.
|
|
*
|
|
* @see \DisplayBlock::RenderList
|
|
*
|
|
* @return array
|
|
* @throws \ArchivedObjectException
|
|
* @throws \CoreException
|
|
*/
|
|
abstract function GetExtraParam(): array;
|
|
|
|
/**
|
|
* Return row actions.
|
|
*
|
|
* Register row actions for table.
|
|
*
|
|
* @see \Combodo\iTop\Application\UI\Base\Component\DataTable\tTableRowActions
|
|
*
|
|
* @return \string[][]
|
|
*/
|
|
abstract function GetRowActions(): array;
|
|
|
|
/**
|
|
* GetTargetClass.
|
|
*
|
|
* Return link set target class.
|
|
*
|
|
* @return string
|
|
* @throws \Exception
|
|
*/
|
|
abstract function GetTargetClass(): string;
|
|
|
|
|
|
|
|
/**
|
|
* @return string
|
|
*/
|
|
public function GetAttCode(): string
|
|
{
|
|
return $this->sAttCode;
|
|
}
|
|
|
|
} |