From 8c0fbe1913477d6b0aeeaf5b244b33c4a72cc73b Mon Sep 17 00:00:00 2001 From: Denis Flaven Date: Wed, 30 May 2012 09:07:41 +0000 Subject: [PATCH] Dashboards edition final touch... SVN:trunk[2059] --- application/dashboard.class.inc.php | 1 + application/dashlet.class.inc.php | 96 +++++++++++++++++++++++++-- application/itopwebpage.class.inc.php | 3 + 3 files changed, 95 insertions(+), 5 deletions(-) diff --git a/application/dashboard.class.inc.php b/application/dashboard.class.inc.php index 4aa051d37..8d1fa7460 100644 --- a/application/dashboard.class.inc.php +++ b/application/dashboard.class.inc.php @@ -216,6 +216,7 @@ abstract class Dashboard $('#row_attr_dashboard_title').property_field('option', {'do_apply': function() { var sTitle = $('#attr_dashboard_title').val(); $(':itop-dashboard').dashboard('option', {title: sTitle}); + return true; } }); EOF diff --git a/application/dashlet.class.inc.php b/application/dashlet.class.inc.php index d8ac37d45..89c6506e0 100644 --- a/application/dashlet.class.inc.php +++ b/application/dashlet.class.inc.php @@ -296,7 +296,12 @@ class DashletObjectList extends Dashlet $sQuery = $this->aProperties['query']; $sShowMenu = $this->aProperties['menu'] ? '1' : '0'; - $oPage->add('
'); + $oPage->add('
'); + $sHtmlTitle = htmlentities(Dict::S($sTitle), ENT_QUOTES, 'UTF-8'); // done in the itop block + if ($sHtmlTitle != '') + { + $oPage->add('

'.$sHtmlTitle.'

'); + } $oFilter = DBObjectSearch::FromOQL($sQuery); $oBlock = new DisplayBlock($oFilter, 'list'); $aExtraParams = array( @@ -752,8 +757,16 @@ class DashletHeaderStatic extends Dashlet { $oField = new DesignerTextField('title', 'Title', $this->aProperties['title']); $oForm->AddField($oField); - - $oField = new DesignerTextField('icon', 'Icon', $this->aProperties['icon']); + + $oField = new DesignerIconSelectionField('icon', 'Icon', $this->aProperties['icon']); + $aAllIcons = self::FindIcons(APPROOT.'env-'.utils::GetCurrentEnvironment()); + ksort($aAllIcons); + $aValues = array(); + foreach($aAllIcons as $sFilePath) + { + $aValues[] = array('value' => $sFilePath, 'label' => basename($sFilePath), 'icon' => utils::GetAbsoluteUrlModulesRoot().$sFilePath); + } + $oField->SetAllowedValues($aValues); $oForm->AddField($oField); } @@ -765,6 +778,30 @@ class DashletHeaderStatic extends Dashlet 'description' => 'Header with stats (grouped by...)', ); } + + static public function FindIcons($sBaseDir, $sDir = '') + { + $aResult = array(); + // Populate automatically the list of icon files + if ($hDir = @opendir($sBaseDir.'/'.$sDir)) + { + while (($sFile = readdir($hDir)) !== false) + { + $aMatches = array(); + if (($sFile != '.') && ($sFile != '..') && is_dir($sBaseDir.'/'.$sDir.'/'.$sFile)) + { + $sDirSubPath = ($sDir == '') ? $sFile : $sDir.'/'.$sFile; + $aResult = array_merge($aResult, self::FindIcons($sBaseDir, $sDirSubPath)); + } + if (preg_match("/\.(png|jpg|jpeg|gif)$/i", $sFile, $aMatches)) // png, jp(e)g and gif are considered valid + { + $aResult[$sFile.'_'.$sDir] = $sDir.'/'.$sFile; + } + } + closedir($hDir); + } + return $aResult; + } } @@ -854,7 +891,15 @@ class DashletHeaderDynamic extends Dashlet $oField = new DesignerTextField('title', 'Title', $this->aProperties['title']); $oForm->AddField($oField); - $oField = new DesignerTextField('icon', 'Icon', $this->aProperties['icon']); + $oField = new DesignerIconSelectionField('icon', 'Icon', $this->aProperties['icon']); + $aAllIcons = DashletHeaderStatic::FindIcons(APPROOT.'env-'.utils::GetCurrentEnvironment()); + ksort($aAllIcons); + $aValues = array(); + foreach($aAllIcons as $sFilePath) + { + $aValues[] = array('value' => $sFilePath, 'label' => basename($sFilePath), 'icon' => utils::GetAbsoluteUrlModulesRoot().$sFilePath); + } + $oField->SetAllowedValues($aValues); $oForm->AddField($oField); $oField = new DesignerTextField('subtitle', 'Subtitle', $this->aProperties['subtitle']); @@ -923,11 +968,52 @@ class DashletBadge extends Dashlet $oBlock->Display($oPage, $sBlockId, $aExtraParams); $oPage->add('
'); + if ($bEditMode) + { + // Since the container div is not rendered the same way in edit mode, add the 'inline' style to it + $oPage->add_ready_script("$('#dashlet_".$this->sId."').addClass('dashlet-inline');"); + } } public function GetPropertiesFields(DesignerForm $oForm) { - $oField = new DesignerTextField('class', 'Class', $this->aProperties['class']); + + $oClassesSet = new ValueSetEnumClasses('bizmodel', array()); + $aClasses = $oClassesSet->GetValues(array()); + + $aLinkClasses = array(); + + foreach(MetaModel::GetClasses('bizmodel') as $sClass) + { + foreach(MetaModel::ListAttributeDefs($sClass) as $sAttCode => $oAttDef) + { + if ($oAttDef instanceof AttributeLinkedSetIndirect) + { + $aLinkClasses[$oAttDef->GetLinkedClass()] = true; + } + } + } + + + $oField = new DesignerIconSelectionField('class', 'Class', $this->aProperties['class']); + ksort($aClasses); + $aValues = array(); + foreach($aClasses as $sClass => $sClass) + { + if (!array_key_exists($sClass, $aLinkClasses)) + { + $sIconUrl = MetaModel::GetClassIcon($sClass, false); + $sIconFilePath = str_replace(utils::GetAbsoluteUrlAppRoot(), APPROOT, $sIconUrl); + if (($sIconUrl == '') || !file_exists($sIconFilePath)) + { + // The icon does not exist, leet's use a transparent one of the same size. + $sIconUrl = utils::GetAbsoluteUrlAppRoot().'images/transparent_32_32.png'; + } + $aValues[] = array('value' => $sClass, 'label' => $sClass, 'icon' => $sIconUrl); + } + } + $oField->SetAllowedValues($aValues); + $oForm->AddField($oField); } diff --git a/application/itopwebpage.class.inc.php b/application/itopwebpage.class.inc.php index 3e9ad03db..f8618fe89 100644 --- a/application/itopwebpage.class.inc.php +++ b/application/itopwebpage.class.inc.php @@ -55,6 +55,7 @@ class iTopWebPage extends NiceWebPage $this->add_header("Cache-control: no-cache"); $this->add_linked_stylesheet("../css/jquery.treeview.css"); $this->add_linked_stylesheet("../css/jquery.autocomplete.css"); + $this->add_linked_stylesheet("../css/fg.menu.css"); $this->add_linked_script('../js/jquery.layout.min.js'); $this->add_linked_script('../js/jquery.ba-bbq.min.js'); $this->add_linked_script("../js/jquery.treeview.js"); @@ -69,6 +70,8 @@ class iTopWebPage extends NiceWebPage $this->add_linked_script("../js/ckeditor/adapters/jquery.js"); $this->add_linked_script("../js/jquery.qtip-1.0.min.js"); $this->add_linked_script('../js/property_field.js'); + $this->add_linked_script('../js/fg.menu.js'); + $this->add_linked_script('../js/icon_select.js'); $this->add_linked_script('../js/raphael-min.js'); $this->add_linked_script('../js/g.raphael.js'); $this->add_linked_script('../js/g.pie.js');