From: Marcin Haba Date: Sat, 20 Jun 2020 15:30:48 +0000 (+0200) Subject: baculum: Add remove runscript button X-Git-Tag: Release-9.6.6~27 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a74a6f7326fc5a999b5ee3f7252ca0f87408ad92;p=thirdparty%2Fbacula.git baculum: Add remove runscript button --- diff --git a/gui/baculum/protected/Web/Portlets/DirectiveRunscript.php b/gui/baculum/protected/Web/Portlets/DirectiveRunscript.php index 953dd93ce..5c2713af9 100644 --- a/gui/baculum/protected/Web/Portlets/DirectiveRunscript.php +++ b/gui/baculum/protected/Web/Portlets/DirectiveRunscript.php @@ -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(); } } diff --git a/gui/baculum/protected/Web/Portlets/JobRunscriptRenderer.php b/gui/baculum/protected/Web/Portlets/JobRunscriptRenderer.php index d47014893..183bcf8d4 100644 --- a/gui/baculum/protected/Web/Portlets/JobRunscriptRenderer.php +++ b/gui/baculum/protected/Web/Portlets/JobRunscriptRenderer.php @@ -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 = '  ' . 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('

Runscript #' . ((self::$index/7) + 1) . '


'); + if (self::$render_index % self::DIRECTIVE_COUNT === 0) { + $writer->write('

Runscript #' . ((self::$render_index / self::DIRECTIVE_COUNT) + 1) . '


'); } - 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; } } ?>