Restore prototypes of cmdbAbstractObject methods in which we added $sMode to preserve compatibility with existing extensions (#240)

* Restore prototypes of cmdbAbstractObject methods in which we added $sMode to preserve compatibility with existing extensions

* Rename cmdbAbstractObject::ENUM_OBJECT_MODE_XXX

* Add cmdbAbstractObject::ENUM_OBJECT_MODE_BULK_EDIT

* Refactor usage of $sDisplayMode in cmdbAbstractObject::DisplayModifyForm()
This commit is contained in:
Molkobain
2021-11-16 17:47:09 +01:00
committed by GitHub
parent 1b2d75efd6
commit 2a913cd484
10 changed files with 147 additions and 77 deletions

View File

@@ -71,16 +71,42 @@ require_once(APPROOT.'sources/application/search/criterionconversion/criterionto
*/ */
abstract class cmdbAbstractObject extends CMDBObject implements iDisplay abstract class cmdbAbstractObject extends CMDBObject implements iDisplay
{ {
/** @var string ENUM_OBJECT_MODE_VIEW */ /**
public const ENUM_OBJECT_MODE_VIEW = 'view'; * @var string
/** @var string ENUM_OBJECT_MODE_EDIT */ * @see static::$sDisplayMode
public const ENUM_OBJECT_MODE_EDIT = 'edit'; * @since 3.0.0
/** @var string ENUM_OBJECT_MODE_CREATE */ */
public const ENUM_OBJECT_MODE_CREATE = 'create'; public const ENUM_DISPLAY_MODE_VIEW = 'view';
/** @var string ENUM_OBJECT_MODE_STIMULUS */ /**
public const ENUM_OBJECT_MODE_STIMULUS = 'stimulus'; * @var string
/** @var string ENUM_OBJECT_MODE_PRINT */ * @see static::$sDisplayMode
public const ENUM_OBJECT_MODE_PRINT = 'print'; * @since 3.0.0
*/
public const ENUM_DISPLAY_MODE_EDIT = 'edit';
/**
* @var string
* @see static::$sDisplayMode
* @since 3.0.0
*/
public const ENUM_DISPLAY_MODE_CREATE = 'create';
/**
* @var string
* @see static::$sDisplayMode
* @since 3.0.0
*/
public const ENUM_DISPLAY_MODE_STIMULUS = 'stimulus';
/**
* @var string
* @see static::$sDisplayMode
* @since 3.0.0
*/
public const ENUM_DISPLAY_MODE_PRINT = 'print';
/**
* @var string
* @see static::$sDisplayMode
* @since 3.0.0
*/
public const ENUM_DISPLAY_MODE_BULK_EDIT = self::ENUM_DISPLAY_MODE_EDIT;
// N°3750 rendering used // N°3750 rendering used
/** @var string */ /** @var string */
@@ -115,10 +141,11 @@ abstract class cmdbAbstractObject extends CMDBObject implements iDisplay
public const ENUM_INPUT_TYPE_LINKEDSET = 'linkedset'; public const ENUM_INPUT_TYPE_LINKEDSET = 'linkedset';
/** /**
* @var string DEFAULT_OBJECT_MODE * @var string DEFAULT_DISPLAY_MODE
* @see static::$sDisplayMode
* @since 3.0.0 * @since 3.0.0
*/ */
public const DEFAULT_OBJECT_MODE = self::ENUM_OBJECT_MODE_VIEW; public const DEFAULT_DISPLAY_MODE = self::ENUM_DISPLAY_MODE_VIEW;
/** /**
* @var string Prefix for tags in the subtitle, allows to identify them more easily * @var string Prefix for tags in the subtitle, allows to identify them more easily
@@ -129,6 +156,11 @@ abstract class cmdbAbstractObject extends CMDBObject implements iDisplay
protected $m_iFormId; // The ID of the form used to edit the object (when in edition mode !) protected $m_iFormId; // The ID of the form used to edit the object (when in edition mode !)
protected static $iGlobalFormId = 1; protected static $iGlobalFormId = 1;
/**
* @var string Mode in which the object is displayed {@see static::ENUM_DISPLAY_MODE_VIEW}, ...)
* @since 3.0.0
*/
protected $sDisplayMode;
protected $aFieldsMap; protected $aFieldsMap;
/** /**
@@ -155,6 +187,7 @@ abstract class cmdbAbstractObject extends CMDBObject implements iDisplay
public function __construct($aRow = null, $sClassAlias = '', $aAttToLoad = null, $aExtendedDataSpec = null) public function __construct($aRow = null, $sClassAlias = '', $aAttToLoad = null, $aExtendedDataSpec = null)
{ {
parent::__construct($aRow, $sClassAlias, $aAttToLoad, $aExtendedDataSpec); parent::__construct($aRow, $sClassAlias, $aAttToLoad, $aExtendedDataSpec);
$this->sDisplayMode = static::DEFAULT_DISPLAY_MODE;
$this->bAllowWrite = false; $this->bAllowWrite = false;
$this->bAllowDelete = false; $this->bAllowDelete = false;
} }
@@ -162,7 +195,7 @@ abstract class cmdbAbstractObject extends CMDBObject implements iDisplay
/** /**
* Return the allowed object modes * Return the allowed object modes
* *
* @see static::ENUM_OBJECT_MODE_XXX * @see static::ENUM_DISPLAY_MODE_XXX
* *
* @return string[] * @return string[]
* @since 3.0.0 * @since 3.0.0
@@ -170,13 +203,39 @@ abstract class cmdbAbstractObject extends CMDBObject implements iDisplay
public static function EnumObjectModes(): array public static function EnumObjectModes(): array
{ {
return [ return [
static::ENUM_OBJECT_MODE_VIEW, static::ENUM_DISPLAY_MODE_VIEW,
static::ENUM_OBJECT_MODE_EDIT, static::ENUM_DISPLAY_MODE_EDIT,
static::ENUM_OBJECT_MODE_CREATE, static::ENUM_DISPLAY_MODE_CREATE,
static::ENUM_OBJECT_MODE_STIMULUS, static::ENUM_DISPLAY_MODE_STIMULUS,
static::ENUM_DISPLAY_MODE_PRINT,
static::ENUM_DISPLAY_MODE_BULK_EDIT,
]; ];
} }
/**
* @see static::$sDisplayMode
* @return string
* @since 3.0.0
*/
public function GetDisplayMode(): string
{
return $this->sDisplayMode;
}
/**
* @param string $sMode
*
* @see static::$sDisplayMode
* @return $this
* @since 3.0.0
*/
public function SetDisplayMode(string $sMode)
{
$this->sDisplayMode = $sMode;
return $this;
}
/** /**
* returns what will be the next ID for the forms * returns what will be the next ID for the forms
*/ */
@@ -285,8 +344,7 @@ JS
* To insert something IN the panel, we now need to add UIBlocks in either the "subtitle" or "toolbar" sections of the array that will be returned. * To insert something IN the panel, we now need to add UIBlocks in either the "subtitle" or "toolbar" sections of the array that will be returned.
* *
* @param \WebPage $oPage * @param \WebPage $oPage
* @param bool $bEditMode * @param bool $bEditMode Note that this parameter is no longer used in this method. Use {@see static::$sDisplayMode} instead
* @param string $sMode Mode in which the object is displayed (see static::ENUM_OBJECT_MODE_XXX)
* *
* @return array UIBlocks to be inserted in the "subtitle" and the "toolbar" sections of the ObjectDetails block. eg. ['subtitle' => [<BLOCK1>, <BLOCK2>], 'toolbar' => [<BLOCK3>]] * @return array UIBlocks to be inserted in the "subtitle" and the "toolbar" sections of the ObjectDetails block. eg. ['subtitle' => [<BLOCK1>, <BLOCK2>], 'toolbar' => [<BLOCK3>]]
* *
@@ -296,10 +354,10 @@ JS
* @throws \CoreUnexpectedValue * @throws \CoreUnexpectedValue
* @throws \MySQLException * @throws \MySQLException
* @throws \OQLException * @throws \OQLException
* @todo 3.0.0: This has to be discussed within the R&D when I come back in 10 days
* *
* @since 3.0.0 $bEditMode is deprecated and no longer used
*/ */
public function DisplayBareHeader(WebPage $oPage, $bEditMode = false, $sMode = self::ENUM_OBJECT_MODE_VIEW) public function DisplayBareHeader(WebPage $oPage, $bEditMode = false)
{ {
$aHeaderBlocks = [ $aHeaderBlocks = [
'subtitle' => [], 'subtitle' => [],
@@ -327,7 +385,7 @@ JS
$oPage->AddSessionMessages($sMessageKey, $aRanks, $aMessages); $oPage->AddSessionMessages($sMessageKey, $aRanks, $aMessages);
} }
if (!$oPage->IsPrintableVersion() && ($sMode === static::ENUM_OBJECT_MODE_VIEW)) { if (!$oPage->IsPrintableVersion() && ($this->GetDisplayMode() === static::ENUM_DISPLAY_MODE_VIEW)) {
// action menu // action menu
$oSingletonFilter = new DBObjectSearch(get_class($this)); $oSingletonFilter = new DBObjectSearch(get_class($this));
$oSingletonFilter->AddCondition('id', $this->GetKey(), '='); $oSingletonFilter->AddCondition('id', $this->GetKey(), '=');
@@ -479,12 +537,14 @@ HTML
* Display properties tab of an object * Display properties tab of an object
* *
* @param \WebPage $oPage * @param \WebPage $oPage
* @param bool $bEditMode * @param bool $bEditMode Note that this parameter is no longer used in this method. Use {@see static::$sDisplayMode} instead
* @param string $sPrefix * @param string $sPrefix
* @param array $aExtraParams * @param array $aExtraParams
* *
* @return array * @return array
* @throws \CoreException * @throws \CoreException
*
* @since 3.0.0 $bEditMode is deprecated and no longer used
*/ */
public function DisplayBareProperties(WebPage $oPage, $bEditMode = false, $sPrefix = '', $aExtraParams = array()) public function DisplayBareProperties(WebPage $oPage, $bEditMode = false, $sPrefix = '', $aExtraParams = array())
{ {
@@ -557,7 +617,7 @@ HTML
/** /**
* @param \WebPage $oPage * @param \WebPage $oPage
* @param bool $bEditMode * @param bool $bEditMode Note that this parameter is no longer used in this method. Use {@see static::$sDisplayMode} instead
* *
* @throws \CoreException * @throws \CoreException
* @throws \CoreUnexpectedValue * @throws \CoreUnexpectedValue
@@ -567,6 +627,8 @@ HTML
* @throws \MySQLHasGoneAwayException * @throws \MySQLHasGoneAwayException
* @throws \OQLException * @throws \OQLException
* @throws \Exception * @throws \Exception
*
* @since 3.0.0 $bEditMode is deprecated and no longer used
*/ */
public function DisplayBareRelations(WebPage $oPage, $bEditMode = false) public function DisplayBareRelations(WebPage $oPage, $bEditMode = false)
{ {
@@ -849,7 +911,7 @@ HTML
/** /**
* @param \WebPage $oPage * @param \WebPage $oPage
* @param bool $bEditMode * @param bool $bEditMode Note that this parameter is no longer used in this method. Use {@see static::$sDisplayMode} instead
* @param string $sPrefix * @param string $sPrefix
* @param array $aExtraParams * @param array $aExtraParams
* *
@@ -861,6 +923,8 @@ HTML
* @throws \MySQLException * @throws \MySQLException
* @throws \OQLException * @throws \OQLException
* @throws \Exception * @throws \Exception
*
* @since 3.0.0 $bEditMode is deprecated and no longer used
*/ */
public function GetBareProperties(WebPage $oPage, $bEditMode, $sPrefix, $aExtraParams = array()) public function GetBareProperties(WebPage $oPage, $bEditMode, $sPrefix, $aExtraParams = array())
{ {
@@ -1042,8 +1106,7 @@ HTML
/** /**
* @param \WebPage $oPage * @param \WebPage $oPage
* @param bool $bEditMode Note that this parameter is no longer used in ths method, $sMode is used instead, but we cannot remove it as it part of the base interface (iDisplay)... * @param bool $bEditMode Note that this parameter is no longer used in this method, {@see static::$sDisplayMode} is used instead, but we cannot remove it as it part of the base interface (iDisplay)...
* @param string $sMode Mode in which the object will be displayed (see static::ENUM_OBJECT_MODE_XXX)
* *
* @throws \ApplicationException * @throws \ApplicationException
* @throws \ArchivedObjectException * @throws \ArchivedObjectException
@@ -1054,8 +1117,10 @@ HTML
* @throws \MySQLException * @throws \MySQLException
* @throws \MySQLHasGoneAwayException * @throws \MySQLHasGoneAwayException
* @throws \OQLException * @throws \OQLException
*
* @since 3.0.0 $bEditMode is deprecated and no longer used
*/ */
public function DisplayDetails(WebPage $oPage, $bEditMode = false, $sMode = self::ENUM_OBJECT_MODE_VIEW) public function DisplayDetails(WebPage $oPage, $bEditMode = false)
{ {
// N°3786: As this can now be call recursively from the self::ReloadAndDisplay(), we need to make sure we don't fall into an infinite loop // N°3786: As this can now be call recursively from the self::ReloadAndDisplay(), we need to make sure we don't fall into an infinite loop
static $bBlockReentrance = false; static $bBlockReentrance = false;
@@ -1063,7 +1128,7 @@ HTML
$sClass = get_class($this); $sClass = get_class($this);
$iKey = $this->GetKey(); $iKey = $this->GetKey();
if ($sMode === static::ENUM_OBJECT_MODE_VIEW) { if ($this->GetDisplayMode() === static::ENUM_DISPLAY_MODE_VIEW) {
// The concurrent access lock makes sense only for already existing objects // The concurrent access lock makes sense only for already existing objects
$LockEnabled = MetaModel::GetConfig()->Get('concurrent_lock_enabled'); $LockEnabled = MetaModel::GetConfig()->Get('concurrent_lock_enabled');
if ($LockEnabled) { if ($LockEnabled) {
@@ -1081,14 +1146,14 @@ HTML
} }
// Object's details // Object's details
$oObjectDetails = ObjectFactory::MakeDetails($this); $oObjectDetails = ObjectFactory::MakeDetails($this, $this->GetDisplayMode());
if ($oPage->IsPrintableVersion()) { if ($oPage->IsPrintableVersion()) {
$oObjectDetails->SetIsHeaderVisibleOnScroll(false); $oObjectDetails->SetIsHeaderVisibleOnScroll(false);
} }
// Note: DisplayBareHeader is called before adding $oObjectDetails to the page, so it can inject HTML before it through $oPage. // Note: DisplayBareHeader is called before adding $oObjectDetails to the page, so it can inject HTML before it through $oPage.
/** @var \iTopWebPage $oPage */ /** @var \iTopWebPage $oPage */
$aHeadersBlocks = $this->DisplayBareHeader($oPage, $bEditMode, $sMode); $aHeadersBlocks = $this->DisplayBareHeader($oPage, $bEditMode);
if (false === empty($aHeadersBlocks['subtitle'])) { if (false === empty($aHeadersBlocks['subtitle'])) {
$oObjectDetails->AddSubTitleBlocks($aHeadersBlocks['subtitle']); $oObjectDetails->AddSubTitleBlocks($aHeadersBlocks['subtitle']);
} }
@@ -2697,10 +2762,11 @@ JS
$sOwnershipToken = null; $sOwnershipToken = null;
$iKey = $this->GetKey(); $iKey = $this->GetKey();
$sClass = get_class($this); $sClass = get_class($this);
$sMode = ($iKey > 0) ? static::ENUM_OBJECT_MODE_EDIT : static::ENUM_OBJECT_MODE_CREATE;
$this->SetDisplayMode(($iKey > 0) ? static::ENUM_DISPLAY_MODE_EDIT : static::ENUM_DISPLAY_MODE_CREATE);
$sDisplayMode = $this->GetDisplayMode();
if ($sMode === static::ENUM_OBJECT_MODE_EDIT) if ($this->GetDisplayMode() === static::ENUM_DISPLAY_MODE_EDIT)
{ {
// The concurrent access lock makes sense only for already existing objects // The concurrent access lock makes sense only for already existing objects
$LockEnabled = MetaModel::GetConfig()->Get('concurrent_lock_enabled'); $LockEnabled = MetaModel::GetConfig()->Get('concurrent_lock_enabled');
@@ -2750,7 +2816,7 @@ JS
if (isset($aExtraParams['custom_button'])) { if (isset($aExtraParams['custom_button'])) {
$sApplyButton = $aExtraParams['custom_button']; $sApplyButton = $aExtraParams['custom_button'];
} else { } else {
if ($sMode === static::ENUM_OBJECT_MODE_EDIT) { if ($this->GetDisplayMode() === static::ENUM_DISPLAY_MODE_EDIT) {
$sApplyButton = Dict::S('UI:Button:Apply'); $sApplyButton = Dict::S('UI:Button:Apply');
} else { } else {
$sApplyButton = Dict::S('UI:Button:Create'); $sApplyButton = Dict::S('UI:Button:Create');
@@ -2760,7 +2826,7 @@ JS
if (isset($aExtraParams['custom_operation'])) { if (isset($aExtraParams['custom_operation'])) {
$sOperation = $aExtraParams['custom_operation']; $sOperation = $aExtraParams['custom_operation'];
} else { } else {
if ($sMode === static::ENUM_OBJECT_MODE_EDIT) { if ($this->GetDisplayMode() === static::ENUM_DISPLAY_MODE_EDIT) {
$sOperation = 'apply_modify'; $sOperation = 'apply_modify';
} else { } else {
$sOperation = 'apply_new'; $sOperation = 'apply_new';
@@ -2775,7 +2841,7 @@ JS
->SetOnSubmitJsCode("return OnSubmit('form_{$this->m_iFormId}');"); ->SetOnSubmitJsCode("return OnSubmit('form_{$this->m_iFormId}');");
$oContentBlock->AddSubBlock($oForm); $oContentBlock->AddSubBlock($oForm);
if ($sMode === static::ENUM_OBJECT_MODE_EDIT) { if ($this->GetDisplayMode() === static::ENUM_DISPLAY_MODE_EDIT) {
// The object already exists in the database, it's a modification // The object already exists in the database, it's a modification
$oForm->AddSubBlock(InputUIBlockFactory::MakeForHidden('id', $iKey, "{$sPrefix}_id")); $oForm->AddSubBlock(InputUIBlockFactory::MakeForHidden('id', $iKey, "{$sPrefix}_id"));
} }
@@ -2790,7 +2856,7 @@ JS
// TODO 3.0.0: Is this (the if condition, not the code inside) still necessary? // TODO 3.0.0: Is this (the if condition, not the code inside) still necessary?
if (isset($aExtraParams['wizard_container']) && $aExtraParams['wizard_container']) { if (isset($aExtraParams['wizard_container']) && $aExtraParams['wizard_container']) {
$sClassLabel = MetaModel::GetName($sClass); $sClassLabel = MetaModel::GetName($sClass);
if ($sMode == static::ENUM_OBJECT_MODE_CREATE) { if ($this->GetDisplayMode() == static::ENUM_DISPLAY_MODE_CREATE) {
$oPage->set_title(Dict::Format('UI:CreationPageTitle_Class', $sClassLabel)); // Set title will take care of the encoding $oPage->set_title(Dict::Format('UI:CreationPageTitle_Class', $sClassLabel)); // Set title will take care of the encoding
} else { } else {
$oPage->set_title(Dict::Format('UI:ModificationPageTitle_Object_Class', $this->GetRawName(), $sClassLabel)); // Set title will take care of the encoding $oPage->set_title(Dict::Format('UI:ModificationPageTitle_Object_Class', $this->GetRawName(), $sClassLabel)); // Set title will take care of the encoding
@@ -2900,7 +2966,7 @@ EOF
$oObjectDetails->SetIcon($sClassIcon); $oObjectDetails->SetIcon($sClassIcon);
$oToolbarButtons->AddCSSClass('ibo-toolbar--button'); $oToolbarButtons->AddCSSClass('ibo-toolbar--button');
} else { } else {
$oObjectDetails = ObjectFactory::MakeDetails($this, $sMode); $oObjectDetails = ObjectFactory::MakeDetails($this, $this->GetDisplayMode());
$oToolbarButtons->AddCSSClass('ibo-toolbar-top'); $oToolbarButtons->AddCSSClass('ibo-toolbar-top');
$oObjectDetails->AddToolbarBlock($oToolbarButtons); $oObjectDetails->AddToolbarBlock($oToolbarButtons);
} }
@@ -2931,7 +2997,7 @@ EOF
if (!is_array($aFieldsMap)) { if (!is_array($aFieldsMap)) {
$aFieldsMap = array(); $aFieldsMap = array();
} }
if ($sMode === static::ENUM_OBJECT_MODE_EDIT) { if ($this->GetDisplayMode() === static::ENUM_DISPLAY_MODE_EDIT) {
$aFieldsMap['id'] = $sPrefix.'_id'; $aFieldsMap['id'] = $sPrefix.'_id';
} }
// Now display the relations, one tab per relation // Now display the relations, one tab per relation
@@ -3122,6 +3188,7 @@ EOF
} else { } else {
$oObj = clone $oSourceObject; $oObj = clone $oSourceObject;
} }
$oObj->SetDisplayMode(static::ENUM_DISPLAY_MODE_CREATE);
// Pre-fill the object with default values, when there is only on possible choice // Pre-fill the object with default values, when there is only on possible choice
// AND the field is mandatory (otherwise there is always the possiblity to let it empty) // AND the field is mandatory (otherwise there is always the possiblity to let it empty)
@@ -3177,10 +3244,10 @@ EOF
} }
/** /**
* @param \WebPage $oPage * @param \WebPage $oPage
* @param string $sStimulus * @param string $sStimulus
* @param null $aPrefillFormParam * @param array|null $aPrefillFormParam
* @param bool $bDisplayBareProperties Whether to display the object details or not * @param bool $bDisplayBareProperties Whether to display the object details or not
* *
* @throws \ApplicationException * @throws \ApplicationException
* @throws \ArchivedObjectException * @throws \ArchivedObjectException
@@ -3194,9 +3261,11 @@ EOF
*/ */
public function DisplayStimulusForm(WebPage $oPage, $sStimulus, $aPrefillFormParam = null, $bDisplayBareProperties = true) public function DisplayStimulusForm(WebPage $oPage, $sStimulus, $aPrefillFormParam = null, $bDisplayBareProperties = true)
{ {
$this->SetDisplayMode(static::ENUM_DISPLAY_MODE_STIMULUS);
$sClass = get_class($this); $sClass = get_class($this);
$iKey = $this->GetKey(); $iKey = $this->GetKey();
$sMode = static::ENUM_OBJECT_MODE_STIMULUS; $sDisplayMode = $this->GetDisplayMode();
$iTransactionId = utils::GetNewTransactionId(); $iTransactionId = utils::GetNewTransactionId();
$aTransitions = $this->EnumTransitions(); $aTransitions = $this->EnumTransitions();
@@ -3352,7 +3421,7 @@ EOF
$oPage->set_title($sActionLabel); $oPage->set_title($sActionLabel);
$oPage->add(<<<HTML $oPage->add(<<<HTML
<!-- Beginning of object-transition --> <!-- Beginning of object-transition -->
<div class="object-transition" data-object-class="$sClass" data-object-id="$iKey" data-object-mode="$sMode" data-object-current-state="$sCurrentState" data-object-target-state="$sTargetState"> <div class="object-transition" data-object-class="$sClass" data-object-id="$iKey" data-object-mode="$sDisplayMode" data-object-current-state="$sCurrentState" data-object-target-state="$sTargetState">
HTML HTML
); );
@@ -4910,6 +4979,7 @@ HTML
// Now create an object that has values for the homogeneous values only // Now create an object that has values for the homogeneous values only
/** @var \cmdbAbstractObject $oDummyObj */ /** @var \cmdbAbstractObject $oDummyObj */
$oDummyObj = new $sClass(); // @@ What if the class is abstract ? $oDummyObj = new $sClass(); // @@ What if the class is abstract ?
$oDummyObj->SetDisplayMode(static::ENUM_DISPLAY_MODE_BULK_EDIT);
$aComments = array(); $aComments = array();
function MyComparison($a, $b) // Sort descending function MyComparison($a, $b) // Sort descending
{ {

View File

@@ -414,7 +414,7 @@ try
$sClassLabel = MetaModel::GetName($sClass); $sClassLabel = MetaModel::GetName($sClass);
$oP->set_title(Dict::Format('UI:DetailsPageTitle', $oObj->GetRawName(), $sClassLabel)); // Set title will take care of the encoding $oP->set_title(Dict::Format('UI:DetailsPageTitle', $oObj->GetRawName(), $sClassLabel)); // Set title will take care of the encoding
$oP->SetContentLayout(PageContentFactory::MakeForObjectDetails($oObj, $oP->IsPrintableVersion() ? cmdbAbstractObject::ENUM_OBJECT_MODE_PRINT : cmdbAbstractObject::ENUM_OBJECT_MODE_VIEW)); $oP->SetContentLayout(PageContentFactory::MakeForObjectDetails($oObj, $oP->IsPrintableVersion() ? cmdbAbstractObject::ENUM_DISPLAY_MODE_PRINT : cmdbAbstractObject::ENUM_DISPLAY_MODE_VIEW));
$oObj->DisplayDetails($oP); $oObj->DisplayDetails($oP);
} }
} }
@@ -435,7 +435,7 @@ try
iTopOwnershipLock::ReleaseLock($sClass, $id, $sToken); iTopOwnershipLock::ReleaseLock($sClass, $id, $sToken);
} }
$oP->SetContentLayout(PageContentFactory::MakeForObjectDetails($oObj, cmdbAbstractObject::ENUM_OBJECT_MODE_VIEW)); $oP->SetContentLayout(PageContentFactory::MakeForObjectDetails($oObj, cmdbAbstractObject::ENUM_DISPLAY_MODE_VIEW));
cmdbAbstractObject::ReloadAndDisplay($oP, $oObj, array('operation' => 'details')); cmdbAbstractObject::ReloadAndDisplay($oP, $oObj, array('operation' => 'details'));
break; break;
@@ -668,7 +668,7 @@ EOF
if (UserRights::IsActionAllowed($sClass, UR_ACTION_MODIFY, $oSet) == UR_ALLOWED_NO) { if (UserRights::IsActionAllowed($sClass, UR_ACTION_MODIFY, $oSet) == UR_ALLOWED_NO) {
throw new SecurityException('User not allowed to modify this object', array('class' => $sClass, 'id' => $id)); throw new SecurityException('User not allowed to modify this object', array('class' => $sClass, 'id' => $id));
} }
$oP->SetContentLayout(PageContentFactory::MakeForObjectDetails($oObj, cmdbAbstractObject::ENUM_OBJECT_MODE_EDIT)); $oP->SetContentLayout(PageContentFactory::MakeForObjectDetails($oObj, cmdbAbstractObject::ENUM_DISPLAY_MODE_EDIT));
// Note: code duplicated to the case 'apply_modify' when a data integrity issue has been found // Note: code duplicated to the case 'apply_modify' when a data integrity issue has been found
$oObj->DisplayModifyForm($oP, array('wizard_container' => 1)); // wizard_container: Display the title above the form $oObj->DisplayModifyForm($oP, array('wizard_container' => 1)); // wizard_container: Display the title above the form
} }
@@ -760,7 +760,7 @@ EOF
$sHeaderTitle = Dict::Format('UI:CreationTitle_Class', $sClassLabel); $sHeaderTitle = Dict::Format('UI:CreationTitle_Class', $sClassLabel);
// Note: some code has been duplicated to the case 'apply_new' when a data integrity issue has been found // Note: some code has been duplicated to the case 'apply_new' when a data integrity issue has been found
$oP->set_title(Dict::Format('UI:CreationPageTitle_Class', $sClassLabel)); $oP->set_title(Dict::Format('UI:CreationPageTitle_Class', $sClassLabel));
$oP->SetContentLayout(PageContentFactory::MakeForObjectDetails($oObjToClone, cmdbAbstractObject::ENUM_OBJECT_MODE_CREATE)); $oP->SetContentLayout(PageContentFactory::MakeForObjectDetails($oObjToClone, cmdbAbstractObject::ENUM_DISPLAY_MODE_CREATE));
cmdbAbstractObject::DisplayCreationForm($oP, $sRealClass, $oObjToClone, array(), array('wizard_container' => 1, 'keep_source_object' => true)); // wizard_container: Display the title above the form cmdbAbstractObject::DisplayCreationForm($oP, $sRealClass, $oObjToClone, array(), array('wizard_container' => 1, 'keep_source_object' => true)); // wizard_container: Display the title above the form
} else { } else {
// Select the derived class to create // Select the derived class to create

View File

@@ -62,11 +62,11 @@ class ActivityPanel extends UIBlock
/** @var \DBObject $oObject The object for which the activity panel is for */ /** @var \DBObject $oObject The object for which the activity panel is for */
protected $oObject; protected $oObject;
/** /**
* @see \cmdbAbstractObject::ENUM_OBJECT_MODE_XXX * @see \cmdbAbstractObject::ENUM_DISPLAY_MODE_XXX
* @var string $sObjectMode Display mode of $oObject (create, edit, view, ...) * @var string $sObjectMode Display mode of $oObject (create, edit, view, ...)
*/ */
protected $sObjectMode; protected $sObjectMode;
/** @var null|string $sTransactionId Only when $sObjectMode is set to \cmdbAbstractObject::ENUM_OBJECT_MODE_VIEW */ /** @var null|string $sTransactionId Only when $sObjectMode is set to \cmdbAbstractObject::ENUM_DISPLAY_MODE_VIEW */
protected $sTransactionId; protected $sTransactionId;
/** @var array $aCaseLogs Metadata of the case logs (att. code, color, ...), will be use to make the tabs and identify them easily */ /** @var array $aCaseLogs Metadata of the case logs (att. code, color, ...), will be use to make the tabs and identify them easily */
protected $aCaseLogs; protected $aCaseLogs;
@@ -107,7 +107,7 @@ class ActivityPanel extends UIBlock
$this->InitializeCaseLogTabs(); $this->InitializeCaseLogTabs();
$this->InitializeCaseLogTabsEntryForms(); $this->InitializeCaseLogTabsEntryForms();
$this->InitializeComposeMenu(); $this->InitializeComposeMenu();
$this->SetObjectMode(cmdbAbstractObject::DEFAULT_OBJECT_MODE); $this->SetObjectMode(cmdbAbstractObject::DEFAULT_DISPLAY_MODE);
$this->SetObject($oObject); $this->SetObject($oObject);
$this->SetEntries($aEntries); $this->SetEntries($aEntries);
$this->bAreEntriesSorted = false; $this->bAreEntriesSorted = false;
@@ -184,7 +184,7 @@ class ActivityPanel extends UIBlock
* Set the display mode of the $oObject * Set the display mode of the $oObject
* *
* @param string $sMode * @param string $sMode
* @see cmdbAbstractObject::ENUM_OBJECT_MODE_XXX * @see cmdbAbstractObject::ENUM_DISPLAY_MODE_XXX
* *
* @return $this * @return $this
* @throws \Exception * @throws \Exception
@@ -204,7 +204,7 @@ class ActivityPanel extends UIBlock
/** /**
* Return the display mode of the $oObject * Return the display mode of the $oObject
* *
* @see cmdbAbstractObject::ENUM_OBJECT_MODE_XXX * @see cmdbAbstractObject::ENUM_DISPLAY_MODE_XXX
* @return string * @return string
*/ */
public function GetObjectMode(): string public function GetObjectMode(): string
@@ -260,13 +260,13 @@ class ActivityPanel extends UIBlock
/** /**
* @return bool True if the lock mechanism has to be enabled * @return bool True if the lock mechanism has to be enabled
* @uses \cmdbAbstractObject::ENUM_OBJECT_MODE_VIEW * @uses \cmdbAbstractObject::ENUM_DISPLAY_MODE_VIEW
* @uses static::HasAnEditableCaseLogTab() * @uses static::HasAnEditableCaseLogTab()
* @uses "concurrent_lock_enabled" config. param. * @uses "concurrent_lock_enabled" config. param.
*/ */
public function IsLockEnabled(): bool public function IsLockEnabled(): bool
{ {
return (cmdbAbstractObject::ENUM_OBJECT_MODE_VIEW === $this->sObjectMode) && (MetaModel::GetConfig()->Get('concurrent_lock_enabled')) && (true === $this->HasAnEditableCaseLogTab()); return (cmdbAbstractObject::ENUM_DISPLAY_MODE_VIEW === $this->sObjectMode) && (MetaModel::GetConfig()->Get('concurrent_lock_enabled')) && (true === $this->HasAnEditableCaseLogTab());
} }
/** /**
@@ -567,8 +567,8 @@ class ActivityPanel extends UIBlock
// - There is a least 1 *writable* case log // - There is a least 1 *writable* case log
// - And object is in view mode (in edit mode, it will be handled by the general form) // - And object is in view mode (in edit mode, it will be handled by the general form)
// Otherwise we generate unnecessary transaction IDs that could saturate the system // Otherwise we generate unnecessary transaction IDs that could saturate the system
if ((false === $bIsReadOnly) && (false === $this->HasTransactionId()) && (cmdbAbstractObject::ENUM_OBJECT_MODE_VIEW === $this->sObjectMode)) { if ((false === $bIsReadOnly) && (false === $this->HasTransactionId()) && (cmdbAbstractObject::ENUM_DISPLAY_MODE_VIEW === $this->sObjectMode)) {
$this->sTransactionId = (cmdbAbstractObject::ENUM_OBJECT_MODE_VIEW === $this->sObjectMode) ? utils::GetNewTransactionId() : null; $this->sTransactionId = (cmdbAbstractObject::ENUM_DISPLAY_MODE_VIEW === $this->sObjectMode) ? utils::GetNewTransactionId() : null;
} }
// Add log to compose button menu only if it is editable // Add log to compose button menu only if it is editable

View File

@@ -43,7 +43,7 @@ class ActivityPanelFactory
/** /**
* Make an activity panel for an object details layout, meaning that it should contain the case logs and the activity. * Make an activity panel for an object details layout, meaning that it should contain the case logs and the activity.
* *
* @see cmdbAbstractObject::ENUM_OBJECT_MODE_XXX * @see cmdbAbstractObject::ENUM_DISPLAY_MODE_XXX
* *
* @param \DBObject $oObject * @param \DBObject $oObject
* @param string $sMode Mode the object is being displayed (view, edit, create, ...), default is view. * @param string $sMode Mode the object is being displayed (view, edit, create, ...), default is view.
@@ -56,14 +56,14 @@ class ActivityPanelFactory
* @throws \MySQLException * @throws \MySQLException
* @throws \OQLException * @throws \OQLException
*/ */
public static function MakeForObjectDetails(DBObject $oObject, string $sMode = cmdbAbstractObject::DEFAULT_OBJECT_MODE) public static function MakeForObjectDetails(DBObject $oObject, string $sMode = cmdbAbstractObject::DEFAULT_DISPLAY_MODE)
{ {
$sObjClass = get_class($oObject); $sObjClass = get_class($oObject);
$sObjId = $oObject->GetKey(); $sObjId = $oObject->GetKey();
if ($sMode == cmdbAbstractObject::ENUM_OBJECT_MODE_PRINT) { if ($sMode == cmdbAbstractObject::ENUM_DISPLAY_MODE_PRINT) {
$oActivityPanel = new ActivityPanelPrint($oObject, [], ActivityPanel::BLOCK_CODE); $oActivityPanel = new ActivityPanelPrint($oObject, [], ActivityPanel::BLOCK_CODE);
$sMode = cmdbAbstractObject::ENUM_OBJECT_MODE_VIEW; $sMode = cmdbAbstractObject::ENUM_DISPLAY_MODE_VIEW;
} else { } else {
$oActivityPanel = new ActivityPanel($oObject, [], ActivityPanel::BLOCK_CODE); $oActivityPanel = new ActivityPanel($oObject, [], ActivityPanel::BLOCK_CODE);
} }

View File

@@ -143,20 +143,20 @@ class CaseLogEntryForm extends UIContentBlock
* *
* @param string $sObjectMode * @param string $sObjectMode
* @see $sSubmitMode * @see $sSubmitMode
* @see cmdbAbstractObject::ENUM_OBJECT_MODE_XXX * @see cmdbAbstractObject::ENUM_DISPLAY_MODE_XXX
* *
* @return $this * @return $this
*/ */
public function SetSubmitModeFromHostObjectMode($sObjectMode) public function SetSubmitModeFromHostObjectMode($sObjectMode)
{ {
switch ($sObjectMode){ switch ($sObjectMode){
case cmdbAbstractObject::ENUM_OBJECT_MODE_CREATE: case cmdbAbstractObject::ENUM_DISPLAY_MODE_CREATE:
case cmdbAbstractObject::ENUM_OBJECT_MODE_EDIT: case cmdbAbstractObject::ENUM_DISPLAY_MODE_EDIT:
$sSubmitMode = static::ENUM_SUBMIT_MODE_BRIDGED; $sSubmitMode = static::ENUM_SUBMIT_MODE_BRIDGED;
break; break;
case cmdbAbstractObject::ENUM_OBJECT_MODE_VIEW: case cmdbAbstractObject::ENUM_DISPLAY_MODE_VIEW:
case cmdbAbstractObject::ENUM_OBJECT_MODE_STIMULUS: case cmdbAbstractObject::ENUM_DISPLAY_MODE_STIMULUS:
default: default:
$sSubmitMode = static::ENUM_SUBMIT_MODE_AUTONOMOUS; $sSubmitMode = static::ENUM_SUBMIT_MODE_AUTONOMOUS;
break; break;

View File

@@ -33,7 +33,7 @@ use UserRights;
*/ */
class CaseLogEntryFormFactory class CaseLogEntryFormFactory
{ {
public static function MakeForCaselogTab(DBObject $oObject, string $sCaseLogAttCode, string $sObjectMode = cmdbAbstractObject::DEFAULT_OBJECT_MODE) public static function MakeForCaselogTab(DBObject $oObject, string $sCaseLogAttCode, string $sObjectMode = cmdbAbstractObject::DEFAULT_DISPLAY_MODE)
{ {
$oCaseLogEntryForm = new CaseLogEntryForm($oObject, $sCaseLogAttCode); $oCaseLogEntryForm = new CaseLogEntryForm($oObject, $sCaseLogAttCode);
$oCaseLogEntryForm->SetSubmitModeFromHostObjectMode($sObjectMode) $oCaseLogEntryForm->SetSubmitModeFromHostObjectMode($sObjectMode)

View File

@@ -54,7 +54,7 @@ class ObjectDetails extends Panel implements iKeyboardShortcut
protected $sObjectName; protected $sObjectName;
/** /**
* @var string The mode in which the object should be displayed (read, edit, create, ...) * @var string The mode in which the object should be displayed (read, edit, create, ...)
* @see \cmdbAbstractObject::ENUM_OBJECT_MODE_XXX * @see \cmdbAbstractObject::ENUM_DISPLAY_MODE_XXX
*/ */
protected $sObjectMode; protected $sObjectMode;
/** @var string */ /** @var string */
@@ -70,14 +70,14 @@ class ObjectDetails extends Panel implements iKeyboardShortcut
* ObjectDetails constructor. * ObjectDetails constructor.
* *
* @param \DBObject $oObject The object for which we display the details * @param \DBObject $oObject The object for which we display the details
* @param string $sMode See \cmdbAbstractObject::ENUM_OBJECT_MODE_XXX * @param string $sMode See \cmdbAbstractObject::ENUM_DISPLAY_MODE_XXX
* @param string|null $sId ID of the block itself, not the $oObject ID * @param string|null $sId ID of the block itself, not the $oObject ID
* *
* @throws \ArchivedObjectException * @throws \ArchivedObjectException
* @throws \CoreException * @throws \CoreException
* @throws \DictExceptionMissingString * @throws \DictExceptionMissingString
*/ */
public function __construct(DBObject $oObject, string $sMode = cmdbAbstractObject::DEFAULT_OBJECT_MODE, ?string $sId = null) public function __construct(DBObject $oObject, string $sMode = cmdbAbstractObject::DEFAULT_DISPLAY_MODE, ?string $sId = null)
{ {
$this->sClassName = get_class($oObject); $this->sClassName = get_class($oObject);
$this->sClassLabel = MetaModel::GetName($this->GetClassName()); $this->sClassLabel = MetaModel::GetName($this->GetClassName());
@@ -252,7 +252,7 @@ class ObjectDetails extends Panel implements iKeyboardShortcut
*/ */
protected function ComputeObjectName(DBObject $oObject): void protected function ComputeObjectName(DBObject $oObject): void
{ {
if ($this->sObjectMode === cmdbAbstractObject::ENUM_OBJECT_MODE_CREATE) { if ($this->sObjectMode === cmdbAbstractObject::ENUM_DISPLAY_MODE_CREATE) {
$this->sObjectName = Dict::Format('UI:CreationTitle_Class', $this->sClassLabel); $this->sObjectName = Dict::Format('UI:CreationTitle_Class', $this->sClassLabel);
} else { } else {
$this->sObjectName = $oObject->GetRawName(); $this->sObjectName = $oObject->GetRawName();

View File

@@ -29,7 +29,7 @@ class ObjectFactory
* @return \Combodo\iTop\Application\UI\Base\Layout\Object\ObjectDetails * @return \Combodo\iTop\Application\UI\Base\Layout\Object\ObjectDetails
* @throws \CoreException * @throws \CoreException
*/ */
public static function MakeDetails(DBObject $oObject, ?string $sMode = cmdbAbstractObject::DEFAULT_OBJECT_MODE) public static function MakeDetails(DBObject $oObject, ?string $sMode = cmdbAbstractObject::DEFAULT_DISPLAY_MODE)
{ {
$oObjectDetails = new ObjectDetails($oObject, $sMode); $oObjectDetails = new ObjectDetails($oObject, $sMode);
$oObjectDetails->SetIsHeaderVisibleOnScroll(true); $oObjectDetails->SetIsHeaderVisibleOnScroll(true);

View File

@@ -51,12 +51,12 @@ class PageContentFactory
* @param \DBObject $oObject * @param \DBObject $oObject
* @param string $sMode Mode the object is being displayed (view, edit, create, ...), default is view. * @param string $sMode Mode the object is being displayed (view, edit, create, ...), default is view.
* *
* @see cmdbAbstractObject::ENUM_OBJECT_MODE_XXX * @see cmdbAbstractObject::ENUM_DISPLAY_MODE_XXX
* *
* @return \Combodo\iTop\Application\UI\Base\Layout\PageContent\PageContentWithSideContent * @return \Combodo\iTop\Application\UI\Base\Layout\PageContent\PageContentWithSideContent
* @throws \CoreException * @throws \CoreException
*/ */
public static function MakeForObjectDetails(DBObject $oObject, string $sMode = cmdbAbstractObject::DEFAULT_OBJECT_MODE) public static function MakeForObjectDetails(DBObject $oObject, string $sMode = cmdbAbstractObject::DEFAULT_DISPLAY_MODE)
{ {
$oLayout = new PageContentWithSideContent(); $oLayout = new PageContentWithSideContent();

View File

@@ -50,11 +50,11 @@
} }
} }
}); });
{% if oUIBlock.GetObjectMode() == constant('cmdbAbstractObject::ENUM_OBJECT_MODE_EDIT') or oUIBlock.GetObjectMode() == constant('cmdbAbstractObject::ENUM_OBJECT_MODE_CREATE') %} {% if oUIBlock.GetObjectMode() == constant('cmdbAbstractObject::ENUM_DISPLAY_MODE_EDIT') or oUIBlock.GetObjectMode() == constant('cmdbAbstractObject::ENUM_DISPLAY_MODE_CREATE') %}
$('#{{ oUIBlock.GetId() }}').on('save_object', function(){ $('#{{ oUIBlock.GetId() }}').on('save_object', function(){
$(this).find('button[type="submit"][name=""][value=""]').click(); $(this).find('button[type="submit"][name=""][value=""]').click();
}); });
{% elseif oUIBlock.GetObjectMode() == constant('cmdbAbstractObject::ENUM_OBJECT_MODE_STIMULUS') %} {% elseif oUIBlock.GetObjectMode() == constant('cmdbAbstractObject::ENUM_DISPLAY_MODE_STIMULUS') %}
$('#{{ oUIBlock.GetId() }}').on('save_object', function(){ $('#{{ oUIBlock.GetId() }}').on('save_object', function(){
$(this).find('button[type="submit"][name="submit"][value="submit"]').click(); $(this).find('button[type="submit"][name="submit"][value="submit"]').click();
}); });