]> git.ipfire.org Git - thirdparty/bacula.git/commitdiff
baculum: Add copy resource function to enable creating new resources based on others
authorMarcin Haba <marcin.haba@bacula.pl>
Wed, 10 Nov 2021 04:09:32 +0000 (05:09 +0100)
committerEric Bollengier <eric@baculasystems.com>
Thu, 24 Mar 2022 08:03:27 +0000 (09:03 +0100)
17 files changed:
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/Lang/ru/messages.mo
gui/baculum/protected/Web/Lang/ru/messages.po
gui/baculum/protected/Web/Pages/NewResource.page
gui/baculum/protected/Web/Pages/NewResource.php
gui/baculum/protected/Web/Portlets/BaculaConfigDirectives.php
gui/baculum/protected/Web/Portlets/BaculaConfigDirectives.tpl
gui/baculum/protected/Web/Portlets/BaculaConfigResourceList.php
gui/baculum/protected/Web/Portlets/BaculaConfigResourceList.tpl
gui/baculum/protected/Web/Portlets/DirectiveListTemplate.php

index 48ac656068bfe673631db3c1c35379f1914abc53..dd33943e8abdf9cd65bf5be6a671f16b10cbb459 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 9184c2e8e03580c68927e7ed8f8986ad6b7444b7..124faafb3b68c4a81b28bebf1a512c033999f257 100644 (file)
@@ -3886,3 +3886,6 @@ msgstr "Enable Bacula messages log window:"
 
 msgid "The messages log window enables to review Bacula logs in one place available from almost every part on the interface. To collect logs is used the bconsole 'messages' command. The messages log window is displayed after clicking on the envelope icon at the top right side of the interface. This function is enabled by default. If enabled, it is available only for users with the Administrator role assigned."
 msgstr "The messages log window enables to review Bacula logs in one place available from almost every part on the interface. To collect logs is used the bconsole 'messages' command. The messages log window is displayed after clicking on the envelope icon at the top right side of the interface. This function is enabled by default. If enabled, it is available only for users with the Administrator role assigned."
+
+msgid "Copy configuration from:"
+msgstr "Copy configuration from:"
index b8ef5cd3c320c634cbe920a2dd9f19cdee971710..795eb23737a0f390bb934ef351572c877a1fa4d4 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 c591bcf4830f9b1d8425d030986b1e29e649c9ef..e1cb0abb02378ea7a0b9d1c8a806b4c38cb4ffe9 100644 (file)
@@ -3972,3 +3972,6 @@ msgstr "Enable Bacula messages log window:"
 
 msgid "The messages log window enables to review Bacula logs in one place available from almost every part on the interface. To collect logs is used the bconsole 'messages' command. The messages log window is displayed after clicking on the envelope icon at the top right side of the interface. This function is enabled by default. If enabled, it is available only for users with the Administrator role assigned."
 msgstr "The messages log window enables to review Bacula logs in one place available from almost every part on the interface. To collect logs is used the bconsole 'messages' command. The messages log window is displayed after clicking on the envelope icon at the top right side of the interface. This function is enabled by default. If enabled, it is available only for users with the Administrator role assigned."
+
+msgid "Copy configuration from:"
+msgstr "Copy configuration from:"
index a81a1f97a32047a92a10b857a7caf5577d2d0fe0..e7a190612392a8604bd3a9347da6b18e57fcf468 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 fd4429486b2a97435c39ac324236e488a988f27b..40711ae0d4d0e5a4356fc42f672fc048d922acbe 100644 (file)
@@ -3896,3 +3896,6 @@ msgstr "Enable Bacula messages log window:"
 
 msgid "The messages log window enables to review Bacula logs in one place available from almost every part on the interface. To collect logs is used the bconsole 'messages' command. The messages log window is displayed after clicking on the envelope icon at the top right side of the interface. This function is enabled by default. If enabled, it is available only for users with the Administrator role assigned."
 msgstr "The messages log window enables to review Bacula logs in one place available from almost every part on the interface. To collect logs is used the bconsole 'messages' command. The messages log window is displayed after clicking on the envelope icon at the top right side of the interface. This function is enabled by default. If enabled, it is available only for users with the Administrator role assigned."
