[icinga-checkins] icinga.org: icingaweb2/feature/add-to-dashboard-4537: AddToDashboard: Form layout and template

git at icinga.org git at icinga.org
Wed Nov 12 10:23:26 CET 2014


Module: icingaweb2
Branch: feature/add-to-dashboard-4537
Commit: 9993c9dc82326405416bf0c4c7f9b8622a4a92a6
URL:    https://git.icinga.org/?p=icingaweb2.git;a=commit;h=9993c9dc82326405416bf0c4c7f9b8622a4a92a6

Author: Marius Hein <marius.hein at netways.de>
Date:   Tue Nov 11 11:51:58 2014 +0100

AddToDashboard: Form layout and template

refa #4537

---

 application/forms/Dashboard/AddUrlForm.php       |  106 ++++++++++++++++------
 application/views/scripts/dashboard/addurl.phtml |    8 +-
 2 files changed, 81 insertions(+), 33 deletions(-)

diff --git a/application/forms/Dashboard/AddUrlForm.php b/application/forms/Dashboard/AddUrlForm.php
index 564ff3d..2e9ea1a 100644
--- a/application/forms/Dashboard/AddUrlForm.php
+++ b/application/forms/Dashboard/AddUrlForm.php
@@ -7,6 +7,7 @@ namespace Icinga\Form\Dashboard;
 use Icinga\Application\Config;
 use Icinga\Web\Widget\Dashboard;
 use Icinga\Web\Form;
+use Icinga\Web\Request;
 
 /**
  * Form to add an url a dashboard pane
@@ -23,35 +24,49 @@ class AddUrlForm extends Form
     }
 
     /**
+     * Build AddUrl form elements
+     *
      * @see Form::createElements()
      */
     public function createElements(array $formData)
     {
+        $paneSelectionValues = $this->getDashboardPaneSelectionValues();
+        $groupElements = array();
+
         $this->addElement(
             'text',
             'url',
             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',
+            'component',
+            array(
                 'required'  => true,
-                'label'     => t('Url'),
-                'helptext'  => t('The url being loaded in the dashlet')
+                'label'     => t('Dashlet Title'),
+                'description'  => t('Enter a title for the dashlet.')
             )
         );
-
-        $paneSelectionValues = $this->getDashboardPaneSelectionValues();
         if (empty($paneSelectionValues) ||
             ((isset($formData['create_new_pane']) && $formData['create_new_pane'] != false) &&
              (false === isset($formData['use_existing_dashboard']) || $formData['use_existing_dashboard'] != true))
         ) {
-            $this->addElement(
+            $groupElements[] = $this->createElement(
                 'text',
                 'pane',
                 array(
-                    'required'  => true,
-                    'label'     => t("The New Pane's Title"),
-                    'style'     => 'display: inline-block'
+                    'required'      => true,
+                    'label'         => t("New Pane Title"),
+                    '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',
                 'create_new_pane',
                 array(
@@ -59,45 +74,62 @@ class AddUrlForm extends Form
                 )
             );
             if (false === empty($paneSelectionValues)) {
-                $this->addElement(
+                $buttonExistingPane = $this->createElement(
                     'submit',
                     'use_existing_dashboard',
                     array(
-                        'ignore'    => true,
-                        'label'     => t('Use An Existing Pane'),
-                        'style'     => 'display: inline-block'
+                        'ignore'        => true,
+                        'label'         => t('Use An Existing Pane'),
+                        'description'   =>
+                            t('Click on the button to add the dashlet to an existing pane on your dashboard.')
                     )
                 );
+                $buttonExistingPane->removeDecorator('Label');
+                $groupElements[] = $buttonExistingPane;
             }
         } else {
-            $this->addElement(
+            $groupElements[] = $this->createElement(
                 'select',
                 'pane',
                 array(
                     'required'      => true,
                     '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',
                 'create_new_pane',
                 array(
-                    'ignore'    => true,
-                    'label'     => t('Create A New Pane'),
-                    'style'     => 'display: inline-block'
+                    'ignore'        => true,
+                    'label'         => t('Create A New Pane'),
+                    '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->addElement(
-            'text',
-            'component',
+        $this->addDisplayGroup(
+            $groupElements,
+            'pane_group',
             array(
-                'required'  => true,
-                'label'     => t('Title'),
-                'helptext'  => t('The title for the dashlet')
+                'legend'        => t('Pane'),
+                'description'   => t(
+                    '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'));
         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)
+    {
+
+    }
 }
diff --git a/application/views/scripts/dashboard/addurl.phtml b/application/views/scripts/dashboard/addurl.phtml
index c2d3f7e..9c41a77 100644
--- a/application/views/scripts/dashboard/addurl.phtml
+++ b/application/views/scripts/dashboard/addurl.phtml
@@ -3,10 +3,6 @@
 </div>
 
 <div class="content">
-    <h1><?= $this->escape($this->translate('This feature is deactivated at the moment.')); ?></h1>
-    <p>
-        <?=
-        $this->escape($this->translate('Please have a little patience, we are hard working on it, take a look at icingaweb2 issues.'));
-        ?>
-    </p>
+    <h1><?= t('Add URL to Dashboard'); ?></h1>
+    <?= $this->form; ?>
 </div>
\ No newline at end of file



More information about the icinga-checkins mailing list