diff --git a/application/displayblock.class.inc.php b/application/displayblock.class.inc.php index 751a3c90c..19456d96c 100644 --- a/application/displayblock.class.inc.php +++ b/application/displayblock.class.inc.php @@ -1765,13 +1765,14 @@ class MenuBlock extends DisplayBlock $bIsCreationAllowed = (UserRights::IsActionAllowed($sClass, UR_ACTION_CREATE) === UR_ALLOWED_YES) && ($oReflectionClass->IsSubclassOf('cmdbAbstractObject')); $bIsModifyAllowed = (UserRights::IsActionAllowed($sClass, UR_ACTION_MODIFY, $oSet) === UR_ALLOWED_YES) && ($oReflectionClass->IsSubclassOf('cmdbAbstractObject')); + // Create in new tab + if ($bIsCreationAllowed && !$bIsCreationInModalAllowed) { + $this->AddNewObjectMenuAction($aRegularActions, $sClass, $sDefaultValuesAsUrlParams); + } + // Any style actions // - Bulk actions on objects set if ($iSetCount > 1) { - if ($bIsCreationAllowed && !$bIsCreationInModalAllowed) { - $this->AddNewObjectMenuAction($aRegularActions, $sClass, $sDefaultValuesAsUrlParams); - } - // Bulk actions for each selected classes (eg. "link" and "remote" on n:n relations) foreach ($aSelectedClasses as $sSelectedAlias => $sSelectedClass) { $sSelectedClassName = MetaModel::GetName($sSelectedClass); @@ -1846,22 +1847,9 @@ class MenuBlock extends DisplayBlock // NOT "listInObject" style actions if ($this->m_sStyle !== 'listInObject') { switch ($iSetCount) { - case 0: - // No object in the set, the only possible action is "new" - if ($bIsCreationAllowed) { - $this->AddNewObjectMenuAction($aRegularActions, $sClass, $sDefaultValuesAsUrlParams); - } - break; - case 1: $oObj = $oSet->Fetch(); - if (is_null($oObj)) { - if (!isset($aExtraParams['link_attr'])) { - if ($bIsCreationAllowed) { - $this->AddNewObjectMenuAction($aRegularActions, $sClass, $sDefaultValuesAsUrlParams); - } - } - } else { + if (false === is_null($oObj)) { $id = $oObj->GetKey(); if (empty($sRefreshAction) && utils::ReadParam('operation') == 'details') { if ($_SERVER['REQUEST_METHOD'] == 'GET') { @@ -2172,6 +2160,26 @@ class MenuBlock extends DisplayBlock $oActionsToolbar->AddSubBlock($oActionButton); } + // - Creation in modal + if ($bIsCreationInModalAllowed === true) { + $oAddLinkActionButton = ButtonUIBlockFactory::MakeIconAction( + 'fas fa-plus', + Dict::S('UI:Links:New:Button:Tooltip'), + 'UI:Links:New', + '', + false + ); + + // - If we are used in a Datatable, 'datatable_' will be prefixed to our $sId, so we do the same here + $sRealId = $sId; + if(in_array($this->m_sStyle, ['list', 'links', 'listInObject'])){ + $sRealId = 'datatable_' . $sId; + } + $oAddLinkActionButton->AddCSSClasses(['ibo-action-button', 'ibo-regular-action-button']) + ->SetOnClickJsCode("$('#$sRealId').trigger('open_creation_modal.object.itop');"); + $oActionsToolbar->AddSubBlock($oAddLinkActionButton); + } + // - Refresh if (utils::IsNotNullOrEmptyString($sRefreshAction)) { $oActionButton = ButtonUIBlockFactory::MakeAlternativeNeutral('', 'UI:Button:Refresh'); @@ -2187,26 +2195,6 @@ class MenuBlock extends DisplayBlock $oActionButton = ButtonUIBlockFactory::MakeIconLink('fas fa-search', Dict::Format('UI:SearchFor_Class', MetaModel::GetName($sClass)), "{$sRootUrl}pages/UI.php?operation=search_form&do_search=0&class=$sClass{$sContext}", '', 'UI:SearchFor_Class'); $oActionButton->AddCSSClasses(['ibo-action-button', 'ibo-regular-action-button']); $oActionsToolbar->AddSubBlock($oActionButton); - } - - // - Creation in modal - if($bIsCreationInModalAllowed === true){ - $oAddLinkActionButton = ButtonUIBlockFactory::MakeIconAction( - 'fas fa-plus', - Dict::S('UI:Links:New:Button:Tooltip'), - 'UI:Links:New', - '', - false - ); - - // - If we are used in a Datatable, 'datatable_' will be prefixed to our $sId, so we do the same here - $sRealId = $sId; - if(in_array($this->m_sStyle, ['list', 'links', 'listInObject'])){ - $sRealId = 'datatable_' . $sId; - } - $oAddLinkActionButton->AddCSSClasses(['ibo-action-button', 'ibo-regular-action-button']) - ->SetOnClickJsCode("$('#$sRealId').trigger('open_creation_modal.object.itop');"); - $oActionsToolbar->AddSubBlock($oAddLinkActionButton); } // - Others