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
$renderer = & $this->defaultRenderer();
//Form template
$formTemplate = '<form{attributes}>
<fieldset>
{content}
<div class="clear"></div>
</fieldset>
{hidden}
</form>';
// Form template
$formTemplate = $this->getFormTemplate();
$renderer->setFormTemplate($formTemplate);
//Element template
// Element template
if (isset($attributes['class']) && $attributes['class'] == 'well form-inline') {
$element_template = ' {label} {element} ';
$renderer->setElementTemplate($element_template);
@ -164,29 +158,7 @@ class FormValidator extends HTML_QuickForm
$element_template = ' {label} {element} ';
$renderer->setElementTemplate($element_template);
} else {
$element_template = '
<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);
$renderer->setElementTemplate($this->getElementTemplate());
//Display a gray div in the buttons
$button_element_template_simple = '<div class="form-actions">{label} {element}</div>';
@ -228,6 +200,49 @@ EOT;
$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.
* A trim-filter is attached to the field.
@ -254,8 +269,8 @@ EOT;
*
* @param string $name
* @param string $label
* @param bool $required
* @param array $attributes
* @param bool $required
* @param array $attributes
*/
public function addDateRangePicker($name, $label, $required = true, $attributes = array())
{
@ -281,49 +296,81 @@ EOT;
* @param string $name
* @param string $label
* @param array $attributes
*
* @return HTML_QuickForm_textarea
*/
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 $label
* @param string $icon font-awesome
* @param string $class
* For example plus is transformed to icon fa fa-plus
* @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['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 $label
* @param string $trailer
* @param array $options
* @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 $label
* @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();
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 $options
* @param array $attributes
*
* @return HTML_QuickForm_select
*/
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 $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 $label
* @param array $attributes
* @param array $attributes
*/
public function add_file($name, $label, $attributes = array())
{
@ -379,9 +430,9 @@ EOT;
* A rule is attached to check for unwanted HTML
* @param string $name
* @param string $label The label for the form-element
* @param boolean $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 array $config (optional) Configuration settings for the online editor.
* @param bool $required (optional) Is the form-element required (default=true)
* @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.
*
*/
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');
}
/**
* 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.

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

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

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

@ -78,7 +78,7 @@ class LinkForm extends \FormValidator
if ($id) {
$url = Chamilo::url('/main/metadata/index.php', array('eid' => "Link.$id"));
$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();
@ -97,7 +97,7 @@ class LinkForm extends \FormValidator
);
$this->addSelect('target', get_lang('LinkTarget'), $targets);
//$help = '<span class="help-block">' . get_lang('AddTargetOfLinkOnHomepage') . '</span>';
//$this->add_label('', $help);
//$this->addLabel('', $help);
$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->addHtml('</div></span>');
$form->add_label(null,
$form->addLabel(null,
' <div id="link-more-attach">
<a href="javascript://" onclick="return add_image_form()">
' . get_lang('AddOneMoreFile') . '</a>
</div>'
);
$form->add_label(null,
$form->addLabel(null,
api_xml_http_response_encode(
sprintf(
get_lang('MaximunFileSizeX'),

Loading…
Cancel
Save