]> git.sur5r.net Git - bacula/bacula/commitdiff
baculum: Add removing single resource
authorMarcin Haba <marcin.haba@bacula.pl>
Sun, 19 Nov 2017 14:04:46 +0000 (15:04 +0100)
committerMarcin Haba <marcin.haba@bacula.pl>
Sun, 19 Nov 2017 14:09:02 +0000 (15:09 +0100)
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/Pages/config.xml
gui/baculum/protected/Web/Portlets/BaculaConfigResources.php
gui/baculum/protected/Web/Portlets/BaculaConfigResources.tpl

index 3d7319622b01c4eb4215e6a21d177524156845d1..523418c02ef99a531ac27da154c1ed2774a0984d 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 b588d8968e6e640434528f6028192b2a648a45f6..b9d0409fd138a32a774f8806aae093e6cedcba91 100644 (file)
@@ -1420,3 +1420,19 @@ msgstr "Field required."
 
 msgid "Invalid value. Integer value required."
 msgstr "Invalid value. Integer value required."
+
+msgid "Resource %s \"%s\" is used in the following resources:"
+msgstr "Resource %s \"%s\" is used in the following resources:"
+
+msgid "Component: %s, Resource: %s \"%s\", Directive: %s"
+msgstr "Component: %s, Resource: %s \"%s\", Directive: %s"
+
+msgid "Are you sure that you want to remove %s resource \"%s\"?"
+msgstr "Are you sure that you want to remove %s resource \"%s\"?"
+
+msgid "Resource %s \"%s\" removed successfully."
+msgstr "Resource %s \"%s\" removed successfully."
+
+msgid "Please unassign resource %s \"%s\" from these resources and try again."
+msgstr "Please unassign resource %s \"%s\" from these resources and try again."
+
index 02a0e29f7d1591b4d3721a73c30346d864605a2c..4454027436636d6b80b82d087c1dc87cb62b4d91 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 a4eab462d5076eb5a953a2496364900110790b57..1d460895ec7d5d7533cc4283bee44bfdbf2e7259 100644 (file)
@@ -1171,3 +1171,19 @@ msgstr "Field required."
 
 msgid "Invalid value. Integer value required."
 msgstr "Invalid value. Integer value required."
+
+msgid "Resource %s \"%s\" is used in the following resources:"
+msgstr "Resource %s \"%s\" is used in the following resources:"
+
+msgid "Component: %s, Resource: %s \"%s\", Directive: %s"
+msgstr "Component: %s, Resource: %s \"%s\", Directive: %s"
+
+msgid "Are you sure that you want to remove %s resource \"%s\"?"
+msgstr "Are you sure that you want to remove %s resource \"%s\"?"
+
+msgid "Resource %s \"%s\" removed successfully."
+msgstr "Resource %s \"%s\" removed successfully."
+
+msgid "Please unassign resource %s \"%s\" from these resources and try again."
+msgstr "Please unassign resource %s \"%s\" from these resources and try again."
+
index 15040e068183a1772bcddf94cbb455177bc322a6..054235dd35a0f55c5893b8e6a042a2b09d113089 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 84f967b446f65dc97ab5f3466a0acb5854ef1aa4..9c5eae621ff6bc3187863db09851c2ad3d33c954 100644 (file)
@@ -1427,3 +1427,19 @@ msgstr "Pole wymagane."
 
 msgid "Invalid value. Integer value required."
 msgstr "Niepoprawna wartość. Wymagane jest podanie liczby całkowitej."
