Преглед изворни кода

#770 Preserve list configuration (if dedicated) when creating a shortcut

git-svn-id: http://svn.code.sf.net/p/itop/code/trunk@2989 a333f486-631f-4898-b8df-5754b55c2be0
romainq пре 11 година
родитељ
комит
f21b226cab

+ 13 - 9
application/datatable.class.inc.php

@@ -1,5 +1,5 @@
 <?php
-// Copyright (C) 2010-2012 Combodo SARL
+// Copyright (C) 2010-2013 Combodo SARL
 //
 //   This file is part of iTop.
 //
@@ -292,13 +292,13 @@ EOF;
 	{
 		$sMenuTitle = Dict::S('UI:ConfigureThisList');
 		$sHtml = '<div class="itop_popup toolkit_menu" id="tk_'.$this->iListId.'"><ul><li><img src="../images/toolkit_menu.png"><ul>';
-		
+
 		$oMenuItem1 = new JSPopupMenuItem('iTop::ConfigureList', $sMenuTitle, "$('#datatable_dlg_".$this->iListId."').dialog('open');");
 		$aActions = array(
 			$oMenuItem1->GetUID() => $oMenuItem1->GetMenuItem(),
 		);
 		$this->oSet->Rewind();
-		utils::GetPopupMenuItems($oPage, iPopupMenuExtension::MENU_OBJLIST_TOOLKIT, $this->oSet, $aActions);
+		utils::GetPopupMenuItems($oPage, iPopupMenuExtension::MENU_OBJLIST_TOOLKIT, $this->oSet, $aActions, $this->sTableId);
 		$this->oSet->Rewind();
 		$sHtml .= $oPage->RenderPopupMenuItems($aActions);
 		return $sHtml;
@@ -764,7 +764,7 @@ class DataTableSettings implements Serializable
 		}		
 	}
 	
-	static public function GetTableSettings($aClassAliases, $sTableId = null)
+	static public function GetTableSettings($aClassAliases, $sTableId = null, $bOnlyOnTable = false)
 	{
 		$pref = null;
 		$oSettings = new DataTableSettings($aClassAliases, $sTableId);
@@ -777,8 +777,11 @@ class DataTableSettings implements Serializable
 		
 		if ($pref == null)
 		{
-			// Try the global preferred values for this class / set of classes
-			$pref = appUserPreferences::GetPref($oSettings->GetPrefsKey(null), null);
+			if (!$bOnlyOnTable)
+			{
+				// Try the global preferred values for this class / set of classes
+				$pref = appUserPreferences::GetPref($oSettings->GetPrefsKey(null), null);
+			}
 			if ($pref == null)
 			{
 				// no such settings, use the default values provided by the data model
@@ -808,12 +811,13 @@ class DataTableSettings implements Serializable
 		return $aSortOrder;
 	}
 	
-	public function Save()
+	public function Save($sTargetTableId = null)
 	{
-		if ($this->sTableId == null) return false; // Cannot save, the table is not identified, use SaveAsDefault instead
+		$sSaveId = is_null($sTargetTableId) ? $this->sTableId : $sTargetTableId;
+		if ($sSaveId == null) return false; // Cannot save, the table is not identified, use SaveAsDefault instead
 		
 		$sSettings = $this->serialize();
-		appUserPreferences::SetPref($this->GetPrefsKey($this->sTableId), $sSettings);
+		appUserPreferences::SetPref($this->GetPrefsKey($sSaveId), $sSettings);
 		return true;
 	}
 

+ 0 - 111
application/displayblock.class.inc.php

@@ -1584,114 +1584,3 @@ class MenuBlock extends DisplayBlock
 		}
 	}	
 }
