Bläddra i källkod

- Renamed the method 'UpdateObject' into 'UpdateObjectFromPostedForm' to avoid misunderstandings.
- Fixed (again !) Trac #427: unable to empty a linkset when editing an object.

git-svn-id: http://svn.code.sf.net/p/itop/code/trunk@1370 a333f486-631f-4898-b8df-5754b55c2be0

dflaven 14 år sedan
förälder
incheckning
846ba7d9fc

+ 1 - 1
application/cmdbabstract.class.inc.php

@@ -2325,7 +2325,7 @@ EOF
 	/**
 	 * Updates the object from the POSTed parameters (form)
 	 */
-	public function UpdateObject($sFormPrefix = '', $aAttList = null)
+	public function UpdateObjectFromPostedForm($sFormPrefix = '', $aAttList = null)
 	{
 		$aErrors = array();
 		$aValues = array();

+ 1 - 1
application/portalwebpage.class.inc.php

@@ -610,7 +610,7 @@ EOF
 	
 		$sClass = get_class($oObj);
 	
-		$oObj->UpdateObject('' /* form prefix */, $aAttList);
+		$oObj->UpdateObjectFromPostedForm('' /* form prefix */, $aAttList);
 	
 	   // Optional: apply a stimulus
 	   //

+ 1 - 1
application/ui.extkeywidget.class.inc.php

@@ -377,7 +377,7 @@ EOF
 	public function DoCreateObject($oPage)
 	{
 		$oObj = MetaModel::NewObject($this->sTargetClass);
-		$aErrors = $oObj->UpdateObject($this->iId);
+		$aErrors = $oObj->UpdateObjectFromPostedForm($this->iId);
 		if (count($aErrors) == 0)
 		{
 			$oMyChange = MetaModel::NewObject("CMDBChange");

+ 8 - 8
application/ui.linkswidget.class.inc.php

@@ -182,17 +182,17 @@ class UILinksWidget
 		
 		// Content
 		$sHtml .= "</tbody>\n";
-		if (count($aData) == 0)
+		$sEmptyRowStyle = '';
+		if (count($aData) != 0)
 		{
-			$sHtml .= "<tr id=\"{$this->m_sAttCode}{$this->m_sNameSuffix}_empty_row\"><td colspan=\"".count($aConfig)."\" style=\"text-align:center;\">".Dict::S('UI:Message:EmptyList:UseAdd')."<input type=\"hidden\" name=\"attr_{$this->m_sAttCode}{$this->m_sNameSuffix}\" value=\"\"></td></td>";
+			$sEmptyRowStyle = 'style="display:none;"';
 		}
-		else
+
+		$sHtml .= "<tr $sEmptyRowStyle id=\"{$this->m_sAttCode}{$this->m_sNameSuffix}_empty_row\"><td colspan=\"".count($aConfig)."\" style=\"text-align:center;\">".Dict::S('UI:Message:EmptyList:UseAdd')."<input type=\"hidden\" name=\"attr_{$this->m_sAttCode}{$this->m_sNameSuffix}\" value=\"\"></td></td>";
+		foreach($aData as $iRowId => $aRow)
 		{
-			foreach($aData as $iRowId => $aRow)
-			{
-				$sHtml .= $this->DisplayFormRow($oP, $aConfig, $aRow, $iRowId);
-			}		
-		}
+			$sHtml .= $this->DisplayFormRow($oP, $aConfig, $aRow, $iRowId);
+		}		
 		$sHtml .= "</tbody>\n";
 		
 		// Footer

+ 7 - 1
js/linkswidget.js

@@ -40,6 +40,12 @@ function LinksWidget(id, sClass, sAttCode, iInputId, sSuffix, bDuplicates)
 		// Re-run the zebra plugin to properly highlight the remaining lines & and take into account the removed ones
 		$('#linkedset_'+this.id+' .listResults').trigger('update').trigger("applyWidgets");
 		
+		if ($('$linkedset_'+this.id+' .selection').length == 0)
+		{
+			// All items were removed: add a dummy hidden input to make sure that the linkset will be updated (emptied) when posted
+			$('#'+me.id+'_empty_row').show();
+		}
+		
 	}
 
 	this.OnSelectChange = function()
@@ -204,7 +210,7 @@ function LinksWidget(id, sClass, sAttCode, iInputId, sSuffix, bDuplicates)
 				//console.log('Data: ' + data);
 				if (data != '')
 				{
-					$('#'+me.id+'_empty_row').remove();
+					$('#'+me.id+'_empty_row').hide();
 					$('#linkedset_'+me.id+' .listResults tbody').append(data);
 					$('#linkedset_'+me.id+' .listResults').trigger('update');
 					$('#linkedset_'+me.id+' .listResults').tableHover();

+ 3 - 3
pages/UI.php

@@ -971,7 +971,7 @@ EOF
 		foreach($aSelectedObj as $iId)
 		{
 			$oObj = MetaModel::GetObject($sClass, $iId);
-			$aErrors = $oObj->UpdateObject('');
+			$aErrors = $oObj->UpdateObjectFromPostedForm('');
 			$bResult = (count($aErrors) == 0);
 			if ($bResult)
 			{
@@ -1187,7 +1187,7 @@ EOF
 			}
 			else
 			{
-				$oObj->UpdateObject();
+				$oObj->UpdateObjectFromPostedForm();
 
 				if (!$oObj->IsModified())
 				{
@@ -1320,7 +1320,7 @@ EOF
 		else
 		{
 			$oObj = MetaModel::NewObject($sClass);
-			$oObj->UpdateObject();
+			$oObj->UpdateObjectFromPostedForm();
 		}
 		if (isset($oObj) && is_object($oObj))
 		{

+ 1 - 1
synchro/synchrodatasource.class.inc.php

@@ -456,7 +456,7 @@ EOF
 		return parent::GetAttributeFlags($sAttCode, $aReasons);
 	}
 		
-	public function UpdateObject($sFormPrefix = '', $sAttList = null)
+	public function UpdateObjectFromPostedForm($sFormPrefix = '', $sAttList = null)
 	{
 		parent::UpdateObject($sFormPrefix, $sAttList);
 		// And now read the other post parameters...