import v1.0.0-RC4 | 2009-05-20
This commit is contained in:
136
libs/Monkeys/Form/Decorator/Composite.php
Normal file
136
libs/Monkeys/Form/Decorator/Composite.php
Normal file
@ -0,0 +1,136 @@
|
||||
<?
|
||||
|
||||
class Monkeys_Form_Decorator_Composite extends Zend_Form_Decorator_Abstract
|
||||
{
|
||||
public function buildLabel()
|
||||
{
|
||||
$element = $this->getElement();
|
||||
$label = $element->getLabel();
|
||||
if ($translator = $element->getTranslator()) {
|
||||
$label = $translator->translate($label);
|
||||
}
|
||||
if ($element->isRequired()) {
|
||||
$label .= '*';
|
||||
}
|
||||
|
||||
return $label . ':';
|
||||
/*return $element->getView()
|
||||
->formLabel($element->getName(), $label);*/
|
||||
}
|
||||
|
||||
public function buildInput($content = '')
|
||||
{
|
||||
$element = $this->getElement();
|
||||
$helper = $element->helper;
|
||||
$attribs = $element->getAttribs();
|
||||
if ($this->getOption('bottom')) {
|
||||
$attribs = array_merge($attribs, array('style' => 'top:0; width:auto'));
|
||||
}
|
||||
|
||||
if ($element instanceof Monkeys_Form_Element_Captcha) {
|
||||
return $content;
|
||||
}
|
||||
|
||||
$input = $element->getView()->$helper(
|
||||
$element->getName(),
|
||||
$element->getValue(),
|
||||
$attribs,
|
||||
$element->options,
|
||||
$this->getSeparator()
|
||||
);
|
||||
|
||||
if ($element instanceof Monkeys_Form_Element_Radio) {
|
||||
return "<div class=\"formRadio\">$input</div>";
|
||||
}
|
||||
|
||||
return $input;
|
||||
}
|
||||
|
||||
public function buildErrors()
|
||||
{
|
||||
$element = $this->getElement();
|
||||
$messages = $element->getMessages();
|
||||
if (empty($messages)) {
|
||||
return '';
|
||||
}
|
||||
|
||||
return $element->getView()->formErrors($messages);
|
||||
/*return '<div class="errors">' .
|
||||
$element->getView()->formErrors($messages) . '</div>';*/
|
||||
}
|
||||
|
||||
public function buildDescription()
|
||||
{
|
||||
$element = $this->getElement();
|
||||
$desc = $element->getDescription();
|
||||
if (empty($desc)) {
|
||||
return '';
|
||||
}
|
||||
if ($translator = $element->getTranslator()) {
|
||||
$desc = $translator->translate($desc);
|
||||
}
|
||||
|
||||
return $desc;
|
||||
}
|
||||
|
||||
public function render($content)
|
||||
{
|
||||
$element = $this->getElement();
|
||||
if (!$element instanceof Zend_Form_Element) {
|
||||
return $content;
|
||||
}
|
||||
if (null === $element->getView()) {
|
||||
return $content;
|
||||
}
|
||||
|
||||
$placement = $this->getPlacement();
|
||||
$label = $this->buildLabel();
|
||||
$input = $this->buildInput($content);
|
||||
$errors = $this->buildErrors();
|
||||
$desc = $this->buildDescription();
|
||||
|
||||
if ($desc && $errors) {
|
||||
$desc = "<div>$desc</div>";
|
||||
} else if ($desc && !$errors) {
|
||||
$desc = "<div class=\"description\">$desc</div>";
|
||||
}
|
||||
|
||||
if ($this->getOption('yuiGridType')) {
|
||||
$yuiGridType = $this->getOption('yuiGridType');
|
||||
} else {
|
||||
$yuiGridType = 'gf';
|
||||
}
|
||||
|
||||
if ($this->getOption('wideLabel')) {
|
||||
$output = "<div class=\"yui-$yuiGridType\" style=\"padding-bottom:10px\">\n"
|
||||
." <div class=\"formLabel\" style=\"padding-bottom:10px\">$label</div>\n"
|
||||
." <div class=\"yui-u first\"> </div>\n"
|
||||
." <div class=\"yui-u\">\n"
|
||||
." $input\n"
|
||||
." $desc\n"
|
||||
. ($errors? " <div>$errors</div>\n" : "")
|
||||
." </div>\n"
|
||||
."</div>\n";
|
||||
} else if ($this->getOption('continuous')) {
|
||||
$output = "<div style=\"padding-bottom:10px\">\n"
|
||||
." <span class=\"formLabel\">$label</span> $input"
|
||||
." <div>\n"
|
||||
." $desc\n"
|
||||
. ($errors? " <div>$errors</div>\n" : "")
|
||||
." </div>\n"
|
||||
."</div>\n";
|
||||
} else {
|
||||
$output = "<div class=\"yui-$yuiGridType\">\n"
|
||||
." <div class=\"yui-u first\">$label</div>\n"
|
||||
." <div class=\"yui-u\">\n"
|
||||
." $input\n"
|
||||
." $desc\n"
|
||||
. ($errors? " <div>$errors</div>\n" : "")
|
||||
." </div>\n"
|
||||
."</div>\n";
|
||||
}
|
||||
|
||||
return $output;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user