-
-/**
- * Some dummy menus for testing
- */
-class ExtraMenus implements iPopupMenuExtension
-{
-	/*
-	const MENU_OBJLIST_ACTIONS = 1; 	// $param is a DBObjectSet containing the list of objects
-	const MENU_OBJLIST_TOOLKIT = 2;		// $param is a DBObjectSet containing the list of objects
-	const MENU_OBJDETAILS_ACTIONS = 3;	// $param is a DBObject instance: the object currently displayed
-	const MENU_DASHBOARD_ACTIONS = 4;	// $param is a Dashboard instance: the dashboard currently displayed
-	const MENU_USER_ACTIONS = 5;		// $param is a null ??
-	*/
-	
-	/**
-	 * Get the list of items to be added to a menu. The items will be inserted in the menu in the order of the returned array
-	 * @param int $iMenuId The identifier of the type of menu, as listed by the constants MENU_xxx above
-	 * @param mixed $param Depends on $iMenuId see the constants define above
-	 * @return Array An array of ApplicationPopupMenuItem or an empty array if no action is to be added to the menu
-	 */
-	public static function EnumItems($iMenuId, $param)
-	{
-		switch($iMenuId)
-		{
-			/*
-			case iPopupMenuExtension::MENU_OBJLIST_ACTIONS:
-			// $param is a DBObjectSet
-			$aResult = array(
-				new JSPopupMenuItem('Test::Item1', 'List Test 1', "alert('Test 1')"),
-				new JSPopupMenuItem('Test::Item2', 'List Test 2', "alert('Test 2')"),
-			);
-			break;
-		
-				$this->AddMenuSeparator($aActions);
-				$sUrl = utils::GetAbsoluteUrlAppRoot();
-				$aActions['UI:Menu:EMail'] = array ('label' => Dict::S('UI:Menu:EMail'), 'url' => "mailto:?subject=$sFilterDesc&body=".urlencode("{$sUrl}pages/$sUIPage?operation=search&filter=".urlencode($sFilter)."{$sContext}"));
-				$aActions['UI:Menu:CSVExport'] = array ('label' => Dict::S('UI:Menu:CSVExport'), 'url' => "{$sRootUrl}pages/$sUIPage?operation=search&filter=".urlencode($sFilter)."&format=csv{$sContext}");
-				$sOQL = addslashes($sFilterDesc);
-				$aActions['UI:Menu:AddToDashboard'] = array ('label' => Dict::S('UI:Menu:AddToDashboard'), 'url' => "#", 'onclick' => "return DashletCreationDlg('$sOQL')");
-			*/
-			
-			case iPopupMenuExtension::MENU_OBJLIST_TOOLKIT:
-			// $param is a DBObjectSet
-			$oAppContext = new ApplicationContext();
-			$sContext = $oAppContext->GetForLink();
-			$sUIPage = cmdbAbstractObject::ComputeStandardUIPage($param->GetFilter()->GetClass());
-			$sOQL = addslashes($param->GetFilter()->ToOQL(true));
-			$sFilter = urlencode($param->GetFilter()->serialize());
-			$sUrl = utils::GetAbsoluteUrlAppRoot()."pages/$sUIPage?operation=search&filter=".$sFilter."&{$sContext}";
-			$aResult = array(
-				new SeparatorPopupMenuItem(),
-				// Static menus: Email this page, CSV Export & Add to Dashboard
-				new URLPopupMenuItem('UI:Menu:EMail', Dict::S('UI:Menu:EMail'), "mailto:?body=".urlencode($sUrl).' '), // Add an extra space to make it work in Outlook
-				new URLPopupMenuItem('UI:Menu:CSVExport', Dict::S('UI:Menu:CSVExport'), $sUrl."&format=csv"),
-				new JSPopupMenuItem('UI:Menu:AddToDashboard', Dict::S('UI:Menu:AddToDashboard'), "DashletCreationDlg('$sOQL')"),
-				new JSPopupMenuItem('UI:Menu:ShortcutList', Dict::S('UI:Menu:ShortcutList'), "ShortcutListDlg('$sOQL', '$sContext')"),
-			);
-			break;
-			
-			
-			case iPopupMenuExtension::MENU_OBJDETAILS_ACTIONS:
-			// $param is a DBObject
-			$oObj = $param;
-			$oFilter = DBobjectSearch::FromOQL("SELECT ".get_class($oObj)." WHERE id=".$oObj->GetKey());
-			$sFilter = $oFilter->serialize();
-			$sUrl = ApplicationContext::MakeObjectUrl(get_class($oObj), $oObj->GetKey());
-			$sUIPage = cmdbAbstractObject::ComputeStandardUIPage(get_class($oObj));
-			$oAppContext = new ApplicationContext();
-			$sContext = $oAppContext->GetForLink();
-			$aResult = array(
-				new SeparatorPopupMenuItem(),
-				// Static menus: Email this page & CSV Export
-				new URLPopupMenuItem('UI:Menu:EMail', Dict::S('UI:Menu:EMail'), "mailto:?subject=".urlencode($oObj->GetRawName())."&body=".urlencode($sUrl).' '), // Add an extra space to make it work in Outlook
-				new URLPopupMenuItem('UI:Menu:CSVExport', Dict::S('UI:Menu:CSVExport'), utils::GetAbsoluteUrlAppRoot()."pages/$sUIPage?operation=search&filter=".urlencode($sFilter)."&format=csv&{$sContext}"),
-			);
-			break;
-			
-			
-			case iPopupMenuExtension::MENU_DASHBOARD_ACTIONS:
-			// $param is a Dashboard
-			$oAppContext = new ApplicationContext();
-			$aParams = $oAppContext->GetAsHash();
-			$sMenuId = ApplicationMenu::GetActiveNodeId();
-			$sDlgTitle = addslashes(Dict::S('UI:ImportDashboardTitle'));
-			$sDlgText = addslashes(Dict::S('UI:ImportDashboardText'));
-			$sCloseBtn = addslashes(Dict::S('UI:Button:Cancel'));
-			$aResult = array(
-				new SeparatorPopupMenuItem(),
-				new URLPopupMenuItem('UI:ExportDashboard', Dict::S('UI:ExportDashBoard'), utils::GetAbsoluteUrlAppRoot().'pages/ajax.render.php?operation=export_dashboard&id='.$sMenuId),
-				new JSPopupMenuItem('UI:ImportDashboard', Dict::S('UI:ImportDashBoard'), "UploadDashboard({dashboard_id: '$sMenuId', title: '$sDlgTitle', text: '$sDlgText', close_btn: '$sCloseBtn' })"),
-			);
-			break;
-			
-			/*
-			case iPopupMenuExtension::MENU_USER_ACTIONS:
-			// $param is null ??
-			$aResult = array(
-				new SeparatorPopupMenuItem(),
-				new JSPopupMenuItem('Test::Item1', 'Reset preferences...', "alert('Test 1')"),
-				new JSPopupMenuItem('Test::Item2', 'Do Something Stupid', "alert('Hey Dude !')"),
-			);
-			break;
-			*/
-			
-			default:
-			// Unknown type of menu, do nothing
-			$aResult = array();
-		}
-		return $aResult;
-	}
-}

