浏览代码

User editable dashboards... implementation in progress

git-svn-id: http://svn.code.sf.net/p/itop/code/trunk@1996 a333f486-631f-4898-b8df-5754b55c2be0
dflaven 13 年之前
父节点
当前提交
05ddf1f75f
共有 3 个文件被更改,包括 79 次插入18 次删除
  1. 29 3
      application/dashboard.class.inc.php
  2. 1 1
      application/dashboardlayout.class.inc.php
  3. 49 14
      application/dashlet.class.inc.php

+ 29 - 3
application/dashboard.class.inc.php

@@ -35,7 +35,8 @@ abstract class Dashboard
 		foreach($oDashletList as $oDomNode)
 		{
 			$sDashletClass = $oDomNode->getAttribute('xsi:type');
-			$oNewDashlet = new $sDashletClass;
+			$sId = $oDomNode->getAttribute('id');
+			$oNewDashlet = new $sDashletClass($sId);
 			$oNewDashlet->FromDOMNode($oDomNode);
 			$this->aDashlets[] = $oNewDashlet;
 		}
@@ -80,6 +81,10 @@ abstract class Dashboard
 		$oPage->add('<h1>'.$this->sTitle.'</h1>');
 		$oLayout = new $this->sLayoutClass;
 		$oLayout->Render($oPage, $this->aDashlets, $bEditMode, $aExtraParams);
+		if (!$bEditMode)
+		{
+			$oPage->add_linked_script('../js/dashlet.js');
+		}
 	}
 	
 	public function RenderProperties($oPage)
@@ -140,7 +145,10 @@ abstract class Dashboard
 		$oPage->add('<div class="ui-widget-content ui-corner-all"><div class="ui-widget-header ui-corner-all" style="text-align:center; padding: 2px;">Dashlet Properties</div>');
 
 		$oPage->add('<div id="dashlet_properties" style="text-align:center">');
-		$oPage->p('Not yet implemented');
+		foreach($this->aDashlets as $oDashlet)
+		{
+			$oDashlet->RenderProperties($oPage);
+		}
 		$oPage->add('</div>');
 
 		$oPage->add('</div>');
