Add Number functionality to Icinga\Form\SendCommand

This commit is contained in:
Johannes Meyer 2013-07-09 13:51:32 +02:00 committed by Marius Hein
parent f102f75eb9
commit 56b8b398c2
5 changed files with 74 additions and 0 deletions

View File

@ -0,0 +1,30 @@
<?php
/**
* Helper to generate a number input
*/
class Zend_View_Helper_FormNumber extends \Zend_View_Helper_FormText
{
/**
* Generates a html number input
*
* @access public
*
* @param string $name The element name.
* @param string $value The default value.
* @param array $attribs Attributes which should be added to the input tag.
*
* @return string The input tag and options XHTML.
*/
public function formNumber($name, $value = null, $attribs = null)
{
return '<input type="number"'
. ' name="' . $this->view->escape($name) . '"'
. ' value="' . $this->view->escape($value) . '"'
. ' id="' . $this->view->escape($name) . '"'
. $this->_htmlAttribs($attribs)
. $this->getClosingBracket();
}
}
?>

View File

@ -3,6 +3,8 @@ namespace Icinga\Form\Elements;
/**
* Date form element
*
* @TODO: The given label for this element is not displayed. (Reason unknown)
*/
class Date extends \Zend_Form_Element_Xhtml
{

View File

@ -0,0 +1,18 @@
<?php
namespace Icinga\Form\Elements;
/**
* Number form element
*
* @TODO: The given label for this element is not displayed. (Reason unknown)
*/
class Number extends \Zend_Form_Element_Xhtml
{
/**
* Default form view helper to use for rendering
* @var string
*/
public $helper = "formNumber";
}
?>

View File

@ -3,6 +3,8 @@ namespace Icinga\Form\Elements;
/**
* Time form element
*
* @TODO: The given label for this element is not displayed. (Reason unknown)
*/
class Time extends \Zend_Form_Element_Xhtml
{

View File

@ -4,6 +4,7 @@ namespace Icinga\Form;
use Icinga\Form\Builder;
use Icinga\Form\Elements\Date;
use Icinga\Form\Elements\Time;
use Icinga\Form\Elements\Number;
class SendCommand extends Builder
{
@ -125,6 +126,27 @@ class SendCommand extends Builder
{
return $this->getElement($id)->options[$_POST[$id]];
}
/**
* @TODO: "min", "max" and "step" seem to have no effect :(
*/
public function addNumberBox($id, $label, $value = "", $min = 0, $max = -1, $step = "any")
{
$number = new Number($id);
$number->setValue($value);
$this->addElement($number, $id, array(
'label' => $label,
'step' => $step,
'min' => $min,
'max' => $max
)
);
}
public function getNumber($id)
{
return $this->getValue($id);
}
}
?>