From: Marcin Haba Date: Sun, 21 Jul 2019 08:59:08 +0000 (+0200) Subject: baculum: Create multiple combobox control and use it in console ACL directives X-Git-Tag: Release-9.6.0~189 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=388777c039111e514b2fdd25236419a35cf8f664;p=thirdparty%2Fbacula.git baculum: Create multiple combobox control and use it in console ACL directives --- diff --git a/gui/baculum/protected/Web/Data/data_desc.json b/gui/baculum/protected/Web/Data/data_desc.json index 4ac97006cc..c6dc63ba23 100644 --- a/gui/baculum/protected/Web/Data/data_desc.json +++ b/gui/baculum/protected/Web/Data/data_desc.json @@ -1701,25 +1701,29 @@ "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, @@ -1731,7 +1735,8 @@ "Required": false, "ValueType": "acl", "DefaultValue": 0, - "FieldType": "MultiTextBox" + "FieldType": "MultiComboBox", + "Resource": "Pool" }, "CommandAcl": { "Required": false, @@ -1743,13 +1748,15 @@ "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, @@ -1763,17 +1770,19 @@ "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, diff --git a/gui/baculum/protected/Web/Lang/en/messages.mo b/gui/baculum/protected/Web/Lang/en/messages.mo index a1ada2e831..ef6051fe74 100644 Binary files a/gui/baculum/protected/Web/Lang/en/messages.mo and b/gui/baculum/protected/Web/Lang/en/messages.mo differ diff --git a/gui/baculum/protected/Web/Lang/en/messages.po b/gui/baculum/protected/Web/Lang/en/messages.po index a5df9e4a23..e4e63ada48 100644 --- a/gui/baculum/protected/Web/Lang/en/messages.po +++ b/gui/baculum/protected/Web/Lang/en/messages.po @@ -2224,3 +2224,6 @@ msgstr "Custom time range" msgid "Version:" msgstr "Version:" + +msgid "Add directive" +msgstr "Add directive" diff --git a/gui/baculum/protected/Web/Lang/ja/messages.mo b/gui/baculum/protected/Web/Lang/ja/messages.mo index 975c79ac2f..778cbace03 100644 Binary files a/gui/baculum/protected/Web/Lang/ja/messages.mo and b/gui/baculum/protected/Web/Lang/ja/messages.mo differ diff --git a/gui/baculum/protected/Web/Lang/ja/messages.po b/gui/baculum/protected/Web/Lang/ja/messages.po index bbbb853deb..2e698858e6 100644 --- a/gui/baculum/protected/Web/Lang/ja/messages.po +++ b/gui/baculum/protected/Web/Lang/ja/messages.po @@ -2314,3 +2314,6 @@ msgstr "Custom time range" msgid "Version:" msgstr "Version:" + +msgid "Add directive" +msgstr "Add directive" diff --git a/gui/baculum/protected/Web/Lang/pl/messages.mo b/gui/baculum/protected/Web/Lang/pl/messages.mo index 0b14df2f34..2cd2482629 100644 Binary files a/gui/baculum/protected/Web/Lang/pl/messages.mo and b/gui/baculum/protected/Web/Lang/pl/messages.mo differ diff --git a/gui/baculum/protected/Web/Lang/pl/messages.po b/gui/baculum/protected/Web/Lang/pl/messages.po index bed6e8854e..d7b1b50884 100644 --- a/gui/baculum/protected/Web/Lang/pl/messages.po +++ b/gui/baculum/protected/Web/Lang/pl/messages.po @@ -2231,3 +2231,6 @@ msgstr "Dopasowany zakres czasu" msgid "Version:" msgstr "Wersja:" + +msgid "Add directive" +msgstr "Dodaj dyrektywę" diff --git a/gui/baculum/protected/Web/Lang/pt/messages.mo b/gui/baculum/protected/Web/Lang/pt/messages.mo index ebd5b154e6..330728d826 100644 Binary files a/gui/baculum/protected/Web/Lang/pt/messages.mo and b/gui/baculum/protected/Web/Lang/pt/messages.mo differ diff --git a/gui/baculum/protected/Web/Lang/pt/messages.po b/gui/baculum/protected/Web/Lang/pt/messages.po index e1f37ce5bd..54f30f0af5 100644 --- a/gui/baculum/protected/Web/Lang/pt/messages.po +++ b/gui/baculum/protected/Web/Lang/pt/messages.po @@ -2239,3 +2239,6 @@ msgstr "Custom time range" msgid "Version:" msgstr "Version:" + +msgid "Add directive" +msgstr "Add directive" diff --git a/gui/baculum/protected/Web/Portlets/BaculaConfigDirectives.php b/gui/baculum/protected/Web/Portlets/BaculaConfigDirectives.php index 045561c573..bbb971b362 100644 --- a/gui/baculum/protected/Web/Portlets/BaculaConfigDirectives.php +++ b/gui/baculum/protected/Web/Portlets/BaculaConfigDirectives.php @@ -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 index 0000000000..9cca3a2277 --- /dev/null +++ b/gui/baculum/protected/Web/Portlets/DirectiveMultiComboBox.php @@ -0,0 +1,105 @@ +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 index 0000000000..6929a793e2 --- /dev/null +++ b/gui/baculum/protected/Web/Portlets/DirectiveMultiComboBox.tpl @@ -0,0 +1,20 @@ + + +
+
:
+
+ + + + +
+
+
+
diff --git a/gui/baculum/protected/Web/Portlets/DirectiveMultiTextBox.php b/gui/baculum/protected/Web/Portlets/DirectiveMultiTextBox.php index 6757059542..6d9c7880a2 100644 --- a/gui/baculum/protected/Web/Portlets/DirectiveMultiTextBox.php +++ b/gui/baculum/protected/Web/Portlets/DirectiveMultiTextBox.php @@ -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(); diff --git a/gui/baculum/protected/Web/Portlets/DirectiveRenderer.php b/gui/baculum/protected/Web/Portlets/DirectiveRenderer.php index cf3545427a..7cc69308bf 100644 --- a/gui/baculum/protected/Web/Portlets/DirectiveRenderer.php +++ b/gui/baculum/protected/Web/Portlets/DirectiveRenderer.php @@ -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') { /*