+ 18 - 5
application/shortcut.class.inc.php

@@ -209,7 +209,19 @@ class ShortcutOQL extends Shortcut
 			
 	}
 
-	public static function GetCreationForm($sOQL = null)
+	public function CloneTableSettings($sSourceTableId)
+	{
+		$oFilter = DBObjectSearch::FromOQL($this->Get('oql'));
+		$oCustomSettings = DataTableSettings::GetTableSettings($oFilter->GetSelectedClasses(), $sSourceTableId, true /*dedicated settings only*/);
+		if (!is_null($oCustomSettings))
+		{
+			//$oTableSettings = new DataTableSettings($oFilter->GetSelectedClasses(), 'shortcut_'.$this->GetKey());
+			//$oTableSettings->unserialize($sSerializedSettings);
+			$oCustomSettings->Save('shortcut_'.$this->GetKey());
+		}
+	}
+
+	public static function GetCreationForm($sOQL = null, $sSourceTableId = null)
 	{
 		$oForm = new DesignerForm();
 
@@ -248,19 +260,20 @@ class ShortcutOQL extends Shortcut
 		$oField->SetMandatory(false);
 		$oForm->AddField($oField);
 
-		//$oField = new DesignerLongTextField('oql', Dict::S('Class:Shortcut/Attribute:oql'), $sOQL);
-		//$oField->SetMandatory();
 		$oField = new DesignerHiddenField('oql', '', $sOQL);
 		$oForm->AddField($oField);
 
+		$oField = new DesignerHiddenField('source_table_id', '', $sSourceTableId);
+		$oForm->AddField($oField);
+
 		return $oForm;
 	}
 