+
+msgid "Resource %s \"%s\" is used in the following resources:"
+msgstr "Zasób %s \"%s\" jest użyty w następujących zasobach:"
+
+msgid "Component: %s, Resource: %s \"%s\", Directive: %s"
+msgstr "Komponent: %s, Zasób: %s \"%s\", Dyrektywa: %s"
+
+msgid "Are you sure that you want to remove %s resource \"%s\"?"
+msgstr "Czy jesteś pewien, że chcesz usunąć zasób %s \"%s\"?"
+
+msgid "Resource %s \"%s\" removed successfully."
+msgstr "Zasób %s \"%s\" został usunięty pomyślnie."
+
+msgid "Please unassign resource %s \"%s\" from these resources and try again."
+msgstr "Proszę wypisać zasób %s \"%s\" z tych zasobów i spróbować ponownie."
+
index 2b901fd01cd575a1897f0adfbfa33904718ed835..a4e3dcdf01408070ce66cf6afe20c57b274406c1 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 09cb86ec7efd9fba243230df822d4d87da5aa0bd..9cbacbd9ae73cb5d820b134b914f2ab66067ab82 100644 (file)
@@ -1435,3 +1435,19 @@ msgstr "Field required."
 
 msgid "Invalid value. Integer value required."
 msgstr "Invalid value. Integer value required."
+
+msgid "Resource %s \"%s\" is used in the following resources:"
+msgstr "Resource %s \"%s\" is used in the following resources:"
+
+msgid "Component: %s, Resource: %s \"%s\", Directive: %s"
+msgstr "Component: %s, Resource: %s \"%s\", Directive: %s"
+
+msgid "Are you sure that you want to remove %s resource \"%s\"?"
+msgstr "Are you sure that you want to remove %s resource \"%s\"?"
+
+msgid "Resource %s \"%s\" removed successfully."
+msgstr "Resource %s \"%s\" removed successfully."
+
+msgid "Please unassign resource %s \"%s\" from these resources and try again."
+msgstr "Please unassign resource %s \"%s\" from these resources and try again."
+
index dbd439b9fe33084340f4a5c0ab3fd7be94294f8b..2b820476887149f13fac1af5f362668f11856894 100644 (file)
@@ -9,6 +9,7 @@
                <!-- data modules -->
                <module id="api" class="Application.Web.Class.BaculumAPIClient" />
                <module id="data_desc" class="Application.Web.Class.DataDescription" />
+               <module id="data_deps" class="Application.Web.Class.DataDependencies" />
                <module id="globalization" class="TGlobalization">
                        <translation type="gettext" source="Application.Web.Lang" marker="@@" autosave="false" cache="false" DefaultCulture="en" />
                </module>
index b24db4997535ff168f54b0c17e2abaeb71129ac5..5083f58fc18d7bb4218be4c35270a7dd6d6304c9 100644 (file)
@@ -77,6 +77,7 @@ class BaculaConfigResources extends ResourceListTemplate {
                        $control->setResourceName($param->Item->DataItem['resource_name']);
                        $control->setResourceNames($this->resource_names);
                }
+               $param->Item->RemoveResource->setCommandParameter($param->Item->DataItem);
        }
 
        public function getDirectives($sender, $param) {
@@ -85,5 +86,144 @@ class BaculaConfigResources extends ResourceListTemplate {
                        $control->raiseEvent('OnDirectiveListLoad', $this, null);
                }
        }
