From 44e188fa2cca019da961e87fe33a5738fc67c38c Mon Sep 17 00:00:00 2001 From: Pierre Goiffon Date: Mon, 10 Aug 2020 12:06:16 +0200 Subject: [PATCH] =?UTF-8?q?N=C2=B03198=20n:n=20relations=20in=20edit=20mod?= =?UTF-8?q?e=20:=20extkey=20to=20remote=20class=20is=20now=20editable?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/ui.linkswidget.class.inc.php | 43 +++++++++++++----------- 1 file changed, 24 insertions(+), 19 deletions(-) diff --git a/application/ui.linkswidget.class.inc.php b/application/ui.linkswidget.class.inc.php index 02804fc5db..970127b8b4 100644 --- a/application/ui.linkswidget.class.inc.php +++ b/application/ui.linkswidget.class.inc.php @@ -39,6 +39,7 @@ class UILinksWidget protected $m_sLinkedClass; protected $m_sRemoteClass; protected $m_bDuplicatesAllowed; + /** @var string[] list of editables attcodes */ protected $m_aEditableFields; protected $m_aTableConfig; @@ -93,6 +94,7 @@ class UILinksWidget 'label' => MetaModel::GetName($this->m_sRemoteClass), 'description' => MetaModel::GetClassDescription($this->m_sRemoteClass), ); + $this->m_aEditableFields[] = $this->m_sExtKeyToRemote; $aRemoteAttDefsToDisplay = MetaModel::GetZListAttDefsFilteredForIndirectRemoteClass($this->m_sRemoteClass); foreach ($aRemoteAttDefsToDisplay as $oRemoteAttDef) @@ -110,7 +112,7 @@ class UILinksWidget * * @param WebPage $oP Web page used for the ouput * @param DBObject $oLinkedObj Remote object - * @param mixed $linkObjOrId Either the object linked or a unique number for new link records to add + * @param DBObject|int $linkObjOrId Either the lnk object or a unique number for new link records to add * @param array $aArgs Extra context arguments * @param DBObject $oCurrentObj The object to which all the elements of the linked set refer to * @param int $iUniqueId A unique identifier of new links @@ -152,15 +154,17 @@ class UILinksWidget $aRow['form::checkbox'] = "m_iInputId.".OnSelectChange();\" value=\"$iKey\">"; foreach($this->m_aEditableFields as $sFieldCode) { - $sFieldId = $this->m_iInputId.'_'.$sFieldCode.'['.$linkObjOrId->GetKey().']'; - $sSafeId = utils::GetSafeId($sFieldId); - $sValue = $linkObjOrId->Get($sFieldCode); - $sDisplayValue = $linkObjOrId->GetEditValue($sFieldCode); - $oAttDef = MetaModel::GetAttributeDef($this->m_sLinkedClass, $sFieldCode); - $aRow[$sFieldCode] = '
'. - cmdbAbstractObject::GetFormElementForField($oP, $this->m_sLinkedClass, $sFieldCode, $oAttDef, $sValue, $sDisplayValue, $sSafeId, $sNameSuffix, 0, $aArgs). - '
'; - $aFieldsMap[$sFieldCode] = $sSafeId; + $sRowFieldCode = ($sFieldCode === $this->m_sExtKeyToRemote) ? 'static::key' : $sFieldCode; + $sFieldId = $this->m_iInputId.'_'.$sFieldCode.'['.$linkObjOrId->GetKey().']'; + $sSafeId = utils::GetSafeId($sFieldId); + $sValue = $linkObjOrId->Get($sFieldCode); + $sDisplayValue = $linkObjOrId->GetEditValue($sFieldCode); + $oAttDef = MetaModel::GetAttributeDef($this->m_sLinkedClass, $sFieldCode); + $aRow[$sRowFieldCode] = '
'. + cmdbAbstractObject::GetFormElementForField($oP, $this->m_sLinkedClass, $sFieldCode, $oAttDef, $sValue, + $sDisplayValue, $sSafeId, $sNameSuffix, 0, $aArgs). + '
'; + $aFieldsMap[$sFieldCode] = $sSafeId; } } @@ -216,19 +220,21 @@ EOF foreach($this->m_aEditableFields as $sFieldCode) { + $sRowFieldCode = ($sFieldCode === $this->m_sExtKeyToRemote) ? 'static::key' : $sFieldCode; $sFieldId = $this->m_iInputId.'_'.$sFieldCode.'['.-$iUniqueId.']'; $sSafeId = utils::GetSafeId($sFieldId); $sValue = $oNewLinkObj->Get($sFieldCode); $sDisplayValue = $oNewLinkObj->GetEditValue($sFieldCode); $oAttDef = MetaModel::GetAttributeDef($this->m_sLinkedClass, $sFieldCode); - $aRow[$sFieldCode] = '
'. - cmdbAbstractObject::GetFormElementForField($oP, $this->m_sLinkedClass, $sFieldCode, $oAttDef, $sValue, $sDisplayValue, $sSafeId /* id */, $sNameSuffix, 0, $aArgs). + $aRow[$sRowFieldCode] = '
'. + cmdbAbstractObject::GetFormElementForField($oP, $this->m_sLinkedClass, $sFieldCode, $oAttDef, $sValue, $sDisplayValue, + $sSafeId /* id */, $sNameSuffix, 0, $aArgs). '
'; $aFieldsMap[$sFieldCode] = $sSafeId; $oP->add_ready_script(<<m_iInputId}.OnValueChange($iKey, $iUniqueId, '$sFieldCode', '$sValue'); EOF - ); + ); } $sState = ''; } @@ -254,7 +260,6 @@ var {$aArgs['wizHelper']} = new WizardHelper('{$this->m_sLinkedClass}', '', '$sS {$aArgs['wizHelper']}.SetFieldsCount($iFieldsCount); EOF ); - $aRow['static::key'] = $oLinkedObj->GetHyperLink(); foreach(MetaModel::GetZListItems($this->m_sRemoteClass, 'list') as $sFieldCode) { $aRow['static::'.$sFieldCode] = $oLinkedObj->GetAsHTML($sFieldCode); @@ -303,7 +308,7 @@ EOF } $sHtml .= "\n"; $sHtml .= "\n"; - + // Content $sHtml .= "\n"; $sEmptyRowStyle = ''; @@ -312,16 +317,16 @@ EOF $sEmptyRowStyle = 'style="display:none;"'; } - foreach($aData as $iRowId => $aRow) + foreach ($aData as $iRowId => $aRow) { $sHtml .= $this->DisplayFormRow($oP, $aConfig, $aRow, $iRowId); - } + } $sHtml .= "m_sAttCode}{$this->m_sNameSuffix}_empty_row\">".Dict::S('UI:Message:EmptyList:UseAdd').""; $sHtml .= "\n"; - + // Footer $sHtml .= "\n"; - + return $sHtml; }