mirror of
https://github.com/Combodo/iTop.git
synced 2026-04-22 01:58:47 +02:00
Better initialization of objects from the "Context" values:
- map the parameters (for example for Provider Contract) - set the default values when creating a "secondary" object via the (+) button SVN:trunk[1391]
This commit is contained in:
@@ -204,6 +204,35 @@ class ApplicationContext
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes the given object with the default values provided by the context
|
||||
*/
|
||||
public function InitObjectFromContext(DBObject &$oObj)
|
||||
{
|
||||
$sClass = get_class($oObj);
|
||||
foreach($this->GetNames() as $key)
|
||||
{
|
||||
$aCallSpec = array($sClass, 'MapContextParam');
|
||||
if (is_callable($aCallSpec))
|
||||
{
|
||||
$sAttCode = call_user_func($aCallSpec, $key); // Returns null when there is no mapping for this parameter
|
||||
}
|
||||
|
||||
if (MetaModel::IsValidAttCode($sClass, $sAttCode))
|
||||
{
|
||||
$oAttDef = MetaModel::GetAttributeDef($sClass, $sAttCode);
|
||||
if ($oAttDef->IsWritable())
|
||||
{
|
||||
$value = $this->GetCurrentValue($key, null);
|
||||
if (!is_null($value))
|
||||
{
|
||||
$oObj->Set($sAttCode, $value);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static $m_sUrlMakerClass = null;
|
||||
|
||||
/**
|
||||
|
||||
@@ -322,10 +322,20 @@ EOF
|
||||
*/
|
||||
public function GetObjectCreationForm(WebPage $oPage)
|
||||
{
|
||||
// Set all the default values in an object and clone this "default" object
|
||||
$oNewObj = MetaModel::NewObject($this->sTargetClass);
|
||||
|
||||
// 1st - set context values
|
||||
$oAppContext = new ApplicationContext();
|
||||
$oAppContext->InitObjectFromContext($oNewObj);
|
||||
|
||||
// 2nd - set values from the page argument 'default'
|
||||
$oNewObj->UpdateObjectFromArg('default');
|
||||
|
||||
$sDialogTitle = addslashes($this->sTitle);
|
||||
$oPage->add('<div id="ac_create_'.$this->iId.'"><div class="wizContainer" style="vertical-align:top;"><div id="dcr_'.$this->iId.'">');
|
||||
$oPage->add("<h1>".MetaModel::GetClassIcon($this->sTargetClass)." ".Dict::Format('UI:CreationTitle_Class', MetaModel::GetName($this->sTargetClass))."</h1>\n");
|
||||
cmdbAbstractObject::DisplayCreationForm($oPage, $this->sTargetClass, null, array(), array('formPrefix' => $this->iId, 'noRelations' => true));
|
||||
cmdbAbstractObject::DisplayCreationForm($oPage, $this->sTargetClass, $oNewObj, array(), array('formPrefix' => $this->iId, 'noRelations' => true));
|
||||
$oPage->add('</div></div></div>');
|
||||
// $oPage->add_ready_script("\$('#ac_create_$this->iId').dialog({ width: $(window).width()*0.8, height: 'auto', autoOpen: false, modal: true, title: '$sDialogTitle'});\n");
|
||||
$oPage->add_ready_script("\$('#ac_create_$this->iId').dialog({ width: 'auto', height: 'auto', autoOpen: false, modal: true, title: '$sDialogTitle'});\n");
|
||||
|
||||
17
pages/UI.php
17
pages/UI.php
@@ -1087,22 +1087,7 @@ EOF
|
||||
$oObjToClone = MetaModel::NewObject($sRealClass);
|
||||
|
||||
// 1st - set context values
|
||||
$aContext = $oAppContext->GetAsHash();
|
||||
foreach($oAppContext->GetNames() as $key)
|
||||
{
|
||||
if (MetaModel::IsValidAttCode($sRealClass, $key))
|
||||
{
|
||||
$oAttDef = MetaModel::GetAttributeDef($sRealClass, $key);
|
||||
if ($oAttDef->IsWritable())
|
||||
{
|
||||
$value = $oAppContext->GetCurrentValue($key, null);
|
||||
if (!is_null($value))
|
||||
{
|
||||
$oObjToClone->Set($key, $value);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
$oAppContext->InitObjectFromContext($oObjToClone);
|
||||
|
||||
// 2nd - set values from the page argument 'default'
|
||||
$oObjToClone->UpdateObjectFromArg('default');
|
||||
|
||||
Reference in New Issue
Block a user