diff --git a/sources/Application/UI/Base/Component/DataTable/DataTableUIBlockFactory.php b/sources/Application/UI/Base/Component/DataTable/DataTableUIBlockFactory.php index 3bdcf6a3c..94e6726d3 100644 --- a/sources/Application/UI/Base/Component/DataTable/DataTableUIBlockFactory.php +++ b/sources/Application/UI/Base/Component/DataTable/DataTableUIBlockFactory.php @@ -527,6 +527,10 @@ class DataTableUIBlockFactory extends AbstractUIBlockFactory $oDataTable->SetRowActions($aExtraParams['row_actions']); } + if (isset($aExtraParams['creation_in_modal_js_handler'])){ + $oDataTable->SetModalCreationHandler($aExtraParams['creation_in_modal_js_handler']); + } + return $oDataTable; } diff --git a/sources/Application/UI/Links/Direct/BlockDirectLinksViewTable.php b/sources/Application/UI/Links/Direct/BlockDirectLinksViewTable.php index 2b3561292..1216236d1 100644 --- a/sources/Application/UI/Links/Direct/BlockDirectLinksViewTable.php +++ b/sources/Application/UI/Links/Direct/BlockDirectLinksViewTable.php @@ -30,14 +30,23 @@ class BlockDirectLinksViewTable extends AbstractBlockLinksViewTable /** @inheritdoc * */ public function GetExtraParam(): array { - return array( + $aExtraParams = array( 'target_attr' => $this->oAttDef->GetExtKeyToMe(), 'object_id' => $this->oDbObject->GetKey(), 'menu' => MetaModel::GetConfig()->Get('allow_menu_on_linkset'), 'default' => $this->GetDefault(), 'table_id' => $this->GetTableId(), '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 * */ @@ -77,6 +86,11 @@ class BlockDirectLinksViewTable extends AbstractBlockLinksViewTable ); break; } + $aRowActions[] = array( + 'tooltip' => 'UI:Links:ActionRow:Modify', + 'icon_classes' => 'fas fa-pen', + 'js_row_action' => "LinkSetWorker.ModifyLinkedObject('{$this->sTargetClass}', aRowData['{$this->oAttDef->GetLinkedClass()}/_key_/raw'], '{$this->GetTableId()}');", + ); } return $aRowActions; diff --git a/sources/Controller/Links/LinksetController.php b/sources/Controller/Links/LinksetController.php index 9c7ba15e8..3ad0fd443 100644 --- a/sources/Controller/Links/LinksetController.php +++ b/sources/Controller/Links/LinksetController.php @@ -8,10 +8,11 @@ namespace Combodo\iTop\Controller\Links; use AjaxPage; use cmdbAbstractObject; -use Combodo\iTop\Application\UI\Base\Layout\PageContent\PageContentFactory; +use Combodo\iTop\Application\UI\Base\Component\Form\FormUIBlockFactory; use Combodo\iTop\Controller\AbstractController; +use CoreException; use DBObject; -use iTopWebPage; +use JsonPage; use MetaModel; use UserRights; use utils; @@ -30,11 +31,16 @@ class LinkSetController extends AbstractController /** * OperationDeleteLinkedObject. * - * @return \JsonPage + * @return JsonPage + * @throws \CoreException */ - public function OperationDeleteLinkedObject(): \JsonPage + public function OperationDeleteLinkedObject(): JsonPage { - $oPage = new \JsonPage(); + if (!$this->IsHandlingXmlHttpRequest()) { + throw new CoreException('LinksetController can only be called in ajax.'); + } + + $oPage = new JsonPage(); $sErrorMessage = null; $bOperationSuccess = false; @@ -70,10 +76,15 @@ class LinkSetController extends AbstractController * OperationDetachLinkedObject. * * @return \JsonPage + * @throws \CoreException */ - public function OperationDetachLinkedObject(): \JsonPage + public function OperationDetachLinkedObject(): JsonPage { - $oPage = new \JsonPage(); + if (!$this->IsHandlingXmlHttpRequest()) { + throw new CoreException('LinksetController can only be called in ajax.'); + } + + $oPage = new JsonPage(); $sErrorMessage = null; $bOperationSuccess = false; @@ -106,7 +117,7 @@ class LinkSetController extends AbstractController } /** - * @return \iTopWebPage|\AjaxPage Create edit form in its webpage + * @return \AjaxPage Create edit form in its webpage * @throws \ApplicationException * @throws \ArchivedObjectException * @throws \CoreException @@ -114,7 +125,12 @@ class LinkSetController extends AbstractController */ public function OperationCreateLinkedObject() { - $bPrintable = utils::ReadParam('printable', '0') === '1'; + if (!$this->IsHandlingXmlHttpRequest()) { + throw new CoreException('LinksetController can only be called in ajax.'); + } + + $oPage = new AjaxPage(''); + $sProposedRealClass = utils::ReadParam('class', '', false, 'class'); $sAttCode = utils::ReadParam('att_code', '', false, 'raw'); $sClass = utils::ReadParam('host_class', '', false, 'class'); @@ -134,6 +150,7 @@ class LinkSetController extends AbstractController $aPossibleClasses[$sCandidateClass] = MetaModel::GetName($sCandidateClass); } } + // Only one of the subclasses can be instantiated... if (count($aPossibleClasses) == 1) { $aKeys = array_keys($aPossibleClasses); @@ -145,14 +162,6 @@ class LinkSetController extends AbstractController $aFieldFlags = array(); // TODO 3.1 array($sExtKeyToMe => OPT_ATT_READONLY); $oObj = DBObject::MakeDefaultInstance($sRealClass); - if ($this->IsHandlingXmlHttpRequest()) { - $oPage = new AjaxPage(''); - } else { - $oPage = new iTopWebPage('', $bPrintable); - $oPage->DisableBreadCrumb(); - $oPage->SetContentLayout(PageContentFactory::MakeForObjectDetails($oObj, cmdbAbstractObject::ENUM_DISPLAY_MODE_CREATE)); - } - $oSourceObj = MetaModel::GetObject($sClass, $sId); $oObj->Set($sExtKeyToMe, $sId); @@ -194,8 +203,38 @@ JS ] ]; cmdbAbstractObject::DisplayCreationForm($oPage, $sRealClass, $oObj, array(), $aExtraParams); - return $oPage; } - return; + else + { + // - We'll let the user select a class if multiple classes are available + $oClassForm = FormUIBlockFactory::MakeStandard(); + + // - When the user submit, redo the same request but with a real class + + $sCurrentParameters = json_encode([ + 'att_code' => $sAttCode, + 'host_class' => $sClass, + 'host_id' => $sId]); + $sCurrentUrl = utils::GetAbsoluteUrlAppRoot().'/pages/UI.php?route=linkset.create_linked_object'; + $oClassForm->SetOnSubmitJsCode( + <<AddSubBlock(cmdbAbstractObject::DisplayBlockSelectClassToCreate( $sProposedRealClass, MetaModel::GetName($sProposedRealClass), $aPossibleClasses)); + + $oPage->AddUiBlock($oClassForm); + } + + return $oPage; } } \ No newline at end of file