From 690d60672c485243c9c8f9256055ed24d3a7364e Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Thu, 20 Aug 2015 14:34:43 +0200 Subject: [PATCH] Introduce form element decorator Spinner refs #8369 --- library/Icinga/Web/Form.php | 8 ++++ library/Icinga/Web/Form/Decorator/Spinner.php | 45 +++++++++++++++++++ public/css/icinga/forms.less | 19 ++++++++ 3 files changed, 72 insertions(+) create mode 100644 library/Icinga/Web/Form/Decorator/Spinner.php diff --git a/library/Icinga/Web/Form.php b/library/Icinga/Web/Form.php index 2730f6998..40d6bb409 100644 --- a/library/Icinga/Web/Form.php +++ b/library/Icinga/Web/Form.php @@ -801,9 +801,17 @@ class Form extends Zend_Form && ! array_key_exists('disabledLoadDefaultDecorators', $options) ) { $options['decorators'] = static::$defaultElementDecorators; + if (! isset($options['data-progress-label']) && ($type === 'submit' + || ($type === 'button' && isset($options['type']) && $options['type'] === 'submit')) + ) { + array_splice($options['decorators'], 1, 0, array(array('Spinner', array('separator' => '')))); + } } } else { $options = array('decorators' => static::$defaultElementDecorators); + if ($type === 'submit') { + array_splice($options['decorators'], 1, 0, array(array('Spinner', array('separator' => '')))); + } } $el = parent::createElement($type, $name, $options); diff --git a/library/Icinga/Web/Form/Decorator/Spinner.php b/library/Icinga/Web/Form/Decorator/Spinner.php new file mode 100644 index 000000000..802e001d9 --- /dev/null +++ b/library/Icinga/Web/Form/Decorator/Spinner.php @@ -0,0 +1,45 @@ +getViewRenderer()->view; + } + + /** + * Add a spinner icon to a form element + * + * @param string $content The html rendered so far + * + * @return string The updated html + */ + public function render($content = '') + { + $spinner = '
' + . $this->getView()->icon('spin6') + . '
'; + + switch ($this->getPlacement()) { + case self::APPEND: + return $content . $spinner; + case self::PREPEND: + return $spinner . $content; + } + } +} \ No newline at end of file diff --git a/public/css/icinga/forms.less b/public/css/icinga/forms.less index 82a5f5184..f49c485a6 100644 --- a/public/css/icinga/forms.less +++ b/public/css/icinga/forms.less @@ -107,6 +107,25 @@ form.inline { display: inline; } +div.spinner { + display: inline-block; + margin-top: 0.2em; + margin-left: 0.25em; + + i { + visibility: hidden; + + &.active { + visibility: visible; + } + + &:before { + margin: 0; // Disables wobbling + .animate(spin 2s infinite linear); + } + } +} + button, .button-like { font-size: 0.9em; font-weight: bold;