summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSjon Hortensius <sjon@hortensius.net>2015-04-26 13:41:15 +0200
committerSjon Hortensius <sjon@hortensius.net>2015-04-26 13:41:15 +0200
commitc251820466fa84c372ace113fd39bc4934434670 (patch)
tree6a796340eca429bb11d85cb52d638bf5e5873cb1
parent687456e3b3c5e6a72dc8bd29169cbfe0d3a5757a (diff)
downloadpfsense-c251820466fa84c372ace113fd39bc4934434670.zip
pfsense-c251820466fa84c372ace113fd39bc4934434670.tar.gz
Prepare for different width, make widths static
refs #141
-rw-r--r--usr/local/www/classes/Form.class.php18
-rw-r--r--usr/local/www/classes/Form/Group.class.php19
-rw-r--r--usr/local/www/classes/Form/Input.class.php4
-rw-r--r--usr/local/www/classes/Form/Section.class.php6
4 files changed, 14 insertions, 33 deletions
diff --git a/usr/local/www/classes/Form.class.php b/usr/local/www/classes/Form.class.php
index 83652bf..a280dd6 100644
--- a/usr/local/www/classes/Form.class.php
+++ b/usr/local/www/classes/Form.class.php
@@ -34,6 +34,8 @@ foreach (glob('classes/Form/*.class.php') as $file)
class Form extends Form_Element
{
+ const LABEL_WIDTH = 2;
+ const MAX_INPUT_WIDTH = 10;
protected $_tagName = 'form';
protected $_attributes = array(
'class' => array('form-horizontal' => true),
@@ -43,7 +45,6 @@ class Form extends Form_Element
);
protected $_sections = array();
protected $_global = array();
- protected $_labelWidth = 2;
public function __construct(Form_Button $submit = null)
{
@@ -64,14 +65,6 @@ class Form extends Form_Element
return $section;
}
- public function setLabelWidth($size)
- {
- if ($size < 1 || $size > 12)
- throw new Exception('Incorrect size, pass a number between 1 and 12');
-
- $this->_labelWidth = (int)$size;
- }
-
public function setAction($url)
{
$this->_attributes['action'] = $url;
@@ -79,11 +72,6 @@ class Form extends Form_Element
return $this;
}
- public function getLabelWidth()
- {
- return $this->_labelWidth;
- }
-
public function addGlobal(Form_Input $input)
{
array_push($this->_global, $input);
@@ -113,7 +101,7 @@ class Form extends Form_Element
if (!empty($buttons))
{
$group = new Form_Element;
- $group->addClass('col-sm-offset-'. $this->_labelWidth, 'col-sm-'. (12 - $this->_labelWidth));
+ $group->addClass('col-sm-'. Form::MAX_INPUT_WIDTH, 'col-sm-offset-'. Form::LABEL_WIDTH);
$html .= $group . $buttons .'</div>';
}
diff --git a/usr/local/www/classes/Form/Group.class.php b/usr/local/www/classes/Form/Group.class.php
index 20e0f98..2b129e5 100644
--- a/usr/local/www/classes/Form/Group.class.php
+++ b/usr/local/www/classes/Form/Group.class.php
@@ -60,12 +60,6 @@ class Form_Group extends Form_Element
$this->_labelTarget = $input;
}
- // Potentially allow overloading
- public function getLabelWidth()
- {
- return $this->_parent->getLabelWidth();
- }
-
public function setHelp($help, array $params = array())
{
$this->_help = $help;
@@ -92,7 +86,7 @@ class Form_Group extends Form_Element
$element = parent::__toString();
// Automatically determine width for inputs without explicit set
- $spaceLeft = 12 - $this->getLabelWidth();
+ $spaceLeft = Form::MAX_INPUT_WIDTH;
$missingWidth = array();
foreach ($this->_inputs as $input)
@@ -116,14 +110,16 @@ class Form_Group extends Form_Element
if (isset($this->_help))
{
+ $group = new Form_Element;
+ $group->addClass('col-sm-'. Form::MAX_INPUT_WIDTH, 'col-sm-offset-'. Form::LABEL_WIDTH);
+
$help = gettext($this->_help);
if (!empty($this->_helpParams))
$help = call_user_func_array('sprintf', array_merge([$help], $this->_helpParams));
- $helpWidth = 12 - $this->getLabelWidth();
$help = <<<EOT
- <div class="col-sm-{$helpWidth} col-sm-offset-{$this->getLabelWidth()}">
+ {$group}
<span class="help-block">
{$help}
</span>
@@ -131,9 +127,12 @@ class Form_Group extends Form_Element
EOT;
}
+ $label = new Form_Element('label', false, ['for' => $target]);
+ $label->addClass('col-sm-'.Form::LABEL_WIDTH, 'control-label');
+
return <<<EOT
{$element}
- <label for="{$target}" class="col-sm-{$this->getLabelWidth()} control-label">
+ {$label}
{$this->_title}
</label>
{$inputs}
diff --git a/usr/local/www/classes/Form/Input.class.php b/usr/local/www/classes/Form/Input.class.php
index 130bff2..c0ed68c 100644
--- a/usr/local/www/classes/Form/Input.class.php
+++ b/usr/local/www/classes/Form/Input.class.php
@@ -93,8 +93,8 @@ class Form_Input extends Form_Element
public function setWidth($size)
{
- if ($size < 1 || $size > 12)
- throw new Exception('Incorrect size, pass a number between 1 and 12');
+ if ($size < 1 || $size > Form::MAX_INPUT_WIDTH)
+ throw new Exception('Incorrect size, pass a number between 1 and '.Form::MAX_INPUT_WIDTH);
$this->column->removeClass('col-sm-'. $this->_columnWidth);
diff --git a/usr/local/www/classes/Form/Section.class.php b/usr/local/www/classes/Form/Section.class.php
index 290b4a6..2b7977a 100644
--- a/usr/local/www/classes/Form/Section.class.php
+++ b/usr/local/www/classes/Form/Section.class.php
@@ -62,12 +62,6 @@ class Form_Section extends Form_Element
return $input;
}
- // Potentially allow overloading
- public function getLabelWidth()
- {
- return $this->_parent->getLabelWidth();
- }
-
public function __toString()
{
$element = parent::__toString();
OpenPOWER on IntegriCloud