Add new function addCheckBoxGroup(), rename add_label to addLabel

1.10.x
Julio Montoya 11 years ago
parent 4d0c8955b1
commit 6a1adb02a8
  1. 162
      main/inc/lib/formvalidator/FormValidator.class.php
  2. 34
      main/inc/lib/pear/HTML/QuickForm/checkbox.php
  3. 67
      main/inc/lib/pear/HTML/QuickForm/label.php
  4. 83
      main/inc/lib/pear/HTML/QuickForm/radio.php
  5. 4
      main/link/link_form.class.php
  6. 4
      main/social/message_for_group_form.inc.php

@ -146,17 +146,11 @@ class FormValidator extends HTML_QuickForm
// Modify the default templates // Modify the default templates
$renderer = & $this->defaultRenderer(); $renderer = & $this->defaultRenderer();
//Form template // Form template
$formTemplate = '<form{attributes}> $formTemplate = $this->getFormTemplate();
<fieldset>
{content}
<div class="clear"></div>
</fieldset>
{hidden}
</form>';
$renderer->setFormTemplate($formTemplate); $renderer->setFormTemplate($formTemplate);
//Element template // Element template
if (isset($attributes['class']) && $attributes['class'] == 'well form-inline') { if (isset($attributes['class']) && $attributes['class'] == 'well form-inline') {
$element_template = ' {label} {element} '; $element_template = ' {label} {element} ';
$renderer->setElementTemplate($element_template); $renderer->setElementTemplate($element_template);
@ -164,29 +158,7 @@ class FormValidator extends HTML_QuickForm
$element_template = ' {label} {element} '; $element_template = ' {label} {element} ';
$renderer->setElementTemplate($element_template); $renderer->setElementTemplate($element_template);
} else { } else {
$element_template = ' $renderer->setElementTemplate($this->getElementTemplate());
<div class="control-group {error_class}">
<label class="control-label" {label-for}>
<!-- BEGIN required --><span class="form_required">*</span><!-- END required -->
{label}
</label>
<div class="controls">
{element}
<!-- BEGIN label_3 -->
{label_3}
<!-- END label_3 -->
<!-- BEGIN label_2 -->
<p class="help-block">{label_2}</p>
<!-- END label_2 -->
<!-- BEGIN error -->
<span class="help-inline">{error}</span>
<!-- END error -->
</div>
</div>';
$renderer->setElementTemplate($element_template);
//Display a gray div in the buttons //Display a gray div in the buttons
$button_element_template_simple = '<div class="form-actions">{label} {element}</div>'; $button_element_template_simple = '<div class="form-actions">{label} {element}</div>';
@ -228,6 +200,49 @@ EOT;
$renderer->setRequiredNoteTemplate($required_note_template); $renderer->setRequiredNoteTemplate($required_note_template);
} }
/**
* @return string
*/
public function getFormTemplate()
{
return '<form{attributes}>
<fieldset>
{content}
<div class="clear"></div>
</fieldset>
{hidden}
</form>';
}
/**
* @return string
*/
public function getElementTemplate()
{
return '
<div class="control-group {error_class}">
<label class="control-label" {label-for}>
<!-- BEGIN required --><span class="form_required">*</span><!-- END required -->
{label}
</label>
<div class="controls">
{element}
<!-- BEGIN label_3 -->
{label_3}
<!-- END label_3 -->
<!-- BEGIN label_2 -->
<p class="help-block">{label_2}</p>
<!-- END label_2 -->
<!-- BEGIN error -->
<span class="help-inline">{error}</span>
<!-- END error -->
</div>
</div>';
}
/** /**
* Adds a text field to the form. * Adds a text field to the form.
* A trim-filter is attached to the field. * A trim-filter is attached to the field.
@ -254,8 +269,8 @@ EOT;
* *
* @param string $name * @param string $name
* @param string $label * @param string $label
* @param bool $required * @param bool $required
* @param array $attributes * @param array $attributes
*/ */
public function addDateRangePicker($name, $label, $required = true, $attributes = array()) public function addDateRangePicker($name, $label, $required = true, $attributes = array())
{ {
@ -281,49 +296,81 @@ EOT;
* @param string $name * @param string $name
* @param string $label * @param string $label
* @param array $attributes * @param array $attributes
*
* @return HTML_QuickForm_textarea
*/ */
public function addTextarea($name, $label, $attributes = array()) public function addTextarea($name, $label, $attributes = array())
{ {
$this->addElement('textarea', $name, $label, $attributes); return $this->addElement('textarea', $name, $label, $attributes);
} }
/** /**
* @param string $name * @param string $name
* @param string $label * @param string $label
* @param string $icon font-awesome * @param string $icon font-awesome
* @param string $class
* For example plus is transformed to icon fa fa-plus * For example plus is transformed to icon fa fa-plus
* @param array $attributes * @param array $attributes
*
* @return HTML_QuickForm_button
*/ */
public function addButton($name, $label, $icon = 'check', $attributes = array()) public function addButton($name, $label, $icon = 'check', $class = 'btn btn-default', $attributes = array())
{ {
//$attributes['class'] = isset($attributes['class']) ? $attributes['class'] : 'btn btn-default'; //$attributes['class'] = isset($attributes['class']) ? $attributes['class'] : 'btn btn-default';
$attributes['icon'] = $icon; $attributes['icon'] = $icon;
$this->addElement('button', $name, $label, $attributes); $attributes['class'] = $class;
return $this->addElement('button', $name, $label, $attributes);
}
/**
* @param string $name
* @param string $label
* @param string $text
* @param array $attributes
*
* @return HTML_QuickForm_checkbox
*/
public function addCheckBox($name, $label, $text = '', $attributes = array())
{
return $this->addElement('checkbox', $name, $label, $text, $attributes);
} }
/** /**
* @param string $name * @param string $name
* @param string $label * @param string $label
* @param string $trailer * @param array $options
* @param array $attributes * @param array $attributes
*
* @return HTML_QuickForm_group
*/ */
public function addCheckBox($name, $label, $trailer = '', $attributes = array()) public function addCheckBoxGroup($name, $label, $options = array(), $attributes = array())
{ {
$this->addElement('checkbox', $name, $label, $trailer, $attributes); $group = array();
foreach ($options as $value => $text) {
$attributes['value'] = $value;
$group[] = $this->createElement('checkbox', null, null, $text, $attributes);
}
return $this->addGroup($group, $name, $label);
} }
/** /**
* @param string $name * @param string $name
* @param string $label * @param string $label
* @param array $options * @param array $options
* @param array $attributes
*
* @return HTML_QuickForm_radio
*/ */
public function addRadio($name, $label, $options = array()) public function addRadio($name, $label, $options = array(), $attributes = array())
{ {
$group = array(); $group = array();
foreach ($options as $key => $value) { foreach ($options as $key => $value) {
$group[] = $this->createElement('radio', null, null, $value, $key); $group[] = $this->createElement('radio', null, null, $value, $key, $attributes);
} }
$this->addGroup($group, $name, $label);
return $this->addGroup($group, $name, $label);
} }
/** /**
@ -331,19 +378,23 @@ EOT;
* @param string $label * @param string $label
* @param string $options * @param string $options
* @param array $attributes * @param array $attributes
*
* @return HTML_QuickForm_select
*/ */
public function addSelect($name, $label, $options = '', $attributes = array()) public function addSelect($name, $label, $options = '', $attributes = array())
{ {
$this->addElement('select', $name, $label, $options, $attributes); return $this->addElement('select', $name, $label, $options, $attributes);
} }
/** /**
* @param string $label * @param string $label
* @param string $text * @param string $text
*
* @return HTML_QuickForm_label
*/ */
public function add_label($label, $text) public function addLabel($label, $text)
{ {
$this->addElement('label', $label, $text); return $this->addElement('label', $label, $text);
} }
/** /**
@ -357,7 +408,7 @@ EOT;
/** /**
* @param string $name * @param string $name
* @param string $label * @param string $label
* @param array $attributes * @param array $attributes
*/ */
public function add_file($name, $label, $attributes = array()) public function add_file($name, $label, $attributes = array())
{ {
@ -379,9 +430,9 @@ EOT;
* A rule is attached to check for unwanted HTML * A rule is attached to check for unwanted HTML
* @param string $name * @param string $name
* @param string $label The label for the form-element * @param string $label The label for the form-element
* @param boolean $required (optional) Is the form-element required (default=true) * @param bool $required (optional) Is the form-element required (default=true)
* @param boolean $full_page (optional) When it is true, the editor loads completed html code for a full page. * @param bool $full_page (optional) When it is true, the editor loads completed html code for a full page.
* @param array $config (optional) Configuration settings for the online editor. * @param array $config (optional) Configuration settings for the online editor.
* *
*/ */
public function addHtmlEditor($name, $label, $required = true, $fullPage = false, $config = null) public function addHtmlEditor($name, $label, $required = true, $fullPage = false, $config = null)
@ -447,17 +498,6 @@ EOT;
$this->addRule(array($name_1, $name_2), get_lang('StartDateShouldBeBeforeEndDate'), 'date_compare', 'lte'); $this->addRule(array($name_1, $name_2), get_lang('StartDateShouldBeBeforeEndDate'), 'date_compare', 'lte');
} }
/**
* Adds a button to the form to add resources.
* @deprecated
*/
function add_resource_button()
{
$group = array();
$group[] = $this->createElement('static', 'add_resource_img', null, '<img src="' . api_get_path(WEB_IMG_PATH) . 'attachment.gif" alt="' . get_lang('Attachment') . '"/>');
$group[] = $this->createElement('submit', 'add_resource', get_lang('Attachment'), 'class="link_alike"');
$this->addGroup($group);
}
/** /**
* Adds a progress bar to the form. * Adds a progress bar to the form.

@ -62,13 +62,23 @@ class HTML_QuickForm_checkbox extends HTML_QuickForm_input
* @access public * @access public
* @return void * @return void
*/ */
function HTML_QuickForm_checkbox($elementName=null, $elementLabel=null, $text='', $attributes=null) public function HTML_QuickForm_checkbox(
{ $elementName = null,
$elementLabel = null,
$text = '',
$attributes = null
) {
HTML_QuickForm_input::HTML_QuickForm_input($elementName, $elementLabel, $attributes); HTML_QuickForm_input::HTML_QuickForm_input($elementName, $elementLabel, $attributes);
$this->_persistantFreeze = true; $this->_persistantFreeze = true;
$this->_text = $text; $this->_text = $text;
$this->setType('checkbox'); $this->setType('checkbox');
$this->updateAttributes(array('value'=>1));
if (!isset($attributes['value'])) {
$this->updateAttributes(array('value' => 1));
} else {
$this->updateAttributes(array('value' => $attributes['value']));
}
$this->_generateId(); $this->_generateId();
} //end constructor } //end constructor
@ -117,17 +127,20 @@ class HTML_QuickForm_checkbox extends HTML_QuickForm_input
* @access public * @access public
* @return string * @return string
*/ */
function toHtml() public function toHtml()
{ {
if (0 == strlen($this->_text)) { if (0 == strlen($this->_text)) {
$label = ''; $label = '';
} elseif ($this->_flagFrozen) { } elseif ($this->_flagFrozen) {
$label = $this->_text; $label = $this->_text;
} else { } else {
//$label = '<label for="' . $this->getAttribute('id') . '">' . $this->_text . '</label>'; $label = '<label class="checkbox '.$this->getAttribute('label-class').' ">' .
$label = '<label class="checkbox">' . HTML_QuickForm_input::toHtml().$this->_text . '</label>'; HTML_QuickForm_input::toHtml().$this->_text
. '</label>';
return $label; return $label;
} }
return HTML_QuickForm_input::toHtml() . $label; return HTML_QuickForm_input::toHtml() . $label;
} //end func toHtml } //end func toHtml
@ -144,10 +157,10 @@ class HTML_QuickForm_checkbox extends HTML_QuickForm_input
function getFrozenHtml() function getFrozenHtml()
{ {
if ($this->getChecked()) { if ($this->getChecked()) {
return '<tt>[x]</tt>' . return '<code>[x]</code>' .
$this->_getPersistantData(); $this->_getPersistantData();
} else { } else {
return '<tt>[ ]</tt>'; return '<code>[ ]</code>';
} }
} //end func getFrozenHtml } //end func getFrozenHtml
@ -269,7 +282,4 @@ class HTML_QuickForm_checkbox extends HTML_QuickForm_input
} }
return $this->_prepareValue($value, $assoc); return $this->_prepareValue($value, $assoc);
} }
}
// }}}
} //end class HTML_QuickForm_checkbox
?>