-	public static function GetCreationDlgFromOQL($oPage, $sOQL)
+	public static function GetCreationDlgFromOQL($oPage, $sOQL, $sSourceTableId)
 	{
 		$oPage->add('<div id="shortcut_creation_dlg">');
 
-		$oForm = self::GetCreationForm($sOQL);
+		$oForm = self::GetCreationForm($sOQL, $sSourceTableId);
 
 		$oForm->Render($oPage);
 		$oPage->add('</div>');

+ 69 - 3
application/utils.inc.php

@@ -1,5 +1,5 @@
 <?php
-// Copyright (C) 2010-2012 Combodo SARL
+// Copyright (C) 2010-2013 Combodo SARL
 //
 //   This file is part of iTop.
 //
@@ -766,10 +766,76 @@ class utils
 	}
 	
 	/**
-	 * Get the "Back" button to go out of the current environment
+	 * Merge standard menu items with plugin provided menus items
 	 */
-	public static function GetPopupMenuItems($oPage, $iMenuId, $param, &$aActions)
+	public static function GetPopupMenuItems($oPage, $iMenuId, $param, &$aActions, $sTableId = null)
 	{
+		// 1st - add standard built-in menu items
+		// 
+		switch($iMenuId)
+		{
+			case iPopupMenuExtension::MENU_OBJLIST_TOOLKIT:
+			// $param is a DBObjectSet
+			$oAppContext = new ApplicationContext();
+			$sContext = $oAppContext->GetForLink();
+			$sSourceTableId = is_null($sTableId) ? '' : $sTableId;
+			$sUIPage = cmdbAbstractObject::ComputeStandardUIPage($param->GetFilter()->GetClass());
+			$sOQL = addslashes($param->GetFilter()->ToOQL(true));
+			$sFilter = urlencode($param->GetFilter()->serialize());
+			$sUrl = utils::GetAbsoluteUrlAppRoot()."pages/$sUIPage?operation=search&filter=".$sFilter."&{$sContext}";
+			$aResult = array(
+				new SeparatorPopupMenuItem(),
+				// Static menus: Email this page, CSV Export & Add to Dashboard
+				new URLPopupMenuItem('UI:Menu:EMail', Dict::S('UI:Menu:EMail'), "mailto:?body=".urlencode($sUrl).' '), // Add an extra space to make it work in Outlook
+				new URLPopupMenuItem('UI:Menu:CSVExport', Dict::S('UI:Menu:CSVExport'), $sUrl."&format=csv"),
+				new JSPopupMenuItem('UI:Menu:AddToDashboard', Dict::S('UI:Menu:AddToDashboard'), "DashletCreationDlg('$sOQL')"),
+				new JSPopupMenuItem('UI:Menu:ShortcutList', Dict::S('UI:Menu:ShortcutList'), "ShortcutListDlg('$sOQL', '$sSourceTableId', '$sContext')"),
+			);
+			break;
+
+			case iPopupMenuExtension::MENU_OBJDETAILS_ACTIONS:
+			// $param is a DBObject
+			$oObj = $param;
+			$oFilter = DBobjectSearch::FromOQL("SELECT ".get_class($oObj)." WHERE id=".$oObj->GetKey());
+			$sFilter = $oFilter->serialize();
+			$sUrl = ApplicationContext::MakeObjectUrl(get_class($oObj), $oObj->GetKey());
+			$sUIPage = cmdbAbstractObject::ComputeStandardUIPage(get_class($oObj));
+			$oAppContext = new ApplicationContext();
+			$sContext = $oAppContext->GetForLink();
+			$aResult = array(
+				new SeparatorPopupMenuItem(),
+				// Static menus: Email this page & CSV Export
+				new URLPopupMenuItem('UI:Menu:EMail', Dict::S('UI:Menu:EMail'), "mailto:?subject=".urlencode($oObj->GetRawName())."&body=".urlencode($sUrl).' '), // Add an extra space to make it work in Outlook
+				new URLPopupMenuItem('UI:Menu:CSVExport', Dict::S('UI:Menu:CSVExport'), utils::GetAbsoluteUrlAppRoot()."pages/$sUIPage?operation=search&filter=".urlencode($sFilter)."&format=csv&{$sContext}"),
+			);
+			break;
+
+			case iPopupMenuExtension::MENU_DASHBOARD_ACTIONS:
+			// $param is a Dashboard
+			$oAppContext = new ApplicationContext();
+			$aParams = $oAppContext->GetAsHash();
+			$sMenuId = ApplicationMenu::GetActiveNodeId();
+			$sDlgTitle = addslashes(Dict::S('UI:ImportDashboardTitle'));
+			$sDlgText = addslashes(Dict::S('UI:ImportDashboardText'));
+			$sCloseBtn = addslashes(Dict::S('UI:Button:Cancel'));
+			$aResult = array(
+				new SeparatorPopupMenuItem(),
+				new URLPopupMenuItem('UI:ExportDashboard', Dict::S('UI:ExportDashBoard'), utils::GetAbsoluteUrlAppRoot().'pages/ajax.render.php?operation=export_dashboard&id='.$sMenuId),
+				new JSPopupMenuItem('UI:ImportDashboard', Dict::S('UI:ImportDashBoard'), "UploadDashboard({dashboard_id: '$sMenuId', title: '$sDlgTitle', text: '$sDlgText', close_btn: '$sCloseBtn' })"),
+			);
+			break;
+
+			default:
+			// Unknown type of menu, do nothing
+			$aResult = array();
+		}
+		foreach($aResult as $oMenuItem)
+		{
+			$aActions[$oMenuItem->GetUID()] = $oMenuItem->GetMenuItem();
+		}
+
+		// Invoke the plugins
+		//
 		foreach (MetaModel::EnumPlugins('iPopupMenuExtension') as $oExtensionInstance)
 		{
 			if (is_object($param) && !($param instanceof DBObject))

+ 2 - 2
js/utils.js

@@ -361,9 +361,9 @@ function DashletCreationDlg(sOQL)
 	return false;
 }
 
-function ShortcutListDlg(sOQL, sContext)
+function ShortcutListDlg(sOQL, sSourceTableId, sContext)
 {
-	$.post(GetAbsoluteUrlAppRoot()+'pages/ajax.render.php?'+sContext, {operation: 'shortcut_list_dlg', oql: sOQL}, function(data){
+	$.post(GetAbsoluteUrlAppRoot()+'pages/ajax.render.php?'+sContext, {operation: 'shortcut_list_dlg', oql: sOQL, source_table_id: sSourceTableId}, function(data){
 		$('body').append(data);
 	});
 	return false;

+ 4 - 1
pages/ajax.render.php

@@ -973,7 +973,8 @@ EOF
 		
 		case 'shortcut_list_dlg':
 		$sOQL = utils::ReadParam('oql', '', false, 'raw_data');
-		ShortcutOQL::GetCreationDlgFromOQL($oPage, $sOQL);
+		$sSourceTableId = utils::ReadParam('source_table_id', '', false, 'raw_data');
+		ShortcutOQL::GetCreationDlgFromOQL($oPage, $sOQL, $sSourceTableId);
 		break;
 		
 		case 'shortcut_list_create':
@@ -997,6 +998,8 @@ EOF
 		}
 		$iId = $oShortcut->DBInsertNoReload();
 
+		$oShortcut->CloneTableSettings($aValues['source_table_id']);
+
 		// Add the menu node in the right place
 		//
 		// Mmmm... already done because the newly created menu is read from the DB