Browse Source

Internal regressions fixes !!!

git-svn-id: http://svn.code.sf.net/p/itop/code/trunk@1327 a333f486-631f-4898-b8df-5754b55c2be0
dflaven 14 năm trước cách đây
mục cha
commit
44760777ce
2 tập tin đã thay đổi với 62 bổ sung46 xóa
  1. 61 45
      application/cmdbabstract.class.inc.php
  2. 1 1
      js/linkswidget.js

+ 61 - 45
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'));
-		}
-		foreach($aAttList as $sAttCode)
-		{
-			$oAttDef = MetaModel::GetAttributeDef(get_class($this), $sAttCode);
-			
-			if ($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))
+			// 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)
 				{
-					foreach($aLinks as $id => $aData)
+					if (!($iFlags & (OPT_ATT_HIDDEN|OPT_ATT_SLAVE|OPT_ATT_READONLY)))
 					{
-						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);
-						}
+						// The case log is editable, append it to the list of fields to retrieve
+						$aAttList[] = $sAttCode;
 					}
 				}
-				$this->Set($sAttCode, $oLinkedSet);
 			}
-			else if ($oAttDef->IsWritable())
+		}
+		foreach($aAttList as $sAttCode)
+		{
+			$oAttDef = MetaModel::GetAttributeDef(get_class($this), $sAttCode);
+			
+			$iFlags = $this->GetAttributeFlags($sAttCode);
+			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_<attCode>

+ 1 - 1
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;
 		}