Also added deprecated functions for the functions that were removed from MoodleQuickForm.
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
SHORTFORMS.ATTRS = ATTRS;
/**
- * The form ID attribute definition
+ * The form ID attribute definition.
*
* @attribute formid
* @type String
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'));
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));
}
});
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
SHOWADVANCED.ATTRS = ATTRS;
/**
- * The form ID attribute definition
+ * The form ID attribute definition.
*
* @attribute formid
* @type String
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) {
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);
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'));
M.form.showadvanced = M.form.showadvanced || function(params) {
return new SHOWADVANCED(params);
};
-}, '@VERSION@', {requires:['base', 'node', 'selector-css3']});
\ No newline at end of file
+}, '@VERSION@', {requires:['base', 'node', 'selector-css3']});
* 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.
*
function setCollapsibleElements($elements) {
$this->_collapsibleElements = $elements;
}
+
/**
* What to do when starting the form
*
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)));
}
}
parent::startGroup($group, $required, $error);
}
+
/**
* Renders element
*
$this->_fieldsetsOpen--;
}
- // Define collapsible classes for fieldsets
+ // Define collapsible classes for fieldsets.
$fieldsetclasses = array('clearfix');
if (isset($this->_collapsibleElements[$name])) {
$fieldsetclasses[] = 'collapsible';