- Display/Creation/Modification of the objects now strictly relies on the display ZList. (i.e any attribute not in the ZList is neither displayed nor edited)

SVN:trunk[560]
This commit is contained in:
Denis Flaven
2010-07-05 16:10:50 +00:00
parent 0335c82710
commit d0ed8f624a
3 changed files with 124 additions and 95 deletions

View File

@@ -153,27 +153,29 @@ class URP_Users extends UserRightsBaseClass
$oPage->table($aDisplayConfig, $aDisplayData);
}
function DisplayBareRelations(WebPage $oPage)
function DisplayBareRelations(WebPage $oPage, $bEditMode = false)
{
parent::DisplayBareRelations($oPage);
$oPage->SetCurrentTab(Dict::S('UI:UserManagement:GrantMatrix'));
$this->DoShowGrantSumary($oPage, 'bizmodel');
// debug
if (false)
parent::DisplayBareRelations($oPage, $bEditMode);
if (!$bEditMode)
{
$oPage->SetCurrentTab('More on user rigths (dev only)');
$oPage->add("<h3>User rights</h3>\n");
$this->DoShowGrantSumary($oPage, 'addon/userrights');
$oPage->add("<h3>Change log</h3>\n");
$this->DoShowGrantSumary($oPage, 'core/cmdb');
$oPage->add("<h3>Application</h3>\n");
$this->DoShowGrantSumary($oPage, 'application');
$oPage->add("<h3>GUI</h3>\n");
$this->DoShowGrantSumary($oPage, 'gui');
}
$oPage->SetCurrentTab(Dict::S('UI:UserManagement:GrantMatrix'));
$this->DoShowGrantSumary($oPage, 'bizmodel');
// debug
if (false)
{
$oPage->SetCurrentTab('More on user rigths (dev only)');
$oPage->add("<h3>User rights</h3>\n");
$this->DoShowGrantSumary($oPage, 'addon/userrights');
$oPage->add("<h3>Change log</h3>\n");
$this->DoShowGrantSumary($oPage, 'core/cmdb');
$oPage->add("<h3>Application</h3>\n");
$this->DoShowGrantSumary($oPage, 'application');
$oPage->add("<h3>GUI</h3>\n");
$this->DoShowGrantSumary($oPage, 'gui');
}
}
}
}
@@ -272,12 +274,14 @@ class URP_Profiles extends UserRightsBaseClass
$oPage->table($aDisplayConfig, $aDisplayData);
}
function DisplayBareRelations(WebPage $oPage)
function DisplayBareRelations(WebPage $oPage, $bEditMode = false)
{
parent::DisplayBareRelations($oPage);
$oPage->SetCurrentTab(Dict::S('UI:UserManagement:GrantMatrix'));
$this->DoShowGrantSumary($oPage);
if (!$bEditMode)
{
$oPage->SetCurrentTab(Dict::S('UI:UserManagement:GrantMatrix'));
$this->DoShowGrantSumary($oPage);
}
}
}

View File

