| 1 |
<?php |
| 2 |
abstract class View extends Base { |
| 3 |
protected $form; |
| 4 |
|
| 5 |
public function __construct(array $properties = null) { |
| 6 |
$this->configure($properties); |
| 7 |
} |
| 8 |
|
| 9 |
/*This method encapsulates the various pieces that are included in an element's label.*/ |
| 10 |
protected function renderLabel($element) { |
| 11 |
$label = $element->getLabel(); |
| 12 |
$id = $element->getID(); |
| 13 |
$description = $element->getDescription(); |
| 14 |
if(!empty($label) || !empty($description)) { |
| 15 |
echo '<div class="pfbc-label">'; |
| 16 |
if(!empty($label)) { |
| 17 |
echo '<label for="', $id, '">'; |
| 18 |
if($element->isRequired()) |
| 19 |
echo '<strong>*</strong> '; |
| 20 |
echo $label, '</label>'; |
| 21 |
} |
| 22 |
if(!empty($description)) |
| 23 |
echo '<em>', $description, '</em>'; |
| 24 |
echo '</div>'; |
| 25 |
} |
| 26 |
} |
| 27 |
|
| 28 |
public function setForm(Form $form) { |
| 29 |
$this->form = $form; |
| 30 |
} |
| 31 |
|
| 32 |
/*jQuery is used to apply css entries to the last element.*/ |
| 33 |
public function jQueryDocumentReady() { |
| 34 |
echo 'jQuery("#', $this->form->getId(), ' .pfbc-element:last").css({ "margin-bottom": "0", "padding-bottom": "0", "border-bottom": "none" });'; |
| 35 |
} |
| 36 |
|
| 37 |
public function render() {} |
| 38 |
|
| 39 |
public function renderCSS() { |
| 40 |
$id = $this->form->getId(); |
| 41 |
|
| 42 |
/*For ease-of-use, default styles are applied to form elements.*/ |
| 43 |
if(!in_array("style", $this->form->getPrevent())) { |
| 44 |
echo <<<CSS |
| 45 |
#$id .pfbc-label label { font-weight: bold; } |
| 46 |
#$id .pfbc-label em { font-size: .9em; color: #888; } |
| 47 |
#$id .pfbc-label strong { color: #990000; } |
| 48 |
#$id .pfbc-textbox, #$id .pfbc-textarea, #$id .pfbc-select { border: 1px solid #ccc; font-size: 14px; } |
| 49 |
#$id .pfbc-textbox, #$id .pfbc-textarea { padding: 7px; } |
| 50 |
#$id .pfbc-select { padding: 6px 7px; } |
| 51 |
#$id img.pfbc-loading { position: absolute; top: 50%; right: .5em; margin-top: -8px; border: 0; } |
| 52 |
CSS; |
| 53 |
} |
| 54 |
} |
| 55 |
|
| 56 |
public function renderJS() {} |
| 57 |
} |
| 58 |
|