blob: b91255c0cffc8198254759297e13147b3ef930d0 (
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
81
82
83
84
85
86
87
88
89
90
91
92
|
<?php
/* Icinga Web 2 | (c) 2016 Icinga Development Team | GPLv2+ */
namespace Icinga\Module\Toplevelview\Controllers;
use Icinga\Module\Toplevelview\Forms\EditForm;
use Icinga\Module\Toplevelview\ViewConfig;
use Icinga\Module\Toplevelview\Web\Controller;
use Icinga\Web\Url;
class EditController extends Controller
{
public function init()
{
$this->assertPermission('toplevelview/edit');
$tabs = $this->getTabs();
if ($name = $this->getParam('name')) {
$tabs->add(
'tiles',
array(
'title' => $this->translate('Tiles'),
'url' => Url::fromPath('toplevelview/show', array(
'name' => $name
))
)
);
$tabs->add(
'index',
array(
'title' => $this->translate('Edit'),
'url' => Url::fromPath('toplevelview/edit', array(
'name' => $name
))
)
);
}
$action = $this->getRequest()->getActionName();
if ($tab = $tabs->get($action)) {
$tab->setActive();
}
}
public function indexAction()
{
$action = $this->getRequest()->getActionName();
if ($action === 'add') {
$this->view->title = sprintf(
'%s Top Level View',
$this->translate('Add')
);
$view = new ViewConfig();
$view->setConfigDir();
} elseif ($action === 'clone') {
$name = $this->params->getRequired('name');
$this->view->title = sprintf(
'%s Top Level View',
$this->translate('Clone')
);
$view = clone ViewConfig::loadByName($name);
} else {
$this->view->name = $name = $this->params->getRequired('name');
$this->view->title = sprintf(
'%s Top Level View: %s',
$this->translate('Edit'),
$this->params->getRequired('name')
);
$view = ViewConfig::loadByName($name);
}
$this->view->form = $form = new EditForm();
$view->setFormat(ViewConfig::FORMAT_YAML);
$form->setViewConfig($view);
$form->handleRequest();
$this->setViewScript('edit/index');
}
public function addAction()
{
$this->indexAction();
}
public function cloneAction()
{
$this->indexAction();
}
}
|