@@ -165,7 +173,6 @@ class RuntimeDashboard extends Dashboard
 <<<EOF
 function EditDashboard(sId)
 {
-	console.log('Ici');
 	$.post(GetAbsoluteUrlAppRoot()+'pages/ajax.render.php', {operation: 'dashboard_editor', id: sId},
 		function(data)
 		{
@@ -190,6 +197,7 @@ EOF
 		$this->RenderDashletsSelection($oPage);
 		$this->RenderDashletsProperties($oPage);
 		$oPage->add('</div>');
+		$oPage->add('<div id="event_bus"/>'); // For exchanging messages between the panes, same as in the designer
 		$oPage->add('</div>');
 		$sDialogTitle = 'Dashboard Editor';
 		$sOkButtonLabel = Dict::S('UI:Button:Ok');
@@ -209,6 +217,24 @@ $('#dashboard_editor').dialog({
 	],
 	close: function() { $(this).remove(); }
 });
+
+$('#event_bus').bind('dashlet-selected', function(event, data){
+		var sDashletId = data.dashlet_id;
+		var sPropId = 'dashlet_properties_'+sDashletId;
+		$('.dashlet_properties').each(function() {
+			var sId = $(this).attr('id');
+			var bShow = (sId == sPropId);
+			if (bShow)
+			{
+				$(this).show();
+			}
+			else
+			{
+				$(this).hide();
+			}
+		});
+
+	});
 EOF
 		);
 		$oPage->add_ready_script("$('#dashboard_editor').layout();");

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

@@ -42,7 +42,7 @@ abstract class DashboardLayoutMultiCol extends DashboardLayout
 				if ($iDashletIdx <= count($aDashlets))
 				{
 					$oDashlet = $aDashlets[$iDashletIdx];
-					$oDashlet->Render($oPage, $bEditMode, $aExtraParams);
+					$oDashlet->DoRender($oPage, $bEditMode, $aExtraParams);
 				}
 				else
 				{

+ 49 - 14
application/dashlet.class.inc.php

@@ -1,9 +1,11 @@
 <?php
 abstract class Dashlet
 {
-	public function __construct()
+	protected $sId;
+	
+	public function __construct($sId)
 	{
-		
+		$this->sId = $sId;
 	}
 	
 	public function FromDOMNode($oDOMNode)
@@ -21,8 +23,47 @@ abstract class Dashlet
 		
 	}
 	
+	public function DoRender($oPage, $bEditMode = false, $aExtraParams = array())
+	{
+		if ($bEditMode)
+		{
+			$sId = $this->GetID();
+			$oPage->add('<div class="dashlet" id="dashlet_'.$sId.'">');
+		}
+		else
+		{
+			$oPage->add('<div class="dashlet">');
+		}
+		$this->Render($oPage, $bEditMode, $aExtraParams);
+		$oPage->add('</div>');
+		if ($bEditMode)
+		{
+			$sClass = get_class($this);
+			$oPage->add_ready_script(
+<<<EOF
+$('#dashlet_$sId').dashlet({dashlet_id: '$sId', dashlet_class: '$sClass'});
+EOF
+			);
+		}
+	}
+	
+	public function GetID()
+	{
+		return $this->sId;
+	}
+	
 	abstract public function Render($oPage, $bEditMode = false, $aExtraParams = array());
 	
+	public function RenderProperties($oPage)
+	{
+		$sId = $this->GetID();
+		$sClass = get_class($this);
+		$oPage->add('<div class="dashlet_properties" id="dashlet_properties_'.$sId.'" style="display:none">');
+		$oPage->add("<p>Properties for $sClass / $sId</p>");
+		$oPage->add('</div>');
+	}
+	
+	
 	public function ToXml(DOMNode $oContainerNode)
 	{
 		
@@ -50,9 +91,9 @@ abstract class Dashlet
 
 class DashletHelloWorld extends Dashlet
 {
-	public function __construct()
+	public function __construct($sId)
 	{
-		
+		parent::__construct($sId);
 	}
 	
 	public function FromDOMNode($oDOMNode)
@@ -72,9 +113,7 @@ class DashletHelloWorld extends Dashlet
 	
 	public function Render($oPage, $bEditMode = false, $aExtraParams = array())
 	{
-		$oPage->add('<div class="dashlet">');
 		$oPage->add('<div style="text-align:center; line-height:5em" class="dashlet-content"><span>Hello World!</span></div>');
-		$oPage->add('</div>');
 	}
 	
 	public function ToXml(DOMNode $oContainerNode)
@@ -110,9 +149,9 @@ class DashletHelloWorld extends Dashlet
 
 class DashletFakeBarChart extends Dashlet
 {
-	public function __construct()
+	public function __construct($sId)
 	{
-		
+		parent::__construct($sId);
 	}
 	
 	public function FromDOMNode($oDOMNode)
@@ -132,9 +171,7 @@ class DashletFakeBarChart extends Dashlet
 	
 	public function Render($oPage, $bEditMode = false, $aExtraParams = array())
 	{
-		$oPage->add('<div class="dashlet">');
 		$oPage->add('<div style="text-align:center" class="dashlet-content"><div>Fake Bar Chart</div><divp><img src="../images/fake-bar-chart.png"/></div></div>');
-		$oPage->add('</div>');
 	}
 	
 	public function ToXml(DOMNode $oContainerNode)
@@ -170,9 +207,9 @@ class DashletFakeBarChart extends Dashlet
 
 class DashletFakePieChart extends Dashlet
 {
-	public function __construct()
+	public function __construct($sId)
 	{
-		
+		parent::__construct($sId);
 	}
 	
 	public function FromDOMNode($oDOMNode)
@@ -192,9 +229,7 @@ class DashletFakePieChart extends Dashlet
 	
 	public function Render($oPage, $bEditMode = false, $aExtraParams = array())
 	{
-		$oPage->add('<div class="dashlet">');
 		$oPage->add('<div style="text-align:center" class="dashlet-content"><div>Fake Pie Chart</div><div><img src="../images/fake-pie-chart.png"/></div></div>');
-		$oPage->add('</div>');
 	}
 	
 	public function ToXml(DOMNode $oContainerNode)