summaryrefslogtreecommitdiffstats
path: root/application/forms/RemoveLinkForm.php
blob: fb43db097d2f920865d01769ee144e1f0d346374 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<?php

namespace Icinga\Module\Director\Forms;

use gipfl\IcingaWeb2\Icon;
use Icinga\Module\Director\Web\Form\DirectorForm;

class RemoveLinkForm extends DirectorForm
{
    private $label;

    private $title;

    private $onSuccessAction;

    public function __construct($label, $title, $action, $params = [])
    {
        // Required to detect the right instance
        $this->formName = 'RemoveSet' . sha1(json_encode($params));
        parent::__construct(['data-base-target' => '_self']);
        $this->label = $label;
        $this->title = $title;
        foreach ($params as $name => $value) {
            $this->addHidden($name, $value);
        }
        $this->setAction($action);
    }

    public function runOnSuccess($action)
    {
        $this->onSuccessAction = $action;

        return $this;
    }

    public function setup()
    {
        $this->addAttribs(['class' => ['inline', 'remove-link-form']]);
        $this->addHtml(Icon::create('cancel'));
        $this->addSubmitButton($this->label, [
            'class' => 'link-button',
            'title' => $this->title,
        ]);
    }

    public function onSuccess()
    {
        if ($this->onSuccessAction !== null) {
            $func = $this->onSuccessAction;
            $func();
            $this->redirectOnSuccess(
                $this->translate('Service Set has been removed')
            );
        }
    }
}