From 362cd72e872ac64a55bb75b8ebb1eee043e4c94f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eric=20Espi=C3=A9?= Date: Tue, 12 Jun 2018 08:56:41 +0000 Subject: [PATCH] =?UTF-8?q?N=C2=B01325=20Dashboards:=20Unknown=20dashlets:?= =?UTF-8?q?=20keep=20the=20original=20type=20of=20the=20unknown=20dashlet?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit SVN:trunk[5855] --- application/dashboard.class.inc.php | 7 ++-- application/dashlet.class.inc.php | 50 ++++++++++++++--------------- js/dashboard.js | 6 ++-- js/dashlet.js | 9 ++++-- 4 files changed, 38 insertions(+), 34 deletions(-) diff --git a/application/dashboard.class.inc.php b/application/dashboard.class.inc.php index ee5358497..18f28b3d4 100644 --- a/application/dashboard.class.inc.php +++ b/application/dashboard.class.inc.php @@ -151,11 +151,13 @@ abstract class Dashboard $sClass = $oDomNode->getAttribute('xsi:type'); // Test if dashlet can be instanciated, otherwise (uninstalled, broken, ...) we display a placeholder + $sDashletType = $sClass; if(!class_exists($sClass)) { $sClass = 'DashletUnknown'; } $oNewDashlet = new $sClass($this->oMetaModel, $sId); + $oNewDashlet->SetDashletType($sDashletType); $oNewDashlet->FromDOMNode($oDomNode); return $oNewDashlet; @@ -234,7 +236,7 @@ abstract class Dashboard $oNode = $oDoc->createElement('dashlet'); $oDashletsNode->appendChild($oNode); $oNode->setAttribute('id', $oDashlet->GetID()); - $oNode->setAttribute('xsi:type', get_class($oDashlet)); + $oNode->setAttribute('xsi:type', $oDashlet->GetDashletType()); $oDashletRank = $oDoc->createElement('rank', $iDashletRank); $oNode->appendChild($oDashletRank); $iDashletRank++; @@ -258,8 +260,9 @@ abstract class Dashboard { $sDashletClass = $aDashletParams['dashlet_class']; $sId = $aDashletParams['dashlet_id']; + $sType = $aDashletParams['dashlet_type']; $oNewDashlet = new $sDashletClass($this->oMetaModel, $sId); - + $oNewDashlet->SetDashletType($sType); $oForm = $oNewDashlet->GetForm(); $oForm->SetParamsContainer($sId); $oForm->SetPrefix(''); diff --git a/application/dashlet.class.inc.php b/application/dashlet.class.inc.php index a576d7ec8..453120b69 100644 --- a/application/dashlet.class.inc.php +++ b/application/dashlet.class.inc.php @@ -32,6 +32,7 @@ abstract class Dashlet protected $bFormRedrawNeeded; protected $aProperties; // array of {property => value} protected $aCSSClasses; + protected $sDashletType; public function __construct(ModelReflection $oModelReflection, $sId) { @@ -41,6 +42,7 @@ abstract class Dashlet $this->bFormRedrawNeeded = false; // By default: no need to redraw the form (independent fields) $this->aProperties = array(); // By default: there is no property $this->aCSSClasses = array('dashlet'); + $this->sDashletType = get_class($this); } // Assuming that a property has the type of its default value, set in the constructor @@ -214,9 +216,10 @@ abstract class Dashlet if ($bEditMode) { $sClass = get_class($this); + $sType = $this->sDashletType; $oPage->add_ready_script( <<AddField($oDashletClassField); + $oDashletTypeField = new DesignerHiddenField('dashlet_type', '', $this->sDashletType); + $oForm->AddField($oDashletTypeField); + $oDashletIdField = new DesignerHiddenField('dashlet_id', '', $this->GetID()); $oForm->AddField($oDashletIdField); @@ -345,6 +351,21 @@ EOF return $aGroupBy; } + /** + * @return string + */ + public function GetDashletType() + { + return $this->sDashletType; + } + + /** + * @param string $sDashletType + */ + public function SetDashletType($sDashletType) + { + $this->sDashletType = $sDashletType; + } } /** @@ -364,33 +385,15 @@ class DashletUnknown extends Dashlet public function __construct($oModelReflection, $sId) { parent::__construct($oModelReflection, $sId); - $this->sOriginalDashletClass = 'Unknown'; $this->sOriginalDashletXML = ''; $this->aCSSClasses[] = 'dashlet-unknown'; } - public function GetOriginalDashletClass() - { - return $this->sOriginalDashletClass; - } - - public function SetOriginalDashletClass($sOriginalDashletClass) - { - $this->sOriginalDashletClass = $sOriginalDashletClass; - } - public function FromDOMNode($oDOMNode) { // Parent won't do anything as there is no property declared parent::FromDOMNode($oDOMNode); - // Original dashlet - // - Class - if($oDOMNode->hasAttribute('xsi:type')) - { - $this->sOriginalDashletClass = $oDOMNode->getAttribute('xsi:type'); - } - // Build properties from XML $this->sOriginalDashletXML = ""; foreach($oDOMNode->childNodes as $oDOMChildNode) @@ -432,7 +435,7 @@ class DashletUnknown extends Dashlet $aInfos = static::GetInfo(); $sIconUrl = utils::GetAbsoluteUrlAppRoot().$aInfos['icon']; - $sExplainText = ($bEditMode) ? Dict::Format('UI:DashletUnknown:RenderText:Edit', $this->sOriginalDashletClass) : Dict::S('UI:DashletUnknown:RenderText:View'); + $sExplainText = ($bEditMode) ? Dict::Format('UI:DashletUnknown:RenderText:Edit', $this->GetDashletType()) : Dict::S('UI:DashletUnknown:RenderText:View'); $oPage->add('
'); @@ -447,7 +450,7 @@ class DashletUnknown extends Dashlet $aInfos = static::GetInfo(); $sIconUrl = utils::GetAbsoluteUrlAppRoot().$aInfos['icon']; - $sExplainText = Dict::Format('UI:DashletUnknown:RenderNoDataText:Edit', $this->sOriginalDashletClass); + $sExplainText = Dict::Format('UI:DashletUnknown:RenderNoDataText:Edit', $this->GetDashletType()); $oPage->add('
'); @@ -522,9 +525,6 @@ class DashletUnknown extends Dashlet class DashletProxy extends DashletUnknown { - protected $sOriginalDashletClass; - protected $sOriginalDashletXML; - public function __construct($oModelReflection, $sId) { parent::__construct($oModelReflection, $sId); @@ -535,8 +535,6 @@ class DashletProxy extends DashletUnknown unset($this->aCSSClasses[$key]); } - $this->sOriginalDashletClass = 'Proxy'; - $this->sOriginalDashletXML = ''; $this->aCSSClasses[] = 'dashlet-proxy'; } diff --git a/js/dashboard.js b/js/dashboard.js index fc3353a12..c84d12542 100644 --- a/js/dashboard.js +++ b/js/dashboard.js @@ -84,14 +84,14 @@ $(function() var oDashletParams = oDashlet.get_params(); var sId = oDashletParams.dashlet_id; oState[sId] = oDashletParams; - aList.push({dashlet_id: sId, dashlet_class: oDashletParams.dashlet_class} ); + aList.push({dashlet_id: sId, dashlet_class: oDashletParams.dashlet_class, dashlet_type: oDashletParams.dashlet_type} ); } }); if (aList.length == 0) { - oState[0] = {dashlet_id: 0, dashlet_class: 'DashletEmptyCell'}; - aList.push({dashlet_id: 0, dashlet_class: 'DashletEmptyCell'}); + oState[0] = {dashlet_id: 0, dashlet_class: 'DashletEmptyCell', dashlet_type: 'DashletEmptyCell'}; + aList.push({dashlet_id: 0, dashlet_class: 'DashletEmptyCell', dashlet_type: 'DashletEmptyCell'}); } oState.cells.push(aList); }); diff --git a/js/dashlet.js b/js/dashlet.js index d1f03b452..ff2c529db 100644 --- a/js/dashlet.js +++ b/js/dashlet.js @@ -9,7 +9,8 @@ $(function() options: { dashlet_id: '', - dashlet_class: '' + dashlet_class: '', + dashlet_type: '' }, // the constructor @@ -75,7 +76,7 @@ $(function() { this.element.addClass('dashlet-selected'); this.closeBox.fadeIn(500); - $('#event_bus').trigger('dashlet-selected', {'dashlet_id': this.options.dashlet_id, 'dashlet_class': this.options.dashlet_class}); + $('#event_bus').trigger('dashlet-selected', {'dashlet_id': this.options.dashlet_id, 'dashlet_class': this.options.dashlet_class, 'dashlet_type': this.options.dashlet_type}); }, deselect: function() { @@ -114,6 +115,7 @@ $(function() oParams.dashlet_id = this.options.dashlet_id; oParams.dashlet_class = this.options.dashlet_class; + oParams.dashlet_type = this.options.dashlet_type; return oParams; }, get_drag_icon: function() @@ -127,11 +129,12 @@ $(function() { var iDashletId = this.options.dashlet_id; var sDashletClass = this.options.dashlet_class; + var sDashletType = this.options.dashlet_type; var oContainer = this.element.parent(); $('#dashlet_properties_'+iDashletId).remove(); this.element.remove(); - $('#event_bus').trigger('dashlet-removed', {'dashlet_id': iDashletId, 'dashlet_class': sDashletClass, 'container': oContainer}); + $('#event_bus').trigger('dashlet-removed', {'dashlet_id': iDashletId, 'dashlet_class': sDashletClass, 'dashlet_type': sDashletType, 'container': oContainer}); $('.itop-dashboard').trigger('mark_as_modified'); } });