mirror of
https://github.com/Combodo/iTop.git
synced 2026-02-13 15:34:12 +01:00
N°3300 - Add creation and modification of 1-n objects in object details (#385)
* 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 * Allow to modify linked object from 1-n relation in modal * Add "New" button to 1-n relations * Fix "new" button on 1-n * Add todo * Handle multiple classes choice * Rework multiple classes choice and only allow LinksetController to be called from an ajax context * PhpDoc * Update sources/Application/UI/Links/Direct/BlockDirectLinksViewTable.php Co-authored-by: Molkobain <lajarige.guillaume@free.fr>
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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(
|
||||
<<<JS
|
||||
let me = this;
|
||||
let aParam = $sCurrentParameters;
|
||||
aParam['class'] = $(this).find('[name="class"]').val();
|
||||
let sPosting = $.post('$sCurrentUrl', aParam);
|
||||
sPosting.done(function(data){
|
||||
$(me).closest('[data-role="ibo-modal"]').html(data);
|
||||
});
|
||||
return false;
|
||||
JS
|
||||
);
|
||||
|
||||
// - Add a select and a button to validate the form
|
||||
$oClassForm->AddSubBlock(cmdbAbstractObject::DisplayBlockSelectClassToCreate( $sProposedRealClass, MetaModel::GetName($sProposedRealClass), $aPossibleClasses));
|
||||
|
||||
$oPage->AddUiBlock($oClassForm);
|
||||
}
|
||||
|
||||
return $oPage;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user