2013-08-06 11:53:42 +02:00
|
|
|
<?php
|
2013-08-08 16:22:22 +02:00
|
|
|
// {{{ICINGA_LICENSE_HEADER}}}
|
|
|
|
// {{{ICINGA_LICENSE_HEADER}}}
|
2013-08-06 11:53:42 +02:00
|
|
|
|
2014-11-14 10:57:14 +01:00
|
|
|
namespace Icinga\Forms\Dashboard;
|
2013-08-06 11:53:42 +02:00
|
|
|
|
|
|
|
use Icinga\Web\Widget\Dashboard;
|
2014-08-12 09:49:27 +02:00
|
|
|
use Icinga\Web\Form;
|
2014-11-20 14:36:33 +01:00
|
|
|
use Icinga\Web\Url;
|
2014-11-20 12:08:50 +01:00
|
|
|
use Icinga\Web\Widget\Dashboard\Dashlet;
|
2013-08-06 11:53:42 +02:00
|
|
|
|
2013-08-07 17:40:18 +02:00
|
|
|
/**
|
|
|
|
* Form to add an url a dashboard pane
|
|
|
|
*/
|
2014-11-20 12:08:50 +01:00
|
|
|
class DashletForm extends Form
|
2013-08-06 11:53:42 +02:00
|
|
|
{
|
2014-11-12 09:22:39 +01:00
|
|
|
/**
|
|
|
|
* @var Dashboard
|
|
|
|
*/
|
|
|
|
private $dashboard;
|
|
|
|
|
2014-08-22 12:15:02 +02:00
|
|
|
/**
|
|
|
|
* Initialize this form
|
|
|
|
*/
|
|
|
|
public function init()
|
|
|
|
{
|
|
|
|
$this->setName('form_dashboard_addurl');
|
2014-11-18 09:50:10 +01:00
|
|
|
if (! $this->getSubmitLabel()) {
|
|
|
|
$this->setSubmitLabel(t('Add To Dashboard'));
|
|
|
|
}
|
2014-11-20 14:36:33 +01:00
|
|
|
$this->setAction(URL::fromRequest());
|
2014-08-22 12:15:02 +02:00
|
|
|
}
|
|
|
|
|
2013-08-07 17:40:18 +02:00
|
|
|
/**
|
2014-11-11 11:51:58 +01:00
|
|
|
* Build AddUrl form elements
|
|
|
|
*
|
2014-08-12 09:49:27 +02:00
|
|
|
* @see Form::createElements()
|
2013-08-07 17:40:18 +02:00
|
|
|
*/
|
2014-08-12 09:49:27 +02:00
|
|
|
public function createElements(array $formData)
|
2013-08-06 11:53:42 +02:00
|
|
|
{
|
2014-11-18 09:50:10 +01:00
|
|
|
$groupElements = array();
|
|
|
|
$panes = array();
|
2014-11-12 09:22:39 +01:00
|
|
|
|
2014-11-18 09:50:10 +01:00
|
|
|
if ($this->dashboard) {
|
|
|
|
$panes = $this->dashboard->getPaneKeyTitleArray();
|
2014-11-12 09:22:39 +01:00
|
|
|
}
|
|
|
|
|
2014-11-18 09:50:10 +01:00
|
|
|
$this->addElement(
|
|
|
|
'hidden',
|
|
|
|
'org_pane',
|
|
|
|
array(
|
|
|
|
'required' => false
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
$this->addElement(
|
|
|
|
'hidden',
|
2014-11-20 12:08:50 +01:00
|
|
|
'org_dashlet',
|
2014-11-18 09:50:10 +01:00
|
|
|
array(
|
|
|
|
'required' => false
|
|
|
|
)
|
|
|
|
);
|
2014-11-11 11:51:58 +01:00
|
|
|
|
2014-09-08 09:10:59 +02:00
|
|
|
$this->addElement(
|
|
|
|
'text',
|
|
|
|
'url',
|
2014-11-11 11:51:58 +01:00
|
|
|
array(
|
|
|
|
'required' => true,
|
|
|
|
'label' => t('Url'),
|
|
|
|
'description' =>
|
|
|
|
t('Enter url being loaded in the dashlet. You can paste the full URL, including filters.')
|
|
|
|
)
|
|
|
|
);
|
|
|
|
$this->addElement(
|
|
|
|
'text',
|
2014-11-20 12:08:50 +01:00
|
|
|
'dashlet',
|
2014-09-08 09:10:59 +02:00
|
|
|
array(
|
2014-11-20 11:31:53 +01:00
|
|
|
'required' => true,
|
|
|
|
'label' => t('Dashlet Title'),
|
|
|
|
'description' => t('Enter a title for the dashlet.')
|
2013-08-07 18:10:39 +02:00
|
|
|
)
|
|
|
|
);
|
2014-11-20 11:31:53 +01:00
|
|
|
$this->addElement(
|
|
|
|
'note',
|
|
|
|
'note',
|
|
|
|
array(
|
|
|
|
'decorators' => array(
|
|
|
|
array('HtmlTag', array('tag' => 'hr'))
|
|
|
|
)
|
|
|
|
)
|
|
|
|
);
|
|
|
|
if (empty($panes) || ((isset($formData['create_new_pane']) && $formData['create_new_pane'] != false))) {
|
2014-11-19 15:40:40 +01:00
|
|
|
$this->addElement(
|
2014-08-12 09:49:27 +02:00
|
|
|
'text',
|
|
|
|
'pane',
|
|
|
|
array(
|
2014-11-11 11:51:58 +01:00
|
|
|
'required' => true,
|
2014-11-19 15:40:40 +01:00
|
|
|
'label' => t("New Dashboard Title"),
|
2014-11-11 11:51:58 +01:00
|
|
|
'description' =>
|
|
|
|
t('Enter a title for the new pane.')
|
2014-08-12 09:49:27 +02:00
|
|
|
)
|
|
|
|
);
|
|
|
|
} else {
|
2014-11-19 15:40:40 +01:00
|
|
|
$this->addElement(
|
2014-08-12 09:49:27 +02:00
|
|
|
'select',
|
|
|
|
'pane',
|
|
|
|
array(
|
|
|
|
'required' => true,
|
2014-11-19 15:40:40 +01:00
|
|
|
'label' => t('Dashboard'),
|
2014-11-18 09:50:10 +01:00
|
|
|
'multiOptions' => $panes,
|
2014-11-11 11:51:58 +01:00
|
|
|
'description' =>
|
|
|
|
t('Select a pane you want to add the dashlet.')
|
2014-08-12 09:49:27 +02:00
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
2014-11-20 11:31:53 +01:00
|
|
|
|
|
|
|
$this->addElement(
|
|
|
|
'checkbox',
|
|
|
|
'create_new_pane',
|
|
|
|
array(
|
|
|
|
'required' => false,
|
|
|
|
'label' => t('New dashboard'),
|
|
|
|
'class' => 'autosubmit',
|
|
|
|
'description' => t('Check this box if you want to add the dashlet to a new dashboard')
|
|
|
|
)
|
|
|
|
);
|
2013-08-06 11:53:42 +02:00
|
|
|
}
|
|
|
|
|
2014-11-12 09:22:39 +01:00
|
|
|
/**
|
2014-11-18 09:50:10 +01:00
|
|
|
* @param \Icinga\Web\Widget\Dashboard $dashboard
|
2014-11-12 09:22:39 +01:00
|
|
|
*/
|
|
|
|
public function setDashboard(Dashboard $dashboard)
|
|
|
|
{
|
|
|
|
$this->dashboard = $dashboard;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2014-11-18 09:50:10 +01:00
|
|
|
* @return \Icinga\Web\Widget\Dashboard
|
2014-11-12 09:22:39 +01:00
|
|
|
*/
|
|
|
|
public function getDashboard()
|
|
|
|
{
|
|
|
|
return $this->dashboard;
|
|
|
|
}
|
2014-11-18 09:50:10 +01:00
|
|
|
|
|
|
|
/**
|
2014-11-20 12:08:50 +01:00
|
|
|
* @param Dashlet $dashlet
|
2014-11-18 09:50:10 +01:00
|
|
|
*/
|
2014-11-20 12:08:50 +01:00
|
|
|
public function load(Dashlet $dashlet)
|
2014-11-18 09:50:10 +01:00
|
|
|
{
|
|
|
|
$this->populate(array(
|
2014-11-20 12:08:50 +01:00
|
|
|
'pane' => $dashlet->getPane()->getName(),
|
|
|
|
'org_pane' => $dashlet->getPane()->getName(),
|
|
|
|
'dashlet' => $dashlet->getTitle(),
|
|
|
|
'org_dashlet' => $dashlet->getTitle(),
|
|
|
|
'url' => $dashlet->getUrl()
|
2014-11-18 09:50:10 +01:00
|
|
|
));
|
|
|
|
}
|
2013-08-06 11:53:42 +02:00
|
|
|
}
|