]> git.mjollnir.org Git - moodle.git/commitdiff
add an update category submit button to update the display of shareable wild cards
authorpichetp <pichetp>
Thu, 19 Apr 2007 16:49:25 +0000 (16:49 +0000)
committerpichetp <pichetp>
Thu, 19 Apr 2007 16:49:25 +0000 (16:49 +0000)
question/type/calculated/edit_calculated_form.php
question/type/calculated/questiontype.php

index b062bff1213fe50890b81a3282b70b48c1729ec3..87c14e7565d96bdbc35b62b29caedf2407cb4383 100644 (file)
@@ -64,8 +64,14 @@ class question_edit_calculated_form extends question_edit_form {
         $this->repeat_elements($repeated, $repeatsatstart, $repeatedoptions, 'noanswers', 'addanswers', 1, get_string('addmoreanswerblanks', 'qtype_calculated'));*/
 //------------------------------------------------------------------------------------------
         $label = get_string("sharedwildcards", "qtype_datasetdependent");
+        $mform->addElement('hidden', 'initialcategory', 1);
         $html2 = $this->qtypeobj->print_dataset_definitions_category($this->question);
-        $mform->insertElementBefore($mform->createElement('static','list',$label,$html2),'questiontext');
+        $mform->insertElementBefore($mform->createElement('static','listcategory',$label,$html2),'name');
+        $addfieldsname='updatecategory';
+        $addstring='Update the category';
+                $mform->registerNoSubmitButton($addfieldsname);
+        $mform->insertElementBefore(    $mform->createElement('submit', $addfieldsname, $addstring),'listcategory');
 
         $mform->addElement('header', 'answerhdr', get_string('answerhdr', 'qtype_calculated'));
 
@@ -158,8 +164,24 @@ class question_edit_calculated_form extends question_edit_form {
         }
         $default_values['submitbutton'] = get_string('nextpage', 'qtype_calculated');
         $default_values['makecopy'] = get_string('makecopynextpage', 'qtype_calculated');
-        $question = (object)((array)$question + $default_values);
-
+        /* set the wild cards category display given that on loading the category element is 
+        unselected when processing this function but have a valid value when processing the 
+        update category button. The value can be obtain by
+         $qu->category =$this->_form->_elements[$this->_form->_elementIndex['category']]->_values[0];
+         but is coded using existing functions
+        */        
+         $qu = new stdClass;
+         $el = new stdClass;
+         /* no need to call elementExists() here */ 
+         $el=$this->_form->getElement('category');  
+         if($value =$el->getSelected()) {
+            $qu->category =$value[0];
+        }else {
+            $qu->category=$question->category;// on load  $question->category is set by question.php
+        }    
+        $html2 = $this->qtypeobj->print_dataset_definitions_category($qu);
+       $this->_form->_elements[$this->_form->_elementIndex['listcategory']]->_text = $html2 ;
+               $question = (object)((array)$question + $default_values);
 
         parent::set_data($question);
     }
index d914b62a21a9fe1a47b031231df73a0ca92478d6..11c4a31dd3856878aa4e12d00592be7c67a7ecd4 100644 (file)
@@ -917,7 +917,7 @@ class question_calculated_qtype extends question_dataset_dependent_questiontype
             }
             $text .="</table>";
         }else{
-             $text .=get_string('no shareable wild card', 'qtype_calculated'); //"<b>NO SHAREABLE DATASETS IN THIS CATEGORY</b>";
+             $text .=get_string('nosharedwildcard', 'qtype_calculated'); 
         }
         return  $text ;
     }