+
+       /**
+        * Remove resource callback method.
+        *
+        * @return object $sender sender instance
+        * @return mixed $param additional parameters
+        * @return none
+        */
+       public function removeResource($sender, $param) {
+               if (!$this->getPage()->IsCallback) {
+                       // removing resource available only by callback
+                       return;
+               }
+               $host_params = $param->getCommandParameter();
+               if (!is_array($host_params) || count($host_params) === 0) {
+                       return;
+               }
+               $host = $this->getHost();
+               $config = $this->getConfigData($host, $host_params['component_type']);
+               $deps = $this->getModule('data_deps')->checkDependencies(
+                       $host_params['component_type'],
+                       $host_params['resource_type'],
+                       $host_params['resource_name'],
+                       $config
+               );
+               if (count($deps) === 0) {
+                       // NO DEPENDENCY. Ready to remove.
+                       $this->removeResourceFromConfig(
+                               $config,
+                               $host_params['resource_type'],
+                               $host_params['resource_name']
+                       );
+                       $result = $this->getModule('api')->set(
+                               array('config', $host_params['component_type']),
+                               array('config' => json_encode($config)),
+                               $host,
+                               false
+                       );
+                       if ($result->error === 0) {
+                               $this->showRemovedResourceInfo(
+                                       $host_params['resource_type'],
+                                       $host_params['resource_name']
+                               );
+                       } else {
+                               $this->showRemovedResourceError($result->output);
+                       }
+               } else {
+                       // DEPENDENCIES EXIST. List them on the interface.
+                       $this->showDependenciesError(
+                               $deps,
+                               $host_params['resource_type'],
+                               $host_params['resource_name']
+                       );
+               }
+       }
+
+       /**
+        * Show removed resource information.
+        *
+        * @param string $resource_type removed resource type
+        * @param string $resource_name removed resource name
+        * @return none
+        */
+       private function showRemovedResourceInfo($resource_type, $resource_name) {
+               $msg = Prado::localize('Resource %s "%s" removed successfully.');
+               $msg = sprintf(
+                       $msg,
+                       $resource_type,
+                       $resource_name
+               );
+               $this->RemoveResourceOk->Text = $msg;
+               $this->getPage()->getCallbackClient()->hide($this->RemoveResourceError);
+               $this->getPage()->getCallbackClient()->show($this->RemoveResourceOk);
+       }
+
+       /**
+        * Show removed resource error message.
+        *
+        * @param string $error_message error message
+        * @return none
+        */
+       private function showRemovedResourceError($error_message) {
+               $this->RemoveResourceError->Text = $error_message;
+               $this->getPage()->getCallbackClient()->hide($this->RemoveResourceOk);
+               $this->getPage()->getCallbackClient()->show($this->RemoveResourceError);
+       }
+
+       /**
+        * Show dependencies error message.
+        *
+        * @param array $deps list dependencies for the removing resource
+        * @param string $resource_type resource type of the removing resource
+        * @param string $resource_name resource name of the removing resource
+        * @return none
+        */
+       private function showDependenciesError($deps, $resource_type, $resource_name) {
+               $emsg = Prado::localize('Resource %s "%s" is used in the following resources:');
+               $emsg = sprintf($emsg, $resource_type, $resource_name);
+               $emsg_deps = Prado::localize('Component: %s, Resource: %s "%s", Directive: %s');
+               $dependencies = array();
+               for ($i = 0; $i < count($deps); $i++) {
+                       $dependencies[] = sprintf(
+                               $emsg_deps,
+                               $deps[$i]['component_type'],
+                               $deps[$i]['resource_type'],
+                               $deps[$i]['resource_name'],
+                               $deps[$i]['directive_name']
+                       );
+               }
+               $emsg_sum = Prado::localize('Please unassign resource %s "%s" from these resources and try again.');
+               $emsg_sum = sprintf($emsg_sum, $resource_type, $resource_name);
+               $error = array($emsg, implode('<br />', $dependencies),  $emsg_sum);
+               $error_message = implode('<br /><br />', $error);
+               $this->showRemovedResourceError($error_message);
+       }
+
+       /**
+        * Remove resource from config.
+        * Note, passing config by reference.
+        *
+        * @param array $config entire config
+        * @param string $resource_type resource type to remove
+        * @param string $resource_name resource name to remove
+        * @return none
+        */
+       private function removeResourceFromConfig(&$config, $resource_type, $resource_name) {
+               for ($i = 0; $i < count($config); $i++) {
+                       foreach ($config[$i] as $rtype => $resource) {
+                               if (!property_exists($resource, 'Name')) {
+                                       continue;
+                               }
+                               if ($rtype === $resource_type && $resource->Name === $resource_name) {
+                                       // remove resource
+                                       array_splice($config, $i, 1);
+                                       break;
+                               }
+                       }
+               }
+       }
 }
 ?>
index 303d8329b6c585aee336ea981a09c63e96294262..1d2090f07182556af327b8fcbc416deedf7124c5 100644 (file)
@@ -1,8 +1,30 @@
 <div class="config_resources" style="display: none">
+       <com:TActiveLabel ID="RemoveResourceOk" Display="None" CssClass="validate" />
+       <com:TActiveLabel ID="RemoveResourceError" Display="None" CssClass="validator" />
        <com:TActiveRepeater ID="RepeaterResources" OnItemCreated="createResourceListElement">
                <prop:ItemTemplate>
                        <com:TPanel>
