From ed2de3c4d04886e5af21ba0f828da2bb4dc0d40c Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Wed, 15 Apr 2015 14:20:36 +0200 Subject: [PATCH] Fix SortBox widget refs #7876 --- library/Icinga/Web/Controller.php | 8 +- library/Icinga/Web/StyleSheet.php | 3 +- library/Icinga/Web/Widget/SortBox.php | 127 +++++++++++--------------- public/css/icinga/controls.less | 18 ++++ 4 files changed, 78 insertions(+), 78 deletions(-) create mode 100644 public/css/icinga/controls.less diff --git a/library/Icinga/Web/Controller.php b/library/Icinga/Web/Controller.php index e7a1d51f57..da9486b9e1 100644 --- a/library/Icinga/Web/Controller.php +++ b/library/Icinga/Web/Controller.php @@ -14,15 +14,15 @@ class Controller extends ModuleActionController { /** - * Create a sort control box at the 'sortControl' view parameter + * Create a SortBox widget at the `sortBox' view property * - * @param array $columns An array containing the sort columns, with the - * submit value as the key and the label as the value + * @param array $columns An array containing the sort columns, with the + * submit value as the key and the label as the value */ protected function setupSortControl(array $columns) { $req = $this->getRequest(); - $this->view->sortControl = SortBox::create( + $this->view->sortBox = SortBox::create( 'sortbox-' . $req->getActionName(), $columns )->applyRequest($req); diff --git a/library/Icinga/Web/StyleSheet.php b/library/Icinga/Web/StyleSheet.php index 3f1e2b2a7c..ab36d78c50 100644 --- a/library/Icinga/Web/StyleSheet.php +++ b/library/Icinga/Web/StyleSheet.php @@ -26,7 +26,8 @@ class StyleSheet 'css/icinga/pagination.less', 'css/icinga/monitoring-colors.less', 'css/icinga/selection-toolbar.less', - 'css/icinga/login.less' + 'css/icinga/login.less', + 'css/icinga/controls.less' ); public static function compileForPdf() diff --git a/library/Icinga/Web/Widget/SortBox.php b/library/Icinga/Web/Widget/SortBox.php index be96b614eb..fc2025e5be 100644 --- a/library/Icinga/Web/Widget/SortBox.php +++ b/library/Icinga/Web/Widget/SortBox.php @@ -3,64 +3,57 @@ namespace Icinga\Web\Widget; -use Zend_Form_Element_Submit; use Icinga\Web\Form; use Icinga\Web\Request; -use Icinga\Web\Form\Decorator\ConditionalHidden; /** - * Sortbox widget + * SortBox widget * - * The "SortBox" Widget allows you to create a generic sort input for sortable views. - * It automatically creates a form containing a select box with all sort options and a - * dropbox with the sort direction. It also handles automatic submission of sorting changes and draws an additional - * submit button when JavaScript is disabled. + * The "SortBox" Widget allows you to create a generic sort input for sortable views. It automatically creates a form + * containing a select box with all sort options and a dropbox with the sort direction. It also handles automatic + * submission of sorting changes and draws an additional submit button when JavaScript is disabled. * - * The constructor takes an string for the component name ad an array containing the select options, where the key is - * the value to be submitted and the value is the label that will be shown. You then should call applyRequest in order - * to make sure the form is correctly populated when a request with a sort parameter is being made. + * The constructor takes an string for the component name and an array containing the select options, where the key is + * the value to be submitted and the value is the label that will be shown. You then should call applyRequest in order + * to make sure the form is correctly populated when a request with a sort parameter is being made. * - * Example: - *

+ * Example:
+ *  

  *      $this->view->sortControl = new SortBox(
- *      $this->getRequest()->getActionName(),
+ *          $this->getRequest()->getActionName(),
  *          $columns
  *      );
  *      $this->view->sortControl->applyRequest($this->getRequest());
