]> git.ipfire.org Git - thirdparty/bacula.git/commitdiff
baculum: Add remove runscript button
authorMarcin Haba <marcin.haba@bacula.pl>
Sat, 20 Jun 2020 15:30:48 +0000 (17:30 +0200)
committerMarcin Haba <marcin.haba@bacula.pl>
Sat, 20 Jun 2020 15:30:48 +0000 (17:30 +0200)
gui/baculum/protected/Web/Portlets/DirectiveRunscript.php
gui/baculum/protected/Web/Portlets/JobRunscriptRenderer.php

index 953dd93ceb8b9cce60c3ee14b096f917239ef2c1..5c2713af97917b93c0a5734adfaf860ae83eb4f7 100644 (file)
@@ -124,7 +124,7 @@ class DirectiveRunscript extends DirectiveListTemplate {
                $this->RepeaterRunscriptOptions->dataBind();
        }
 
-       public function getDirectiveValue($allow_empty = false) {
+       public function getDirectiveValue() {
                $directive_values = null;
                $component_type = $this->getComponentType();
                $resource_type = $this->getResourceType();
@@ -167,6 +167,18 @@ class DirectiveRunscript extends DirectiveListTemplate {
                return $directive_values;
        }
 
+       public function removeRunscript($sender, $param) {
+               if ($param instanceof Prado\Web\UI\TCommandEventParameter) {
+                       $idx = $param->getCommandName();
+                       $data = $this->getDirectiveValue();
+                       if (is_array($data)) {
+                               array_splice($data['Runscript'], $idx, 1);
+                               $this->setData($data);
+                               $this->loadConfig();
+                       }
+               }
+       }
+
        public function newRunscriptDirective() {
                $data = $this->getDirectiveValue(true);
                if (is_array($data) && key_exists('Runscript', $data) && is_array($data['Runscript'])) {
@@ -176,6 +188,6 @@ class DirectiveRunscript extends DirectiveListTemplate {
                }
                $this->setData($data);
                $this->SourceTemplateControl->setShowAllDirectives(true);
-               $this->loadConfig(null, null);
+               $this->loadConfig();
        }
 }
index d47014893167706fc5991ca3f268de8b4c3591d9..183bcf8d473f9c52adade07fe72c3d3f208d566b 100644 (file)
@@ -20,6 +20,7 @@
  * Bacula(R) is a registered trademark of Kern Sibbald.
  */
 
+Prado::using('System.Web.UI.ActiveControls.TActiveLinkButton');
 Prado::using('Application.Web.Portlets.DirectiveRenderer');
 
 /**
@@ -31,28 +32,43 @@ Prado::using('Application.Web.Portlets.DirectiveRenderer');
  */
 class JobRunscriptRenderer extends DirectiveRenderer {
 
-       private static $index = 0;
+       const DIRECTIVE_COUNT = 7;
+
+       private static $render_index = 0;
        private $item_count;
 
+       public function onInit($param) {
+               parent::onInit($param);
+               if ($this->ItemIndex % self::DIRECTIVE_COUNT === 0) {
+                       $alb = new TActiveLinkButton;
+                       $alb->CssClass = 'w3-button w3-green w3-right';
+                       $alb->OnCommand = 'SourceTemplateControl.removeRunscript';
+                       $alb->CommandName = $this->ItemIndex / self::DIRECTIVE_COUNT;
+                       $alb->CommandParameter = 'save';
+                       $alb->Text = '<i class="fa fa-trash-alt"></i> &nbsp;' . Prado::localize('Remove');
+                       $this->addParsedObject($alb);
+               }
+       }
+
        public function onPreRender($param) {
                parent::onPreRender($param);
                $this->item_count = $this->getParent()->getItems()->getCount();
        }
 
        public function render($writer) {
-               if (self::$index % 7 === 0) {
-                       $writer->write('<h3 class="runscript_options">Runscript #' . ((self::$index/7) + 1) . '</h3><hr />');
+               if (self::$render_index % self::DIRECTIVE_COUNT === 0) {
+                       $writer->write('<h3 class="w3-left runscript_options">Runscript #' . ((self::$render_index / self::DIRECTIVE_COUNT) + 1) . '</h3><hr />');
                }
-               self::$index++;
+               self::$render_index++;
 
-               if (self::$index === $this->item_count) {
-                       $this->resetIndex();
+               if (self::$render_index === $this->item_count) {
+                       $this->resetRenderIndex();
                }
                parent::render($writer);
        }
 
-       public static function resetIndex() {
-               self::$index = 0;
+       public static function resetRenderIndex() {
+               self::$render_index = 0;
        }
 }
 ?>