From 21bea2e7c39089f752f2e85e685c05a9092591c8 Mon Sep 17 00:00:00 2001 From: Denis Flaven Date: Mon, 14 Jun 2010 15:49:35 +0000 Subject: [PATCH] - Enhanced the display and modification/creation of objects in order to be able to get rid of templates... (Trac#138) SVN:trunk[463] --- application/cmdbabstract.class.inc.php | 216 ++++++++++++++++++++----- application/displayblock.class.inc.php | 2 +- core/metamodel.class.php | 2 +- pages/UI.php | 5 +- pages/ajax.render.php | 2 +- 5 files changed, 179 insertions(+), 48 deletions(-) diff --git a/application/cmdbabstract.class.inc.php b/application/cmdbabstract.class.inc.php index 43674138f..88bb1c955 100644 --- a/application/cmdbabstract.class.inc.php +++ b/application/cmdbabstract.class.inc.php @@ -119,11 +119,12 @@ abstract class cmdbAbstractObject extends CMDBObject $oBlock->Display($oPage, -1); $oPage->add("\n"); + $oPage->add("GetIcon()."\" style=\"margin-top:-30px; margin-right:10px; float:right\">\n"); } - function DisplayBareDetails(WebPage $oPage) + function DisplayBareProperties(WebPage $oPage) { - $oPage->add($this->GetBareDetails($oPage)); + $oPage->add($this->GetBareProperties($oPage)); } function DisplayBareRelations(WebPage $oPage) @@ -133,7 +134,7 @@ abstract class cmdbAbstractObject extends CMDBObject $oPage->SetCurrentTabContainer('Related Objects'); foreach(MetaModel::ListAttributeDefs(get_class($this)) as $sAttCode=>$oAttDef) { - if ((get_class($oAttDef) == 'AttributeLinkedSetIndirect') || (get_class($oAttDef) == 'AttributeLinkedSet')) + if ($oAttDef->IsLinkset()) { $oPage->SetCurrentTab($oAttDef->GetLabel()); $oPage->p($oAttDef->GetDescription()); @@ -142,7 +143,7 @@ abstract class cmdbAbstractObject extends CMDBObject { $sTargetClass = $oAttDef->GetLinkedClass(); $oFilter = new DBObjectSearch($sTargetClass); - $oFilter->AddCondition($oAttDef->GetExtKeyToMe(), $this->GetKey()); // @@@ condition has same name as field ?? + $oFilter->AddCondition($oAttDef->GetExtKeyToMe(), $this->GetKey()); $oBlock = new DisplayBlock($oFilter, 'list', false); $oBlock->Display($oPage, 0); @@ -178,19 +179,32 @@ abstract class cmdbAbstractObject extends CMDBObject return $sDisplayName; } - function GetBareDetails(WebPage $oPage) + function GetBareProperties(WebPage $oPage) { $sHtml = ''; $oAppContext = new ApplicationContext(); $sStateAttCode = MetaModel::GetStateAttributeCode(get_class($this)); $aDetails = array(); $sClass = get_class($this); - $aList = MetaModel::GetZListItems($sClass, 'details'); + $aDetailsList = MetaModel::GetZListItems($sClass, 'details'); + $aFullList = MetaModel::ListAttributeDefs($sClass); + $aList = $aDetailsList; + // Compute the list of properties to display, first the attributes in the 'details' list, then + // all the remaining attributes that are not external fields + foreach($aFullList as $sAttCode => $void) + { + $oAttDef = MetaModel::GetAttributeDef($sClass, $sAttCode); + if (!in_array($sAttCode, $aDetailsList) && (!$oAttDef->IsExternalField())) + { + $aList[] = $sAttCode; + } + } foreach($aList as $sAttCode) { $iFlags = $this->GetAttributeFlags($sAttCode); - if ( ($iFlags & OPT_ATT_HIDDEN) == 0) + $oAttDef = MetaModel::GetAttributeDef($sClass, $sAttCode); + if ( (!$oAttDef->IsLinkSet()) && (($iFlags & OPT_ATT_HIDDEN) == 0) ) { // The field is visible in the current state of the object if ($sStateAttCode == $sAttCode) @@ -240,7 +254,7 @@ abstract class cmdbAbstractObject extends CMDBObject // Object's details // template not found display the object using the *old style* $this->DisplayBareHeader($oPage); - $this->DisplayBareDetails($oPage); + $this->DisplayBareProperties($oPage); $this->DisplayBareRelations($oPage); } } @@ -987,46 +1001,104 @@ abstract class cmdbAbstractObject extends CMDBObject $aDetails = array(); $aFieldsMap = array(); $oPage->add("
\n"); - foreach(MetaModel::ListAttributeDefs($sClass) as $sAttCode=>$oAttDef) + + $aDetailsList = MetaModel::GetZListItems($sClass, 'details'); + $aFullList = MetaModel::ListAttributeDefs($sClass); + $aList = $aDetailsList; + // Compute the list of properties to display, first the attributes in the 'details' list, then + // all the remaining attributes that are not external fields + foreach($aFullList as $sAttCode => $void) { - if ($oAttDef->IsWritable()) + $oAttDef = MetaModel::GetAttributeDef($sClass, $sAttCode); + if (!in_array($sAttCode, $aDetailsList) && (!$oAttDef->IsExternalField())) { - if ($sStateAttCode == $sAttCode) + $aList[] = $sAttCode; + } + } + + foreach($aList as $sAttCode) + { + $oAttDef = MetaModel::GetAttributeDef($sClass, $sAttCode); + $iFlags = $this->GetAttributeFlags($sAttCode); + $oAttDef = MetaModel::GetAttributeDef($sClass, $sAttCode); + if ( (!$oAttDef->IsLinkSet()) && (($iFlags & OPT_ATT_HIDDEN) == 0) ) + { + if ($oAttDef->IsWritable()) { - // State attribute is always read-only from the UI - $sHTMLValue = $this->GetStateLabel(); - $aDetails[] = array('label' => $oAttDef->GetLabel(), 'value' => $sHTMLValue); - } - else - { - $iFlags = $this->GetAttributeFlags($sAttCode); - if ($iFlags & OPT_ATT_HIDDEN) + if ($sStateAttCode == $sAttCode) { - // Attribute is hidden, do nothing + // State attribute is always read-only from the UI + $sHTMLValue = $this->GetStateLabel(); + $aDetails[] = array('label' => $oAttDef->GetLabel(), 'value' => $sHTMLValue); } else { - if ($iFlags & OPT_ATT_READONLY) + $iFlags = $this->GetAttributeFlags($sAttCode); + if ($iFlags & OPT_ATT_HIDDEN) { - // Attribute is read-only - $sHTMLValue = $this->GetAsHTML($sAttCode); + // Attribute is hidden, do nothing } else { - $sValue = $this->Get($sAttCode); - $sDisplayValue = $this->GetEditValue($sAttCode); - $aArgs = array('this' => $this); - $sInputId = $iFormId.'_'.$sAttCode; - $sHTMLValue = "".self::GetFormElementForField($oPage, $sClass, $sAttCode, $oAttDef, $sValue, $sDisplayValue, $sInputId, '', $iFlags, $aArgs); - $aFieldsMap[$sAttCode] = $sInputId; - + if ($iFlags & OPT_ATT_READONLY) + { + // Attribute is read-only + $sHTMLValue = $this->GetAsHTML($sAttCode); + } + else + { + $sValue = $this->Get($sAttCode); + $sDisplayValue = $this->GetEditValue($sAttCode); + $aArgs = array('this' => $this); + $sInputId = $iFormId.'_'.$sAttCode; + $sHTMLValue = "".self::GetFormElementForField($oPage, $sClass, $sAttCode, $oAttDef, $sValue, $sDisplayValue, $sInputId, '', $iFlags, $aArgs).''; + $aFieldsMap[$sAttCode] = $sInputId; + + } + $aDetails[] = array('label' => ''.$oAttDef->GetLabel().'', 'value' => $sHTMLValue); } - $aDetails[] = array('label' => ''.$oAttDef->GetLabel().'', 'value' => $sHTMLValue); } } + else + { + $aDetails[] = array('label' => ''.$oAttDef->GetLabel().'', 'value' => $this->GetAsHTML($sAttCode)); + } } } $oPage->details($aDetails); + // Now display the relations, one tab per relation + $oPage->AddTabContainer('Related Objects'); + $oPage->SetCurrentTabContainer('Related Objects'); + foreach($aList as $sAttCode) + { + $oAttDef = MetaModel::GetAttributeDef($sClass, $sAttCode); + if ($oAttDef->IsLinkset()) + { + $oPage->SetCurrentTab($oAttDef->GetLabel()); + $oPage->p($oAttDef->GetDescription()); + + if (get_class($oAttDef) == 'AttributeLinkedSet') + { + $sTargetClass = $oAttDef->GetLinkedClass(); + $oFilter = new DBObjectSearch($sTargetClass); + $oFilter->AddCondition($oAttDef->GetExtKeyToMe(), $this->GetKey()); + + $oBlock = new DisplayBlock($oFilter, 'list', false); + $oBlock->Display($oPage, 0); + } + else // get_class($oAttDef) == 'AttributeLinkedSetIndirect' + { + $sValue = $this->Get($sAttCode); + $sDisplayValue = $this->GetEditValue($sAttCode); + $aArgs = array('this' => $this); + $sInputId = $iFormId.'_'.$sAttCode; + $sHTMLValue = "".self::GetFormElementForField($oPage, $sClass, $sAttCode, $oAttDef, $sValue, $sDisplayValue, $sInputId, '', $iFlags, $aArgs).''; + $aFieldsMap[$sAttCode] = $sInputId; + $oPage->add($sHTMLValue); + } + } + } + $oPage->SetCurrentTab(''); $oPage->add("\n"); $oPage->add("\n"); $oPage->add("\n"); @@ -1082,32 +1154,88 @@ EOF $sTargetState = $oObjectToClone->GetState(); } - //foreach(MetaModel::ListAttributeDefs($sClass) as $sAttCode=>$oAttDef) - foreach(MetaModel::GetZListItems($sClass, 'details') as $sAttCode) + $aDetailsList = MetaModel::GetZListItems($sClass, 'details'); + $aFullList = MetaModel::ListAttributeDefs($sClass); + $aList = $aDetailsList; + // Compute the list of properties to display, first the attributes in the 'details' list, then + // all the remaining attributes that are not external fields + foreach($aFullList as $sAttCode => $void) { $oAttDef = MetaModel::GetAttributeDef($sClass, $sAttCode); - $iOptions = isset($aStates[$sTargetState]['attribute_list'][$sAttCode]) ? $aStates[$sTargetState]['attribute_list'][$sAttCode] : 0; - if ($sStateAttCode == $sAttCode) + if (!in_array($sAttCode, $aDetailsList) && (!$oAttDef->IsExternalField())) { - // State attribute is always read-only from the UI - $sHTMLValue = MetaModel::GetStateLabel($sClass, $sTargetState); - $aDetails[] = array('label' => $oAttDef->GetLabel(), 'value' => $sHTMLValue); + $aList[] = $sAttCode; } - else if ((!$oAttDef->IsExternalField()) && ($oAttDef->IsWritable()) && ($iOptions != OPT_ATT_HIDDEN) && ($iOptions != OPT_ATT_READONLY) ) + } + foreach($aList as $sAttCode) + { + $oAttDef = MetaModel::GetAttributeDef($sClass, $sAttCode); + $iFlags = isset($aStates[$sTargetState]['attribute_list'][$sAttCode]) ? $aStates[$sTargetState]['attribute_list'][$sAttCode] : 0; + + if ( (!$oAttDef->IsLinkSet()) && (($iFlags & OPT_ATT_HIDDEN) == 0) ) { + if ($oAttDef->IsWritable()) + { + if ($sStateAttCode == $sAttCode) + { + // State attribute is always read-only from the UI + $sHTMLValue = MetaModel::GetStateLabel($sClass, $sTargetState); + $aDetails[] = array('label' => $oAttDef->GetLabel(), 'value' => $sHTMLValue); + } + else + { + if ($iFlags & OPT_ATT_HIDDEN) + { + // Attribute is hidden, do nothing + } + else + { + if ($iFlags & OPT_ATT_READONLY) + { + // Attribute is read-only + $sHTMLValue = ($oObjectToClone == null) ? '' : $oObjectToClone->GetAsHTML($sAttCode); + } + else + { + $sFieldId = 'att_'.$iFieldIndex; + $sValue = ($oObjectToClone == null) ? '' : $oObjectToClone->Get($sAttCode); + $sDisplayValue = ($oObjectToClone == null) ? '' : $oObjectToClone->GetEditValue($sAttCode); + $sHTMLValue = "
".self::GetFormElementForField($oPage, $sClass, $sAttCode, $oAttDef, $sValue, $sDisplayValue, $sFieldId, '', $iFlags, $aArgs)."
"; + $aFieldsMap[$sFieldId] = $sAttCode; + $aDetails[] = array('label' => $oAttDef->GetLabel(), 'value' => $sHTMLValue); + $iFieldIndex++; + } + } + } + } + } + } + $oPage->details($aDetails); + // Now display the relations, one tab per relation + $oPage->AddTabContainer('Related Objects'); + $oPage->SetCurrentTabContainer('Related Objects'); + foreach($aList as $sAttCode) + { + $oAttDef = MetaModel::GetAttributeDef($sClass, $sAttCode); + if ($oAttDef->IsLinkset()) + { + $oPage->SetCurrentTab($oAttDef->GetLabel()); + $oPage->p($oAttDef->GetDescription()); + + $iFlags = isset($aStates[$sTargetState]['attribute_list'][$sAttCode]) ? $aStates[$sTargetState]['attribute_list'][$sAttCode] : 0; $sFieldId = 'att_'.$iFieldIndex; $sValue = ($oObjectToClone == null) ? '' : $oObjectToClone->Get($sAttCode); $sDisplayValue = ($oObjectToClone == null) ? '' : $oObjectToClone->GetEditValue($sAttCode); - $iOptions = isset($aStates[$sTargetState]['attribute_list'][$sAttCode]) ? $aStates[$sTargetState]['attribute_list'][$sAttCode] : 0; - - $sHTMLValue = "
".self::GetFormElementForField($oPage, $sClass, $sAttCode, $oAttDef, $sValue, $sDisplayValue, $sFieldId, '', $iOptions, $aArgs)."
"; + $iFlags = isset($aStates[$sTargetState]['attribute_list'][$sAttCode]) ? $aStates[$sTargetState]['attribute_list'][$sAttCode] : 0; + $sHTMLValue = "
".self::GetFormElementForField($oPage, $sClass, $sAttCode, $oAttDef, $sValue, $sDisplayValue, $sFieldId, '', $iFlags, $aArgs)."
"; $aFieldsMap[$sFieldId] = $sAttCode; $aDetails[] = array('label' => $oAttDef->GetLabel(), 'value' => $sHTMLValue); $iFieldIndex++; + $oPage->add($sHTMLValue); } } - - $oPage->details($aDetails); + $oPage->SetCurrentTab(''); + if ($oObjectToClone != null) { $oPage->add("GetKey()."\">\n"); diff --git a/application/displayblock.class.inc.php b/application/displayblock.class.inc.php index c30bda818..72f79a75f 100644 --- a/application/displayblock.class.inc.php +++ b/application/displayblock.class.inc.php @@ -543,7 +543,7 @@ class DisplayBlock { while($oObj = $this->m_oSet->Fetch()) { - $sHtml .= $oObj->GetBareDetails($oPage); + $sHtml .= $oObj->GetBareProperties($oPage); } } break; diff --git a/core/metamodel.class.php b/core/metamodel.class.php index 5ebf60e57..2367d80d9 100644 --- a/core/metamodel.class.php +++ b/core/metamodel.class.php @@ -338,7 +338,7 @@ abstract class MetaModel final static public function GetDisplayTemplate($sClass) { self::_check_subclass($sClass); - return self::$m_aClassParams[$sClass]["display_template"]; + return array_key_exists("display_template", self::$m_aClassParams[$sClass]) ? self::$m_aClassParams[$sClass]["display_template"]: ''; } final static public function GetAttributeOrigin($sClass, $sAttCode) { diff --git a/pages/UI.php b/pages/UI.php index 9f6ce5cc7..b31d7279a 100644 --- a/pages/UI.php +++ b/pages/UI.php @@ -616,6 +616,7 @@ try $oP->add("
\n"); $oP->add("

".Dict::Format('UI:ModificationTitle_Class_Object', $sClassLabel, $oObj->GetName())."

\n"); $oP->add("
\n"); + $oP->add("GetIcon()."\" style=\"margin-top:-30px; margin-right:10px; float:right\">\n"); $oP->add("
\n"); $oObj->DisplayModifyForm($oP); @@ -661,6 +662,7 @@ try $oP->add("

".Dict::Format('UI:CloneTitle_Class_Object', $sClassLabel, $oObj->GetName())."

\n"); $oP->add("
\n"); + $oP->add("GetIcon()."\" style=\"margin-top:-30px; margin-right:10px; float:right\">\n"); $oP->add("
\n"); cmdbAbstractObject::DisplayCreationForm($oP, $sClass, $oObjToClone); $oP->add("
\n"); @@ -693,6 +695,7 @@ try $oP->set_title(Dict::Format('UI:CreationPageTitle_Class', $sClassLabel)); $oP->add("

".Dict::Format('UI:CreationTitle_Class', $sClassLabel)."

\n"); $oP->add("
\n"); + $oP->add("\n"); cmdbAbstractObject::DisplayCreationForm($oP, $sClass, null /* $oObjToClone */); $oP->add("
\n"); break; @@ -1055,7 +1058,7 @@ try $oP->add("

$sActionLabel - {$oObj->GetName()}

\n"); $oP->set_title($sActionLabel); $oP->add("\n"); - $oObj->DisplayBareDetails($oP); + $oObj->DisplayBareProperties($oP); $aTargetState = $aTargetStates[$sTargetState]; $aExpectedAttributes = $aTargetState['attribute_list']; $oP->add("

$sActionDetails

\n"); diff --git a/pages/ajax.render.php b/pages/ajax.render.php index fb71b3726..d993d9153 100644 --- a/pages/ajax.render.php +++ b/pages/ajax.render.php @@ -94,7 +94,7 @@ switch($operation) $sJson = utils::ReadParam('json_obj', '', 'post'); $oWizardHelper = WizardHelper::FromJSON($sJson); $oObj = $oWizardHelper->GetTargetObject(); - $oObj->DisplayBareDetails($oPage); + $oObj->DisplayBareProperties($oPage); break; case 'wizard_helper':