diff --git a/application/cmdbabstract.class.inc.php b/application/cmdbabstract.class.inc.php index 0621b96ff..2d79b41c4 100644 --- a/application/cmdbabstract.class.inc.php +++ b/application/cmdbabstract.class.inc.php @@ -209,6 +209,7 @@ abstract class cmdbAbstractObject extends CMDBObject implements iDisplay $oPage->add($this->GetBareProperties($oPage, $bEditMode)); // Special case to display the case log, if any... + // WARNING: if you modify the loop below, also check the corresponding code in UpdateObject and DisplayModifyForm foreach(MetaModel::ListAttributeDefs(get_class($this)) as $sAttCode => $oAttDef) { if ($oAttDef instanceof AttributeCaseLog) @@ -1717,6 +1718,7 @@ EOF } // Special case to display the case log, if any... + // WARNING: if you modify the loop below, also check the corresponding code in UpdateObject and DisplayDetails foreach(MetaModel::ListAttributeDefs($sClass) as $sAttCode => $oAttDef) { if ($oAttDef instanceof AttributeCaseLog) @@ -2157,57 +2159,28 @@ EOF if (!is_array($aAttList)) { $aAttList = $this->FlattenZList(MetaModel::GetZListItems(get_class($this), 'details')); + // Special case to process the case log, if any... + // WARNING: if you change this also check the functions DisplayModifyForm and DisplayCaseLog + foreach(MetaModel::ListAttributeDefs(get_class($this)) as $sAttCode => $oAttDef) + { + $iFlags = $this->GetAttributeFlags($sAttCode); + if ($oAttDef instanceof AttributeCaseLog) + { + if (!($iFlags & (OPT_ATT_HIDDEN|OPT_ATT_SLAVE|OPT_ATT_READONLY))) + { + // The case log is editable, append it to the list of fields to retrieve + $aAttList[] = $sAttCode; + } + } + } } foreach($aAttList as $sAttCode) { $oAttDef = MetaModel::GetAttributeDef(get_class($this), $sAttCode); - if ($oAttDef->IsLinkSet() && $oAttDef->IsIndirect()) + $iFlags = $this->GetAttributeFlags($sAttCode); + if ($oAttDef->IsWritable()) { - $aLinks = utils::ReadPostedParam("attr_{$sFormPrefix}{$sAttCode}", null); - $sLinkedClass = $oAttDef->GetLinkedClass(); - $sExtKeyToRemote = $oAttDef->GetExtKeyToRemote(); - $sExtKeyToMe = $oAttDef->GetExtKeyToMe(); - $oLinkedSet = DBObjectSet::FromScratch($sLinkedClass); - if (is_array($aLinks)) - { - foreach($aLinks as $id => $aData) - { - if (is_numeric($id)) - { - if ($id < 0) - { - // New link to be created, the opposite of the id (-$id) is the ID of the remote object - $oLink = MetaModel::NewObject($sLinkedClass); - $oLink->Set($sExtKeyToRemote, -$id); - $oLink->Set($sExtKeyToMe, $this->GetKey()); - } - else - { - // Existing link, potentially to be updated... - $oLink = MetaModel::GetObject($sLinkedClass, $id); - } - // Now populate the attributes - foreach($aData as $sName => $value) - { - if (MetaModel::IsValidAttCode($sLinkedClass, $sName)) - { - $oLinkAttDef = MetaModel::GetAttributeDef($sLinkedClass, $sName); - if ($oLinkAttDef->IsWritable()) - { - $oLink->Set($sName, $value); - } - } - } - $oLinkedSet->AddObject($oLink); - } - } - } - $this->Set($sAttCode, $oLinkedSet); - } - else if ($oAttDef->IsWritable()) - { - $iFlags = $this->GetAttributeFlags($sAttCode); if ( $iFlags & (OPT_ATT_HIDDEN | OPT_ATT_READONLY)) { // Non-visible, or read-only attribute, do nothing @@ -2220,6 +2193,49 @@ EOF $aErrors[] = Dict::Format('UI:AttemptingToSetASlaveAttribute_Name', $oAttDef->GetLabel()); } } + elseif ($oAttDef->IsLinkSet() && $oAttDef->IsIndirect()) + { + $aLinks = utils::ReadPostedParam("attr_{$sFormPrefix}{$sAttCode}", null); + $sLinkedClass = $oAttDef->GetLinkedClass(); + $sExtKeyToRemote = $oAttDef->GetExtKeyToRemote(); + $sExtKeyToMe = $oAttDef->GetExtKeyToMe(); + $oLinkedSet = DBObjectSet::FromScratch($sLinkedClass); + if (is_array($aLinks)) + { + foreach($aLinks as $id => $aData) + { + if (is_numeric($id)) + { + if ($id < 0) + { + // New link to be created, the opposite of the id (-$id) is the ID of the remote object + $oLink = MetaModel::NewObject($sLinkedClass); + $oLink->Set($sExtKeyToRemote, -$id); + $oLink->Set($sExtKeyToMe, $this->GetKey()); + } + else + { + // Existing link, potentially to be updated... + $oLink = MetaModel::GetObject($sLinkedClass, $id); + } + // Now populate the attributes + foreach($aData as $sName => $value) + { + if (MetaModel::IsValidAttCode($sLinkedClass, $sName)) + { + $oLinkAttDef = MetaModel::GetAttributeDef($sLinkedClass, $sName); + if ($oLinkAttDef->IsWritable()) + { + $oLink->Set($sName, $value); + } + } + } + $oLinkedSet->AddObject($oLink); + } + } + } + $this->Set($sAttCode, $oLinkedSet); + } elseif ($oAttDef->GetEditClass() == 'Document') { // There should be an uploaded file with the named attr_ diff --git a/js/linkswidget.js b/js/linkswidget.js index 8c9c867bf..443bd0e95 100644 --- a/js/linkswidget.js +++ b/js/linkswidget.js @@ -162,7 +162,7 @@ function LinksWidget(id, sClass, sAttCode, iInputId, sSuffix, bDuplicates) $(this).remove(); // Remove the selection for the next time the dialog re-opens }); // Retrieve the 'filter' definition - var table = $('#ResultsToAdd_member_list').find('table.listResults')[0]; + var table = $('#ResultsToAdd_'+me.id).find('table.listResults')[0]; theMap['filter'] = table.config.filter; theMap['extra_params'] = table.config.extra_params; }