From: Marcin Haba Date: Wed, 7 Aug 2019 04:57:16 +0000 (+0200) Subject: baculum: Make loading configuration controls easier X-Git-Tag: Release-9.6.0~153 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=130b190d26e8db36e1a886afca27afca6e14cf07;p=thirdparty%2Fbacula.git baculum: Make loading configuration controls easier --- diff --git a/gui/baculum/protected/Web/Portlets/BaculaConfigDirectives.php b/gui/baculum/protected/Web/Portlets/BaculaConfigDirectives.php index bbb971b36..1b173e8a2 100644 --- a/gui/baculum/protected/Web/Portlets/BaculaConfigDirectives.php +++ b/gui/baculum/protected/Web/Portlets/BaculaConfigDirectives.php @@ -84,6 +84,15 @@ class BaculaConfigDirectives extends DirectiveListTemplate { } } + public function onPreRender($param) { + /** + * This method overwrites DirectiveListTemplate::onPreRender() + * Not calling parent method is intentional here because this class + * isn't typical control list class and calling parent::onPreRender() + * causes error. + */ + } + private function getConfigData($host, array $parameters) { $default_params = array('config'); $params = array_merge($default_params, $parameters); diff --git a/gui/baculum/protected/Web/Portlets/DirectiveComboBox.php b/gui/baculum/protected/Web/Portlets/DirectiveComboBox.php index 62adbd31b..6609a3178 100644 --- a/gui/baculum/protected/Web/Portlets/DirectiveComboBox.php +++ b/gui/baculum/protected/Web/Portlets/DirectiveComboBox.php @@ -26,10 +26,10 @@ Prado::using('Application.Web.Portlets.DirectiveTemplate'); class DirectiveComboBox extends DirectiveTemplate { - public function onLoad($param) { + public function onPreRender($param) { $this->createDirectiveInternal(); $this->saveDirective(); - parent::onLoad($param); + parent::onPreRender($param); } public function saveDirective() { diff --git a/gui/baculum/protected/Web/Portlets/DirectiveControlTemplate.php b/gui/baculum/protected/Web/Portlets/DirectiveControlTemplate.php index 8ec576f28..042eef9c9 100644 --- a/gui/baculum/protected/Web/Portlets/DirectiveControlTemplate.php +++ b/gui/baculum/protected/Web/Portlets/DirectiveControlTemplate.php @@ -29,6 +29,8 @@ abstract class DirectiveControlTemplate extends TTemplateControl { if ($this->getPage()->IsCallBack) { if (method_exists($this->getPage()->CallBackEventTarget, 'getCommandParameter')) { $command_param = $this->getPage()->CallBackEventTarget->getCommandParameter(); + } else { + $command_param = $this->getPage()->getCallbackEventParameter(); } } elseif ($this->getPage()->IsPostBack) { if (method_exists($this->getPage()->PostBackEventTarget, 'getCommandParameter')) { diff --git a/gui/baculum/protected/Web/Portlets/DirectiveListTemplate.php b/gui/baculum/protected/Web/Portlets/DirectiveListTemplate.php index 0d92f0641..c955411fb 100644 --- a/gui/baculum/protected/Web/Portlets/DirectiveListTemplate.php +++ b/gui/baculum/protected/Web/Portlets/DirectiveListTemplate.php @@ -60,8 +60,12 @@ class DirectiveListTemplate extends ConfigListTemplate implements IActiveControl $this->attachEventHandler('OnDirectiveListLoad', $handler); } - public function onLoad($param) { - parent::onLoad($param); + public function onPreRender($param) { + parent::onPreRender($param); + $cmd = $this->getCmdParam(); + if ($this->getPage()->IsCallBack && (!$cmd || $cmd === 'show_all_directives') && method_exists($this, 'loadConfig')) { + $this->loadConfig(); + } if ($this->getPage()->IsCallBack || $this->getPage()->IsPostBack) { return; } diff --git a/gui/baculum/protected/Web/Portlets/DirectiveMultiComboBox.php b/gui/baculum/protected/Web/Portlets/DirectiveMultiComboBox.php index 9cca3a227..5b453e10f 100644 --- a/gui/baculum/protected/Web/Portlets/DirectiveMultiComboBox.php +++ b/gui/baculum/protected/Web/Portlets/DirectiveMultiComboBox.php @@ -27,11 +27,8 @@ Prado::using('Application.Web.Portlets.DirectiveListTemplate'); class DirectiveMultiComboBox extends DirectiveListTemplate { - public function onLoad($param) { - parent::onLoad($param); - if ($this->getCmdParam() !== 'add_multicombobox') { - $this->loadConfig(); - } + public function dataBind() { + $this->loadConfig(); } public function getDirectiveValue() { diff --git a/gui/baculum/protected/Web/Portlets/DirectiveMultiTextBox.php b/gui/baculum/protected/Web/Portlets/DirectiveMultiTextBox.php index 6d9c7880a..ed85b7c6f 100644 --- a/gui/baculum/protected/Web/Portlets/DirectiveMultiTextBox.php +++ b/gui/baculum/protected/Web/Portlets/DirectiveMultiTextBox.php @@ -27,11 +27,8 @@ Prado::using('Application.Web.Portlets.DirectiveListTemplate'); class DirectiveMultiTextBox extends DirectiveListTemplate { - public function onLoad($param) { - parent::onLoad($param); - if ($this->getCmdParam() !== 'add_multitextbox') { - $this->loadConfig(); - } + public function dataBind() { + $this->loadConfig(); } public function getDirectiveValue() { @@ -72,7 +69,6 @@ class DirectiveMultiTextBox extends DirectiveListTemplate { public function createMultiTextBoxElement($sender, $param) { $param->Item->Label->Text = $param->Item->Data['label']; $param->Item->Directive->Text = $param->Item->Data['directive_value']; - } public function addField($sender, $param) { diff --git a/gui/baculum/protected/Web/Portlets/DirectiveRenderer.php b/gui/baculum/protected/Web/Portlets/DirectiveRenderer.php index b9352fee7..52f7d76a0 100644 --- a/gui/baculum/protected/Web/Portlets/DirectiveRenderer.php +++ b/gui/baculum/protected/Web/Portlets/DirectiveRenderer.php @@ -24,6 +24,7 @@ Prado::using('System.Web.UI.ActiveControls.TActiveLabel'); Prado::using('System.Web.UI.ActiveControls.TActiveLinkButton'); Prado::using('System.Web.UI.ActiveControls.TActivePanel'); Prado::using('System.Web.UI.ActiveControls.TActiveRepeater'); +Prado::using('System.Web.UI.WebControls.TItemDataRenderer'); Prado::using('Application.Web.Portlets.DirectiveListTemplate'); Prado::using('Application.Web.Portlets.DirectiveCheckBox'); Prado::using('Application.Web.Portlets.DirectiveComboBox'); @@ -39,7 +40,7 @@ Prado::using('Application.Web.Portlets.DirectiveTimePeriod'); Prado::using('Application.Web.Portlets.DirectiveRunscript'); Prado::using('Application.Web.Portlets.DirectiveMessages'); -class DirectiveRenderer extends DirectiveListTemplate implements IDataRenderer { +class DirectiveRenderer extends TItemDataRenderer { const DATA = 'Data'; @@ -64,38 +65,15 @@ class DirectiveRenderer extends DirectiveListTemplate implements IDataRenderer { 'DirectiveMultiTextBox' ); - public $resource_names = array(); - - private $item_loaded = false; - - public function onLoad($param) { - parent::onLoad($param); - if (!$this->item_loaded) { - $this->createItemInternal(); - $this->item_loaded = true; - } - } - - public function dataBind() { - if (!$this->item_loaded) { - $this->createItemInternal(); - $this->item_loaded = true; - } - parent::dataBind(); + public function loadState() { + parent::loadState(); + $this->createItemInternal(); } public function createItemInternal() { $data = $this->getData(); $item = $this->createItem($data); - $this->addParsedObject($item); - $cmd = $item->getCmdParam(); - - if ($item instanceof DirectiveTemplate) { - $item->createDirective(); - } elseif ($item instanceof DirectiveListTemplate && $cmd === '') { - $item->loadConfig(); - } } public function createItem($data) {