diff --git a/application/dashboard.class.inc.php b/application/dashboard.class.inc.php
index 29fef433a..0dd949b5d 100644
--- a/application/dashboard.class.inc.php
+++ b/application/dashboard.class.inc.php
@@ -1,7 +1,26 @@
add_linked_script('../js/dashlet.js');
+ $oPage->add_linked_script('../js/property_field.js');
}
}
@@ -149,16 +169,29 @@ abstract class Dashboard
$oPage->add('
');
foreach($this->aDashlets as $oDashlet)
{
- $oDashlet->RenderProperties($oPage);
+ $sId = $oDashlet->GetID();
+ $sClass = get_class($oDashlet);
+
+ $oPage->add('
');
+ $oForm = $oDashlet->GetForm($oPage);
+ $this->SetFormParams($oForm);
+ $oForm->RenderAsPropertySheet($oPage);
+ $oPage->add('
');
}
$oPage->add('
');
$oPage->add('');
}
+
+ abstract protected function SetFormParams($oForm);
}
class RuntimeDashboard extends Dashboard
{
+ protected function SetFormParams($oForm)
+ {
+ $oForm->SetSubmitParams(utils::GetAbsoluteUrlAppRoot().'pages/ajax.render.php', array('operation' => 'update_dashlet_property'));
+ }
public function Save()
{
diff --git a/application/dashlet.class.inc.php b/application/dashlet.class.inc.php
index 1c2d6b6aa..c4c465d33 100644
--- a/application/dashlet.class.inc.php
+++ b/application/dashlet.class.inc.php
@@ -1,11 +1,37 @@
sId = $sId;
+ $this->bRedrawNeeded = true; // By default: redraw each time a property changes
+ $this->bFormRedrawNeeded = false; // By default: no need to redraw the form (independent fields)
}
public function FromDOMNode($oDOMNode)
@@ -53,30 +79,27 @@ EOF
}
abstract public function Render($oPage, $bEditMode = false, $aExtraParams = array());
-
- public function RenderProperties($oPage)
- {
- $sId = $this->GetID();
- $sClass = get_class($this);
- $oPage->add('');
- $oPage->add("
Properties for $sClass / $sId
");
- $oPage->add('
');
- }
-
+
+ abstract public function GetPropertiesFields(DesignerForm $oForm);
public function ToXml(DOMNode $oContainerNode)
{
}
-
- public function GetForm()
+
+ public function Update($aValues, $aUpdatedFields)
{
}
- public function OnFieldUpdate($aParams, $sUpdatedFieldCode)
+ public function IsRedrawNeeded()
{
-
+ return $this->bRedrawNeeded;
+ }
+
+ public function IsFormRedrawNeeded()
+ {
+ return $this->bFormRedrawNeeded;
}
static public function GetInfo()
@@ -87,33 +110,71 @@ EOF
'description' => '',
);
}
+
+ public function GetForm($oPage, $bReturnHTML = false)
+ {
+ $oForm = new DesignerForm();
+ $oForm->SetPrefix("dashlet_". $this->GetID());
+ $oForm->SetParamsContainer('params');
+
+ $this->GetPropertiesFields($oForm);
+
+ $oDashletClassField = new DesignerHiddenField('dashlet_class', '', get_class($this));
+ $oForm->AddField($oDashletClassField);
+
+ $oDashletIdField = new DesignerHiddenField('dashlet_id', '', $this->GetID());
+ $oForm->AddField($oDashletIdField);
+
+ return $oForm;
+ }
}
class DashletHelloWorld extends Dashlet
{
+ protected $sText;
+
public function __construct($sId)
{
parent::__construct($sId);
+ $this->sText = 'Hello World';
}
public function FromDOMNode($oDOMNode)
{
-
+ //$this->sText = 'Hello World!';
}
public function FromXml($sXml)
{
-
+ //$this->sText = 'Hello World!';
}
public function FromParams($aParams)
{
-
+ $this->sText = $aParams['text'];
+ }
+
+ public function Update($aValues, $aUpdatedFields)
+ {
+ foreach($aUpdatedFields as $sProp)
+ {
+ switch($sProp)
+ {
+ case 'text':
+ $this->sText = $aValues['text'];
+ break;
+ }
+ }
}
public function Render($oPage, $bEditMode = false, $aExtraParams = array())
{
- $oPage->add('Hello World!
');
+ $oPage->add(''.$this->sText.'
');
+ }
+ public function GetPropertiesFields(DesignerForm $oForm)
+ {
+ $oField = new DesignerTextField('text', 'Text', $this->sText);
+ $oForm->AddField($oField);
}
public function ToXml(DOMNode $oContainerNode)
@@ -121,21 +182,7 @@ class DashletHelloWorld extends Dashlet
$oNewNodeNode = $oContainerNode->ownerDocument->createElement('hello_world', 'test');
$oContainerNode->appendChild($oNewNodeNode);
}
-
- public function GetForm()
- {
-
- }
-
- public function OnFieldUpdate($aParams, $sUpdatedFieldCode)
- {
- return array(
- 'status_ok' => true,
- 'redraw' => false,
- 'fields' => array(),
- );
- }
-
+
static public function GetInfo()
{
return array(
@@ -174,26 +221,16 @@ class DashletFakeBarChart extends Dashlet
$oPage->add('Fake Bar Chart

');
}
+ public function GetPropertiesFields(DesignerForm $oForm, $oDashlet = null)
+ {
+ }
+
public function ToXml(DOMNode $oContainerNode)
{
$oNewNodeNode = $oContainerNode->ownerDocument->createElement('fake_bar_chart', 'test');
$oContainerNode->appendChild($oNewNodeNode);
}
-
- public function GetForm()
- {
-
- }
-
- public function OnFieldUpdate($aParams, $sUpdatedFieldCode)
- {
- return array(
- 'status_ok' => true,
- 'redraw' => false,
- 'fields' => array(),
- );
- }
-
+
static public function GetInfo()
{
return array(
@@ -232,26 +269,16 @@ class DashletFakePieChart extends Dashlet
$oPage->add('');
}
+ public function GetPropertiesFields(DesignerForm $oForm, $oDashlet = null)
+ {
+ }
+
public function ToXml(DOMNode $oContainerNode)
{
$oNewNodeNode = $oContainerNode->ownerDocument->createElement('fake_pie_chart', 'test');
$oContainerNode->appendChild($oNewNodeNode);
}
- public function GetForm()
- {
-
- }
-
- public function OnFieldUpdate($aParams, $sUpdatedFieldCode)
- {
- return array(
- 'status_ok' => true,
- 'redraw' => false,
- 'fields' => array(),
- );
- }
-
static public function GetInfo()
{
return array(
diff --git a/application/forms.class.inc.php b/application/forms.class.inc.php
new file mode 100644
index 000000000..f927e40dc
--- /dev/null
+++ b/application/forms.class.inc.php
@@ -0,0 +1,984 @@
+aFieldSets = array();
+ $this->sCurrentFieldSet = '';
+ $this->sScript = '';
+ $this->sReadyScript = '';
+ $this->sFormPrefix = '';
+ $this->sParamsContainer = '';
+ $this->sFormId = 'form_'.rand();
+ $this->oParentForm = null;
+ $this->bReadOnly = false;
+ $this->StartFieldSet($this->sCurrentFieldSet);
+ }
+
+ public function AddField(DesignerFormField $oField)
+ {
+ if (!is_array($this->aFieldSets[$this->sCurrentFieldSet]))
+ {
+ $this->aFieldSets[$this->sCurrentFieldSet] = array();
+ }
+ $this->aFieldSets[$this->sCurrentFieldSet][] = $oField;
+ $oField->SetForm($this);
+ }
+
+ public function StartFieldSet($sLabel)
+ {
+ $this->sCurrentFieldSet = $sLabel;
+ if (!array_key_exists($this->sCurrentFieldSet, $this->aFieldSets))
+ {
+ $this->aFieldSets[$this->sCurrentFieldSet] = array();
+ }
+ }
+
+ public function Render($oP, $bReturnHTML = false)
+ {
+ $sReturn = '';
+ if ($this->oParentForm == null)
+ {
+ $sFormId = $this->sFormId;
+ $sReturn = '';
+ }
+ if($this->sScript != '')
+ {
+ $oP->add_script($this->sScript);
+ }
+ if($this->sReadyScript != '')
+ {
+ $oP->add_ready_script($this->sReadyScript);
+ }
+ if ($bReturnHTML)
+ {
+ return $sReturn;
+ }
+ else
+ {
+ $oP->add($sReturn);
+ }
+ }
+
+ public function SetSubmitParams($sSubmitToUrl, $aSubmitParams)
+ {
+ $this->sSubmitTo = $sSubmitToUrl;
+ $this->aSubmitParams = $aSubmitParams;
+ }
+
+ public function CopySubmitParams($oParentForm)
+ {
+ $this->sSubmitTo = $oParentForm->sSubmitTo;
+ $this->aSubmitParams = $oParentForm->aSubmitParams;
+ }
+
+
+ public function RenderAsPropertySheet($oP, $bReturnHTML = false)
+ {
+ $sReturn = '';
+ $sActionUrl = addslashes($this->sSubmitTo);
+ $sJSSubmitParams = json_encode($this->aSubmitParams);
+ if ($this->oParentForm == null)
+ {
+ $sFormId = $this->sFormId;
+ $sReturn = '';
+ $sReturn .= ''; // for the return of the submit operation
+ }
+ else
+ {
+ $sReturn .= $sHiddenFields;
+ }
+ $this->AddReadyScript(
+<<sScript != '')
+ {
+ $oP->add_script($this->sScript);
+ }
+ if($this->sReadyScript != '')
+ {
+ $oP->add_ready_script($this->sReadyScript);
+ }
+ if ($bReturnHTML)
+ {
+ return $sReturn;
+ }
+ else
+ {
+ $oP->add($sReturn);
+ }
+ }
+ public function RenderAsDialog($oPage, $sDialogId, $sDialogTitle, $iDialogWidth, $sOkButtonLabel)
+ {
+ $sDialogTitle = addslashes($sDialogTitle);
+ $sOkButtonLabel = addslashes($sOkButtonLabel);
+ $sCancelButtonLabel = 'Cancel'; //TODO: localize
+ $oPage->add("");
+ $this->Render($oPage);
+ $oPage->add('
');
+
+ $oPage->add_ready_script(
+<<aFieldSets as $sLabel => $aFields)
+ {
+ foreach($aFields as $oField)
+ {
+ $oField->ReadParam($aValues);
+ }
+ }
+ return $aValues;
+ }
+
+ public function SetPrefix($sPrefix)
+ {
+ $this->sFormPrefix = $sPrefix;
+ }
+
+ public function GetPrefix()
+ {
+ return $this->sFormPrefix;
+ }
+
+ public function SetReadOnly($bReadOnly = true)
+ {
+ $this->bReadOnly = $bReadOnly;
+ }
+
+ public function IsReadOnly()
+ {
+ if ($this->oParentForm == null)
+ {
+ return $this->bReadOnly;
+ }
+ else
+ {
+ return $this->oParentForm->IsReadOnly();
+ }
+ }
+
+ public function SetParamsContainer($sParamsContainer)
+ {
+ $this->sParamsContainer = $sParamsContainer;
+ }
+
+ public function GetParamsContainer()
+ {
+ if ($this->oParentForm == null)
+ {
+ return $this->sParamsContainer;
+ }
+ else
+ {
+ return $this->oParentForm->GetParamsContainer();
+ }
+ }
+
+ public function SetParentForm($oParentForm)
+ {
+ $this->oParentForm = $oParentForm;
+ }
+
+ public function AddScript($sScript)
+ {
+ $this->sScript .= $sScript;
+ }
+
+ public function AddReadyScript($sScript)
+ {
+ $this->sReadyScript .= $sScript;
+ }
+
+ public function GetFieldId($sCode)
+ {
+ return $this->sFormPrefix.'attr_'.$sCode;
+ }
+
+ public function GetFieldName($sCode)
+ {
+ return 'attr_'.$sCode;
+ }
+
+ public function GetParamName($sCode)
+ {
+ return 'attr_'.$sCode;
+ }
+
+ public function GetValidationArea($sCode)
+ {
+ return "sFormPrefix}attr_$sCode\">";
+ }
+ public function GetAsyncActionClass()
+ {
+ return $this->sAsyncActionClass;
+ }
+}
+
+class DesignerTabularForm extends DesignerForm
+{
+ protected $aTable;
+
+ public function __construct()
+ {
+ parent::__construct();
+ $this->aTable = array();
+ }
+ public function AddRow($aRow)
+ {
+ $this->aTable[] = $aRow;
+ }
+
+ public function Render($oP, $bReturnHTML = false)
+ {
+ $sReturn = '';
+ if ($this->oParentForm == null)
+ {
+ $sFormId = $this->sFormId;
+ $sReturn = '