Allow updating/recomputing of read-only attributes on the fly in the edit form.

Also fixed a regerssion due to #446

SVN:trunk[1457]
This commit is contained in:
Denis Flaven
2011-08-16 15:58:09 +00:00
parent 1e20253229
commit cb55a75bcf
3 changed files with 25 additions and 15 deletions

View File

@@ -487,8 +487,8 @@ abstract class cmdbAbstractObject extends CMDBObject implements iDisplay
}
// Attribute is read-only
$sHTMLValue = $this->GetAsHTML($sAttCode);
$sHTMLValue .= '<input type="hidden" id="'.$sInputId.'" name="attr_'.$sPrefix.$sAttCode.'" value="'.htmlentities($this->Get($sAttCode), ENT_QUOTES, 'UTF-8').'"/>';
$sHTMLValue = "<span id=\"field_{$sInputId}\">".$this->GetAsHTML($sAttCode);
$sHTMLValue .= '<input type="hidden" id="'.$sInputId.'" name="attr_'.$sPrefix.$sAttCode.'" value="'.htmlentities($this->Get($sAttCode), ENT_QUOTES, 'UTF-8').'"/></span>';
$aFieldsMap[$sAttCode] = $sInputId;
$sComments = $sSynchroIcon;
}

View File

@@ -125,7 +125,7 @@ class WizardHelper
{
$oObj->Set(MetaModel::GetStateAttributeCode($this->m_aData['m_sClass']), $this->m_aData['m_sState']);
}
$oObj->DoComputeValues();
return $oObj;
}

View File

@@ -317,7 +317,7 @@ try
break;
case 'wizard_helper':
$oPage->SetContentType('application/json');
$oPage->SetContentType('text/html');
$sJson = utils::ReadParam('json_obj', '', false, 'raw_data');
$oWizardHelper = WizardHelper::FromJSON($sJson);
$oObj = $oWizardHelper->GetTargetObject();
@@ -335,17 +335,27 @@ try
$sId = $oWizardHelper->GetIdForField($sAttCode);
if ($sId != '')
{
// It may happen that the field we'd like to update does not
// exist in the form. For example, if the field should be hidden/read-only
// in the current state of the object
$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 immediatly validate the field when we reload it
$oPage->add_ready_script("$('#$sId').trigger('validate');");
$oWizardHelper->SetAllowedValuesHtml($sAttCode, $sHTMLValue);
$iFlags = $oObj->GetAttributeFlags($sAttCode);
if ($iFlags & OPT_ATT_READONLY)
{
$sHTMLValue = "<span id=\"field_{$sId}\">".$oObj->GetAsHTML($sAttCode);
$sHTMLValue .= '<input type="hidden" id="'.$sId.'" name="attr_'.$sFormPrefix.$sAttCode.'" value="'.htmlentities($this->Get($sAttCode), ENT_QUOTES, 'UTF-8').'"/></span>';
$oWizardHelper->SetAllowedValuesHtml($sAttCode, $sHTMLValue);
}
else
{
// It may happen that the field we'd like to update does not
// exist in the form. For example, if the field should be hidden/read-only
// in the current state of the object
$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');");
$oWizardHelper->SetAllowedValuesHtml($sAttCode, $sHTMLValue);
}
}
}
$oPage->add_script("oWizardHelper{$sFormPrefix}.m_oData=".$oWizardHelper->ToJSON().";\noWizardHelper{$sFormPrefix}.UpdateFields();\n");