AddToDashboard: Form layout and template

refa #4537
This commit is contained in:
Marius Hein 2014-11-11 11:51:58 +01:00
parent 1000b4661f
commit 5f9d394bbe
2 changed files with 82 additions and 34 deletions

View File

@ -7,6 +7,7 @@ namespace Icinga\Forms\Dashboard;
use Icinga\Application\Config; use Icinga\Application\Config;
use Icinga\Web\Widget\Dashboard; use Icinga\Web\Widget\Dashboard;
use Icinga\Web\Form; use Icinga\Web\Form;
use Icinga\Web\Request;
/** /**
* Form to add an url a dashboard pane * Form to add an url a dashboard pane
@ -23,35 +24,49 @@ class AddUrlForm extends Form
} }
/** /**
* Build AddUrl form elements
*
* @see Form::createElements() * @see Form::createElements()
*/ */
public function createElements(array $formData) public function createElements(array $formData)
{ {
$paneSelectionValues = $this->getDashboardPaneSelectionValues();
$groupElements = array();
$this->addElement( $this->addElement(
'text', 'text',
'url', 'url',
array( array(
'required' => true, 'required' => true,
'label' => t('Url'), 'label' => t('Url'),
'helptext' => t('The url being loaded in the dashlet') 'description' =>
t('Enter url being loaded in the dashlet. You can paste the full URL, including filters.')
)
);
$this->addElement(
'text',
'component',
array(
'required' => true,
'label' => t('Dashlet Title'),
'description' => t('Enter a title for the dashlet.')
) )
); );
$paneSelectionValues = $this->getDashboardPaneSelectionValues();
if (empty($paneSelectionValues) || if (empty($paneSelectionValues) ||
((isset($formData['create_new_pane']) && $formData['create_new_pane'] != false) && ((isset($formData['create_new_pane']) && $formData['create_new_pane'] != false) &&
(false === isset($formData['use_existing_dashboard']) || $formData['use_existing_dashboard'] != true)) (false === isset($formData['use_existing_dashboard']) || $formData['use_existing_dashboard'] != true))
) { ) {
$this->addElement( $groupElements[] = $this->createElement(
'text', 'text',
'pane', 'pane',
array( array(
'required' => true, 'required' => true,
'label' => t("The New Pane's Title"), 'label' => t("New Pane Title"),
'style' => 'display: inline-block' 'description' =>
t('Enter a title for the new pane.')
) )
); );
$this->addElement( // Prevent the button from being displayed again on validation errors $groupElements[] = $this->createElement( // Prevent the button from being displayed again on validation errors
'hidden', 'hidden',
'create_new_pane', 'create_new_pane',
array( array(
@ -59,45 +74,62 @@ class AddUrlForm extends Form
) )
); );
if (false === empty($paneSelectionValues)) { if (false === empty($paneSelectionValues)) {
$this->addElement( $buttonExistingPane = $this->createElement(
'submit', 'submit',
'use_existing_dashboard', 'use_existing_dashboard',
array( array(
'ignore' => true, 'ignore' => true,
'label' => t('Use An Existing Pane'), 'label' => t('Use An Existing Pane'),
'style' => 'display: inline-block' 'description' =>
t('Click on the button to add the dashlet to an existing pane on your dashboard.')
) )
); );
$buttonExistingPane->removeDecorator('Label');
$groupElements[] = $buttonExistingPane;
} }
} else { } else {
$this->addElement( $groupElements[] = $this->createElement(
'select', 'select',
'pane', 'pane',
array( array(
'required' => true, 'required' => true,
'label' => t('Pane'), 'label' => t('Pane'),
'style' => 'display: inline-block;', 'multiOptions' => $paneSelectionValues,
'multiOptions' => $paneSelectionValues 'description' =>
t('Select a pane you want to add the dashlet.')
) )
); );
$this->addElement( $buttonNewPane = $this->createElement(
'submit', 'submit',
'create_new_pane', 'create_new_pane',
array( array(
'ignore' => true, 'ignore' => true,
'label' => t('Create A New Pane'), 'label' => t('Create A New Pane'),
'style' => 'display: inline-block' 'description' =>
t('Click on the button if you want to add the dashlet to a new pane on the dashboard.')
) )
); );
$buttonNewPane->removeDecorator('Label');
$groupElements[] = $buttonNewPane;
} }
$this->addDisplayGroup(
$this->addElement( $groupElements,
'text', 'pane_group',
'component',
array( array(
'required' => true, 'legend' => t('Pane'),
'label' => t('Title'), 'description' => t(
'helptext' => t('The title for the dashlet') 'Decide if you want add the dashlet to an existing pane'
. ' or create a new pane. Have a look on the button below.'
),
'decorators' => array(
'FormElements',
array('HtmlTag', array('tag' => 'div', 'class' => 'control-group')),
array(
'Description',
array('tag' => 'span', 'class' => 'description', 'placement' => 'prepend')
),
'Fieldset'
)
) )
); );
} }
@ -113,4 +145,24 @@ class AddUrlForm extends Form
$dashboard->readConfig(Config::app('dashboard/dashboard')); $dashboard->readConfig(Config::app('dashboard/dashboard'));
return $dashboard->getPaneKeyTitleArray(); return $dashboard->getPaneKeyTitleArray();
} }
/**
* Adjust preferences and persist them
*
* @see Form::onSuccess()
*/
public function onSuccess(Request $request)
{
return false;
}
/**
* Populate data if any
*
* @see Form::onRequest()
*/
public function onRequest(Request $request)
{
}
} }

View File

@ -3,10 +3,6 @@
</div> </div>
<div class="content"> <div class="content">
<h1><?= $this->escape($this->translate('This feature is deactivated at the moment.')); ?></h1> <h1><?= t('Add URL to Dashboard'); ?></h1>
<p> <?= $this->form; ?>
<?=
$this->escape($this->translate('Please have a little patience, we are hard working on it, take a look at icingaweb2 issues.'));
?>
</p>
</div> </div>