2013-08-06 05:53:42 -04:00
|
|
|
<?php
|
2016-02-08 09:41:00 -05:00
|
|
|
/* Icinga Web 2 | (c) 2013 Icinga Development Team | GPLv2+ */
|
2013-08-06 05:53:42 -04:00
|
|
|
|
2014-11-14 04:57:14 -05:00
|
|
|
namespace Icinga\Forms\Dashboard;
|
2013-08-06 05:53:42 -04:00
|
|
|
|
2014-08-12 03:49:27 -04:00
|
|
|
use Icinga\Web\Form;
|
2016-09-09 09:20:45 -04:00
|
|
|
use Icinga\Web\Form\Validator\InternalUrlValidator;
|
2016-02-23 07:33:58 -05:00
|
|
|
use Icinga\Web\Form\Validator\UrlValidator;
|
2014-11-20 08:36:33 -05:00
|
|
|
use Icinga\Web\Url;
|
2016-09-09 09:20:45 -04:00
|
|
|
use Icinga\Web\Widget\Dashboard;
|
2014-11-20 06:08:50 -05:00
|
|
|
use Icinga\Web\Widget\Dashboard\Dashlet;
|
2013-08-06 05:53:42 -04:00
|
|
|
|
2013-08-07 11:40:18 -04:00
|
|
|
/**
|
|
|
|
|
* Form to add an url a dashboard pane
|
|
|
|
|
*/
|
2014-11-20 06:08:50 -05:00
|
|
|
class DashletForm extends Form
|
2013-08-06 05:53:42 -04:00
|
|
|
{
|
2014-11-12 03:22:39 -05:00
|
|
|
/**
|
|
|
|
|
* @var Dashboard
|
|
|
|
|
*/
|
|
|
|
|
private $dashboard;
|
|
|
|
|
|
2014-08-22 06:15:02 -04:00
|
|
|
/**
|
|
|
|
|
* Initialize this form
|
|
|
|
|
*/
|
|
|
|
|
public function init()
|
|
|
|
|
{
|
|
|
|
|
$this->setName('form_dashboard_addurl');
|
2014-11-18 03:50:10 -05:00
|
|
|
if (! $this->getSubmitLabel()) {
|
2015-01-19 05:26:23 -05:00
|
|
|
$this->setSubmitLabel($this->translate('Add To Dashboard'));
|
2014-11-18 03:50:10 -05:00
|
|
|
}
|
2016-02-23 07:25:55 -05:00
|
|
|
$this->setAction(Url::fromRequest());
|
2014-08-22 06:15:02 -04:00
|
|
|
}
|
|
|
|
|
|
2013-08-07 11:40:18 -04:00
|
|
|
/**
|
2014-11-11 05:51:58 -05:00
|
|
|
* Build AddUrl form elements
|
|
|
|
|
*
|
2014-08-12 03:49:27 -04:00
|
|
|
* @see Form::createElements()
|
2013-08-07 11:40:18 -04:00
|
|
|
*/
|
2014-08-12 03:49:27 -04:00
|
|
|
public function createElements(array $formData)
|
2013-08-06 05:53:42 -04:00
|
|
|
{
|
2014-11-18 03:50:10 -05:00
|
|
|
$groupElements = array();
|
|
|
|
|
$panes = array();
|
2014-11-12 03:22:39 -05:00
|
|
|
|
2014-11-18 03:50:10 -05:00
|
|
|
if ($this->dashboard) {
|
|
|
|
|
$panes = $this->dashboard->getPaneKeyTitleArray();
|
2014-11-12 03:22:39 -05:00
|
|
|
}
|
|
|
|
|
|
2019-02-01 04:59:31 -05:00
|
|
|
$sectionNameValidator = ['Callback', true, [
|
|
|
|
|
'callback' => function ($value) {
|
|
|
|
|
if (strpos($value, '[') === false && strpos($value, ']') === false) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
'messages' => [
|
|
|
|
|
'callbackValue' => $this->translate('Brackets ([, ]) cannot be used here')
|
|
|
|
|
]
|
|
|
|
|
]];
|
|
|
|
|
|
2014-11-18 03:50:10 -05:00
|
|
|
$this->addElement(
|
|
|
|
|
'hidden',
|
|
|
|
|
'org_pane',
|
|
|
|
|
array(
|
|
|
|
|
'required' => false
|
|
|
|
|
)
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
$this->addElement(
|
|
|
|
|
'hidden',
|
2014-11-20 06:08:50 -05:00
|
|
|
'org_dashlet',
|
2014-11-18 03:50:10 -05:00
|
|
|
array(
|
|
|
|
|
'required' => false
|
|
|
|
|
)
|
|
|
|
|
);
|
2014-11-11 05:51:58 -05:00
|
|
|
|
2014-09-08 03:10:59 -04:00
|
|
|
$this->addElement(
|
2017-05-04 07:52:25 -04:00
|
|
|
'textarea',
|
2014-09-08 03:10:59 -04:00
|
|
|
'url',
|
2014-11-11 05:51:58 -05:00
|
|
|
array(
|
|
|
|
|
'required' => true,
|
2015-01-19 05:26:23 -05:00
|
|
|
'label' => $this->translate('Url'),
|
|
|
|
|
'description' => $this->translate(
|
2016-12-13 07:46:01 -05:00
|
|
|
'Enter url to be loaded in the dashlet. You can paste the full URL, including filters.'
|
2016-02-23 07:33:58 -05:00
|
|
|
),
|
2016-08-31 09:11:55 -04:00
|
|
|
'validators' => array(new UrlValidator(), new InternalUrlValidator())
|
2014-11-11 05:51:58 -05:00
|
|
|
)
|
|
|
|
|
);
|
|
|
|
|
$this->addElement(
|
|
|
|
|
'text',
|
2014-11-20 06:08:50 -05:00
|
|
|
'dashlet',
|
2014-09-08 03:10:59 -04:00
|
|
|
array(
|
2014-11-20 05:31:53 -05:00
|
|
|
'required' => true,
|
2015-01-19 05:26:23 -05:00
|
|
|
'label' => $this->translate('Dashlet Title'),
|
2019-02-01 04:59:31 -05:00
|
|
|
'description' => $this->translate('Enter a title for the dashlet.'),
|
|
|
|
|
'validators' => [$sectionNameValidator]
|
2013-08-07 12:10:39 -04:00
|
|
|
)
|
|
|
|
|
);
|
2014-11-20 05:31:53 -05:00
|
|
|
$this->addElement(
|
|
|
|
|
'note',
|
|
|
|
|
'note',
|
|
|
|
|
array(
|
|
|
|
|
'decorators' => array(
|
|
|
|
|
array('HtmlTag', array('tag' => 'hr'))
|
|
|
|
|
)
|
|
|
|
|
)
|
|
|
|
|
);
|
2016-01-18 06:49:10 -05:00
|
|
|
$this->addElement(
|
|
|
|
|
'checkbox',
|
|
|
|
|
'create_new_pane',
|
|
|
|
|
array(
|
|
|
|
|
'autosubmit' => true,
|
|
|
|
|
'required' => false,
|
|
|
|
|
'label' => $this->translate('New dashboard'),
|
|
|
|
|
'description' => $this->translate('Check this box if you want to add the dashlet to a new dashboard')
|
|
|
|
|
)
|
|
|
|
|
);
|
2014-11-20 05:31:53 -05:00
|
|
|
if (empty($panes) || ((isset($formData['create_new_pane']) && $formData['create_new_pane'] != false))) {
|
2014-11-19 09:40:40 -05:00
|
|
|
$this->addElement(
|
2014-08-12 03:49:27 -04:00
|
|
|
'text',
|
|
|
|
|
'pane',
|
|
|
|
|
array(
|
2014-11-11 05:51:58 -05:00
|
|
|
'required' => true,
|
2016-01-18 06:49:10 -05:00
|
|
|
'label' => $this->translate('New Dashboard Title'),
|
2019-02-01 04:59:31 -05:00
|
|
|
'description' => $this->translate('Enter a title for the new dashboard'),
|
|
|
|
|
'validators' => [$sectionNameValidator]
|
2014-08-12 03:49:27 -04:00
|
|
|
)
|
|
|
|
|
);
|
|
|
|
|
} else {
|
2014-11-19 09:40:40 -05:00
|
|
|
$this->addElement(
|
2014-08-12 03:49:27 -04:00
|
|
|
'select',
|
|
|
|
|
'pane',
|
|
|
|
|
array(
|
|
|
|
|
'required' => true,
|
2015-01-19 05:26:23 -05:00
|
|
|
'label' => $this->translate('Dashboard'),
|
2014-11-18 03:50:10 -05:00
|
|
|
'multiOptions' => $panes,
|
2015-11-12 09:57:03 -05:00
|
|
|
'description' => $this->translate('Select a dashboard you want to add the dashlet to')
|
2014-08-12 03:49:27 -04:00
|
|
|
)
|
|
|
|
|
);
|
|
|
|
|
}
|
2013-08-06 05:53:42 -04:00
|
|
|
}
|
|
|
|
|
|
2014-11-12 03:22:39 -05:00
|
|
|
/**
|
2014-11-18 03:50:10 -05:00
|
|
|
* @param \Icinga\Web\Widget\Dashboard $dashboard
|
2014-11-12 03:22:39 -05:00
|
|
|
*/
|
|
|
|
|
public function setDashboard(Dashboard $dashboard)
|
|
|
|
|
{
|
|
|
|
|
$this->dashboard = $dashboard;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2014-11-18 03:50:10 -05:00
|
|
|
* @return \Icinga\Web\Widget\Dashboard
|
2014-11-12 03:22:39 -05:00
|
|
|
*/
|
|
|
|
|
public function getDashboard()
|
|
|
|
|
{
|
|
|
|
|
return $this->dashboard;
|
|
|
|
|
}
|
2014-11-18 03:50:10 -05:00
|
|
|
|
|
|
|
|
/**
|
2014-11-20 06:08:50 -05:00
|
|
|
* @param Dashlet $dashlet
|
2014-11-18 03:50:10 -05:00
|
|
|
*/
|
2014-11-20 06:08:50 -05:00
|
|
|
public function load(Dashlet $dashlet)
|
2014-11-18 03:50:10 -05:00
|
|
|
{
|
|
|
|
|
$this->populate(array(
|
2019-06-26 09:46:06 -04:00
|
|
|
'pane' => $dashlet->getPane()->getTitle(),
|
2014-11-20 06:08:50 -05:00
|
|
|
'org_pane' => $dashlet->getPane()->getName(),
|
2015-04-07 07:05:12 -04:00
|
|
|
'dashlet' => $dashlet->getTitle(),
|
2019-06-26 09:46:06 -04:00
|
|
|
'org_dashlet' => $dashlet->getName(),
|
2015-04-07 07:05:12 -04:00
|
|
|
'url' => $dashlet->getUrl()->getRelativeUrl()
|
2014-11-18 03:50:10 -05:00
|
|
|
));
|
|
|
|
|
}
|
2013-08-06 05:53:42 -04:00
|
|
|
}
|