瀏覽代碼

User editable dashboards... implementation in progress

git-svn-id: http://svn.code.sf.net/p/itop/code/trunk@2017 a333f486-631f-4898-b8df-5754b55c2be0
dflaven 13 年之前
父節點
當前提交
a381f6f300
共有 3 個文件被更改,包括 87 次插入13 次删除
  1. 25 12
      application/dashboard.class.inc.php
  2. 26 1
      application/dashboardlayout.class.inc.php
  3. 36 0
      application/dashlet.class.inc.php

+ 25 - 12
application/dashboard.class.inc.php

@@ -205,9 +205,14 @@ EOF
 				$oReflection = new ReflectionClass($sDashletClass);
 				if (!$oReflection->isAbstract())
 				{
-					$aCallSpec = array($sDashletClass, 'GetInfo');
-					$aInfo = call_user_func($aCallSpec);
-					$oPage->add('<span class="dashlet_icon ui-widget-content ui-corner-all" id="dashlet_'.$sDashletClass.'" title="'.$aInfo['label'].'" style="width:34px; height:34px; display:inline-block; margin:2px;"><img src="'.$sUrl.$aInfo['icon'].'" /></span>');
+					$aCallSpec = array($sDashletClass, 'IsVisible');
+					$bVisible = call_user_func($aCallSpec);
+					if ($bVisible)
+					{
+						$aCallSpec = array($sDashletClass, 'GetInfo');
+						$aInfo = call_user_func($aCallSpec);
+						$oPage->add('<span dashlet_class="'.$sDashletClass.'" class="dashlet_icon ui-widget-content ui-corner-all" id="dashlet_'.$sDashletClass.'" title="'.$aInfo['label'].'" style="width:34px; height:34px; display:inline-block; margin:2px;"><img src="'.$sUrl.$aInfo['icon'].'" /></span>');
+					}
 				}
 			}
 		}
@@ -228,12 +233,14 @@ EOF
 		{
 			$sId = $oDashlet->GetID();
 			$sClass = get_class($oDashlet);
-			
-			$oPage->add('<div class="dashlet_properties" id="dashlet_properties_'.$sId.'" style="display:none">');
-			$oForm = $oDashlet->GetForm();
-			$this->SetFormParams($oForm);
-			$oForm->RenderAsPropertySheet($oPage);		
-			$oPage->add('</div>');
+			if ($oDashlet->IsVisible())
+			{
+				$oPage->add('<div class="dashlet_properties" id="dashlet_properties_'.$sId.'" style="display:none">');
+				$oForm = $oDashlet->GetForm();
+				$this->SetFormParams($oForm);
+				$oForm->RenderAsPropertySheet($oPage);		
+				$oPage->add('</div>');
+			}
 		}
 		$oPage->add('</div>');
 
@@ -343,11 +350,17 @@ $('#dashboard_editor').dialog({
 $('#dashboard_editor .ui-layout-center').dashboard({
 	dashboard_id: '$sId', layout_class: '$sLayoutClass', title: '$sTitle',
 	submit_to: '$sUrl', submit_parameters: {operation: 'save_dashboard'},
-	render_to: '$sUrl', render_parameters: {operation: 'render_dashboard'}
+	render_to: '$sUrl', render_parameters: {operation: 'render_dashboard'},
+	new_dashlet_parameters: {operation: 'new_dashlet'}
 });
 
-$('#dashboard_editor table').sortable({
-	items: '.dashlet'
+$('#select_dashlet').droppable({
+	accept: '.dashlet',
+	drop: function(event, ui) {
+		$( this ).find( ".placeholder" ).remove();
+		var oDashlet = ui.draggable;
+		oDashlet.remove();
+	},
 });
 
 $('#event_bus').bind('dashlet-selected', function(event, data){

+ 26 - 1
application/dashboardlayout.class.inc.php

@@ -29,6 +29,24 @@ abstract class DashboardLayoutMultiCol extends DashboardLayout
 	
 	public function Render($oPage, $aDashlets, $bEditMode = false, $aExtraParams = array())
 	{
+		// Trim the list of dashlets to remove the invisible ones at the end of the array
+		$aKeys = array_reverse(array_keys($aDashlets));
+		$idx = 0;
+		$bNoVisibleFound = true;
+		while($idx < count($aKeys) && $bNoVisibleFound)
+		{
+			$oDashlet = $aDashlets[$aKeys[$idx]];
+			if ($oDashlet->IsVisible())
+			{
+				$bNoVisibleFound = false;
+			}
+			else
+			{
+				unset($aDashlets[$aKeys[$idx]]);
+			}
+			$idx++;
+		}
+		
 		$oPage->add('<table style="width:100%"><tbody>');
 		$iDashletIdx = 0;
 		$fColSize = 100 / $this->iNbCols;
@@ -43,7 +61,14 @@ abstract class DashboardLayoutMultiCol extends DashboardLayout
 				if (array_key_exists($iDashletIdx, $aDashlets))
 				{
 					$oDashlet = $aDashlets[$iDashletIdx];
-					$oDashlet->DoRender($oPage, $bEditMode, $aExtraParams);
+					if ($oDashlet->IsVisible())
+					{
+						$oDashlet->DoRender($oPage, $bEditMode, $aExtraParams);
+					}
+					else
+					{
+						$oPage->add('&nbsp;');
+					}
 				}
 				else
 				{

+ 36 - 0
application/dashlet.class.inc.php

@@ -192,6 +192,42 @@ EOF
 		
 		return $oForm;
 	}
+	
+	static public function IsVisible()
+	{
+		return true;
+	}
+}
+
+class DashletEmptyCell extends Dashlet
+{
+	public function __construct($sId)
+	{
+		parent::__construct($sId);
+	}
+	
+	public function Render($oPage, $bEditMode = false, $aExtraParams = array())
+	{
+		$oPage->add('&nbsp;');
+	}
+
+	public function GetPropertiesFields(DesignerForm $oForm)
+	{
+	}
+	
+	static public function GetInfo()
+	{
+		return array(
+			'label' => 'Empty Cell',
+			'icon' => 'images/dashlet-text.png',
+			'description' => 'Empty Cell Dashlet Placeholder',
+		);
+	}
+	
+	static public function IsVisible()
+	{
+		return false;
+	}
 }
 
 class DashletHelloWorld extends Dashlet