From 0dd3e11c8c9376439aa879b31b4d883fd2f48241 Mon Sep 17 00:00:00 2001 From: pichetp Date: Thu, 19 Apr 2007 16:49:25 +0000 Subject: [PATCH] add an update category submit button to update the display of shareable wild cards --- .../type/calculated/edit_calculated_form.php | 28 +++++++++++++++++-- question/type/calculated/questiontype.php | 2 +- 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/question/type/calculated/edit_calculated_form.php b/question/type/calculated/edit_calculated_form.php index b062bff1213fe..87c14e7565d96 100644 --- a/question/type/calculated/edit_calculated_form.php +++ b/question/type/calculated/edit_calculated_form.php @@ -64,8 +64,14 @@ function definition_inner(&$mform) { $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 @@ function set_data($question) { } $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); } diff --git a/question/type/calculated/questiontype.php b/question/type/calculated/questiontype.php index d914b62a21a9f..11c4a31dd3856 100644 --- a/question/type/calculated/questiontype.php +++ b/question/type/calculated/questiontype.php @@ -917,7 +917,7 @@ function print_dataset_definitions_category($form) { } $text .=""; }else{ - $text .=get_string('no shareable wild card', 'qtype_calculated'); //"NO SHAREABLE DATASETS IN THIS CATEGORY"; + $text .=get_string('nosharedwildcard', 'qtype_calculated'); } return $text ; }