]> git.ipfire.org Git - thirdparty/bacula.git/commitdiff
baculum: Create multiple combobox control and use it in console ACL directives
authorMarcin Haba <marcin.haba@bacula.pl>
Sun, 21 Jul 2019 08:59:08 +0000 (10:59 +0200)
committerMarcin Haba <marcin.haba@bacula.pl>
Sat, 14 Dec 2019 14:55:26 +0000 (15:55 +0100)
14 files changed:
gui/baculum/protected/Web/Data/data_desc.json
gui/baculum/protected/Web/Lang/en/messages.mo
gui/baculum/protected/Web/Lang/en/messages.po
gui/baculum/protected/Web/Lang/ja/messages.mo
gui/baculum/protected/Web/Lang/ja/messages.po
gui/baculum/protected/Web/Lang/pl/messages.mo
gui/baculum/protected/Web/Lang/pl/messages.po
gui/baculum/protected/Web/Lang/pt/messages.mo
gui/baculum/protected/Web/Lang/pt/messages.po
gui/baculum/protected/Web/Portlets/BaculaConfigDirectives.php
gui/baculum/protected/Web/Portlets/DirectiveMultiComboBox.php [new file with mode: 0644]
gui/baculum/protected/Web/Portlets/DirectiveMultiComboBox.tpl [new file with mode: 0644]
gui/baculum/protected/Web/Portlets/DirectiveMultiTextBox.php
gui/baculum/protected/Web/Portlets/DirectiveRenderer.php

index 4ac97006cc88964504f29d74815855481f7e0797..c6dc63ba2352fe77649234e26657b4c93f1cc07a 100644 (file)
                                "Required": false,
                                "ValueType": "acl",
                                "DefaultValue": 0,
-                               "FieldType": "MultiTextBox"
+                               "FieldType": "MultiComboBox",
+                               "Resource": "Job"
                        },
                        "ClientAcl": {
                                "Required": false,
                                "ValueType": "acl",
                                "DefaultValue": 0,
-                               "FieldType": "MultiTextBox"
+                               "FieldType": "MultiComboBox",
+                               "Resource": "Client"
                        },
                        "StorageAcl": {
                                "Required": false,
                                "ValueType": "acl",
                                "DefaultValue": 0,
-                               "FieldType": "MultiTextBox"
+                               "FieldType": "MultiComboBox",
+                               "Resource": "Storage"
                        },
                        "ScheduleAcl": {
                                "Required": false,
                                "ValueType": "acl",
                                "DefaultValue": 0,
-                               "FieldType": "MultiTextBox"
+                               "FieldType": "MultiComboBox",
+                               "Resource": "Schedule"
                        },
                        "RunAcl": {
                                "Required": false,
                                "Required": false,
                                "ValueType": "acl",
                                "DefaultValue": 0,
-                               "FieldType": "MultiTextBox"
+                               "FieldType": "MultiComboBox",
+                               "Resource": "Pool"
                        },
                        "CommandAcl": {
                                "Required": false,
                                "Required": false,
                                "ValueType": "acl",
                                "DefaultValue": 0,
-                               "FieldType": "MultiTextBox"
+                               "FieldType": "MultiComboBox",
+                               "Resource": "Fileset"
                        },
                        "CatalogAcl": {
                                "Required": false,
                                "ValueType": "acl",
                                "DefaultValue": 0,
-                               "FieldType": "MultiTextBox"
+                               "FieldType": "MultiComboBox",
+                               "Resource": "Catalog"
                        },
                        "WhereAcl": {
                                "Required": false,
                                "DefaultValue": 0,
                                "FieldType": "MultiTextBox"
                        },
