]> git.ipfire.org Git - thirdparty/bacula.git/commitdiff
baculum: Make loading configuration controls easier
authorMarcin Haba <marcin.haba@bacula.pl>
Wed, 7 Aug 2019 04:57:16 +0000 (06:57 +0200)
committerMarcin Haba <marcin.haba@bacula.pl>
Sat, 14 Dec 2019 14:55:28 +0000 (15:55 +0100)
gui/baculum/protected/Web/Portlets/BaculaConfigDirectives.php
gui/baculum/protected/Web/Portlets/DirectiveComboBox.php
gui/baculum/protected/Web/Portlets/DirectiveControlTemplate.php
gui/baculum/protected/Web/Portlets/DirectiveListTemplate.php
gui/baculum/protected/Web/Portlets/DirectiveMultiComboBox.php
gui/baculum/protected/Web/Portlets/DirectiveMultiTextBox.php
gui/baculum/protected/Web/Portlets/DirectiveRenderer.php

index bbb971b362af380b59cc1031bdc7b45e1c2fb3d4..1b173e8a260659a9d34c8edace9666c1cf30fb81 100644 (file)
@@ -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);
index 62adbd31ba15696fad8370ed97187631e001b473..6609a3178584a832997d63b099f2e3f8852a8846 100644 (file)
@@ -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() {
index 8ec576f28d07624b122d673e56acbf15209d268e..042eef9c95b524f8f9298d150e158ae866a5d727 100644 (file)
@@ -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')) {
index 0d92f06415169114b7b1ccafb8639c4698f2f078..c955411fb569438cec5007227be13647ae4ead3e 100644 (file)
@@ -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;
                }
index 9cca3a2277004db1db750ffd39462dbc2cf53f53..5b453e10ffd76bb60b2d29efec5aca1d11153a8d 100644 (file)
@@ -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() {
index 6d9c7880a237d88bc20c63283a9294218f5715bf..ed85b7c6f32f6af0eb9e1d7a74851d21c641d13a 100644 (file)
@@ -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) {
index b9352fee709dd6a5df8bbca81130aea1c74e12b2..52f7d76a09253e0a97c1df74eb1032a0de422777 100644 (file)
@@ -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) {