Example #1
0
 public function __construct($name)
 {
     parent::__construct('', array('id' => 'mail-editor'));
     $subject = $this->addElement('text', 'subject', array('size' => 80))->setLabel(___('Subject'));
     $subject->addRule('required');
     $this->addStatic()->setContent('<br /><br />');
     $format = $this->addGroup(null)->setLabel(___('E-Mail Format'));
     $format->addRadio('format', array('value' => 'html'))->setContent(___('HTML Message'));
     $format->addRadio('format', array('value' => 'text'))->setContent(___('Plain-Text Message'));
     $this->addStatic()->setContent('<br /><br />');
     $this->editor = $this->addElement(new Am_Form_Element_HtmlEditor('txt', null, true));
     $this->editor->addRule('required');
     $this->addStatic()->setContent('<br /><br />');
     $this->tagsOptions = Am_Mail_TemplateTypes::getInstance()->getTagsOptions($name);
     $tagsOptions = array();
     foreach ($this->tagsOptions as $k => $v) {
         $tagsOptions[$k] = "{$k} - {$v}";
     }
     $sel = $this->addSelect('', array('id' => 'insert-tags'));
     $sel->loadOptions(array_merge(array('' => ''), $tagsOptions));
     $this->addStatic()->setContent('<br /><br />');
     $this->addClass('no-label');
     $fileChooser = new Am_Form_Element_Upload('attachments', array('multiple' => 1), array('prefix' => EmailTemplate::ATTACHMENT_FILE_PREFIX));
     $this->addElement($fileChooser)->setLabel(___('Attachments'));
 }
Example #2
0
 public function __construct($name = null, $attributes = null, $data = null)
 {
     parent::__construct($name, $attributes, null);
     $this->addElement('text', $data . '_c', array('size' => 5));
     $this->addStatic()->setContent(' ');
     $sel = $this->addElement('select', $data . '_t', array('size' => 1), array('options' => array('%' => '%', '$' => Am_Currency::getDefault())));
 }
Example #3
0
 protected function updateValue()
 {
     $name = $this->getName();
     foreach ($this->getDataSources() as $ds) {
         if (null !== ($value = $ds->getValue($name))) {
             $this->setValue($value);
             return;
         }
     }
     return parent::updateValue();
 }
 /**
  * Renders the hierselect using the given renderer
  *
  * @param HTML_QuickForm2_Renderer $renderer
  *
  * @return   HTML_QuickForm2_Renderer
  * @throws   HTML_QuickForm2_Exception   if number of selects in hierselect cannot
  *                                       be determined
  */
 public function render(HTML_QuickForm2_Renderer $renderer)
 {
     if (0 == $this->size) {
         throw new HTML_QuickForm2_Exception('Unable to determine number of selects in hierselect');
     }
     if ($this->toggleFrozen()) {
         // frozen hierselect does not need any javascript
         return parent::render($renderer);
     }
     $jsBuilder = $renderer->getJavascriptBuilder();
     $jsBuilder->addLibrary('hierselect', 'quickform-hierselect.js');
     $jsBuilder->addElementJavascript($this->_generateInitScript());
     $script = $this->appendChild(new HTML_QuickForm2_Element_Script('script'))->setContent($this->_generateInlineScript());
     parent::render($renderer);
     $this->removeChild($script);
     return $renderer;
 }
Example #5
0
 public static function _renderGroup(HTML_QuickForm2_Renderer $renderer, HTML_QuickForm2_Container_Group $group)
 {
     $error = $group->getError();
     if ($error) {
         $html[] = '<div class="form-group error">';
         $renderer->errors[] = $error;
     } else {
         $html[] = '<div class="form-group">';
     }
     $html[] = "\n";
     $html[] = $renderer->renderLabel($group);
     $html[] = '<div class="form-control">';
     //        $html[] = '<div class="input inline">';
     $html[] = "\n";
     $separator = $group->getSeparator();
     /*
             foreach ($group as $element) {
                 echo '<pre>';
                 var_dump($element);
                 echo '</pre>';
                 //$elements[] = (string)$element;
             }
     */
     /*
             $elements[]  = (string)array_pop($group->getElements());
             echo '<pre>';
             //var_dump($elements);
             echo '</pre>';
             /*
             foreach($elements as $k => $v)
             {
                 $elements[$k] = (string)$elements[$k];
             }*/
     /*
         echo '<pre>';
         //var_dump($elements);
         echo '</pre>';
     */
     $elements = array_pop($renderer->html);
     if (!is_array($separator)) {
         $content = implode((string) $separator, $elements);
     } else {
         $content = '';
         $cSeparator = count($separator);
         for ($i = 0, $count = count($elements); $i < $count; $i++) {
             $content .= (0 == $i ? '' : $separator[($i - 1) % $cSeparator]) . $elements[$i];
         }
     }
     $html[] = $content;
     if ($error) {
         $html[] = '<span class="help-inline">' . $error . '</span>';
     } else {
         $label = $group->getLabel();
         if (is_array($label) && !empty($label[1])) {
             $html[] = '<span class="help-block">' . $label[1] . '</span>';
         }
     }
     $html[] = "\n";
     //        $html[] = '</div>';
     $html[] = '</div>';
     $html[] = '</div><!-- of group -->';
     return implode('', $html);
     /*
     $break = HTML_Common2::getOption('linebreak');
     //$html[] = '<div class="row">';
     $error = $group->getError();
     if ($error) {
         $html[] = '<div class="form-inline control-group error">';
         $html[] = $renderer->renderLabel($group);
     
         if ($renderer->getOption('group_errors')) {
             $renderer->errors[] = $error;
         } else {
             $html[] = '<span class="help-inline">'.$error.'</span><br />';
         }
     } else {
         $html[] = '<span class="form-inline">';
         $html[] = $renderer->renderLabel($group);
     }
     
     $separator = $group->getSeparator();
     $elements  = array_pop($renderer->html);
     if (!is_array($separator)) {
         $content = implode((string)$separator, $elements);
     } else {
         $content    = '';
         $cSeparator = count($separator);
         for ($i = 0, $count = count($elements); $i < $count; $i++) {
             $content .= (0 == $i? '': $separator[($i - 1) % $cSeparator]) .
                         $elements[$i];
         }
     }
     $html[] = $content;
     $html[] = '</span>';
     //$html[] = '</div>';
     return implode($break, $html) . $break;
     */
 }
 /**
  * If defaults contain null values, previous values are reused
  * @link http://pear.php.net/bugs/bug.php?id=20295
  */
 public function testBug20295()
 {
     $form = new HTML_QuickForm2('repeat-bug');
     $form->addDataSource(new HTML_QuickForm2_DataSource_Array(array('buggy' => array('name' => array(1 => 'First', 2 => 'Second'), 'extra' => array(1 => 'Has extra', 2 => null)))));
     $group = new HTML_QuickForm2_Container_Group('buggy');
     $group->addText('name');
     $group->addText('extra');
     $repeat = $form->addRepeat(null, array('id' => 'buggy-repeat'), array('prototype' => $group));
     $value = $repeat->getValue();
     $this->assertEquals('', $value['buggy']['extra'][2]);
 }