@ -21,45 +21,46 @@ class HTML_QuickForm_label extends HTML_QuickForm_static
{ {
// {{{ constructor // {{{ constructor
/** /**
* Class constructor * Class constructor
* *
* @param string $text raw HTML to add * @param string $text raw HTML to add
* @access public * @access public
* @return void * @return void
*/ */
function HTML_QuickForm_label($label = null, $text = null, $attributes = null) { function HTML_QuickForm_label(
$label = null,
$text = null,
$attributes = null
) {
$this->HTML_QuickForm_static(null, $label, $text, $attributes); $this->HTML_QuickForm_static(null, $label, $text, $attributes);
$this->_type = 'html'; $this->_type = 'html';
} }
// }}} /**
// {{{ accept() * Accepts a renderer
*
/** * @param HTML_QuickForm_Renderer renderer object (only works with Default renderer!)
* Accepts a renderer * @access public
* * @return void
* @param HTML_QuickForm_Renderer renderer object (only works with Default renderer!) */
* @access public public function accept(&$renderer, $required = false, $error = null)
* @return void {
*/
function accept(&$renderer, $required=false, $error=null) {
$renderer->renderHtml($this); $renderer->renderHtml($this);
} }
function toHtml() { /**
$for = $this->getLabelFor(); * @return string
return '<div class="control-group "> */
<label class="control-label"'.(empty($for)?'':' for="'.$for.'"').'>'.$this->getLabel().'</label> public function toHtml()
{
$for = $this->getLabelFor();
return '<div class="control-group ">
<label class="control-label"' . (empty($for) ? '' : ' for="' . $for . '"') . '>' . $this->getLabel() . '</label>
<div class="controls"> <div class="controls">
'.HTML_QuickForm_static::toHtml().' ' . HTML_QuickForm_static::toHtml() . '
</div> </div>
</div> </div>
';
'; }
} //end func toHtml }
// }}}
} //end class HTML_QuickForm_html

@ -34,7 +34,6 @@
*/ */
class HTML_QuickForm_radio extends HTML_QuickForm_input class HTML_QuickForm_radio extends HTML_QuickForm_input
{ {
// {{{ properties
/** /**
* Radio display text * Radio display text
@ -44,9 +43,6 @@ class HTML_QuickForm_radio extends HTML_QuickForm_input
*/ */
var $_text = ''; var $_text = '';
// }}}
// {{{ constructor
/** /**
* Class constructor * Class constructor
* *
@ -59,8 +55,13 @@ class HTML_QuickForm_radio extends HTML_QuickForm_input
* @access public * @access public
* @return void * @return void
*/ */
function HTML_QuickForm_radio($elementName=null, $elementLabel=null, $text=null, $value=null, $attributes=null) public function HTML_QuickForm_radio(
{ $elementName = null,
$elementLabel = null,
$text = null,
$value = null,
$attributes = null
) {
$this->HTML_QuickForm_element($elementName, $elementLabel, $attributes); $this->HTML_QuickForm_element($elementName, $elementLabel, $attributes);
if (isset($value)) { if (isset($value)) {
$this->setValue($value); $this->setValue($value);
@ -69,10 +70,7 @@ class HTML_QuickForm_radio extends HTML_QuickForm_input
$this->setType('radio'); $this->setType('radio');
$this->_text = $text; $this->_text = $text;
$this->_generateId(); $this->_generateId();
} //end constructor }
// }}}
// {{{ setChecked()
/** /**
* Sets whether radio button is checked * Sets whether radio button is checked
@ -89,10 +87,7 @@ class HTML_QuickForm_radio extends HTML_QuickForm_input
} else { } else {
$this->updateAttributes(array('checked'=>'checked')); $this->updateAttributes(array('checked'=>'checked'));
} }
} //end func setChecked }
// }}}
// {{{ getChecked()
/** /**
* Returns whether radio button is checked * Returns whether radio button is checked
@ -104,10 +99,7 @@ class HTML_QuickForm_radio extends HTML_QuickForm_input
function getChecked() function getChecked()
{ {
return $this->getAttribute('checked'); return $this->getAttribute('checked');
} //end func getChecked }
// }}}
// {{{ toHtml()
/** /**
* Returns the radio element in HTML * Returns the radio element in HTML
@ -116,22 +108,22 @@ class HTML_QuickForm_radio extends HTML_QuickForm_input
* @access public * @access public
* @return string * @return string
*/ */
function toHtml() public function toHtml()
{ {
if (0 == strlen($this->_text)) { if (0 == strlen($this->_text)) {
$label = ''; $label = '';
} elseif ($this->_flagFrozen) { } elseif ($this->_flagFrozen) {
$label = $this->_text; $label = $this->_text;
} else { } else {
///$label = '<label for="' . $this->getAttribute('id') . '">' . $this->_text . '</label>'; $label = '<label class="radio '.$this->getAttribute('label-class').'">' .
$label = '<label class="radio">' .HTML_QuickForm_input::toHtml().$this->_text . '</label>'; HTML_QuickForm_input::toHtml().$this->_text .
'</label>';
return $label; return $label;
} }
return HTML_QuickForm_input::toHtml() . $label;
} //end func toHtml
// }}} return HTML_QuickForm_input::toHtml() . $label;
// {{{ getFrozenHtml() }
/** /**
* Returns the value of field without HTML tags * Returns the value of field without HTML tags
@ -140,18 +132,15 @@ class HTML_QuickForm_radio extends HTML_QuickForm_input
* @access public * @access public
* @return string * @return string
*/ */
function getFrozenHtml() public function getFrozenHtml()
{ {
if ($this->getChecked()) { if ($this->getChecked()) {
return '<tt>(x)</tt>' . return '<code>(x)</code>' .
$this->_getPersistantData(); $this->_getPersistantData();
} else { } else {
return '<tt>( )</tt>'; return '<code>( )</code>';
} }
} //end func getFrozenHtml }
// }}}
// {{{ setText()
/** /**
* Sets the radio text * Sets the radio text
@ -161,13 +150,10 @@ class HTML_QuickForm_radio extends HTML_QuickForm_input
* @access public * @access public
* @return void * @return void
*/ */
function setText($text) public function setText($text)
{ {
$this->_text = $text; $this->_text = $text;
} //end func setText }
// }}}
// {{{ getText()
/** /**
* Returns the radio text * Returns the radio text
@ -176,13 +162,10 @@ class HTML_QuickForm_radio extends HTML_QuickForm_input
* @access public * @access public
* @return string * @return string
*/ */
function getText() public function getText()
{ {
return $this->_text; return $this->_text;
} //end func getText }
// }}}
// {{{ onQuickFormEvent()
/** /**
* Called by HTML_QuickForm whenever form event is made on this element * Called by HTML_QuickForm whenever form event is made on this element
@ -194,7 +177,7 @@ class HTML_QuickForm_radio extends HTML_QuickForm_input
* @access public * @access public
* @return void * @return void
*/ */
function onQuickFormEvent($event, $arg, &$caller) public function onQuickFormEvent($event, $arg, &$caller)
{ {
switch ($event) { switch ($event) {
case 'updateValue': case 'updateValue':
@ -223,16 +206,14 @@ class HTML_QuickForm_radio extends HTML_QuickForm_input
default: default:
parent::onQuickFormEvent($event, $arg, $caller); parent::onQuickFormEvent($event, $arg, $caller);
} }
return true;
} // end func onQuickFormLoad
// }}} return true;
// {{{ exportValue() }
/** /**
* Returns the value attribute if the radio is checked, null if it is not * Returns the value attribute if the radio is checked, null if it is not
*/ */
function exportValue(&$submitValues, $assoc = false) public function exportValue(&$submitValues, $assoc = false)
{ {
$value = $this->_findValue($submitValues); $value = $this->_findValue($submitValues);
if (null === $value) { if (null === $value) {
@ -240,9 +221,7 @@ class HTML_QuickForm_radio extends HTML_QuickForm_input
} elseif ($value != $this->getValue()) { } elseif ($value != $this->getValue()) {
$value = null; $value = null;
} }
return $this->_prepareValue($value, $assoc); return $this->_prepareValue($value, $assoc);
} }
}
// }}}
} //end class HTML_QuickForm_radio
?>

@ -78,7 +78,7 @@ class LinkForm extends \FormValidator
if ($id) { if ($id) {
$url = Chamilo::url('/main/metadata/index.php', array('eid' => "Link.$id")); $url = Chamilo::url('/main/metadata/index.php', array('eid' => "Link.$id"));
$metadata = '<a class="control-text" href="' . $url . '">' . get_lang('AddMetadata') . '</a>'; $metadata = '<a class="control-text" href="' . $url . '">' . get_lang('AddMetadata') . '</a>';
$this->add_label(get_lang('Metadata'), $metadata); $this->addLabel(get_lang('Metadata'), $metadata);
} }
$options = array(); $options = array();
@ -97,7 +97,7 @@ class LinkForm extends \FormValidator
); );
$this->addSelect('target', get_lang('LinkTarget'), $targets); $this->addSelect('target', get_lang('LinkTarget'), $targets);
//$help = '<span class="help-block">' . get_lang('AddTargetOfLinkOnHomepage') . '</span>'; //$help = '<span class="help-block">' . get_lang('AddTargetOfLinkOnHomepage') . '</span>';
//$this->add_label('', $help); //$this->addLabel('', $help);
$this->addButton('save', get_lang('Save')); $this->addButton('save', get_lang('Save'));

@ -109,13 +109,13 @@ if (api_get_setting('allow_message_tool') == 'true') {
$form->add_file('attach_1', get_lang('AttachmentFiles')); $form->add_file('attach_1', get_lang('AttachmentFiles'));
$form->addHtml('</div></span>'); $form->addHtml('</div></span>');
$form->add_label(null, $form->addLabel(null,
' <div id="link-more-attach"> ' <div id="link-more-attach">
<a href="javascript://" onclick="return add_image_form()"> <a href="javascript://" onclick="return add_image_form()">
' . get_lang('AddOneMoreFile') . '</a> ' . get_lang('AddOneMoreFile') . '</a>
</div>' </div>'
); );
$form->add_label(null, $form->addLabel(null,
api_xml_http_response_encode( api_xml_http_response_encode(
sprintf( sprintf(
get_lang('MaximunFileSizeX'), get_lang('MaximunFileSizeX'),

Loading…
Cancel
Save