+
+msgid "Copy configuration from:"
+msgstr "Copy configuration from:"
index 3e6dc26106991ddd54184009b9cf38daa07e085a..3f9bef2315764e004fb2b26f01c37270045ebfe4 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 f9f98bda9217eacc2e213aff436b2d6c135a0720..f35c06402ccd94f1317ca976ac7d936cc3a722fc 100644 (file)
@@ -3897,3 +3897,6 @@ msgstr "Enable Bacula messages log window:"
 
 msgid "The messages log window enables to review Bacula logs in one place available from almost every part on the interface. To collect logs is used the bconsole 'messages' command. The messages log window is displayed after clicking on the envelope icon at the top right side of the interface. This function is enabled by default. If enabled, it is available only for users with the Administrator role assigned."
 msgstr "The messages log window enables to review Bacula logs in one place available from almost every part on the interface. To collect logs is used the bconsole 'messages' command. The messages log window is displayed after clicking on the envelope icon at the top right side of the interface. This function is enabled by default. If enabled, it is available only for users with the Administrator role assigned."
+
+msgid "Copy configuration from:"
+msgstr "Copy configuration from:"
index 1eba14ae58f0e42698ff5ad249ddf970a039ab36..c78b950260dc8d9850636ced7c864395950a7383 100644 (file)
Binary files a/gui/baculum/protected/Web/Lang/ru/messages.mo and b/gui/baculum/protected/Web/Lang/ru/messages.mo differ
index 4f68bea31b34f335e0e1c77b7599d1b8f8461fa3..c94092edfdf9f9ebbf4cb56cb09143c92b44b15d 100644 (file)
@@ -3897,3 +3897,6 @@ msgstr "Enable Bacula messages log window:"
 
 msgid "The messages log window enables to review Bacula logs in one place available from almost every part on the interface. To collect logs is used the bconsole 'messages' command. The messages log window is displayed after clicking on the envelope icon at the top right side of the interface. This function is enabled by default. If enabled, it is available only for users with the Administrator role assigned."
 msgstr "The messages log window enables to review Bacula logs in one place available from almost every part on the interface. To collect logs is used the bconsole 'messages' command. The messages log window is displayed after clicking on the envelope icon at the top right side of the interface. This function is enabled by default. If enabled, it is available only for users with the Administrator role assigned."
+
+msgid "Copy configuration from:"
+msgstr "Copy configuration from:"
index 7d91ce4c1bb615f35c7f6671673b485f8bf2a532..40b3e9b2648cc38f220ace07fc3789e0fcdd81bb 100644 (file)
@@ -7,9 +7,18 @@
                </h5>
        </header>
        <div>
-               <button type="button" class="w3-button w3-green w3-margin-left w3-margin-bottom" onclick="document.getElementById('new_resource').style.display = 'block'">
+               <button type="button" class="w3-button w3-green w3-margin-left w3-margin-bottom w3-margin-right w3-show-inline-block" onclick="document.getElementById('new_resource').style.display = 'block'">
                        <i class="fa fa-plus"></i> &nbsp;<%=Prado::localize('Add new resource')%>
                </button>
+               <span style="vertical-align: super"><%[ Copy configuration from: ]%></span>
+               <div class="directive_field w3-show-inline-block w3-margin-bottom" style="vertical-align: middle">
+                       <com:TActiveDropDownList
+                               ID="ResourcesToCopy"
+                               CssClass="w3-select w3-border w3-show-inline-block"
+                               Style="min-width: 300px"
+                               OnSelectedIndexChanged="copyConfig"
+                       />
+               </div>
                <div id="resource_save_ok_box" class="w3-modal" style="display: none">
                        <div class="w3-modal-content w3-card-4 w3-animate-zoom" style="width: 600px">
                                <header class="w3-container w3-green">
