Просмотр исходного кода

- Use the 'style' of the MenuBlock (inherited from DisplayBlock) to distinguish between a list of one object and the details of the same object.

git-svn-id: http://svn.code.sf.net/p/itop/code/trunk@2145 a333f486-631f-4898-b8df-5754b55c2be0
dflaven 13 лет назад
Родитель
Сommit
c74deda92c

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

@@ -99,7 +99,7 @@ abstract class cmdbAbstractObject extends CMDBObject implements iDisplay
 		// action menu
 		$oSingletonFilter = new DBObjectSearch(get_class($this));
 		$oSingletonFilter->AddCondition('id', $this->GetKey(), '=');
-		$oBlock = new MenuBlock($oSingletonFilter, 'popup', false);
+		$oBlock = new MenuBlock($oSingletonFilter, 'details', false);
 		$oBlock->Display($oPage, -1);
 	
 		// Master data sources

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

@@ -230,7 +230,7 @@ EOF;
 	
 	protected function GetActionsMenu(WebPage $oPage, $aExtraParams)
 	{
-		$oMenuBlock = new MenuBlock($this->oSet->GetFilter());
+		$oMenuBlock = new MenuBlock($this->oSet->GetFilter(), 'list');
 		
 		$sHtml = $oMenuBlock->GetRenderContent($oPage, $aExtraParams, $this->iListId);
 		return $sHtml;

+ 29 - 5
application/displayblock.class.inc.php

@@ -1130,8 +1130,13 @@ class HistoryBlock extends DisplayBlock
 	}
 }
 
+/**
+ * Displays the 'Actions' menu for a given (list of) object(s)
+ * The 'style' of the list (see constructor of DisplayBlock) can be either 'list' or 'details'
+ * For backward compatibility 'popup' is equivalent to 'list'...
+ */
 class MenuBlock extends DisplayBlock
-{
+{	
 	/**
 	 * Renders the "Actions" popup menu for the given set of objects
 	 * 
@@ -1143,6 +1148,10 @@ class MenuBlock extends DisplayBlock
 	 */
 	public function GetRenderContent(WebPage $oPage, $aExtraParams = array(), $sId)
 	{
+		if ($this->m_sStyle == 'popup') // popup is a synonym of 'list' for backward compatibility
+		{
+			$this->m_sStyle = 'list';
+		}
 		$sHtml = '';
 		$oAppContext = new ApplicationContext();
 		$sContext = $oAppContext->GetForLink();
@@ -1226,8 +1235,13 @@ class MenuBlock extends DisplayBlock
 				$sUrl = ApplicationContext::MakeObjectUrl($sClass, $id);
 				$aActions['UI:Menu:EMail'] = array ('label' => Dict::S('UI:Menu:EMail'), 'url' => "mailto:?subject=".urlencode($oObj->GetRawName())."&body=".urlencode($sUrl));
 				$aActions['UI:Menu:CSVExport'] = array ('label' => Dict::S('UI:Menu:CSVExport'), 'url' => "{$sRootUrl}pages/$sUIPage?operation=search&filter=$sFilter&format=csv{$sContext}");
-				$sOQL = addslashes($sFilterDesc);
-				$aActions['UI:Menu:AddToDashboard'] = array ('label' => Dict::S('UI:Menu:AddToDashboard'), 'url' => "#", 'onclick' => "return DashletCreationDlg('$sOQL')");
+				// The style tells us whether the menu is displayed on a list of one object, or on the details of the given object 
+				if ($this->m_sStyle == 'list')
+				{
+					// Actions specific to the list
+					$sOQL = addslashes($sFilterDesc);
+					$aActions['UI:Menu:AddToDashboard'] = array ('label' => Dict::S('UI:Menu:AddToDashboard'), 'url' => "#", 'onclick' => "return DashletCreationDlg('$sOQL')");
+				}
 			}
 			$this->AddMenuSeparator($aActions);
 			foreach (MetaModel::EnumPlugins('iApplicationUIExtension') as $oExtensionInstance)
@@ -1314,9 +1328,19 @@ class MenuBlock extends DisplayBlock
 			foreach (MetaModel::EnumPlugins('iApplicationUIExtension') as $oExtensionInstance)
 			{
 				$oSet->Rewind();
-				foreach($oExtensionInstance->EnumAllowedActions($oSet) as $sLabel => $sUrl)
+				foreach($oExtensionInstance->EnumAllowedActions($oSet) as $sLabel => $data)
 				{
-					$aActions[$sLabel] = array ('label' => $sLabel, 'url' => $sUrl);
+					if (is_array($data))
+					{
+						// New plugins can provide javascript handlers via the 'onclick' property
+						//TODO: enable extension of different menus by checking the 'target' property ??
+						$aActions[$sLabel] = array ('label' => $sLabel, 'url' => isset($data['url']) ? $data['url'] : '#', 'url' => isset($data['onclick']) ? $data['onclick'] : '');
+					}
+					else
+					{
+						// Backward compatibility with old plugins
+						$aActions[$sLabel] = array ('label' => $sLabel, 'url' => $data);
+					}
 				}
 			}
 		}