-                               <table class="resource" onmousedown="(event.target||event.srcElement).id != '<%=$this->Resource->ClientID%>' ? $('#<%=$this->Resource->ClientID%>').trigger('click') : '';" onmouseover="$(this).find('a.action_link').addClass('resource_selected');" onmouseout="$(this).find('a.action_link').removeClass('resource_selected');">
+                               <script type="text/javascript">
+                               <%=$this->Resource->ClientID%>_mousedown = function(event) {
+                                       var t = (event.target||event.srcElement);
+                                       var res_id = '<%=$this->Resource->ClientID%>';
+                                       if (t.id != res_id && !/^<%=$this->RemoveResource->ClientID%>/.test(t.id)) {
+                                               $('.validate, .validator').hide(); // hide validator messages
+                                               $('#' + res_id).trigger('click');
+                                       }
+                               };
+                               document.getElementById('<%=$this->RemoveResource->ClientID%>').onclick = function(event) {
+                                       var t = (event.target||event.srcElement);
+                                       var cmsg = '<%[ Are you sure that you want to remove %s resource "%s"? ]%>';
+                                       cmsg = cmsg.replace('%s', '<%=$this->DataItem['resource_type']%>');
+                                       cmsg = cmsg.replace('%s', '<%=$this->DataItem['resource_name']%>');
+                                       if (/^<%=$this->RemoveResource->ClientID%>/.test(t.id) && confirm(cmsg)) {
+                                               return true;
+                                       }
+                                       return false;
+                               };
+                               </script>
+                               <table class="resource" onmousedown="return <%=$this->Resource->ClientID%>_mousedown(event);" onmouseover="$(this).find('a.action_link').addClass('resource_selected');" onmouseout="$(this).find('a.action_link').removeClass('resource_selected');">
                                        <tr>
                                                <td><com:TActiveLinkButton
                                                        ID="Resource"
                                                        <img src="<%=$this->getPage()->getTheme()->getBaseUrl()%>/ajax-loader-arrows.gif" alt="" style="display: none" />
                                                </td>
                                                <td class="right" style="height: 26px">
-                                                       <!--a class="action_link" href="javascript:void(0)"><img src="<%=$this->getPage()->getTheme()->getBaseUrl()%>/config.png" alt="<%[ Edit ]%>" /> <%[ Edit ]%></a>
-                                                       <a class="action_link" href="javascript:void(0)"><img src="<%=$this->getPage()->getTheme()->getBaseUrl()%>/icon_err.png" alt="<%[ Remove ]%>" /> <%[ Remove ]%></a--></td>
+                                                       <!--a class="action_link" href="javascript:void(0)"><img src="<%=$this->getPage()->getTheme()->getBaseUrl()%>/config.png" alt="<%[ Edit ]%>" /> <%[ Edit ]%></a -->
+                                                       <com:TActiveLinkButton
+                                                               ID="RemoveResource"
+                                                               OnCommand="SourceTemplateControl.removeResource"
+                                                               CssClass="action_link"
+                                                       >
+                                                       <prop:ClientSide.OnComplete>
+                                                               var vid = '<%=$this->SourceTemplateControl->RemoveResourceError->ClientId%>';
+                                                               if (document.getElementById(vid).style.display === 'none') {
+                                                                       var container = $('#<%=$this->RemoveResource->ClientID%>').closest('div')[0];
+                                                                       container.parentNode.removeChild(container);
+                                                               }
+                                                               $('html, body').animate({
+                                                                       scrollTop: $('#' + vid).closest('div').prev().offset().top
+                                                               }, 500);
+                                                       </prop:ClientSide.OnComplete>
+                                                               <img id="<%=$this->RemoveResource->ClientID%>_img" src="<%=$this->getPage()->getTheme()->getBaseUrl()%>/icon_err.png" alt="<%[ Remove ]%>" /> <%[ Remove ]%>
+                                                       </com:TActiveLinkButton>
+                                               </td>
                                        </tr>
                                </table>
                                <com:Application.Web.Portlets.BaculaConfigDirectives