mirror of
https://github.com/Icinga/icingaweb2.git
synced 2025-07-30 09:14:08 +02:00
Adjust Icinga\Form\Dashboard\AddUrlForm to suit the new form interface
refs #5525
This commit is contained in:
parent
be14844fa8
commit
eea43e9a60
@ -82,11 +82,9 @@ class DashboardController extends ActionController
|
|||||||
)->activate('addurl');
|
)->activate('addurl');
|
||||||
|
|
||||||
$form = new AddUrlForm();
|
$form = new AddUrlForm();
|
||||||
$form->setRequest($this->getRequest());
|
$request = $this->getRequest();
|
||||||
$form->setAction(Url::fromRequest()->setParams(array())->getAbsoluteUrl());
|
if ($request->isPost()) {
|
||||||
$this->view->form = $form;
|
if ($form->isValid($request->getPost()) && $form->getElement('btn_submit')->isChecked()) {
|
||||||
|
|
||||||
if ($form->isSubmittedAndValid()) {
|
|
||||||
$dashboard = $this->getDashboard();
|
$dashboard = $this->getDashboard();
|
||||||
$dashboard->setComponentUrl(
|
$dashboard->setComponentUrl(
|
||||||
$form->getValue('pane'),
|
$form->getValue('pane'),
|
||||||
@ -99,8 +97,14 @@ class DashboardController extends ActionController
|
|||||||
$this->redirectNow(Url::fromPath('dashboard', array('pane' => $form->getValue('pane'))));
|
$this->redirectNow(Url::fromPath('dashboard', array('pane' => $form->getValue('pane'))));
|
||||||
} else {
|
} else {
|
||||||
$this->render('show-configuration');
|
$this->render('show-configuration');
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
$form->create()->setDefault('url', htmlspecialchars_decode($request->getParam('url', '')));
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->view->form = $form;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -5,12 +5,8 @@
|
|||||||
namespace Icinga\Form\Dashboard;
|
namespace Icinga\Form\Dashboard;
|
||||||
|
|
||||||
use Icinga\Application\Config as IcingaConfig;
|
use Icinga\Application\Config as IcingaConfig;
|
||||||
use Icinga\Web\Form;
|
|
||||||
use Icinga\Web\Widget\Dashboard;
|
use Icinga\Web\Widget\Dashboard;
|
||||||
use Zend_Form_Element_Text;
|
use Icinga\Web\Form;
|
||||||
use Zend_Form_Element_Submit;
|
|
||||||
use Zend_Form_Element_Hidden;
|
|
||||||
use Zend_Form_Element_Select;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Form to add an url a dashboard pane
|
* Form to add an url a dashboard pane
|
||||||
@ -18,124 +14,111 @@ use Zend_Form_Element_Select;
|
|||||||
class AddUrlForm extends Form
|
class AddUrlForm extends Form
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Add a selection box for different panes to the form
|
* @see Form::createElements()
|
||||||
*
|
|
||||||
* @param Dashboard $dashboard The dashboard to retrieve the panes from
|
|
||||||
*/
|
*/
|
||||||
private function addPaneSelectionBox(Dashboard $dashboard)
|
public function createElements(array $formData)
|
||||||
{
|
{
|
||||||
$selectPane = new Zend_Form_Element_Select(
|
$elements = array(
|
||||||
'pane',
|
$this->createElement(
|
||||||
array(
|
|
||||||
'label' => 'Dashboard',
|
|
||||||
'required' => true,
|
|
||||||
'style' => 'display:inline-block;',
|
|
||||||
|
|
||||||
'multiOptions' => $dashboard->getPaneKeyTitleArray()
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
$newDashboardBtn = new Zend_Form_Element_Submit(
|
|
||||||
'create_new_pane',
|
|
||||||
array(
|
|
||||||
'label' => 'Create A New Pane',
|
|
||||||
'required' => false,
|
|
||||||
'class' => 'btn btn-default',
|
|
||||||
'style' => 'display:inline-block'
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
$newDashboardBtn->removeDecorator('DtDdWrapper');
|
|
||||||
$selectPane->removeDecorator('DtDdWrapper');
|
|
||||||
$selectPane->removeDecorator('htmlTag');
|
|
||||||
|
|
||||||
$this->addElement($selectPane);
|
|
||||||
$this->addElement($newDashboardBtn);
|
|
||||||
$this->enableAutoSubmit(array('create_new_pane'));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Add a textfield for creating a new pane to this form
|
|
||||||
*/
|
|
||||||
private function addNewPaneTextField($showExistingButton = true)
|
|
||||||
{
|
|
||||||
$txtCreatePane = new Zend_Form_Element_Text(
|
|
||||||
'pane',
|
|
||||||
array(
|
|
||||||
'label' => 'New Dashboard Title',
|
|
||||||
'required' => true,
|
|
||||||
'style' => 'display:inline-block'
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
// Marks this field as a new pane (and prevents the checkbox being displayed when validation errors occur)
|
|
||||||
$markAsNewPane = new Zend_Form_Element_Hidden(
|
|
||||||
'create_new_pane',
|
|
||||||
array(
|
|
||||||
'required' => true,
|
|
||||||
'value' => 1
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
$cancelDashboardBtn = new Zend_Form_Element_Submit(
|
|
||||||
'use_existing_dashboard',
|
|
||||||
array(
|
|
||||||
'class' => 'btn',
|
|
||||||
'escape' => false,
|
|
||||||
'label' => 'Use An Existing Dashboard',
|
|
||||||
'required' => false
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
|
|
||||||
$cancelDashboardBtn->removeDecorator('DtDdWrapper');
|
|
||||||
$txtCreatePane->removeDecorator('DtDdWrapper');
|
|
||||||
$txtCreatePane->removeDecorator('htmlTag');
|
|
||||||
|
|
||||||
$this->addElement($txtCreatePane);
|
|
||||||
if ($showExistingButton) {
|
|
||||||
$this->addElement($cancelDashboardBtn);
|
|
||||||
}
|
|
||||||
$this->addElement($markAsNewPane);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Add elements to this form (used by extending classes)
|
|
||||||
*/
|
|
||||||
protected function create()
|
|
||||||
{
|
|
||||||
$dashboard = new Dashboard();
|
|
||||||
$this->setName('form_dashboard_add');
|
|
||||||
$dashboard->readConfig(IcingaConfig::app('dashboard/dashboard'));
|
|
||||||
$this->addElement(
|
|
||||||
'text',
|
'text',
|
||||||
'url',
|
'url',
|
||||||
array(
|
array(
|
||||||
'label' => 'Url',
|
|
||||||
'required' => true,
|
'required' => true,
|
||||||
'value' => htmlspecialchars_decode($this->getRequest()->getParam('url', ''))
|
'label' => t('Url'),
|
||||||
|
'helptext' => t('The url being loaded in the dashlet')
|
||||||
|
)
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
$elems = $dashboard->getPaneKeyTitleArray();
|
|
||||||
|
|
||||||
if (empty($elems) || // show textfield instead of combobox when no pane is available
|
$paneSelectionValues = $this->getDashboardPaneSelectionValues();
|
||||||
($this->getRequest()->getPost('create_new_pane', '0') && // or when a new pane should be created (+ button)
|
if (empty($paneSelectionValues) ||
|
||||||
!$this->getRequest()->getPost('use_existing_dashboard', '0')) // and the user didn't click the 'use
|
((isset($formData['create_new_pane']) && $formData['create_new_pane'] != false) &&
|
||||||
// existing' button
|
(false === isset($formData['use_existing_dashboard']) || $formData['use_existing_dashboard'] != true))
|
||||||
) {
|
) {
|
||||||
$this->addNewPaneTextField(!empty($elems));
|
$elements[] = $this->createElement(
|
||||||
|
'text',
|
||||||
|
'pane',
|
||||||
|
array(
|
||||||
|
'required' => true,
|
||||||
|
'label' => t("The New Pane's Title"),
|
||||||
|
'style' => 'display: inline-block'
|
||||||
|
)
|
||||||
|
);
|
||||||
|
$elements[] = $this->createElement( // Prevent the button from being displayed again on validation errors
|
||||||
|
'hidden',
|
||||||
|
'create_new_pane',
|
||||||
|
array(
|
||||||
|
'value' => 1
|
||||||
|
)
|
||||||
|
);
|
||||||
|
if (false === empty($paneSelectionValues)) {
|
||||||
|
$elements[] = $this->createElement(
|
||||||
|
'submit',
|
||||||
|
'use_existing_dashboard',
|
||||||
|
array(
|
||||||
|
'label' => t('Use An Existing Pane'),
|
||||||
|
'style' => 'display: inline-block'
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
$this->addPaneSelectionBox($dashboard);
|
$elements[] = $this->createElement(
|
||||||
|
'select',
|
||||||
|
'pane',
|
||||||
|
array(
|
||||||
|
'required' => true,
|
||||||
|
'label' => t('Pane'),
|
||||||
|
'style' => 'display: inline-block;',
|
||||||
|
'multiOptions' => $paneSelectionValues
|
||||||
|
)
|
||||||
|
);
|
||||||
|
$elements[] = $this->createElement(
|
||||||
|
'submit',
|
||||||
|
'create_new_pane',
|
||||||
|
array(
|
||||||
|
'label' => t('Create A New Pane'),
|
||||||
|
'style' => 'display: inline-block'
|
||||||
|
)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->addElement(
|
$elements[] = $this->createElement(
|
||||||
'text',
|
'text',
|
||||||
'component',
|
'component',
|
||||||
array(
|
array(
|
||||||
'label' => 'Title',
|
|
||||||
'required' => true,
|
'required' => true,
|
||||||
|
'label' => t('Title'),
|
||||||
|
'helptext' => t('The title for the dashlet')
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
$this->setSubmitLabel("Add To Dashboard");
|
return $elements;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see Form::addSubmitButton()
|
||||||
|
*/
|
||||||
|
public function addSubmitButton()
|
||||||
|
{
|
||||||
|
$this->addElement(
|
||||||
|
'submit',
|
||||||
|
'btn_submit',
|
||||||
|
array(
|
||||||
|
'label' => t('Add To Dashboard')
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the names and titles of the available dashboard panes as key-value array
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
protected function getDashboardPaneSelectionValues()
|
||||||
|
{
|
||||||
|
$dashboard = new Dashboard();
|
||||||
|
$dashboard->readConfig(IcingaConfig::app('dashboard/dashboard'));
|
||||||
|
return $dashboard->getPaneKeyTitleArray();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user