Fixed the handling of default values in the object creation form.

SVN:trunk[472]
This commit is contained in:
Denis Flaven
2010-06-19 08:07:08 +00:00
parent c481830858
commit 4cb5651dca
2 changed files with 55 additions and 10 deletions

View File

@@ -949,11 +949,6 @@ abstract class cmdbAbstractObject extends CMDBObject
$sHTMLValue .= "<input type=\"hidden\" id=\"$iId\" name=\"attr_{$sAttCode}{$sNameSuffix}\" value=\"$value\" />\n";
$oPage->add_ready_script("\$('#label_$iId').autocomplete('./ajax.render.php', { scroll:true, minChars:3, onItemSelect:selectItem, onFindValue:findValue, formatItem:formatItem, autoFill:true, keyHolder:'#$iId', extraParams:{operation:'autocomplete', sclass:'$sClass',attCode:'".$sAttCode."'}});");
$oPage->add_ready_script("\$('#label_$iId').result( function(event, data, formatted) { if (data) { $('#{$iId}').val(data[1]); } } );");
// Prepopulate with a default value -- but no display value...
//if (!empty($value))
//{
// $oPage->add_ready_script("\$('#label_$iInputId').search( 'domino.combodo.com' );");
//}
$aEventsList[] ='change';
}
else
@@ -1176,6 +1171,46 @@ EOF
{
if ($oAttDef->IsWritable())
{
if ($oObjectToClone != null)
{
$sValue = $oObjectToClone->GetEditValue($sAttCode);
$aArgs['this'] = $oObjectToClone;
}
else
{
if(isset($aArgs['default'][$sAttCode]))
{
$sValue = $aArgs['default'][$sAttCode];
}
else
{
$sValue = $oAttDef->GetDefaultValue();
}
}
// Prepopulate with a default value -- but no display value...
$sDisplayValue = '';
if (!empty($sValue))
{
$aAllowedValues = MetaModel::GetAllowedValues_att($sClass, $sAttCode, $aArgs, '');
switch (count($aAllowedValues))
{
case 1:
case 0:
$sDisplayValue = $sValue;
break;
default:
$sDisplayValue = $sValue;
foreach($aAllowedValues as $key => $display)
{
if ($key == $sValue)
{
$sDisplayValue = $display;
break;
}
}
}
}
if ($sStateAttCode == $sAttCode)
{
// State attribute is always read-only from the UI
@@ -1193,13 +1228,11 @@ EOF
if ($iFlags & OPT_ATT_READONLY)
{
// Attribute is read-only
$sHTMLValue = ($oObjectToClone == null) ? '' : $oObjectToClone->GetAsHTML($sAttCode);
$sHTMLValue = ($oObjectToClone == null) ? $sDisplayValue : $oObjectToClone->GetAsHTML($sAttCode);
}
else
{
$sFieldId = 'att_'.$iFieldIndex;
$sValue = ($oObjectToClone == null) ? '' : $oObjectToClone->Get($sAttCode);
$sDisplayValue = ($oObjectToClone == null) ? '' : $oObjectToClone->GetEditValue($sAttCode);
$sHTMLValue = "<div id=\"field_{$sFieldId}\">".self::GetFormElementForField($oPage, $sClass, $sAttCode, $oAttDef, $sValue, $sDisplayValue, $sFieldId, '', $iFlags, $aArgs)."</div>";
$aFieldsMap[$sFieldId] = $sAttCode;
$aDetails[] = array('label' => $oAttDef->GetLabel(), 'value' => $sHTMLValue);

View File

@@ -664,7 +664,13 @@ try
$oP->add("<img src=\"".$oObjToClone->GetIcon()."\" style=\"margin-top:-30px; margin-right:10px; float:right\">\n");
$oP->add("<div class=\"wizContainer\">\n");
cmdbAbstractObject::DisplayCreationForm($oP, $sClass, $oObjToClone);
$aDefaults = utils::ReadParam('default', array());
$aContext = $oAppContext->GetAsHash();
foreach($aContext as $key => $value)
{
$aDefaults[$key] = $value;
}
cmdbAbstractObject::DisplayCreationForm($oP, $sClass, $oObjToClone, array( 'default' => $aDefaults));
$oP->add("</div>\n");
}
else
@@ -696,7 +702,13 @@ try
$oP->add("<h1>".Dict::Format('UI:CreationTitle_Class', $sClassLabel)."</h1>\n");
$oP->add("<div class=\"wizContainer\">\n");
$oP->add("<img src=\"".MetaModel::GetClassIcon($sClass)."\" style=\"margin-top:-30px; margin-right:10px; float:right\">\n");
cmdbAbstractObject::DisplayCreationForm($oP, $sClass, null /* $oObjToClone */);
$aDefaults = utils::ReadParam('default', array());
$aContext = $oAppContext->GetAsHash();
foreach($aContext as $key => $value)
{
$aDefaults[$key] = $value;
}
cmdbAbstractObject::DisplayCreationForm($oP, $sClass, null /* $oObjToClone */, array('default' => $aDefaults));
$oP->add("</div>\n");
break;