-                       "RestoreClientAcl": {
+                       "BackupClientAcl": {
                                "Required": false,
                                "ValueType": "acl",
                                "DefaultValue": 0,
-                               "FieldType": "MultiTextBox"
+                               "FieldType": "MultiComboBox",
+                               "Resource": "Client"
                        },
-                       "BackupClientAcl": {
+                       "RestoreClientAcl": {
                                "Required": false,
                                "ValueType": "acl",
                                "DefaultValue": 0,
-                               "FieldType": "MultiTextBox"
+                               "FieldType": "MultiComboBox",
+                               "Resource": "Client"
                        },
                        "DirectoryAcl": {
                                "Required": false,
index a1ada2e831820dc0bf6d8094a9b1e6570aab5846..ef6051fe74b2163f4c28a19298f51044dee0565e 100644 (file)
Binary files a/gui/baculum/protected/Web/Lang/en/messages.mo and b/gui/baculum/protected/Web/Lang/en/messages.mo differ
index a5df9e4a23c7bd0d035e1ecf6e7b27e56a619ca1..e4e63ada483dd25a2d6334450dd93653823e20d5 100644 (file)
@@ -2224,3 +2224,6 @@ msgstr "Custom time range"
 
 msgid "Version:"
 msgstr "Version:"
+
+msgid "Add directive"
+msgstr "Add directive"
index 975c79ac2f9e7a9ab4af084aa179cb22fb9b0aa3..778cbace032310c4cfd3a8a36d80cc77feb771f7 100644 (file)
Binary files a/gui/baculum/protected/Web/Lang/ja/messages.mo and b/gui/baculum/protected/Web/Lang/ja/messages.mo differ
index bbbb853debccc841ef113136416d3349dc664604..2e698858e6be2e33a61049f27f4299ef945cc27d 100644 (file)
@@ -2314,3 +2314,6 @@ msgstr "Custom time range"
 
 msgid "Version:"
 msgstr "Version:"
+
+msgid "Add directive"
+msgstr "Add directive"
index 0b14df2f34ff3a02f76c2f57cbca88b20364ed20..2cd248262965cd7997bcf8452af35ab5d2de58dd 100644 (file)
Binary files a/gui/baculum/protected/Web/Lang/pl/messages.mo and b/gui/baculum/protected/Web/Lang/pl/messages.mo differ
index bed6e8854e04cfb33d235c71b81e75b0e447e29a..d7b1b50884f3d8932a7c42b9148e28e0d4a0b92b 100644 (file)
@@ -2231,3 +2231,6 @@ msgstr "Dopasowany zakres czasu"
 
 msgid "Version:"
 msgstr "Wersja:"
+
+msgid "Add directive"
+msgstr "Dodaj dyrektywÄ™"
index ebd5b154e62c05cc05b431c416f474bbbd35998a..330728d8262f03093c4db52830f4174121efc291 100644 (file)
Binary files a/gui/baculum/protected/Web/Lang/pt/messages.mo and b/gui/baculum/protected/Web/Lang/pt/messages.mo differ
index e1f37ce5bdf637bb9751d7fbd9889f8bca2810c7..54f30f0af598663912be0b84982591b606305aa3 100644 (file)
@@ -2239,3 +2239,6 @@ msgstr "Custom time range"
 
 msgid "Version:"
 msgstr "Version:"
+
+msgid "Add directive"
+msgstr "Add directive"
index 045561c573dcd3ee26df4b10073894b231533b87..bbb971b362af380b59cc1031bdc7b45e1c2fb3d4 100644 (file)
@@ -33,6 +33,7 @@ Prado::using('Application.Web.Portlets.DirectivePassword');
 Prado::using('Application.Web.Portlets.DirectiveSize');
 Prado::using('Application.Web.Portlets.DirectiveSpeed');
 Prado::using('Application.Web.Portlets.DirectiveTextBox');
+Prado::using('Application.Web.Portlets.DirectiveMultiComboBox');
 Prado::using('Application.Web.Portlets.DirectiveMultiTextBox');
 Prado::using('Application.Web.Portlets.DirectiveTimePeriod');
 Prado::using('Application.Web.Portlets.DirectiveRunscript');
@@ -66,6 +67,7 @@ class BaculaConfigDirectives extends DirectiveListTemplate {
                'DirectiveSchedule',
                'DirectiveMessages',
                'DirectiveRunscript',
+               'DirectiveMultiComboBox',
                'DirectiveMultiTextBox'
        );
 
@@ -307,7 +309,7 @@ class BaculaConfigDirectives extends DirectiveListTemplate {
                                                $directives[$directive_name] = $directive_value[$directive_name];
                                        } elseif ($this->directive_list_types[$i] === 'DirectiveSchedule') {
                                                $directives[$directive_name] = $directive_value[$directive_name];
-                                       } elseif ($this->directive_list_types[$i] === 'DirectiveMultiTextBox') {
+                                       } elseif ($this->directive_list_types[$i] === 'DirectiveMultiTextBox' || $this->directive_list_types[$i] === 'DirectiveMultiComboBox') {
                                                if (key_exists($directive_name, $directives)) {
                                                        $directive_value = array_merge($directives[$directive_name], $directive_value);
                                                }
diff --git a/gui/baculum/protected/Web/Portlets/DirectiveMultiComboBox.php b/gui/baculum/protected/Web/Portlets/DirectiveMultiComboBox.php
new file mode 100644 (file)
index 0000000..9cca3a2
--- /dev/null
@@ -0,0 +1,105 @@
+<?php
+/*
+ * Bacula(R) - The Network Backup Solution
+ * Baculum   - Bacula web interface
+ *
+ * Copyright (C) 2013-2019 Kern Sibbald
+ *
+ * The main author of Baculum is Marcin Haba.
+ * The original author of Bacula is Kern Sibbald, with contributions
+ * from many others, a complete list can be found in the file AUTHORS.
+ *
+ * You may use this file and others of this release according to the
+ * license defined in the LICENSE file, which includes the Affero General
+ * Public License, v3.0 ("AGPLv3") and some additional permissions and
+ * terms pursuant to its AGPLv3 Section 7.
+ *
+ * This notice must be preserved when any source code is
+ * conveyed and/or propagated.
+ *
+ * Bacula(R) is a registered trademark of Kern Sibbald.
+ */
+
+Prado::using('System.Web.UI.ActiveControls.TActiveLabel');
+Prado::using('System.Web.UI.ActiveControls.TActiveDropDownList');
+Prado::using('System.Web.UI.ActiveControls.TActiveLinkButton');
+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 getDirectiveValue() {
+               $values = array();
+               $controls = $this->MultiComboBoxRepeater->getItems();
+               foreach ($controls as $control) {
+                       $val = $control->Directive->getSelectedValue();
+                       if (!empty($val)) {
+                               $values[] = $val;
+                       }
+               }
+               return $values;
+       }
+
+       public function loadConfig() {
+               $resource_type = $this->getResourceType();
+               $resource_name = $this->getResourceName();
+               $directive_name = $this->getDirectiveName();
+               $resource = $this->getResource();
+               $resource_names = $this->getResourceNames();
+               $data = $this->getData();
+               $items = array();
+
+               if (!is_array($data)) {
+                       $data = array($data);
+               }
+               if (is_array($resource_names)) {
+                       if (key_exists($directive_name, $resource_names)) {
+                               $items = $resource_names[$directive_name];
+                       } elseif (key_exists($resource, $resource_names)) {
+                               $items = $resource_names[$resource];
+                       }
+               }
+
+               /**
+                * Dirty hack to support *all* keyword in resource name list
+                * @TODO: Add an control property to support this type cases
+                */
+               if ($resource_type == 'Console' && preg_match('/Acl$/i', $directive_name) == 1) {
+                       array_unshift($items, '*all*');
+               }
+
+               array_unshift($items, '');
+               $values = array();
+               for ($i = 0; $i < count($data); $i++) {
+                       $values[] = array(
+                               'items' => $items,
+                               'directive_value' => $data[$i],
+                               'label' => $this->getDirectiveName(),
+                               'show' => $this->getShow()
+                       );
+               }
+               $this->MultiComboBoxRepeater->DataSource = $values;
+               $this->MultiComboBoxRepeater->dataBind();
+       }
+
+       public function createMultiComboBoxElement($sender, $param) {
+               $param->Item->Label->Text = $param->Item->Data['label'];
+               $param->Item->Directive->DataSource = array_combine($param->Item->Data['items'], $param->Item->Data['items']);
+               $param->Item->Directive->setSelectedValue($param->Item->Data['directive_value']);
+               $param->Item->Directive->dataBind();
+       }
+
+       public function addField($sender, $param) {
+               $data = $this->getDirectiveValue();
+               $data[] = '';
+               $this->setData($data);
+               $this->loadConfig();
+       }
+}
+?>
diff --git a/gui/baculum/protected/Web/Portlets/DirectiveMultiComboBox.tpl b/gui/baculum/protected/Web/Portlets/DirectiveMultiComboBox.tpl
new file mode 100644 (file)
index 0000000..6929a79
--- /dev/null
@@ -0,0 +1,20 @@
+<com:TActiveRepeater ID="MultiComboBoxRepeater" OnItemDataBound="createMultiComboBoxElement">
+       <prop:ItemTemplate>
+               <div class="w3-row w3-margin-bottom<%=!$this->Data['show'] ? ' hide' : '';%>">
+                       <div class="w3-col w3-quarter"><com:TActiveLabel ID="Label" ActiveControl.EnableUpdate="false" />:</div>
+                       <div class="w3-col w3-threequarter directive_value">
+                               <com:TActiveDropDownList ID="Directive"
+                                       CssClass="w3-input w3-border w3-twothird"
+                                       AutoPostBack="false"
+                                       ActiveControl.EnableUpdate="false"
+                               />      <com:TActiveLinkButton ID="AddFieldBtn"
+                                               OnCommand="SourceTemplateControl.addField"
+                                               CommandParameter="add_multicombobox"
+                                       >
+                                       <i class="fa fa-plus" title="<%[ Add directive ]%>" alt="<%[ Add directive ]%>"></i>
+                               </com:TActiveLinkButton>
+                               <i class="fa fa-trash-alt remove_btn" onclick="document.getElementById('<%=$this->Directive->ClientID%>').value = '';" alt="<%[ Remove directive ]%>" title="<%[ Remove directive ]%>"></i>
+                       </div>
+               </div>
+       </prop:ItemTemplate>
+</com:TActiveRepeater>
index 67570595424d93e4f17451dfe3934cbd0db863a3..6d9c7880a237d88bc20c63283a9294218f5715bf 100644 (file)
@@ -49,10 +49,6 @@ class DirectiveMultiTextBox extends DirectiveListTemplate {
        }
 
        public function loadConfig() {
-               $load_values = $this->getLoadValues();
-               $host = $this->getHost();
-               $component_type = $this->getComponentType();
-               $component_name = $this->getComponentName();
                $resource_type = $this->getResourceType();
                $resource_name = $this->getResourceName();
                $directive_name = $this->getDirectiveName();
index cf3545427a5c6e7162906198d2def9420eaaad38..7cc69308bfa6ad8d3b839092d268c7d2541ae260 100644 (file)
@@ -33,6 +33,7 @@ Prado::using('Application.Web.Portlets.DirectivePassword');
 Prado::using('Application.Web.Portlets.DirectiveSize');
 Prado::using('Application.Web.Portlets.DirectiveSpeed');
 Prado::using('Application.Web.Portlets.DirectiveTextBox');
+Prado::using('Application.Web.Portlets.DirectiveMultiComboBox');
 Prado::using('Application.Web.Portlets.DirectiveMultiTextBox');
 Prado::using('Application.Web.Portlets.DirectiveTimePeriod');
 Prado::using('Application.Web.Portlets.DirectiveRunscript');
@@ -60,6 +61,7 @@ class DirectiveRenderer extends DirectiveListTemplate implements IItemDataRender
                'DirectiveSchedule',
                'DirectiveMessages',
                'DirectiveRunscript',
+               'DirectiveMultiComboBox',
                'DirectiveMultiTextBox'
        );
 
@@ -109,6 +111,7 @@ class DirectiveRenderer extends DirectiveListTemplate implements IItemDataRender
                        $control->setResourceNames($this->SourceTemplateControl->getResourceNames());
                        $control->setShow($data['show']);
                        $control->setGroupName($data['group_name']);
+                       $control->setResource($data['resource']);
                        $this->getControls()->add($control);
                        if (!$this->getPage()->IsCallBack || $this->getPage()->getCallbackEventParameter()  === 'show_all_directives' || $this->getCmdParam() === 'show') {
                                /*