index af33052d2aa4ec7fe6a9fc05f33ecb175f541adb..54eb8c314ecae990797402e2f9b3d38700f56e09 100644 (file)
@@ -44,6 +44,14 @@ class NewResource extends BaculumWebPage {
                if ($this->IsCallBack || $this->IsPostBack) {
                        return;
                }
+               if (key_exists('HTTP_REFERER', $_SERVER)) {
+                       $this->setOriginUrl($_SERVER['HTTP_REFERER']);
+               }
+               $this->setConfigForm();
+               $this->loadResourcesToCopy();
+       }
+
+       private function setConfigForm($resource_name = null) {
                $component_type = null;
                $component_name = null;
                $resource_type = null;
@@ -65,12 +73,45 @@ class NewResource extends BaculumWebPage {
                        $this->NewResource->setComponentType($component_type);
                        $this->NewResource->setComponentName($component_name);
                        $this->NewResource->setResourceType($resource_type);
-                       $this->NewResource->setLoadValues(false);
+                       if (is_string($resource_name)) {
+                               $this->NewResource->setResourceName($resource_name);
+                               $this->NewResource->setLoadValues(true);
+                               $this->NewResource->setCopyMode(true);
+                       } else {
+                               $this->NewResource->setLoadValues(false);
+                               $this->NewResource->setCopyMode(false);
+                       }
                        $this->NewResource->raiseEvent('OnDirectiveListLoad', $this, null);
                        $this->setHosts();
                }
-               if (key_exists('HTTP_REFERER', $_SERVER)) {
-                       $this->setOriginUrl($_SERVER['HTTP_REFERER']);
+       }
+
+       private function loadResourcesToCopy() {
+               if ($this->Request->contains('component_type') && $this->Request->contains('resource_type')) {
+                       $component_type = $this->Request['component_type'];
+                       $resource_type = $this->Request['resource_type'];
+                       $resources = ['' => ''];
+                       $params = [
+                               'config',
+                               $component_type,
+                               $resource_type
+                       ];
+                       $res = $this->getModule('api')->get($params);
+                       if ($res->error === 0) {
+                               for ($i = 0; $i < count($res->output); $i++) {
+                                       $r = $res->output[$i]->{$resource_type}->Name;
+                                       $resources[$r] = $r;
+                               }
+                       }
+                       $this->ResourcesToCopy->DataSource = $resources;
+                       $this->ResourcesToCopy->dataBind();
+               }
+       }
+
+       public function copyConfig($sender, $param) {
+               $resource_name = $this->ResourcesToCopy->SelectedValue;
+               if (!empty($resource_name)) {
+                       $this->setConfigForm($resource_name);
                }
        }
 
index 1892ef70390463653113a1c88e50c1387eec09a2..3e98b4361ec764866cbe8c79a1076a7a331bb84f 100644 (file)
@@ -111,6 +111,10 @@ class BaculaConfigDirectives extends DirectiveListTemplate {
                        // This control is loaded only once, otherwise fields loose assigned values.
                        return;
                }
+               $copy_mode = $this->getCopyMode();
+               if ($copy_mode) {
+                       $this->setShowAllDirectives(true);
+               }
 
                $host = $this->getHost();
                $component_type = $this->getComponentType();
@@ -250,6 +254,12 @@ class BaculaConfigDirectives extends DirectiveListTemplate {
                $this->RepeaterDirectives->dataBind();
                $this->ConfigDirectives->Display = 'Dynamic';
                $this->IsDirectiveCreated = true;
+               if ($copy_mode) {
+                       $this->getPage()->getCallbackClient()->callClientFunction(
+                               'oBaculaConfigSection.show_sections',
+                               [true]
+                       );
+               }
        }
 
        public function loadDirectives($sender, $param) {
@@ -364,7 +374,7 @@ class BaculaConfigDirectives extends DirectiveListTemplate {
                        // In some cases with double control load Name value stays empty. Recreate it here.
                        $directives['Name'] = $res_name_dir = $resource_name;
                }
-               if ($load_values === true) {
+               if ($load_values === true && $this->getCopyMode() === false) {
                        if ($resource_name !== $res_name_dir) {
                                // RENAME RESOURCE
                                if ($this->renameResource($res_name_dir)) {
index f54ee41f5f257d4fa7a5e9295333066995ee5357..0675d7425db71155d98325adae1e8848d072472b 100644 (file)
@@ -42,7 +42,7 @@
                        ID="DirectiveSetting"
                        Resource="<%=$this->getResource()%>"
                        OnLoadDirectives="loadDirectives"
-                       Visible="<%=$this->LoadValues%>"
+                       Visible="<%=$this->LoadValues && !$this->CopyMode%>"
                />
                <com:TActiveLinkButton
                        CssClass="w3-button w3-red w3-right"
@@ -71,7 +71,7 @@
                        CommandParameter="save"
                >
                        <prop:Text>
-                               <i class="fa fa-save"></i> &nbsp;<%=$this->getLoadValues() ? Prado::localize('Save') : Prado::localize('Create')%>
+                               <i class="fa fa-save"></i> &nbsp;<%=$this->getLoadValues() && !$this->getCopyMode() ? Prado::localize('Save') : Prado::localize('Create')%>
                        </prop:Text>
                        <prop:ClientSide.OnLoading>
                                $('.save_progress').css({'visibility': '', 'display': 'inline-block'});
index d75e622114a3b646c6a1c22d896a9b5d30635fd8..2f5be191e13fef2ee3295611a58fb445a8d729a9 100644 (file)
@@ -106,10 +106,13 @@ class BaculaConfigResourceList extends Portlets {
 
        public function loadResourceWindow($sender, $param) {
                list($cmd, $name) = $param->getCallbackParameter();
+               $copy_el_id = 'resource_window_copy_resource' . $this->ClientID;
                if (!empty($name)) {
                        // edit existing resource
                        $this->ResourceConfig->setResourceName($name);
                        $this->ResourceConfig->setLoadValues(true);
+                       $this->ResourceConfig->setCopyMode(false);
+                       $this->getPage()->getCallbackClient()->hide($copy_el_id);
                } else {
                        // add new resource
                        $this->ResourceConfig->setLoadValues(false);
@@ -117,6 +120,8 @@ class BaculaConfigResourceList extends Portlets {
                                'oBaculaConfigSection.show_sections',
                                [true]
                        );
+                       $this->loadResourcesToCopy();
+                       $this->getPage()->getCallbackClient()->show($copy_el_id);
                }
                $host = $this->getHost();
                $component_type = $this->getComponentType();
@@ -134,6 +139,37 @@ class BaculaConfigResourceList extends Portlets {
                $this->ResourceConfig->unloadDirectives();
        }
 
+       private function loadResourcesToCopy() {
+               $component_type = $this->getComponentType();
+               $resource_type = $this->getResourceType();
+               $resources = ['' => ''];
+               $params = [
+                       'config',
+                       $component_type,
+                       $resource_type
+               ];
+               $res = $this->getModule('api')->get($params);
+               if ($res->error === 0) {
+                       for ($i = 0; $i < count($res->output); $i++) {
+                               $r = $res->output[$i]->{$resource_type}->Name;
+                               $resources[$r] = $r;
+                       }
+               }
+               $this->ResourcesToCopy->DataSource = $resources;
+               $this->ResourcesToCopy->dataBind();
+       }
+
+       public function copyConfig($sender, $param) {
+               $resource_name = $this->ResourcesToCopy->SelectedValue;
+               if (!empty($resource_name)) {
+                       $this->ResourceConfig->setResourceName($resource_name);
+                       $this->ResourceConfig->setLoadValues(true);
+                       $this->ResourceConfig->setCopyMode(true);
+                       $this->ResourceConfig->raiseEvent('OnDirectiveListLoad', $this, null);
+               }
+       }
+
+
        public function removeResource($sender, $param) {
                $host = $this->getHost();
                $component_type = $this->getComponentType();
index 94dc6b0bc3e63f0b967cd8f4590279d4a9ed421b..6d03245d7bbbb3d6032885646dd933625e48c65d 100644 (file)
@@ -133,6 +133,17 @@ var oBaculaConfigResourceList<%=$this->ClientID%> = {
                        <h2 id="resource_window_title_add<%=$this->ClientID%>" style="display: none"><%[ Add ]%> <com:TActiveLabel ID="ResourceTypeAddWindowTitle" /></h2>
                        <h2 id="resource_window_title_edit<%=$this->ClientID%>" style="display: none"><%[ Edit ]%> <com:TActiveLabel ID="ResourceTypeEditWindowTitle" /></h2>
                </header>
+               <div id="resource_window_copy_resource<%=$this->ClientID%>"class="w3-container w3-margin-left w3-margin-right w3-margin-top w3-right" style="display: none">
+                       <span style="vertical-align: super"><%[ Copy configuration from: ]%></span>
+                       <div class="directive_field w3-show-inline-block w3-margin-bottom" style="vertical-align: middle">
+                               <com:TActiveDropDownList
+                                       ID="ResourcesToCopy"
+                                       CssClass="w3-select w3-border w3-show-inline-block"
+                                       Style="min-width: 300px"
+                                       OnSelectedIndexChanged="copyConfig"
+                               />
+                       </div>
+               </div>
                <div class="w3-container w3-margin-left w3-margin-right w3-margin-top">
                        <com:Application.Web.Portlets.BaculaConfigDirectives
                                ID="ResourceConfig"
index 45c72e0f67dbe5164260a09ecee766206245c6c9..1d1332cc9b495f935249cb81047eefe02076345f 100644 (file)
@@ -46,6 +46,7 @@ class DirectiveListTemplate extends ConfigListTemplate implements IActiveControl
        const PARENT_NAME = 'ParentName';
        const GROUP_NAME = 'GroupName';
        const IS_DIRECTIVE_CREATED = 'IsDirectiveCreated';
+       const COPY_MODE = 'CopyMode';
 
        public $doc;
 
@@ -198,6 +199,15 @@ class DirectiveListTemplate extends ConfigListTemplate implements IActiveControl
                $this->setViewState(self::IS_DIRECTIVE_CREATED, $is_created);
        }
 
+       public function getCopyMode() {
+               return $this->getViewState(self::COPY_MODE, false);
+       }
+
+       public function setCopyMode($copy_mode) {
+               $copy_mode = TPropertyValue::ensureBoolean($copy_mode);
+               $this->setViewState(self::COPY_MODE, $copy_mode, false);
+       }
+
        public function setDoc() {
                $component_type = $this->getComponentType();
                $resource_type = $this->getResourceType();