Example #7
0
    public function __construct($name = null, $attributes = null, $data = null)
    {
        parent::__construct(null, $attributes, $data);
        $this->setSeparator(' ');
        $el = $this->addAdvCheckbox($name);
        $id = $el->getId();
        $this->addScript()->setScript(<<<CUT
// init checkboxed group {$id}
\$(function(){
    var el = \$("#{$id}").closest(".element");
    el.html(el.html().replace(/(<[\\s\\S]+checkbox[\\s\\S]+?>)([\\s\\S]+)/, '\$1<span class="checkboxed-cnt">\$2</span>'));
    \$(".checkboxed-cnt", el).toggle( \$("#{$id}").is(":checked") );
    \$("#{$id}").change(function()
    {
        \$(this).closest(".element").find(".checkboxed-cnt").toggle( this.checked );
    });
});
// end of init checkboxed group    
CUT
);
    }
 public static function _renderGroup(HTML_QuickForm2_Renderer $renderer, HTML_QuickForm2_Container_Group $group)
 {
     $break = HTML_Common2::getOption('linebreak');
     $class = $group->getAttribute('class');
     $html[] = '<div class="row' . (!empty($class) ? ' ' . $class : '') . '">';
     $html[] = $renderer->renderLabel($group);
     $error = $group->getError();
     if ($error) {
         $html[] = '<div class="element group error" id="' . $group->getId() . '">';
         if ($renderer->getOption('group_errors')) {
             $renderer->errors[] = $error;
         } else {
             $html[] = '<span class="error">' . $error . '</span><br />';
         }
     } else {
         $html[] = '<div class="element group" id="' . $group->getId() . '">';
     }
     $separator = $group->getSeparator();
     $elements = array_pop($renderer->html);
     if (!is_array($separator)) {
         $content = implode((string) $separator, $elements);
     } else {
         $content = '';
         $cSeparator = count($separator);
         for ($i = 0, $count = count($elements); $i < $count; $i++) {
             $content .= (0 == $i ? '' : $separator[($i - 1) % $cSeparator]) . $elements[$i];
         }
     }
     $html[] = $content;
     $html[] = '</div>';
     $html[] = '</div>';
     return implode($break, $html) . $break;
 }
 public function testSetValueUpdatesAllElements()
 {
     $group = new HTML_QuickForm2_Container_Group();
     $foo = $group->addText('foo')->setValue('foo value');
     $bar = $group->addText('bar')->setValue('bar value');
     $group->setValue(array('foo' => 'new foo value'));
     $this->assertEquals('new foo value', $foo->getValue());
     $this->assertEquals('', $bar->getValue());
     $group->setValue(null);
     $this->assertEquals('', $foo->getValue());
     $this->assertEquals('', $bar->getValue());
 }
Example #10
0
 /**
  * Called when the element needs to update its value from form's data sources
  *
  * Since the date element also accepts a timestamp as value, the default
  * group behavior is changed.
  */
 protected function updateValue()
 {
     $name = $this->getName();
     /* @var $ds HTML_QuickForm2_DataSource_NullAware */
     foreach ($this->getDataSources() as $ds) {
         if (null !== ($value = $ds->getValue($name)) || $ds instanceof HTML_QuickForm2_DataSource_NullAware && $ds->hasValue($name)) {
             $this->setValue($value);
             return;
         }
     }
     parent::updateValue();
 }