| 1 |
<?php |
| 2 |
class View_SideBySide extends View { |
| 3 |
protected $labelWidth; |
| 4 |
protected $labelRightAlign; |
| 5 |
protected $labelPaddingRight = 5; |
| 6 |
protected $labelPaddingTop; |
| 7 |
|
| 8 |
public function __construct($labelWidth, array $properties = null) { |
| 9 |
if(!empty($properties)) |
| 10 |
$properties["labelWidth"] = $labelWidth; |
| 11 |
else |
| 12 |
$properties = array("labelWidth" => $labelWidth); |
| 13 |
|
| 14 |
parent::__construct($properties); |
| 15 |
} |
| 16 |
|
| 17 |
public function render() { |
| 18 |
echo '<form', $this->form->getAttributes(), '>'; |
| 19 |
$this->form->getError()->render(); |
| 20 |
|
| 21 |
$elements = $this->form->getElements(); |
| 22 |
$elementSize = sizeof($elements); |
| 23 |
$elementCount = 0; |
| 24 |
for($e = 0; $e < $elementSize; ++$e) { |
| 25 |
$element = $elements[$e]; |
| 26 |
|
| 27 |
if($element instanceof Element_Hidden || $element instanceof Element_HTMLExternal) |
| 28 |
$element->render(); |
| 29 |
elseif($element instanceof Element_Button) { |
| 30 |
if($e == 0 || !$elements[($e - 1)] instanceof Element_Button) |
| 31 |
echo '<div class="pfbc-element pfbc-buttons">'; |
| 32 |
$element->render(); |
| 33 |
if(($e + 1) == $elementSize || !$elements[($e + 1)] instanceof Element_Button) |
| 34 |
echo '</div>'; |
| 35 |
} |
| 36 |
else { |
| 37 |
echo '<div id="pfbc-element-', $elementCount, '" class="pfbc-element">', $element->getPreHTML(); |
| 38 |
$this->renderLabel($element); |
| 39 |
echo '<div class="pfbc-right">'; |
| 40 |
$element->render(); |
| 41 |
echo '</div><div style="clear: both;"></div>', $element->getPostHTML(), '</div>'; |
| 42 |
++$elementCount; |
| 43 |
} |
| 44 |
} |
| 45 |
|
| 46 |
echo '</form>'; |
| 47 |
} |
| 48 |
|
| 49 |
public function renderCSS() { |
| 50 |
$id = $this->form->getId(); |
| 51 |
$width = $this->form->getWidth(); |
| 52 |
$widthSuffix = $this->form->getWidthSuffix(); |
| 53 |
|
| 54 |
if($widthSuffix == "px") |
| 55 |
$elementWidth = $width - $this->labelWidth - $this->labelPaddingRight; |
| 56 |
else |
| 57 |
$elementWidth = 100 - $this->labelWidth - $this->labelPaddingRight; |
| 58 |
|
| 59 |
View::renderCSS(); |
| 60 |
echo <<<CSS |
| 61 |
#$id { width: $width{$widthSuffix}; } |
| 62 |
#$id .pfbc-element { margin-bottom: 1em; padding-bottom: 1em; border-bottom: 1px solid #f4f4f4; } |
| 63 |
#$id .pfbc-label { width: {$this->labelWidth}$widthSuffix; float: left; padding-right: {$this->labelPaddingRight}$widthSuffix; } |
| 64 |
#$id .pfbc-buttons { text-align: right; } |
| 65 |
#$id .pfbc-textbox, #$id .pfbc-textarea, #$id .pfbc-select, #$id .pfbc-right { width: $elementWidth{$widthSuffix}; } |
| 66 |
#$id .pfbc-right { float: right; } |
| 67 |
CSS; |
| 68 |
|
| 69 |
if(!empty($this->labelRightAlign)) |
| 70 |
echo '#', $id, ' .pfbc-label { text-align: right; }'; |
| 71 |
|
| 72 |
if(empty($this->labelPaddingTop) && !in_array("style", $this->form->getPrevent())) |
| 73 |
$this->labelPaddingTop = ".75em"; |
| 74 |
|
| 75 |
if(!empty($this->labelPaddingTop)) { |
| 76 |
if(is_numeric($this->labelPaddingTop)) |
| 77 |
$this->labelPaddingTop .= "px"; |
| 78 |
echo '#', $id, ' .pfbc-label { padding-top: ', $this->labelPaddingTop, '; }'; |
| 79 |
} |
| 80 |
|
| 81 |
$elements = $this->form->getElements(); |
| 82 |
$elementSize = sizeof($elements); |
| 83 |
$elementCount = 0; |
| 84 |
for($e = 0; $e < $elementSize; ++$e) { |
| 85 |
$element = $elements[$e]; |
| 86 |
$elementWidth = $element->getWidth(); |
| 87 |
if(!$element instanceof Element_Hidden && !$element instanceof Element_HTMLExternal && !$element instanceof Element_HTMLExternal) { |
| 88 |
if(!empty($elementWidth)) { |
| 89 |
echo '#', $id, ' #pfbc-element-', $elementCount, ' { width: ', $elementWidth, $widthSuffix, '; }'; |
| 90 |
if($widthSuffix == "px") { |
| 91 |
$elementWidth = $elementWidth - $this->labelWidth - $this->labelPaddingRight; |
| 92 |
echo '#', $id, ' #pfbc-element-', $elementCount, ' .pfbc-textbox, #', $id, ' #pfbc-element-', $elementCount, ' .pfbc-textarea, #', $id, ' #pfbc-element-', $elementCount, ' .pfbc-select, #', $id, ' #pfbc-element-', $elementCount, ' .pfbc-right { width: ', $elementWidth, $widthSuffix, '; }'; |
| 93 |
} |
| 94 |
} |
| 95 |
$elementCount++; |
| 96 |
} |
| 97 |
} |
| 98 |
} |
| 99 |
} |
| 100 |
|