mirror of
https://github.com/Combodo/iTop.git
synced 2026-05-02 23:18:43 +02:00
N°3136 - Add creation and modification of n-n objects in object details (#378)
* 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
This commit is contained in:
@@ -24,6 +24,7 @@ abstract class AbstractBlockLinksViewTable extends UIContentBlock
|
||||
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 */
|
||||
@@ -40,6 +41,8 @@ abstract class AbstractBlockLinksViewTable extends UIContentBlock
|
||||
|
||||
/** @var string $sTargetClass links target classname */
|
||||
protected string $sTargetClass;
|
||||
|
||||
protected string $sTableId;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
@@ -62,7 +65,8 @@ abstract class AbstractBlockLinksViewTable extends UIContentBlock
|
||||
$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();
|
||||
|
||||
@@ -131,7 +135,7 @@ abstract class AbstractBlockLinksViewTable extends UIContentBlock
|
||||
|
||||
// add list block
|
||||
$oBlock = new \DisplayBlock($oLinkSet->GetFilter(), 'list', false);
|
||||
$this->AddSubBlock($oBlock->GetRenderContent($oPage, $this->GetExtraParam(), 'rel_'.$this->sAttCode));
|
||||
$this->AddSubBlock($oBlock->GetRenderContent($oPage, $this->GetExtraParam(), $this->sTableId));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -187,4 +191,15 @@ abstract class AbstractBlockLinksViewTable extends UIContentBlock
|
||||
* @throws \Exception
|
||||
*/
|
||||
abstract function GetTargetClass(): string;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function GetAttCode(): string
|
||||
{
|
||||
return $this->sAttCode;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -37,7 +37,7 @@ class BlockIndirectLinksViewTable extends AbstractBlockLinksViewTable
|
||||
/** @inheritdoc */
|
||||
public function GetExtraParam(): array
|
||||
{
|
||||
return array(
|
||||
$aExtraParams = array(
|
||||
'link_attr' => $this->oAttDef->GetExtKeyToMe(),
|
||||
'object_id' => $this->oDbObject->GetKey(),
|
||||
'target_attr' => $this->oAttDef->GetExtKeyToRemote(),
|
||||
@@ -48,7 +48,17 @@ class BlockIndirectLinksViewTable extends AbstractBlockLinksViewTable
|
||||
'zlist' => false,
|
||||
'extra_fields' => $this->GetAttCodesToDisplay(),
|
||||
'row_actions' => $this->GetRowActions(),
|
||||
'currentId' => $this->GetTableId(),
|
||||
);
|
||||
|
||||
// - Add creation in modal if the linkset is not readonly
|
||||
|
||||
if (!$this->oAttDef->GetReadOnly()) {
|
||||
$aExtraParams['creation_in_modal_is_allowed'] = true;
|
||||
$aExtraParams['creation_in_modal_js_handler'] = 'LinkSetWorker.CreateLinkedObject("'.$this->GetTableId().'");';
|
||||
}
|
||||
|
||||
return $aExtraParams;
|
||||
}
|
||||
|
||||
/** @inheritdoc */
|
||||
@@ -70,6 +80,12 @@ class BlockIndirectLinksViewTable extends AbstractBlockLinksViewTable
|
||||
],
|
||||
);
|
||||
|
||||
$aRowActions[] = array(
|
||||
'tooltip' => 'UI:Links:ActionRow:Modify',
|
||||
'icon_classes' => 'fas fa-pen',
|
||||
'js_row_action' => "LinkSetWorker.ModifyLinkedObject('{$this->oAttDef->GetLinkedClass()}', aRowData['Link/_key_/raw'], '{$this->GetTableId()}');",
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
return $aRowActions;
|
||||
|
||||
Reference in New Issue
Block a user