summaryrefslogtreecommitdiffstats
path: root/application/forms/Events/AckFilterForm.php
blob: 829c6cef6074f3289dae3076f989c4492cb5f12f (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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
<?php
/* Icinga Web 2 | (c) 2016 Icinga Development Team | GPLv2+ */

namespace Icinga\Module\Eventdb\Forms\Events;

use Icinga\Data\Filter\Filter;
use Icinga\Web\Form;

class AckFilterForm extends Form
{
    /**
     * {@inheritdoc}
     */
    public function init()
    {
        $this->setAttrib('class', 'inline ack-filter-form');
    }

    /**
     * {@inheritdoc}
     */
    public function addSubmitButton()
    {
        if ((bool) $this->getRequest()->getUrl()->getParams()->get('ack', true)) {
            $icon = 'ok';
            $title = $this->translate('Hide acknowledged events');
        } else {
            $icon = 'cancel';
            $title = $this->translate('Show also acknowledged events');
        }

        $this->addElements(array(
            array(
                'button',
                'btn_submit',
                array(
                    'class'         => 'link-button spinner',
                    'decorators'    => array(
                        'ViewHelper',
                        array('HtmlTag', array('tag' => 'div', 'class' => 'control-group form-controls'))
                    ),
                    'escape'        => false,
                    'ignore'        => true,
                    'label'         => $this->getView()->icon($icon) . $this->translate('Ack'),
                    'type'          => 'submit',
                    'title'         => $title,
                    'value'         => $this->translate('Ack')
                )
            )
        ));

        return $this;
    }

    public function onSuccess()
    {
        $redirect = clone $this->getRequest()->getUrl();
        $params = $redirect->getParams();
        $modifyFilter = $params->shift('modifyFilter');
        $columns = $params->shift('columns');
        if (! (bool) $this->getRequest()->getUrl()->getParams()->get('ack', true)) {
            $params->remove('ack');
        } else {
            $redirect->setQueryString(
                Filter::fromQueryString($redirect->getQueryString())
                    ->andFilter(Filter::expression('ack', '=', 0))
                    ->toQueryString()
            );
        }
        $params = $redirect->getParams();
        if ($modifyFilter) {
            $params->add('modifyFilter');
        }
        if ($columns) {
            $params->add('columns', $columns);
        }
        $this->setRedirectUrl($redirect);
        return true;
    }
}