@@ -33,6 +33,7 @@ require_once('../application/ui.linkswidget.class.inc.php');
abstract class cmdbAbstractObject extends CMDBObject
{
protected $m_iFormId; // The ID of the form used to edit the object (when in edition mode !)
public static function GetUIPage()
{
@@ -99,7 +100,7 @@ abstract class cmdbAbstractObject extends CMDBObject
return "<a href=\"{$sAbsoluteUrl}{$sPage}?operation=details&class=$sObjClass&id=$sObjKey&".$oAppContext->GetForLink()."\" title=\"$sHint\">$sLabel</a>";
}
function DisplayBareHeader(WebPage $oPage)
function DisplayBareHeader(WebPage $oPage, $bEditMode = false)
{
// Standard Header with name, actions menu and history block
//
@@ -114,7 +115,7 @@ abstract class cmdbAbstractObject extends CMDBObject
$oPage->add("</div>\n");
}
function DisplayBareHistory(WebPage $oPage)
function DisplayBareHistory(WebPage $oPage, $bEditMode = false)
{
// history block (with as a tab)
$oHistoryFilter = new DBObjectSearch('CMDBChangeOp');
@@ -124,24 +125,64 @@ abstract class cmdbAbstractObject extends CMDBObject
$oBlock->Display($oPage, -1);
}
function DisplayBareProperties(WebPage $oPage)
function DisplayBareProperties(WebPage $oPage, $bEditMode = false)
{
$oPage->add($this->GetBareProperties($oPage));
$oPage->add($this->GetBareProperties($oPage, $bEditMode));
}
function DisplayBareRelations(WebPage $oPage)
function DisplayBareRelations(WebPage $oPage, $bEditMode = false)
{
// Related objects: display all the linkset attributes, each as a separate tab
// First in the order described by the 'display' ZList, then the remaining ones
// In the order described by the 'display' ZList
$aList = $this->FlattenZList(MetaModel::GetZListItems(get_class($this), 'details'));
$aList = array_unique(array_merge($aList, array_keys(MetaModel::ListAttributeDefs(get_class($this)))));
if (count($aList) == 0)
{
// Empty ZList defined, display all the linkedset attributes defined
$aList = array_keys(MetaModel::ListAttributeDefs(get_class($this)));
}
foreach($aList as $sAttCode)
{
$oAttDef = MetaModel::GetAttributeDef(get_class($this), $sAttCode);
if ($oAttDef->IsLinkset())
// Display mode
if (!$oAttDef->IsLinkset()) continue; // Process only linkset attributes...
$oPage->SetCurrentTab($oAttDef->GetLabel());
if ($bEditMode)
{
$oPage->SetCurrentTab($oAttDef->GetLabel());
$iFlags = $this->GetAttributeFlags($sAttCode);
$sClass = get_class($this);
if (get_class($oAttDef) == 'AttributeLinkedSet')
{
// 1:n links
$sTargetClass = $oAttDef->GetLinkedClass();
$oPage->p("<img src=\"".MetaModel::GetClassIcon($sTargetClass)."\" style=\"vertical-align:middle;\">&nbsp;".$oAttDef->GetDescription());
$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'
{
// n:n links
$sLinkedClass = $oAttDef->GetLinkedClass();
$oLinkingAttDef = MetaModel::GetAttributeDef($sLinkedClass, $oAttDef->GetExtKeyToRemote());
$sTargetClass = $oLinkingAttDef->GetTargetClass();
$oPage->p("<img src=\"".MetaModel::GetClassIcon($sTargetClass)."\" style=\"vertical-align:middle;\">&nbsp;".$oAttDef->GetDescription());
$sValue = $this->Get($sAttCode);
$sDisplayValue = $this->GetEditValue($sAttCode);
$aArgs = array('this' => $this);
$sInputId = $this->m_iFormId.'_'.$sAttCode;
$sHTMLValue = "<span id=\"field_{$sInputId}\">".self::GetFormElementForField($oPage, $sClass, $sAttCode, $oAttDef, $sValue, $sDisplayValue, $sInputId, '', $iFlags, $aArgs).'</span>';
$aFieldsMap[$sAttCode] = $sInputId;
$oPage->add($sHTMLValue);
}
}
else
{
// Display mode
if (!$oAttDef->IsIndirect())
{
// 1:n links
@@ -176,7 +217,7 @@ abstract class cmdbAbstractObject extends CMDBObject
$oPage->SetCurrentTab('');
}
function GetBareProperties(WebPage $oPage)
function GetBareProperties(WebPage $oPage, $bEditMode = false)
{
$sHtml = '';
$oAppContext = new ApplicationContext();
@@ -223,7 +264,7 @@ abstract class cmdbAbstractObject extends CMDBObject
}
function DisplayDetails(WebPage $oPage)
function DisplayDetails(WebPage $oPage, $bEditMode = false)
{
$sTemplate = Utils::ReadFromFile(MetaModel::GetDisplayTemplate(get_class($this)));
if (!empty($sTemplate))
@@ -238,14 +279,14 @@ abstract class cmdbAbstractObject extends CMDBObject
{
// Object's details
// template not found display the object using the *old style*
$this->DisplayBareHeader($oPage);
$this->DisplayBareHeader($oPage, $bEditMode);
$oPage->AddTabContainer(OBJECT_PROPERTIES_TAB);
$oPage->SetCurrentTabContainer(OBJECT_PROPERTIES_TAB);
$oPage->SetCurrentTab(Dict::S('UI:PropertiesTab'));
$this->DisplayBareProperties($oPage);
$this->DisplayBareRelations($oPage);
$this->DisplayBareProperties($oPage, $bEditMode);
$this->DisplayBareRelations($oPage, $bEditMode);
$oPage->SetCurrentTab(Dict::S('UI:HistoryTab'));
$this->DisplayBareHistory($oPage);
$this->DisplayBareHistory($oPage, $bEditMode);
}
}
@@ -990,28 +1031,29 @@ abstract class cmdbAbstractObject extends CMDBObject
public function DisplayModifyForm(WebPage $oPage, $aExtraParams = array())
{
static $iFormId = 0;
$iFormId++;
static $iGlobalFormId = 0;
$iGlobalFormId++;
$this->m_iFormId = $iGlobalFormId;
$sClass = get_class($this);
$oAppContext = new ApplicationContext();
$sStateAttCode = MetaModel::GetStateAttributeCode($sClass);
$iKey = $this->GetKey();
$aDetails = array();
$aFieldsMap = array();
$oPage->add("<form id=\"form_{$iFormId}\" enctype=\"multipart/form-data\" method=\"post\" onSubmit=\"return CheckFields('form_{$iFormId}', true)\">\n");
$oPage->add("<form id=\"form_{$this->m_iFormId}\" enctype=\"multipart/form-data\" method=\"post\" onSubmit=\"return CheckFields('form_{$this->m_iFormId}', true)\">\n");
$oPage->AddTabContainer(OBJECT_PROPERTIES_TAB);
$oPage->SetCurrentTabContainer(OBJECT_PROPERTIES_TAB);
$oPage->SetCurrentTab(Dict::S('UI:PropertiesTab'));
$aDetailsList = MetaModel::GetZListItems($sClass, 'details');
$aFullList = MetaModel::ListAttributeDefs($sClass);
$aList = $aDetailsList;
$aDetailsList = $this->FLattenZList(MetaModel::GetZListItems($sClass, 'details'));
//$aFullList = MetaModel::ListAttributeDefs($sClass);
$aList = array();
// 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)
foreach($aDetailsList as $sAttCode)
{
$oAttDef = MetaModel::GetAttributeDef($sClass, $sAttCode);
if (!in_array($sAttCode, $aDetailsList) && (!$oAttDef->IsExternalField()))
if (!$oAttDef->IsExternalField())
{
$aList[] = $sAttCode;
}
@@ -1019,7 +1061,6 @@ abstract class cmdbAbstractObject extends CMDBObject
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) )
@@ -1051,7 +1092,7 @@ abstract class cmdbAbstractObject extends CMDBObject
$sValue = $this->Get($sAttCode);
$sDisplayValue = $this->GetEditValue($sAttCode);
$aArgs = array('this' => $this);
$sInputId = $iFormId.'_'.$sAttCode;
$sInputId = $this->m_iFormId.'_'.$sAttCode;
$sHTMLValue = "<span id=\"field_{$sInputId}\">".self::GetFormElementForField($oPage, $sClass, $sAttCode, $oAttDef, $sValue, $sDisplayValue, $sInputId, '', $iFlags, $aArgs).'</span>';
$aFieldsMap[$sAttCode] = $sInputId;
@@ -1068,43 +1109,9 @@ abstract class cmdbAbstractObject extends CMDBObject
}
$oPage->details($aDetails);
// Now display the relations, one tab per relation
foreach($aList as $sAttCode)
{
$oAttDef = MetaModel::GetAttributeDef($sClass, $sAttCode);
if ($oAttDef->IsLinkset())
{
$oPage->SetCurrentTab($oAttDef->GetLabel());
if (get_class($oAttDef) == 'AttributeLinkedSet')
{
// 1:n links
$sTargetClass = $oAttDef->GetLinkedClass();
$oPage->p("<img src=\"".MetaModel::GetClassIcon($sTargetClass)."\" style=\"vertical-align:middle;\">&nbsp;".$oAttDef->GetDescription());
$oFilter = new DBObjectSearch($sTargetClass);
$oFilter->AddCondition($oAttDef->GetExtKeyToMe(), $this->GetKey());
$this->DisplayBareRelations($oPage, true); // Edit mode
$oBlock = new DisplayBlock($oFilter, 'list', false);
$oBlock->Display($oPage, 0);
}
else // get_class($oAttDef) == 'AttributeLinkedSetIndirect'
{
// n:n links
$sLinkedClass = $oAttDef->GetLinkedClass();
$oLinkingAttDef = MetaModel::GetAttributeDef($sLinkedClass, $oAttDef->GetExtKeyToRemote());
$sTargetClass = $oLinkingAttDef->GetTargetClass();
$oPage->p("<img src=\"".MetaModel::GetClassIcon($sTargetClass)."\" style=\"vertical-align:middle;\">&nbsp;".$oAttDef->GetDescription());
$sValue = $this->Get($sAttCode);
$sDisplayValue = $this->GetEditValue($sAttCode);
$aArgs = array('this' => $this);
$sInputId = $iFormId.'_'.$sAttCode;
$sHTMLValue = "<span id=\"field_{$sInputId}\">".self::GetFormElementForField($oPage, $sClass, $sAttCode, $oAttDef, $sValue, $sDisplayValue, $sInputId, '', $iFlags, $aArgs).'</span>';
$aFieldsMap[$sAttCode] = $sInputId;
$oPage->add($sHTMLValue);
}
}
}
$oPage->SetCurrentTab('');
$oPage->add("<input type=\"hidden\" name=\"id\" value=\"$iKey\">\n");
$oPage->add("<input type=\"hidden\" name=\"class\" value=\"$sClass\">\n");
@@ -1133,7 +1140,7 @@ EOF
$oPage->add_ready_script(
<<<EOF
// Initializes the object once at the beginning of the page...
CheckFields('form_{$iFormId}', false);
CheckFields('form_{$this->m_iFormId}', false);
EOF
);
}
@@ -1164,15 +1171,15 @@ EOF
$sTargetState = $oObjectToClone->GetState();
}
$aDetailsList = MetaModel::GetZListItems($sClass, 'details');
$aFullList = MetaModel::ListAttributeDefs($sClass);
$aList = $aDetailsList;
$aDetailsList = self::FlattenZList(MetaModel::GetZListItems($sClass, 'details'));
//$aFullList = MetaModel::ListAttributeDefs($sClass);
$aList = array();
// 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)
foreach($aDetailsList as $sAttCode)
{
$oAttDef = MetaModel::GetAttributeDef($sClass, $sAttCode);
if (!in_array($sAttCode, $aDetailsList) && (!$oAttDef->IsExternalField()))
if (!$oAttDef->IsExternalField())
{
$aList[] = $sAttCode;
}
@@ -1260,6 +1267,17 @@ EOF
}
$oPage->details($aDetails);
// Now display the relations, one tab per relation
if ($oObjectToClone != null)
{
$oObj = $oObjectToClone; // Hmm, likely to fail...
}
else
{
$oObj = new $sClass;
}
$oObj->m_iFormId = $iCreationFormId;
$oObj->DisplayBareRelations($oPage, true);
/*
foreach($aList as $sAttCode)
{
$oAttDef = MetaModel::GetAttributeDef($sClass, $sAttCode);
@@ -1281,6 +1299,7 @@ EOF
}
}
$oPage->SetCurrentTab('');
*/
if ($oObjectToClone != null)
{
@@ -1377,7 +1396,7 @@ EOF
return $aDetails;
}
protected function FlattenZList($aList)
protected static function FlattenZList($aList)
{
$aResult = array();
foreach($aList as $value)

View File

@@ -355,12 +355,15 @@ class FileDoc extends Document
* Overload the display of the properties to add a tab (the first one)
* with the preview of the document
*/
public function DisplayBareProperties(WebPage $oPage)
public function DisplayBareProperties(WebPage $oPage, $bEditMode = false)
{
if (!$bEditMode)
{
$oPage->SetCurrentTab(Dict::S('Class:Document:PreviewTab'));
$oPage->add($this->DisplayDocumentInline($oPage, 'contents'));
$oPage->SetCurrentTab(Dict::S('UI:PropertiesTab'));
parent::DisplayBareProperties($oPage);
}
parent::DisplayBareProperties($oPage, $bEditMode);
}
}
@@ -435,10 +438,12 @@ class Subnet extends cmdbAbstractObject
$this->Set('name', $sName);
}
function DisplayBareRelations(WebPage $oPage)
function DisplayBareRelations(WebPage $oPage, $bEditMode = false)
{
parent::DisplayBareRelations($oPage);
parent::DisplayBareRelations($oPage, $bEditMode);
if (!$bEditMode)
{
$oPage->SetCurrentTab(Dict::S('Class:Subnet/Tab:IPUsage'));
$bit_ip = ip2long($this->Get('ip'));
@@ -481,6 +486,7 @@ class Subnet extends cmdbAbstractObject
}
}
}
}
class Patch extends cmdbAbstractObject
{