MDL-30637 Formslib - Cleanup for shortforms implementation (mostly comments)

Also added deprecated functions for the functions that were removed from MoodleQuickForm.
This commit is contained in:
Damyon Wiese
2013-02-11 10:37:13 +08:00
parent 40f1c065b4
commit 8dcca4aacb
3 changed files with 52 additions and 27 deletions
+10 -10
View File
@@ -1,12 +1,12 @@
YUI.add('moodle-form-shortforms', function(Y) {
/**
* Provides the form shortforms class
* Provides the form shortforms class.
*
* @module moodle-form-shortforms
*/
/**
* A class for a shortforms
* A class for a shortforms.
*
* @param {Object} config Object literal specifying shortforms configuration properties.
* @class M.form.shortforms
@@ -47,7 +47,7 @@ YUI.add('moodle-form-shortforms', function(Y) {
SHORTFORMS.ATTRS = ATTRS;
/**
* The form ID attribute definition
* The form ID attribute definition.
*
* @attribute formid
* @type String
@@ -61,17 +61,17 @@ YUI.add('moodle-form-shortforms', function(Y) {
Y.extend(SHORTFORMS, Y.Base, {
initializer : function() {
var fieldlist = Y.Node.all('#'+this.get('formid')+' '+SELECTORS.FIELDSETCOLLAPSIBLE);
// Look through collapsible fieldset divs
// Look through collapsible fieldset divs.
fieldlist.each(this.process_fieldset, this);
// Subscribe collapsible fieldsets to click event
// Subscribe collapsible fieldsets to click event.
Y.one('#'+this.get('formid')).delegate('click', this.switch_state, SELECTORS.FIELDSETCOLLAPSIBLE+' .'+CSS.FHEADER);
},
process_fieldset : function(fieldset) {
fieldset.addClass(CSS.JSPROCESSED);
// Get legend element
// Get legend element.
var legendelement = fieldset.one(SELECTORS.LEGENDFTOGGLER);
// Turn headers to links for accessibility
// Turn headers to links for accessibility.
var headerlink = Y.Node.create('<a href="#"></a>');
headerlink.addClass(CSS.FHEADER);
headerlink.appendChild(legendelement.get('firstChild'));
@@ -80,11 +80,11 @@ YUI.add('moodle-form-shortforms', function(Y) {
switch_state : function(e) {
e.preventDefault();
var fieldset = this.ancestor(SELECTORS.FIELDSETCOLLAPSIBLE);
// toggle collapsed class
// Toggle collapsed class.
fieldset.toggleClass(CSS.COLLAPSED);
// get corresponding hidden variable
// Get corresponding hidden variable
// - and invert it.
var statuselement = new Y.one('input[name=mform_isexpanded_'+fieldset.get('id')+']');
// and invert it
statuselement.set('value', Math.abs(Number(statuselement.get('value'))-1));
}
});
+10 -10
View File
@@ -1,12 +1,12 @@
YUI.add('moodle-form-showadvanced', function(Y) {
/**
* Provides the form showadvanced class
* Provides the form showadvanced class.
*
* @module moodle-form-showadvanced
*/
/**
* A class for a showadvanced
* A class for a showadvanced.
*
* @param {Object} config Object literal specifying showadvanced configuration properties.
* @class M.form.showadvanced
@@ -47,7 +47,7 @@ YUI.add('moodle-form-showadvanced', function(Y) {
SHOWADVANCED.ATTRS = ATTRS;
/**
* The form ID attribute definition
* The form ID attribute definition.
*
* @attribute formid
* @type String
@@ -61,9 +61,9 @@ YUI.add('moodle-form-showadvanced', function(Y) {
Y.extend(SHOWADVANCED, Y.Base, {
initializer : function() {
var fieldlist = Y.Node.all('#'+this.get('formid')+' '+SELECTORS.FIELDSETCONTAINSADVANCED);
// Look through fieldset divs that contain advanced elements
// Look through fieldset divs that contain advanced elements.
fieldlist.each(this.process_fieldset, this);
// Subscribe more/less links to click event
// Subscribe more/less links to click event.
Y.one('#'+this.get('formid')).delegate('click', this.switch_state, SELECTORS.FIELDSETCONTAINSADVANCED+' .'+CSS.MORELESSTOGGLER);
},
process_fieldset : function(fieldset) {
@@ -72,7 +72,7 @@ YUI.add('moodle-form-showadvanced', function(Y) {
morelesslink.addClass(CSS.MORELESSTOGGLER);
if (statuselement.get('value') === '0') {
morelesslink.setHTML(M.str.form.showmore);
// hide advanced stuff initially
// Hide advanced stuff initially.
fieldset.all(SELECTORS.DIVFITEMADVANCED).addClass(CSS.HIDE);
} else {
morelesslink.setHTML(M.str.form.showless);
@@ -82,11 +82,11 @@ YUI.add('moodle-form-showadvanced', function(Y) {
switch_state : function(e) {
e.preventDefault();
var fieldset = this.ancestor(SELECTORS.FIELDSETCONTAINSADVANCED);
// toggle collapsed class
// Toggle collapsed class.
fieldset.all(SELECTORS.DIVFITEMADVANCED).toggleClass(CSS.HIDE);
// get corresponding hidden variable
// Get corresponding hidden variable.
var statuselement = new Y.one('input[name=mform_showmore_'+fieldset.get('id')+']');
// invert it and change the link text
// Invert it and change the link text.
if (statuselement.get('value') === '0') {
statuselement.set('value', 1);
this.setHTML(M.util.get_string('showless', 'form'));
@@ -101,4 +101,4 @@ YUI.add('moodle-form-showadvanced', function(Y) {
M.form.showadvanced = M.form.showadvanced || function(params) {
return new SHOWADVANCED(params);
};
}, '@VERSION@', {requires:['base', 'node', 'selector-css3']});
}, '@VERSION@', {requires:['base', 'node', 'selector-css3']});
+32 -7
View File
@@ -1387,25 +1387,48 @@ class MoodleQuickForm extends HTML_QuickForm_DHTMLRulesTableless {
* Use this method to add show more/less status element required for passing
* over the advanced elements visibility status on the form submission.
*
* @param string $headerName header element name
* @param string $headerName header element name.
* @param boolean $showmore default false sets the advanced elements to be hidden.
*/
function addAdvancedStatusElement($headerName, $showmore=false){
// Add extra hidden element to store advanced items state for each section
// Add extra hidden element to store advanced items state for each section.
if ($this->getElementType('mform_showmore_' . $headerName) === false) {
// see if we the form has been submitted already
// See if we the form has been submitted already.
$formshowmore = optional_param('mform_showmore_' . $headerName, -1, PARAM_INT);
if (!$showmore && $formshowmore != -1) {
// override showmore state with the form variable
// Override showmore state with the form variable.
$showmore = $formshowmore;
}
// create the form element for storing advanced items state
// Create the form element for storing advanced items state.
$this->addElement('hidden', 'mform_showmore_' . $headerName);
$this->setType('mform_showmore_' . $headerName, PARAM_INT);
$this->setConstant('mform_showmore_' . $headerName, (int)$showmore);
}
}
/**
* This function has been deprecated. Show advanced has been replaced by
* "Show more.../Show less..." in the shortforms javascript module.
*
* @deprecated since Moodle 2.5
* @param bool $showadvancedNow if true will show advanced elements.
*/
function setShowAdvanced($showadvancedNow = null){
debugging('Call to deprecated function setShowAdvanced. See "Show more.../Show less..." in shortforms yui module.');
}
/**
* This function has been deprecated. Show advanced has been replaced by
* "Show more.../Show less..." in the shortforms javascript module.
*
* @deprecated since Moodle 2.5
* @return bool (Always false)
*/
function getShowAdvanced(){
debugging('Call to deprecated function setShowAdvanced. See "Show more.../Show less..." in shortforms yui module.');
return false;
}
/**
* Use this method to indicate that the form will not be using shortforms.
*
@@ -2367,6 +2390,7 @@ class MoodleQuickForm_Renderer extends HTML_QuickForm_Renderer_Tableless{
function setCollapsibleElements($elements) {
$this->_collapsibleElements = $elements;
}
/**
* What to do when starting the form
*
@@ -2398,7 +2422,7 @@ class MoodleQuickForm_Renderer extends HTML_QuickForm_Renderer_Tableless{
if (count($this->_collapsibleElements)) {
$PAGE->requires->yui_module('moodle-form-shortforms', 'M.form.shortforms', array(array('formid' => $formid)));
}
if (count($this->_advancedElements)){
if (!empty($this->_advancedElements)){
$PAGE->requires->strings_for_js(array('showmore', 'showless'), 'form');
$PAGE->requires->yui_module('moodle-form-showadvanced', 'M.form.showadvanced', array(array('formid' => $formid)));
}
@@ -2450,6 +2474,7 @@ class MoodleQuickForm_Renderer extends HTML_QuickForm_Renderer_Tableless{
}
parent::startGroup($group, $required, $error);
}
/**
* Renders element
*
@@ -2547,7 +2572,7 @@ class MoodleQuickForm_Renderer extends HTML_QuickForm_Renderer_Tableless{
$this->_fieldsetsOpen--;
}
// Define collapsible classes for fieldsets
// Define collapsible classes for fieldsets.
$fieldsetclasses = array('clearfix');
if (isset($this->_collapsibleElements[$name])) {
$fieldsetclasses[] = 'collapsible';