diff --git a/application/cmdbabstract.class.inc.php b/application/cmdbabstract.class.inc.php
index c645b870c..ad471e4f1 100644
--- a/application/cmdbabstract.class.inc.php
+++ b/application/cmdbabstract.class.inc.php
@@ -1565,8 +1565,8 @@ EOF
case 'LinkedSet':
$aEventsList[] ='validate';
$aEventsList[] ='change';
- $oWidget = new UILinksWidget($sClass, $sAttCode, $iId, $sNameSuffix, $oAttDef->DuplicatesAllowed());
- $sHTMLValue = $oWidget->Display($oPage, $value);
+ $oWidget = new UILinksWidget($sClass, $sAttCode, $iId, $sNameSuffix, $oAttDef->DuplicatesAllowed(), $aArgs);
+ $sHTMLValue = $oWidget->Display($oPage, $value, array(), '', $this);
break;
case 'Document':
@@ -1733,7 +1733,7 @@ EOF
if ($iKey > 0)
{
// The object already exists in the database, it's a modification
- $sButtons = "\n";
+ $sButtons = "\n";
$sButtons .= "\n";
$sButtons .= " \n";
$sButtons .= "\n";
@@ -1819,6 +1819,10 @@ EOF
$oPage->SetCurrentTab(Dict::S('UI:PropertiesTab'));
$aFieldsMap = $this->DisplayBareProperties($oPage, true, $sPrefix, $aExtraParams);
+ if ($iKey > 0)
+ {
+ $aFieldsMap['id'] = $sPrefix.'_id';
+ }
// Now display the relations, one tab per relation
if (!isset($aExtraParams['noRelations']))
{
diff --git a/application/ui.linkswidget.class.inc.php b/application/ui.linkswidget.class.inc.php
index b06ca81c0..96289a5c6 100644
--- a/application/ui.linkswidget.class.inc.php
+++ b/application/ui.linkswidget.class.inc.php
@@ -34,6 +34,7 @@ class UILinksWidget
protected $m_iInputId;
protected $m_aAttributes;
protected $m_sExtKeyToRemote;
+ protected $m_sExtKeyToMe;
protected $m_sLinkedClass;
protected $m_sRemoteClass;
protected $m_bDuplicatesAllowed;
@@ -50,6 +51,7 @@ class UILinksWidget
$oAttDef = MetaModel::GetAttributeDef($this->m_sClass, $this->m_sAttCode);
$this->m_sLinkedClass = $oAttDef->GetLinkedClass();
$this->m_sExtKeyToRemote = $oAttDef->GetExtKeyToRemote();
+ $this->m_sExtKeyToMe = $oAttDef->GetExtKeyToMe();
$oLinkingAttDef = MetaModel::GetAttributeDef($this->m_sLinkedClass, $this->m_sExtKeyToRemote);
$this->m_sRemoteClass = $oLinkingAttDef->GetTargetClass();
$sExtKeyToMe = $oAttDef->GetExtKeyToMe();
@@ -97,7 +99,7 @@ class UILinksWidget
* @param Hash $aArgs Extra context arguments
* @return string The HTML fragment of the one-row form
*/
- protected function GetFormRow(WebPage $oP, DBObject $oLinkedObj, $linkObjOrId = null, $aArgs = array() )
+ protected function GetFormRow(WebPage $oP, DBObject $oLinkedObj, $linkObjOrId = null, $aArgs = array(), $oCurrentObj )
{
$sPrefix = "$this->m_sAttCode{$this->m_sNameSuffix}";
$aRow = array();
@@ -107,6 +109,7 @@ class UILinksWidget
$sPrefix .= "[$key][";
$sNameSuffix = "]"; // To make a tabular form
$aArgs['prefix'] = $sPrefix;
+ $aArgs['this'] = $linkObjOrId;
$aRow['form::checkbox'] = "m_iInputId.".OnSelectChange();\" value=\"$key\">";
$aRow['form::checkbox'] .= "";
foreach($this->m_aEditableFields as $sFieldCode)
@@ -122,10 +125,12 @@ class UILinksWidget
// form for creating a new record
$sPrefix .= "[$linkObjOrId][";
$oNewLinkObj = MetaModel::NewObject($this->m_sLinkedClass);
- $oNewLinkObj->Set($this->m_sExtKeyToRemote, -$linkObjOrId);
- $oNewLinkObj->ComputeValues();
+ $oRemoteObj = MetaModel::GetObject($this->m_sRemoteClass, -$linkObjOrId);
+ $oNewLinkObj->Set($this->m_sExtKeyToRemote, $oRemoteObj); // Setting the extkey with the object alsoo fills the related external fields
+ $oNewLinkObj->Set($this->m_sExtKeyToMe, $oCurrentObj); // Setting the extkey with the object alsoo fills the related external fields
$sNameSuffix = "]"; // To make a tabular form
$aArgs['prefix'] = $sPrefix;
+ $aArgs['this'] = $oNewLinkObj;
$aRow['form::checkbox'] = "m_iInputId.".OnSelectChange();\" value=\"$linkObjOrId\">";
$aRow['form::checkbox'] .= "";
foreach($this->m_aEditableFields as $sFieldCode)
@@ -210,9 +215,11 @@ class UILinksWidget
* @param WebPage $oP The web page used for all the output
* @param DBObjectSet The initial value of the linked set
* @param Hash $aArgs Extra context arguments
+ * @param string $sFormPrefix prefix of the fields in the current form
+ * @param DBObject $oCurrentObj the current object to which the linkset is related
* @return string The HTML fragment to be inserted into the page
*/
- public function Display(WebPage $oPage, DBObjectSet $oValue, $aArgs = array())
+ public function Display(WebPage $oPage, DBObjectSet $oValue, $aArgs = array(), $sFormPrefix, $oCurrentObj)
{
$sHtmlValue = '';
$sTargetClass = self::GetTargetClass($this->m_sClass, $this->m_sAttCode);
@@ -226,19 +233,20 @@ class UILinksWidget
if ($oCurrentLink->IsNew())
{
$key = -$oLinkedObj->GetKey();
- $aForm[$key] = $this->GetFormRow($oPage, $oLinkedObj, $key, $aArgs);
+ $aForm[$key] = $this->GetFormRow($oPage, $oLinkedObj, $key, $aArgs, $oCurrentObj);
}
else
{
$key = $oCurrentLink->GetKey();
- $aForm[$key] = $this->GetFormRow($oPage, $oLinkedObj, $oCurrentLink, $aArgs);
+ $aForm[$key] = $this->GetFormRow($oPage, $oLinkedObj, $oCurrentLink, $aArgs, $oCurrentObj);
}
}
$sHtmlValue .= $this->DisplayFormTable($oPage, $this->m_aTableConfig, $aForm);
$sDuplicates = ($this->m_bDuplicatesAllowed) ? 'true' : 'false';
+ $sWizHelper = 'oWizardHelper'.$this->m_sFormPrefix;
$oPage->add_ready_script(<<m_iInputId} = new LinksWidget('{$this->m_sAttCode}{$this->m_sNameSuffix}', '{$this->m_sClass}', '{$this->m_sAttCode}', '{$this->m_iInputId}', '{$this->m_sNameSuffix}', $sDuplicates);
+ oWidget{$this->m_iInputId} = new LinksWidget('{$this->m_sAttCode}{$this->m_sNameSuffix}', '{$this->m_sClass}', '{$this->m_sAttCode}', '{$this->m_iInputId}', '{$this->m_sNameSuffix}', $sDuplicates, $sWizHelper);
oWidget{$this->m_iInputId}.Init();
EOF
);
@@ -347,7 +355,7 @@ EOF
$oBlock->Display($oP, "ResultsToAdd_{$this->m_sAttCode}", array('menu' => false, 'cssCount'=> '#count_'.$this->m_sAttCode.$this->m_sNameSuffix , 'selection_mode' => true)); // Don't display the 'Actions' menu on the results
}
- public function DoAddObjects(WebPage $oP, $oFullSetFilter)
+ public function DoAddObjects(WebPage $oP, $oFullSetFilter, $oCurrentObj)
{
$aLinkedObjectIds = utils::ReadMultipleSelection($oFullSetFilter);
@@ -356,7 +364,7 @@ EOF
$oLinkedObj = MetaModel::GetObject($this->m_sRemoteClass, $iObjectId);
if (is_object($oLinkedObj))
{
- $aRow = $this->GetFormRow($oP, $oLinkedObj, -$iObjectId ); // Not yet created link get negative Ids
+ $aRow = $this->GetFormRow($oP, $oLinkedObj, -$iObjectId, array(), $oCurrentObj ); // Not yet created link get negative Ids
$oP->add($this->DisplayFormRow($oP, $this->m_aTableConfig, $aRow, -$iObjectId));
}
else
diff --git a/js/linkswidget.js b/js/linkswidget.js
index e5db1dcc4..ef7980bb6 100644
--- a/js/linkswidget.js
+++ b/js/linkswidget.js
@@ -1,5 +1,5 @@
// JavaScript Document
-function LinksWidget(id, sClass, sAttCode, iInputId, sSuffix, bDuplicates)
+function LinksWidget(id, sClass, sAttCode, iInputId, sSuffix, bDuplicates, oWizHelper)
{
this.id = id;
this.iInputId = iInputId;
@@ -7,6 +7,7 @@ function LinksWidget(id, sClass, sAttCode, iInputId, sSuffix, bDuplicates)
this.sAttCode = sAttCode;
this.sSuffix = sSuffix;
this.bDuplicates = bDuplicates;
+ this.oWizardHelper = oWizHelper;
var me = this;
this.Init = function()
{
@@ -202,6 +203,16 @@ function LinksWidget(id, sClass, sAttCode, iInputId, sSuffix, bDuplicates)
// }
theMap['operation'] = 'doAddObjects';
+ if (me.oWizardHelper == null)
+ {
+ theMap['json'] = '';
+ }
+ else
+ {
+ // Not inside a "search form", updating a real object
+ me.oWizardHelper.UpdateWizard();
+ theMap['json'] = me.oWizardHelper.ToJSON();
+ }
$('#busy_'+me.iInputId).html('
');
// Run the query and display the results
$.post( GetAbsoluteUrlAppRoot()+'pages/ajax.render.php', theMap,
diff --git a/pages/ajax.render.php b/pages/ajax.render.php
index d7f90dd6c..5fe40e0ac 100644
--- a/pages/ajax.render.php
+++ b/pages/ajax.render.php
@@ -297,6 +297,9 @@ try
$sSuffix = utils::ReadParam('sSuffix', '');
$sRemoteClass = utils::ReadParam('sRemoteClass', $sClass, false, 'class');
$bDuplicates = (utils::ReadParam('bDuplicates', 'false') == 'false') ? false : true;
+ $sJson = utils::ReadParam('json', '', false, 'raw_data');
+ $oWizardHelper = WizardHelper::FromJSON($sJson);
+ $oObj = $oWizardHelper->GetTargetObject();
$oWidget = new UILinksWidget($sClass, $sAttCode, $iInputId, $sSuffix, $bDuplicates);
if ($sFilter != '')
{
@@ -306,7 +309,7 @@ try
{
$oFullSetFilter = new DBObjectSearch($sRemoteClass);
}
- $oWidget->DoAddObjects($oPage, $oFullSetFilter);
+ $oWidget->DoAddObjects($oPage, $oFullSetFilter, $oObj);
break;
case 'wizard_helper_preview':