#930 AttributeExternalFields displayed in a form are automatically refreshed when their "parent" field is modified...

SVN:trunk[3186]
This commit is contained in:
Denis Flaven
2014-06-02 16:05:20 +00:00
parent 2d0ca37f27
commit 1572d9da5a
4 changed files with 25 additions and 15 deletions

View File

@@ -545,6 +545,7 @@ abstract class cmdbAbstractObject extends CMDBObject implements iDisplay
$oAttDef = MetaModel::GetAttributeDef($sClass, $sAttCode);
if ( (!$oAttDef->IsLinkSet()) && (($iFlags & OPT_ATT_HIDDEN) == 0))
{
$sInputId = $this->m_iFormId.'_'.$sAttCode;
if ($oAttDef->IsWritable())
{
if ($sStateAttCode == $sAttCode)
@@ -555,7 +556,6 @@ abstract class cmdbAbstractObject extends CMDBObject implements iDisplay
}
else
{
$sInputId = $this->m_iFormId.'_'.$sAttCode;
if ($iFlags & OPT_ATT_HIDDEN)
{
// Attribute is hidden, add a hidden input
@@ -604,7 +604,8 @@ abstract class cmdbAbstractObject extends CMDBObject implements iDisplay
}
else
{
$val = array('label' => '<span title="'.$oAttDef->GetDescription().'">'.$oAttDef->GetLabel().'</span>', 'value' => $this->GetAsHTML($sAttCode), 'comments' => $sComments, 'infos' => $sInfos);
$val = array('label' => '<span title="'.$oAttDef->GetDescription().'">'.$oAttDef->GetLabel().'</span>', 'value' => "<span id=\"field_{$sInputId}\">".$this->GetAsHTML($sAttCode)."</span>", 'comments' => $sComments, 'infos' => $sInfos);
$aFieldsMap[$sAttCode] = $sInputId;
}
}
else

View File

@@ -3251,6 +3251,12 @@ class AttributeExternalField extends AttributeDefinition
throw new CoreException("Unexpected value for argument iType: '$iType'");
}
}
public function GetPrerequisiteAttributes()
{
return array($this->Get("extkey_attcode"));
}
public function GetExtAttDef()
{

View File

@@ -593,15 +593,10 @@ abstract class MetaModel
$oAtt = self::GetAttributeDef($sClass, $sAttCode);
// Temporary implementation: later, we might be able to compute
// the dependencies, based on the attributes definition
// (allowed values and default values)
if ($oAtt->IsWritable())
{
return $oAtt->GetPrerequisiteAttributes();
}
else
{
return array();
}
// (allowed values and default values)
// Even non-writable attributes (like ExternalFields) can now have Prerequisites
return $oAtt->GetPrerequisiteAttributes();
}
/**
* Find all attributes that depend on the specified one (reverse of GetPrequisiteAttributes)

View File

@@ -593,10 +593,18 @@ try
$value = $oObj->Get($sAttCode);
$displayValue = $oObj->GetEditValue($sAttCode);
$oAttDef = MetaModel::GetAttributeDef($sClass, $sAttCode);
$iFlags = MetaModel::GetAttributeFlags($sClass, $oObj->GetState(), $sAttCode);
$sHTMLValue = cmdbAbstractObject::GetFormElementForField($oPage, $sClass, $sAttCode, $oAttDef, $value, $displayValue, $sId, '', $iFlags, array('this' => $oObj, 'formPrefix' => $sFormPrefix));
// Make sure that we immediately validate the field when we reload it
$oPage->add_ready_script("$('#$sId').trigger('validate');");
if (!$oAttDef->IsWritable())
{
// Even non-writable fields (like AttributeExternal) can be refreshed
$sHTMLValue = $oObj->GetAsHTML($sAttCode);
}
else
{
$iFlags = MetaModel::GetAttributeFlags($sClass, $oObj->GetState(), $sAttCode);
$sHTMLValue = cmdbAbstractObject::GetFormElementForField($oPage, $sClass, $sAttCode, $oAttDef, $value, $displayValue, $sId, '', $iFlags, array('this' => $oObj, 'formPrefix' => $sFormPrefix));
// Make sure that we immediately validate the field when we reload it
$oPage->add_ready_script("$('#$sId').trigger('validate');");
}
$oWizardHelper->SetAllowedValuesHtml($sAttCode, $sHTMLValue);
}
}