summaryrefslogtreecommitdiffstats
path: root/library/Director/Web/Tabs/ImportsourceTabs.php
blob: 74dedb390e5cd2fcb2a4a527802ae3402d09dec8 (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
<?php

namespace Icinga\Module\Director\Web\Tabs;

use gipfl\Translation\TranslationHelper;
use gipfl\IcingaWeb2\Widget\Tabs;

class ImportsourceTabs extends Tabs
{
    use TranslationHelper;

    protected $id;

    public function __construct($id = null)
    {
        $this->id = $id;
        $this->assemble();
    }

    public function activateMainWithPostfix($postfix)
    {
        $mainTab = 'index';
        $tab = $this->get($mainTab);
        $tab->setLabel($tab->getLabel() . ": $postfix");
        $this->activate($mainTab);

        return $this;
    }

    protected function assemble()
    {
        if ($id = $this->id) {
            $params = ['id' => $id];
            $this->add('index', [
                'url'       => 'director/importsource',
                'urlParams' => $params,
                'label'     => $this->translate('Import source'),
            ])->add('modifier', [
                'url'       => 'director/importsource/modifier',
                'urlParams' => ['source_id' => $id],
                'label'     => $this->translate('Modifiers'),
            ])->add('history', [
                'url'       => 'director/importsource/history',
                'urlParams' => $params,
                'label'     => $this->translate('History'),
            ])->add('preview', [
                'url'       => 'director/importsource/preview',
                'urlParams' => $params,
                'label'     => $this->translate('Preview'),
            ]);
        } else {
            $this->add('add', [
                'url'   => 'director/importsource/add',
                'label' => $this->translate('New import source'),
            ])->activate('add');
        }
    }
}