mirror of
https://github.com/Combodo/iTop.git
synced 2026-04-19 00:28:47 +02:00
N°6385 - Move Linkset flags and edit_when logic from UIBlock to DisplayBareRelations
This commit is contained in:
@@ -746,7 +746,9 @@ HTML
|
||||
$aArgs = array('this' => $this);
|
||||
|
||||
$sEditWhen = $oAttDef->GetEditWhen();
|
||||
$bIsEditableBasedOnEditWhen = ($sEditWhen === LINKSET_EDITWHEN_ALWAYS || $sEditWhen === LINKSET_EDITWHEN_ON_HOST_EDITION);
|
||||
// Calculate if edit_when allows to edit based on current $bEditMode
|
||||
$bIsEditableBasedOnEditWhen = ($sEditWhen === LINKSET_EDITWHEN_ALWAYS) ||
|
||||
($bEditMode ? $sEditWhen === LINKSET_EDITWHEN_ON_HOST_EDITION : $sEditWhen === LINKSET_EDITWHEN_ON_HOST_DISPLAY);
|
||||
|
||||
$bReadOnly = ($iFlags & (OPT_ATT_READONLY | OPT_ATT_SLAVE)) || !$bIsEditableBasedOnEditWhen;
|
||||
if ($bEditMode && (!$bReadOnly)) {
|
||||
@@ -758,9 +760,9 @@ HTML
|
||||
$oPage->add($sHTMLValue);
|
||||
} else {
|
||||
if ($oAttDef->IsIndirect()) {
|
||||
$oBlockLinkSetViewTable = new BlockIndirectLinkSetViewTable($oPage, $this, $sClass, $sAttCode, $oAttDef);
|
||||
$oBlockLinkSetViewTable = new BlockIndirectLinkSetViewTable($oPage, $this, $sClass, $sAttCode, $oAttDef, $bReadOnly);
|
||||
} else {
|
||||
$oBlockLinkSetViewTable = new BlockDirectLinkSetViewTable($oPage, $this, $sClass, $sAttCode, $oAttDef);
|
||||
$oBlockLinkSetViewTable = new BlockDirectLinkSetViewTable($oPage, $this, $sClass, $sAttCode, $oAttDef, $bReadOnly);
|
||||
}
|
||||
$oPage->AddUiBlock($oBlockLinkSetViewTable);
|
||||
}
|
||||
|
||||
@@ -91,11 +91,11 @@ abstract class AbstractBlockLinkSetViewTable extends UIContentBlock
|
||||
* @param string $sObjectClass
|
||||
* @param string $sAttCode
|
||||
* @param AttributeLinkedSet $oAttDef
|
||||
* @param bool $bIsReadOnly
|
||||
*
|
||||
* @throws CoreException
|
||||
* @throws Exception
|
||||
* @throws \CoreException
|
||||
*/
|
||||
public function __construct(WebPage $oPage, DBObject $oDbObject, string $sObjectClass, string $sAttCode, AttributeLinkedSet $oAttDef)
|
||||
public function __construct(WebPage $oPage, DBObject $oDbObject, string $sObjectClass, string $sAttCode, AttributeLinkedSet $oAttDef, bool $bIsReadOnly = false)
|
||||
{
|
||||
parent::__construct("links_view_table_$sAttCode", ["ibo-block-links-table"]);
|
||||
|
||||
@@ -105,6 +105,7 @@ abstract class AbstractBlockLinkSetViewTable extends UIContentBlock
|
||||
$this->sObjectClass = $sObjectClass;
|
||||
$this->oDbObject = $oDbObject;
|
||||
$this->sTableId = 'rel_'.$this->sAttCode;
|
||||
$this->bIsAttEditable = !$bIsReadOnly;
|
||||
$this->SetDataAttributes(['role' => 'ibo-block-links-table', 'link-attcode' => $sAttCode, 'link-class' => $this->oAttDef->GetLinkedClass()]);
|
||||
// Initialization
|
||||
$this->Init();
|
||||
@@ -122,7 +123,6 @@ abstract class AbstractBlockLinkSetViewTable extends UIContentBlock
|
||||
private function Init()
|
||||
{
|
||||
$this->sTargetClass = $this->GetTargetClass();
|
||||
$this->InitIsAttEditable();
|
||||
|
||||
// User rights
|
||||
$this->bIsAllowCreate = $this->bIsAttEditable && UserRights::IsActionAllowed($this->oAttDef->GetLinkedClass(), UR_ACTION_CREATE) == UR_ALLOWED_YES;
|
||||
@@ -199,38 +199,8 @@ abstract class AbstractBlockLinkSetViewTable extends UIContentBlock
|
||||
$oBlock = new DisplayBlock($oLinkSet->GetFilter(), DisplayBlock::ENUM_STYLE_LIST_IN_OBJECT, false);
|
||||
$this->AddSubBlock($oBlock->GetRenderContent($oPage, $this->GetExtraParam(), $this->sTableId));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
* @throws \CoreException
|
||||
*/
|
||||
private function InitIsAttEditable(): void
|
||||
{
|
||||
$iFlags = OPT_ATT_NORMAL;
|
||||
|
||||
if ($this->oDbObject->IsNew())
|
||||
{
|
||||
$iFlags = $this->oDbObject->GetInitialStateAttributeFlags($this->sAttCode);
|
||||
}
|
||||
else
|
||||
{
|
||||
$iFlags = $this->oDbObject->GetAttributeFlags($this->sAttCode);
|
||||
}
|
||||
|
||||
$bEditWhen = $this->IsEditableBasedOnEditWhen();
|
||||
|
||||
$this->bIsAttEditable = !($iFlags & (OPT_ATT_READONLY | OPT_ATT_SLAVE | OPT_ATT_HIDDEN)) && $bEditWhen;
|
||||
}
|
||||
|
||||
/**
|
||||
* Compares Linkset attribute edit_when values with its usage requirements
|
||||
*
|
||||
* @return bool
|
||||
* @since 3.1.1 3.2.0 N°6385
|
||||
*/
|
||||
protected function IsEditableBasedOnEditWhen(): bool{
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* GetTableId.
|
||||
|
||||
@@ -179,13 +179,4 @@ class BlockDirectLinkSetViewTable extends AbstractBlockLinkSetViewTable
|
||||
|
||||
return $aDefaults;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
protected function IsEditableBasedOnEditWhen(): bool
|
||||
{
|
||||
$sEditWhen = $this->oAttDef->GetEditWhen();
|
||||
return $sEditWhen === LINKSET_EDITWHEN_ALWAYS || $sEditWhen === LINKSET_EDITWHEN_ON_HOST_DISPLAY;
|
||||
}
|
||||
}
|
||||
@@ -126,13 +126,4 @@ class BlockIndirectLinkSetViewTable extends AbstractBlockLinkSetViewTable
|
||||
|
||||
return $sAttCodesToDisplay;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
protected function IsEditableBasedOnEditWhen(): bool
|
||||
{
|
||||
$sEditWhen = $this->oAttDef->GetEditWhen();
|
||||
return $sEditWhen === LINKSET_EDITWHEN_ALWAYS || $sEditWhen === LINKSET_EDITWHEN_ON_HOST_DISPLAY;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user