From 64360ee7b551897ae000b8e31a45ec21abbc53d8 Mon Sep 17 00:00:00 2001 From: jamiesensei Date: Sun, 27 May 2007 05:01:51 +0000 Subject: [PATCH] made hardFreeze work properly for a whole form. New paramater in moodleform constructor 'editable' defaults to true. If true then display form as normal. If false then hardFreeze whole form. Now displays form without an submit buttons. If form is hard frozen no data is ever passed to get_data. --- lib/form/advcheckbox.php | 15 +++++++++- lib/form/button.php | 12 ++++++++ lib/form/cancel.php | 9 +++++- lib/form/file.php | 12 ++++++++ lib/form/group.php | 13 ++++++-- lib/form/htmleditor.php | 5 +--- lib/form/radio.php | 12 ++++++++ lib/form/selectgroups.php | 10 ++++--- lib/form/submit.php | 18 +++++++++++ lib/form/textarea.php | 12 ++++++++ lib/formslib.php | 39 +++++++++++++++++++----- theme/standard/styles_layout.css | 51 ++++++++++++++++++-------------- 12 files changed, 167 insertions(+), 41 deletions(-) diff --git a/lib/form/advcheckbox.php b/lib/form/advcheckbox.php index 3c2cb92c4c..43cd2d3a68 100644 --- a/lib/form/advcheckbox.php +++ b/lib/form/advcheckbox.php @@ -88,6 +88,19 @@ class MoodleQuickForm_advcheckbox extends HTML_QuickForm_advcheckbox{ $this->updateAttributes(array('id' => 'id_'.substr(md5(microtime() . $idx++), 0, 6))); } } // end func _generateId - + /** + * Slightly different container template when frozen. Don't want to use a label tag + * with a for attribute in that case for the element label but instead use a div. + * Templates are defined in renderer constructor. + * + * @return string + */ + function getElementTemplateType(){ + if ($this->_flagFrozen){ + return 'static'; + } else { + return 'default'; + } + } } ?> \ No newline at end of file diff --git a/lib/form/button.php b/lib/form/button.php index a58f8d079a..2e5649f3f8 100644 --- a/lib/form/button.php +++ b/lib/form/button.php @@ -68,5 +68,17 @@ class MoodleQuickForm_button extends HTML_QuickForm_button function getHelpButton(){ return $this->_helpbutton; } + /** + * Slightly different container template when frozen. + * + * @return string + */ + function getElementTemplateType(){ + if ($this->_flagFrozen){ + return 'nodisplay'; + } else { + return 'default'; + } + } } //end class MoodleQuickForm_button ?> diff --git a/lib/form/cancel.php b/lib/form/cancel.php index ed263ec4f8..1ef1128b05 100644 --- a/lib/form/cancel.php +++ b/lib/form/cancel.php @@ -41,7 +41,14 @@ class MoodleQuickForm_cancel extends MoodleQuickForm_submit } return parent::onQuickFormEvent($event, $arg, $caller); } // end func onQuickFormEvent - + + function getFrozenHtml(){ + return HTML_QuickForm_submit::getFrozenHtml(); + } + + function freeze(){ + return HTML_QuickForm_submit::freeze(); + } // }}} } //end class MoodleQuickForm_cancel ?> \ No newline at end of file diff --git a/lib/form/file.php b/lib/form/file.php index 8c18830c6c..b25842b702 100644 --- a/lib/form/file.php +++ b/lib/form/file.php @@ -58,6 +58,18 @@ class MoodleQuickForm_file extends HTML_QuickForm_file{ } return parent::onQuickFormEvent($event, $arg, $caller); } // end func onQuickFormEvent + /** + * Slightly different container template when frozen. + * + * @return string + */ + function getElementTemplateType(){ + if ($this->_flagFrozen){ + return 'static'; + } else { + return 'default'; + } + } } ?> \ No newline at end of file diff --git a/lib/form/group.php b/lib/form/group.php index af8be99528..b4f3f16d9e 100644 --- a/lib/form/group.php +++ b/lib/form/group.php @@ -17,7 +17,6 @@ class MoodleQuickForm_group extends HTML_QuickForm_group{ * @var string */ var $_helpbutton=''; - var $_elementTemplateType='fieldset'; //would cause problems with client side validation so will leave for now //var $_elementTemplateType='fieldset'; /** @@ -52,8 +51,18 @@ class MoodleQuickForm_group extends HTML_QuickForm_group{ return $this->_helpbutton; } function getElementTemplateType(){ - return $this->_elementTemplateType; + if ($this->_flagFrozen){ + if ($this->getGroupType() == 'submit'){ + return 'nodisplay'; + } else { + return 'static'; + } + } else { + return 'fieldset'; + } } + + function setElements($elements){ parent::setElements($elements); foreach ($this->_elements as $element){ diff --git a/lib/form/htmleditor.php b/lib/form/htmleditor.php index 8d50419bb0..fc145f73f2 100644 --- a/lib/form/htmleditor.php +++ b/lib/form/htmleditor.php @@ -10,7 +10,6 @@ require_once("$CFG->libdir/form/textarea.php"); */ class MoodleQuickForm_htmleditor extends MoodleQuickForm_textarea{ var $_type; - var $_elementTemplateType='default'; var $_canUseHtmlEditor; var $_options=array('canUseHtmlEditor'=>'detect','rows'=>10, 'cols'=>45, 'width'=>0,'height'=>0, 'course'=>0); function MoodleQuickForm_htmleditor($elementName=null, $elementLabel=null, $options=array(), $attributes=null){ @@ -59,9 +58,7 @@ class MoodleQuickForm_htmleditor extends MoodleQuickForm_textarea{ } return parent::setHelpButton($helpbuttonargs, $function); } - function getElementTemplateType(){ - return $this->_elementTemplateType; - } + function toHtml(){ if ($this->_canUseHtmlEditor && !$this->_flagFrozen){ ob_start(); diff --git a/lib/form/radio.php b/lib/form/radio.php index 9d305ee6a7..7b2ce8ebf6 100644 --- a/lib/form/radio.php +++ b/lib/form/radio.php @@ -62,5 +62,17 @@ class MoodleQuickForm_radio extends HTML_QuickForm_radio{ $this->updateAttributes(array('id' => 'id_'.substr(md5(microtime() . $idx++), 0, 6))); } } // end func _generateId + /** + * Slightly different container template when frozen. + * + * @return string + */ + function getElementTemplateType(){ + if ($this->_flagFrozen){ + return 'static'; + } else { + return 'default'; + } + } } ?> \ No newline at end of file diff --git a/lib/form/selectgroups.php b/lib/form/selectgroups.php index 3516df091d..c226f5da6e 100644 --- a/lib/form/selectgroups.php +++ b/lib/form/selectgroups.php @@ -437,10 +437,12 @@ class MoodleQuickForm_selectgroups extends HTML_QuickForm_element { $value = array(); if (is_array($this->_values)) { foreach ($this->_values as $key => $val) { - for ($i = 0, $optCount = count($this->_options); $i < $optCount; $i++) { - if ((string)$val == (string)$this->_options[$i]['attr']['value']) { - $value[$key] = $this->_options[$i]['text']; - break; + foreach ($this->_optGroups as $optGroup) { + for ($i = 0, $optCount = count($optGroup['options']); $i < $optCount; $i++) { + if ((string)$val == (string)$optGroup['options'][$i]['attr']['value']) { + $value[$key] = $optGroup['options'][$i]['text']; + break; + } } } } diff --git a/lib/form/submit.php b/lib/form/submit.php index 09a5bccac9..406b2941a3 100644 --- a/lib/form/submit.php +++ b/lib/form/submit.php @@ -41,5 +41,23 @@ class MoodleQuickForm_submit extends HTML_QuickForm_submit { return parent::onQuickFormEvent($event, $arg, $caller); } // end func onQuickFormEvent + /** + * Slightly different container template when frozen. Don't want to display a submit + * button if the form is frozen. + * + * @return string + */ + function getElementTemplateType(){ + if ($this->_flagFrozen){ + return 'nodisplay'; + } else { + return 'default'; + } + } + + function freeze(){ + $this->_flagFrozen = true; + } + } ?> \ No newline at end of file diff --git a/lib/form/textarea.php b/lib/form/textarea.php index 348d3c039d..06d3ed1a4b 100644 --- a/lib/form/textarea.php +++ b/lib/form/textarea.php @@ -75,5 +75,17 @@ class MoodleQuickForm_textarea extends HTML_QuickForm_textarea{ } return parent::onQuickFormEvent($event, $arg, $caller); } // end func onQuickFormEvent + /** + * Slightly different container template when frozen. + * + * @return string + */ + function getElementTemplateType(){ + if ($this->_flagFrozen){ + return 'static'; + } else { + return 'default'; + } + } } ?> \ No newline at end of file diff --git a/lib/formslib.php b/lib/formslib.php index 2232df8597..627a2e9d30 100644 --- a/lib/formslib.php +++ b/lib/formslib.php @@ -101,7 +101,7 @@ class moodleform { * @param mixed $attributes you can pass a string of html attributes here or an array. * @return moodleform */ - function moodleform($action=null, $customdata=null, $method='post', $target='', $attributes=null) { + function moodleform($action=null, $customdata=null, $method='post', $target='', $attributes=null, $editable=true) { if (empty($action)){ $action = strip_querystring(qualified_me()); } @@ -109,6 +109,9 @@ class moodleform { $this->_formname = get_class($this); // '_form' suffix kept in order to prevent collisions of form id and other element $this->_customdata = $customdata; $this->_form =& new MoodleQuickForm($this->_formname, $method, $action, $target, $attributes); + if (!$editable){ + $this->_form->hardFreeze(); + } $this->set_upload_manager(new upload_manager()); $this->definition(); @@ -1335,8 +1338,19 @@ function validate_' . $this->_formName . '(frm) { } return true; } // end func hardFreeze - - // }}} + /** + * Tells whether the form was already submitted + * + * This is useful since the _submitFiles and _submitValues arrays + * may be completely empty after the trackSubmit value is removed. + * + * @access public + * @return bool + */ + function isSubmitted() + { + return parent::isSubmitted() && (!$this->isFrozen()); + } } @@ -1411,7 +1425,9 @@ class MoodleQuickForm_Renderer extends HTML_QuickForm_Renderer_Tableless{ 'fieldset'=>"\n\t\t".'
{label}{req} {advancedimg}
{help}
{error}
{element}
', - 'static'=>"\n\t\t".'
{label}{req} {advancedimg}
{help}
{error}
{element}
'); + 'static'=>"\n\t\t".'
{label}{req} {advancedimg}
{help}
{error}
{element} 
', + + 'nodisplay'=>''); parent::HTML_QuickForm_Renderer_Tableless(); } @@ -1431,7 +1447,13 @@ class MoodleQuickForm_Renderer extends HTML_QuickForm_Renderer_Tableless{ $this->_advancedHTML = $form->getAdvancedHTML(); $this->_showAdvanced = $form->getShowAdvanced(); parent::startForm($form); - $this->_hiddenHtml .= $form->_pageparams; + if ($form->isFrozen()){ + $this->_formTemplate = "\n
\n{content}\n
"; + } else { + $this->_hiddenHtml .= $form->_pageparams; + } + + } function startGroup(&$group, $required, $error){ @@ -1523,9 +1545,12 @@ class MoodleQuickForm_Renderer extends HTML_QuickForm_Renderer_Tableless{ } function finishForm(&$form){ + if ($form->isFrozen()){ + $this->_hiddenHtml = ''; + } parent::finishForm($form); - // add a lockoptions script - if ('' != ($script = $form->getLockOptionEndScript())) { + if ((!$form->isFrozen()) && ('' != ($script = $form->getLockOptionEndScript()))) { + // add a lockoptions script $this->_html = $this->_html . "\n" . $script; } } diff --git a/theme/standard/styles_layout.css b/theme/standard/styles_layout.css index 772f49ebbd..e571115aca 100644 --- a/theme/standard/styles_layout.css +++ b/theme/standard/styles_layout.css @@ -464,38 +464,38 @@ div.hide { *** Forms ***/ -form.mform { +.mform { margin: 0 auto; padding: 0; width: 80%; } -form.mform fieldset { +.mform fieldset { border: 1px solid #DDDDDD; padding: 10px 0; margin: 0.7em 0; width:100%; } -form.mform fieldset.hidden, form.mform fieldset.felement { +.mform fieldset.hidden, .mform fieldset.felement { border: 0; } -form.mform fieldset.felement { +.mform fieldset.felement { width: auto; } -form.mform fieldset legend { +.mform fieldset legend { font-weight: bold; margin-left: 0.5em; } -form.mform fieldset .advancedbutton{ +.mform fieldset .advancedbutton{ width:100%; text-align:right; } -form.mform div.fitem { +.mform div.fitem { clear: both; width: 100%; min-height: 1.5em; } -form.mform .fitemtitle { +.mform .fitemtitle { display: block; float: left; width: 30%; @@ -504,7 +504,7 @@ form.mform .fitemtitle { text-align: right; } -form.mform .fitemtitle div{ +.mform .fitemtitle div{ display: inline; } @@ -515,7 +515,7 @@ fieldset.fdate_selector label { width: auto; } -form.mform div.felement, form.mform fieldset.felement{ +.mform div.felement, .mform fieldset.felement{ display: block; float: left; margin: 5px 0 0 10px; @@ -524,45 +524,45 @@ form.mform div.felement, form.mform fieldset.felement{ width: 60%; } -form.mform div.fdescription { +.mform div.fdescription { clear: both; min-height: 1.5em; } -form.mform .fdescription.required { +.mform .fdescription.required { text-align:right; } -form.mform input, form.mform select { +.mform input, .mform select { width: auto; } -form.mform ftextarea { +.mform ftextarea { } -form.mform br { +.mform br { clear: left; } -form.mform div.fhtmleditor { +.mform div.fhtmleditor { margin: 0 auto 10px auto; width : 600px; clear:both; float:none; padding: 25px 0 20px 0; } -form.mform span.error, form.mform span.required { +.mform span.error, .mform span.required { color: red; } -form.mform div.error,form.mform fieldset.error { +.mform div.error,.mform fieldset.error { border: 1px solid red; padding: 5px; color: inherit; } -form.mform .fcheckbox input { +.mform .fcheckbox input { margin-left: 0px; } -form.mform .fpassword .unmask { +.mform .fpassword .unmask { display:inline; } -form.mform .fpassword .unmask input { +.mform .fpassword .unmask input { margin-left:5px; margin-right:3px; } @@ -576,7 +576,14 @@ form#adminsettings div.htmlarea { cursor: help; } -#admin-register form.mform .fsubmit { +/* form frozen */ +div.mform div.fitem div.fstatic{ + border-color : lightgrey; + border-style : dashed; + border-width : thin; +} + +#admin-register .mform .fsubmit { padding:20px; text-align:center; } -- 2.39.5