]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-14591 New "warning" form element
authornicolasconnault <nicolasconnault>
Tue, 2 Sep 2008 12:14:58 +0000 (12:14 +0000)
committernicolasconnault <nicolasconnault>
Tue, 2 Sep 2008 12:14:58 +0000 (12:14 +0000)
lib/form/warning.php [new file with mode: 0644]
lib/formslib.php
theme/standard/styles_color.css

diff --git a/lib/form/warning.php b/lib/form/warning.php
new file mode 100644 (file)
index 0000000..125ad64
--- /dev/null
@@ -0,0 +1,64 @@
+<?php
+require_once("HTML/QuickForm/static.php");
+
+/**
+ * HTML class for a text type element
+ *
+ * @author       Jamie Pratt
+ * @access       public
+ */
+class MoodleQuickForm_warning extends HTML_QuickForm_static{
+    var $_elementTemplateType='warning';
+    /**
+     * html for help button, if empty then no help
+     *
+     * @var string
+     */
+    var $_helpbutton='';
+
+    function MoodleQuickForm_warning($elementName=null, $elementLabel=null, $text=null) {
+        parent::HTML_QuickForm_static($elementName, $elementLabel, $text);
+        $this->_type = 'warning';
+    }
+
+    /**
+     * set html for help button
+     *
+     * @access   public
+     * @param array $help array of arguments to make a help button
+     * @param string $function function name to call to get html
+     */
+    function setHelpButton($helpbuttonargs, $function='helpbutton'){
+        if (!is_array($helpbuttonargs)){
+            $helpbuttonargs=array($helpbuttonargs);
+        }else{
+            $helpbuttonargs=$helpbuttonargs;
+        }
+        //we do this to to return html instead of printing it
+        //without having to specify it in every call to make a button.
+        if ('helpbutton' == $function){
+            $defaultargs=array('', '', 'moodle', true, false, '', true);
+            $helpbuttonargs=$helpbuttonargs + $defaultargs ;
+        }
+        $this->_helpbutton=call_user_func_array($function, $helpbuttonargs);
+    }
+
+    function toHtml() {
+        return notify($this->_text, 'formwarning', 'center', true);
+    }
+
+    /**
+     * get html for help button
+     *
+     * @access   public
+     * @return  string html for help button
+     */
+    function getHelpButton(){
+        return $this->_helpbutton;
+    }
+
+    function getElementTemplateType(){
+        return $this->_elementTemplateType;
+    }
+}
+?>
index e5212ce61bd946ce8494420c954bfaf099448a89..d186bf89737a4c542d25327239f44139234beb52 100644 (file)
@@ -548,7 +548,7 @@ class moodleform {
      * @param int $newuserid - new userid if required
      * @return mixed stored_file object or false if error; may throw exception if duplicate found
      */
-    function save_stored_file($elname, $newcontextid, $newfilearea, $newitemid, $newfilepath, 
+    function save_stored_file($elname, $newcontextid, $newfilearea, $newitemid, $newfilepath,
                               $newfilename=null, $override=false, $newuserid=null) {
 
         global $USER;
@@ -585,7 +585,7 @@ class moodleform {
             return $fs->create_file_from_pathname($file_record, $_FILES[$elname]['tmp_name']);
 
         } else if (isset($this->exportValues[$elname])) {    // Submitted data contains itemid in user's draft_area
-            
+
             $itemid = $this->exportValues[$elname];
 
             if (!$context = get_context_instance(CONTEXT_USER, $USER->id)) {
@@ -597,7 +597,7 @@ class moodleform {
             }
 
             $file = array_pop($files);   // Get the one and only item out of the array
-            
+
             $params = $file->get_params();
 
             $fs = get_file_storage();
@@ -1801,6 +1801,8 @@ class MoodleQuickForm_Renderer extends HTML_QuickForm_Renderer_Tableless{
 
         'static'=>"\n\t\t".'<div class="fitem {advanced}"><div class="fitemtitle"><div class="fstaticlabel"><label>{label}<!-- BEGIN required -->{req}<!-- END required -->{advancedimg} {help}</label></div></div><div class="felement fstatic <!-- BEGIN error --> error<!-- END error -->"><!-- BEGIN error --><span class="error">{error}</span><br /><!-- END error -->{element}&nbsp;</div></div>',
 
+'warning'=>"\n\t\t".'<div class="fitem {advanced}">{element}</div>',
+
         'nodisplay'=>'');
 
         parent::HTML_QuickForm_Renderer_Tableless();
@@ -1887,7 +1889,7 @@ class MoodleQuickForm_Renderer extends HTML_QuickForm_Renderer_Tableless{
         //check if this is a group element first
         if (($this->_inGroup) and !empty($this->_groupElementTemplate)) {
                // so it gets substitutions for *each* element
-            $html = $this->_groupTemplates[$element->getName()];       
+            $html = $this->_groupTemplates[$element->getName()];
         }
         elseif (method_exists($element, 'getElementTemplateType')){
             $html = $this->_elementTemplates[$element->getElementTemplateType()];
@@ -2045,4 +2047,5 @@ MoodleQuickForm::registerElementType('submit', "$CFG->libdir/form/submit.php", '
 MoodleQuickForm::registerElementType('questioncategory', "$CFG->libdir/form/questioncategory.php", 'MoodleQuickForm_questioncategory');
 MoodleQuickForm::registerElementType('advcheckbox', "$CFG->libdir/form/advcheckbox.php", 'MoodleQuickForm_advcheckbox');
 MoodleQuickForm::registerElementType('recaptcha', "$CFG->libdir/form/recaptcha.php", 'MoodleQuickForm_recaptcha');
+MoodleQuickForm::registerElementType('warning', "$CFG->libdir/form/warning.php", 'MoodleQuickForm_warning');
 ?>
index 2ede663ad18a1ed0e26407478e19881bbd3c2617..a88b1382a96f25908aa8e0d9d53e93ca614d3da6 100644 (file)
@@ -648,7 +648,7 @@ table.minicalendar {
 
 /* .content should match the body background, sides are white. */
 #course-view .weeks .content ,
-#course-view .topics .content, 
+#course-view .topics .content,
 #course-view .weeks .section,
 #course-view .topics .section {
   background: #FAFAFA;
@@ -745,11 +745,11 @@ td.grade div.overridden {
 }
 
 .grade-report-grader table#user-grades td.cell span.gradepass {
-  background-color: #C2EBBD; 
+  background-color: #C2EBBD;
 }
 
 .grade-report-grader table#user-grades td.cell span.gradefail {
-  background-color: #EBC4BD; 
+  background-color: #EBC4BD;
 }
 
 /* grade edit */
@@ -1156,4 +1156,13 @@ form.mform .fdescription.required {
 }
 form.mform .required .fgroup span label {
   color:#000;
-}
\ No newline at end of file
+}
+
+form.mform .formwarning {
+    background-color: red;
+    color: yellow;
+    margin-top: 15px;
+    padding: 10px 0px 10px 0px;
+    font-size: 110%;
+    font-weight: bold;
+}