- *      
- * By default the sortBox uses the GET parameter 'sort' for the sorting key and 'dir' for the sorting direction - * + *
*/ class SortBox extends AbstractWidget { - /** * An array containing all sort columns with their associated labels * * @var array */ - private $sortFields; + protected $sortFields; /** * The name of the form that will be created * * @var string */ - private $name; + protected $name; /** * A request object used for initial form population * - * @var \Icinga\Web\Request + * @var Request */ - private $request; + protected $request; /** * Create a SortBox with the entries from $sortFields * - * @param string $name The name of the sort form - * @param array $sortFields An array containing the columns and their labels to be displayed - * in the sort select box + * @param string $name The name for the SortBox + * @param array $sortFields An array containing the columns and their labels to be displayed in the SortBox */ public function __construct($name, array $sortFields) { @@ -69,13 +62,12 @@ public function __construct($name, array $sortFields) } /** - * Create a SortBox with the entries from $sortFields + * Create a SortBox * - * @param string $name The name of the sort form - * @param array $sortFields An array containing the columns and their labels to be displayed - * in the sort select box + * @param string $name The name for the SortBox + * @param array $sortFields An array containing the columns and their labels to be displayed in the SortBox * - * @return static + * @return SortBox */ public static function create($name, array $sortFields) { @@ -85,9 +77,9 @@ public static function create($name, array $sortFields) /** * Apply the parameters from the given request on this SortBox * - * @param Request $request The request to use for populating the form + * @param Request $request The request to use for populating the form * - * @return $this + * @return $this */ public function applyRequest($request) { @@ -96,60 +88,49 @@ public function applyRequest($request) } /** - * Create a submit button that is hidden via the ConditionalDecorator - * in order to allow sorting changes to be submitted in a JavaScript-less environment - * - * @return Zend_Form_Element_Submit The submit button that is hidden by default - * @see ConditionalDecorator - */ - private function createFallbackSubmitButton() - { - $manualSubmitButton = new Zend_Form_Element_Submit( - array( - 'name' => 'submit_' . $this->name, - 'label' => 'Sort', - 'class' => '', - 'condition' => 0, - 'value' => '{{SUBMIT_ICON}}' - ) - ); - $manualSubmitButton->addDecorator(new ConditionalHidden()); - $manualSubmitButton->setAttrib('addLabelPlaceholder', true); - return $manualSubmitButton; - } - - /** - * Renders this widget via the given view and returns the - * HTML as a string + * Render this SortBox as HTML * * @return string */ public function render() { $form = new Form(); - $form->setAttrib('class', 'inline'); - $form->setMethod('POST'); $form->setTokenDisabled(); $form->setName($this->name); - $form->addElement('select', 'sort', array( - 'label' => 'Sort By', - 'multiOptions' => $this->sortFields, - 'style' => 'width: 12em', - 'autosubmit' => true - )); - $form->addElement('select', 'dir', array( - 'multiOptions' => array( - 'asc' => 'Asc', - 'desc' => 'Desc', - ), - 'style' => 'width: 5em', - 'autosubmit' => true + $form->setAttrib('class', 'sort-control inline'); + + $form->addElement( + 'select', + 'sort', + array( + 'autosubmit' => true, + 'label' => $this->view()->translate('Sort by'), + 'multiOptions' => $this->sortFields + ) + ); + $form->getElement('sort')->setDecorators(array( + array('ViewHelper'), + array('Label') )); - $sort = $form->getElement('sort')->setDecorators(array('ViewHelper')); - $dir = $form->getElement('dir')->setDecorators(array('ViewHelper')); + $form->addElement( + 'select', + 'dir', + array( + 'autosubmit' => true, + 'multiOptions' => array( + 'asc' => 'Asc', + 'desc' => 'Desc', + ), + 'decorators' => array( + array('ViewHelper') + ) + ) + ); + if ($this->request) { $form->populate($this->request->getParams()); } + return $form; } } diff --git a/public/css/icinga/controls.less b/public/css/icinga/controls.less new file mode 100644 index 0000000000..9445beb466 --- /dev/null +++ b/public/css/icinga/controls.less @@ -0,0 +1,18 @@ +/*! Icinga Web 2 | (c) 2013-2015 Icinga Development Team | GPLv2+ */ + +form.sort-control { + label { + width: auto; + margin-right: 0.5em; + } + + select[name=sort] { + width: 12em; + margin-left: 0; + } + + select[name=dir] { + width: 5em; + margin-left: 0; + } +}