Explorar el Código

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

git-svn-id: http://svn.code.sf.net/p/itop/code/trunk@3186 a333f486-631f-4898-b8df-5754b55c2be0
dflaven hace 11 años
padre
commit
16da811bf6

+ 3 - 2
application/cmdbabstract.class.inc.php

@@ -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

+ 6 - 0
core/attributedef.class.inc.php

@@ -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()
 	{

+ 4 - 9
core/metamodel.class.php

@@ -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)

+ 12 - 4
pages/ajax.render.php

@@ -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);
 				}
 			}