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

User editable dashboards... implementation in progress

git-svn-id: http://svn.code.sf.net/p/itop/code/trunk@2011 a333f486-631f-4898-b8df-5754b55c2be0
dflaven пре 13 година
родитељ
комит
59a751ad95
2 измењених фајлова са 23 додато и 6 уклоњено
  1. 20 4
      application/dashboard.class.inc.php
  2. 3 2
      application/dashboardlayout.class.inc.php

+ 20 - 4
application/dashboard.class.inc.php

@@ -105,7 +105,7 @@ abstract class Dashboard
 			$oNewDashlet = new $sDashletClass($sId);
 			
 			$oForm = $oNewDashlet->GetForm();
-			$oForm->SetParamsContainer('dashlet_'.$sId);
+			$oForm->SetParamsContainer($sId);
 			$oForm->SetPrefix('');
 			$aValues = $oForm->ReadParams();
 			$oNewDashlet->FromParams($aValues);
@@ -173,14 +173,22 @@ abstract class Dashboard
 				{
 					$aCallSpec = array($sLayoutClass, 'GetInfo');
 					$aInfo = call_user_func($aCallSpec);
-					$oPage->add('<input type="radio" name="layout_class" id="layout_'.$sLayoutClass.'"><label for="layout_'.$sLayoutClass.'"><img src="'.$sUrl.$aInfo['icon'].'" /></label>'); // title="" on either the img or the label does nothing !
+					$oPage->add('<input type="radio" name="layout_class" value="'.$sLayoutClass.'" id="layout_'.$sLayoutClass.'"><label for="layout_'.$sLayoutClass.'"><img src="'.$sUrl.$aInfo['icon'].'" /></label>'); // title="" on either the img or the label does nothing !
 				}
 			}
 		}
 		$oPage->add('</div>');
 		
 		$oPage->add('</div>');
-		$oPage->add_ready_script("$('#select_layout').buttonset();");
+		$oPage->add_ready_script(
+<<<EOF
+	$('#select_layout').buttonset();
+	$('#select_layout input').click( function() {
+		var sLayoutClass = $(this).val();
+		$(':itop-dashboard').dashboard('option', {layout_class: sLayoutClass});
+	} );
+EOF
+		);
 	}
 	
 	public function RenderDashletsSelection($oPage)
@@ -332,7 +340,15 @@ $('#dashboard_editor').dialog({
 	close: function() { $(this).remove(); }
 });
 
-$('#dashboard_editor .ui-layout-center').dashboard({ dashboard_id: '$sId', layout_class: '$sLayoutClass', title: '$sTitle', submit_to: '$sUrl', submit_parameters: {operation: 'save_dashboard'} });
+$('#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'}
+});
+
+$('#dashboard_editor table').sortable({
+	items: '.dashlet'
+});
 
 $('#event_bus').bind('dashlet-selected', function(event, data){
 		var sDashletId = data.dashlet_id;

+ 3 - 2
application/dashboardlayout.class.inc.php

@@ -31,7 +31,8 @@ abstract class DashboardLayoutMultiCol extends DashboardLayout
 	{
 		$oPage->add('<table style="width:100%"><tbody>');
 		$iDashletIdx = 0;
-		$sStyle = $bEditMode ? 'style="border: 1px #ccc dashed;" class="layout_cell edit_mode"' : '';
+		$fColSize = 100 / $this->iNbCols;
+		$sStyle = $bEditMode ? 'style="border: 1px #ccc dashed; width:'.$fColSize.'%;" class="layout_cell edit_mode"' : 'style="width: '.$fColSize.'%;  "';
 		$iNbRows = ceil(count($aDashlets) / $this->iNbCols);
 		for($iRows = 0; $iRows < $iNbRows; $iRows++)
 		{
@@ -39,7 +40,7 @@ abstract class DashboardLayoutMultiCol extends DashboardLayout
 			for($iCols = 0; $iCols < $this->iNbCols; $iCols++)
 			{
 				$oPage->add("<td $sStyle>");
-				if ($iDashletIdx <= count($aDashlets))
+				if (array_key_exists($iDashletIdx, $aDashlets))
 				{
 					$oDashlet = $aDashlets[$iDashletIdx];
 					$oDashlet->DoRender($oPage, $bEditMode, $aExtraParams);