Index: openacs-4/packages/xowf/tcl/test-item-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/xowf/tcl/test-item-procs.tcl,v diff -u -N -r1.7.2.9 -r1.7.2.10 --- openacs-4/packages/xowf/tcl/test-item-procs.tcl 6 Nov 2019 18:45:47 -0000 1.7.2.9 +++ openacs-4/packages/xowf/tcl/test-item-procs.tcl 25 Nov 2019 14:51:46 -0000 1.7.2.10 @@ -1,4 +1,11 @@ +::xo::library doc { + Test Item procs - support for different kind of tests and exercises. + + @author Gustaf Neumann +} + :::xo::db::require package xowiki + namespace eval ::xowiki::formfield { ########################################################### # @@ -56,7 +63,7 @@ @param feedback_level "full", "single", or "none" @param grading one of "exact", "partial", or "none" @param nr_choices number of choices - @param question_type "mc", "sc", "ot", or "te" + @param question_type "mc", "sc", "ot", or "st" } # @@ -119,8 +126,8 @@ set can_shuffle false } sc { # we should support as well: minChoices, maxChoices - set interaction_class mc_interaction - set options nr_choices=[:nr_choices],multiple=false + set interaction_class mc_interaction2 + set options multiple=false set auto_correct true set can_shuffle true } @@ -135,8 +142,9 @@ set auto_correct ${:auto_correct} set can_shuffle false } - te { - set interaction_class text_entry_interaction + te - + st { + set interaction_class short_text_interaction #set options nr_choices=[:nr_choices] set auto_correct ${:auto_correct} set can_shuffle true @@ -168,13 +176,16 @@ } if {$can_shuffle} { - set shuffle_options "{None none} {{Per user} peruser} {Always always}" - set shuffleSpec [subst {{shuffle {radio,horizontal=true,options=$shuffle_options,default=none,label=#xowf.Shuffle#}}}] + set shuffle_options "{#xowf.shuffle_none# none} {#xowf.shuffle_peruser# peruser} {#xowf.shuffle_always# always}" + set shuffleSpec [subst { + {shuffle {radio,horizontal=true,form_item_wrapper_CSSclass=form-inline,options=$shuffle_options,default=none,label=#xowf.Shuffle#}} + {show_max {number,form_item_wrapper_CSSclass=form-inline,min=2,label=#xowf.show_max#}} + }] } else { set shuffleSpec "" } :create_components [subst { - {minutes number,min=1,default=2,label=#xowf.Minutes#} + {minutes number,form_item_wrapper_CSSclass=form-inline,min=1,default=2,label=#xowf.Minutes#} $gradingSpec $shuffleSpec {interaction {$interaction_class,$options,feedback_level=${:feedback_level},auto_correct=${:auto_correct},label=}} @@ -201,6 +212,7 @@ mc_interaction instproc set_compound_value {value} { set r [next] + if {!${:multiple}} { # For single choice questions, we have a fake-field for denoting # the correct entry. We have to distribute this to the radio @@ -218,6 +230,7 @@ } mc_interaction instproc initialize {} { + if {${:__state} ne "after_specs"} return # # build choices @@ -250,7 +263,7 @@ #:msg " input_field_names=${:input_field_names}" set mc [:get_named_sub_component_value mc] - ns_log notice "MC <$mc>" + #ns_log notice "MC <$mc>" if {!${:multiple}} { set correct_field_name [:get_named_sub_component_value correct] @@ -400,25 +413,23 @@ :create_components [subst { {text {$widget,label=#xowf.exercise-text#,plugins=OacsFs}} - {lines {number,min=1,default=10,label=#xowf.answer_lines#}} - {columns {number,min=1,max=80,default=60,label=#xowf.answer_columns#}} + {lines {number,form_item_wrapper_CSSclass=form-inline,min=1,default=10,label=#xowf.answer_lines#}} + {columns {number,form_item_wrapper_CSSclass=form-inline,min=1,max=80,default=60,label=#xowf.answer_columns#}} $autoCorrectSpec }] set :__initialized 1 } text_interaction instproc convert_to_internal {} { set intro_text [:get_named_sub_component_value text] - set lines [:get_named_sub_component_value lines] - set columns [:get_named_sub_component_value columns] - if {${:auto_correct}} { - set correct_when [:get_named_sub_component_value correct_when] - set correct_when [::xowiki::formfield::FormField fc_encode correct_when=$correct_when], - #ns_log notice "correct_when <$correct_when>" + dict set fc_dict rows [:get_named_sub_component_value lines] + dict set fc_dict cols [:get_named_sub_component_value columns] + dict set fc_dict disabled_as_div 1 + dict set fc_dict label #xowf.answer# - } else { - set correct_when "" + if {${:auto_correct}} { + dict set fc_dict correct_when [:get_named_sub_component_value correct_when] } append form \ @@ -430,7 +441,7 @@ "\n" append fc \ "@categories:off @cr_fields:hidden\n" \ - "{answer:textarea,disabled_as_div=1,rows=$lines,cols=$columns,$correct_when,label=Answer}" + "{answer:[:dict_to_fc -type textarea $fc_dict]}" #ns_log notice "text_interaction $form\n$fc" ${:object} set_property -new 1 form $form @@ -445,14 +456,14 @@ namespace eval ::xowiki::formfield { ########################################################### # - # ::xowiki::formfield::text_entry_interaction + # ::xowiki::formfield::short_text_interaction # ########################################################### - Class create text_entry_interaction -superclass TestItemField -parameter { + Class create short_text_interaction -superclass TestItemField -parameter { } - text_entry_interaction instproc initialize {} { + short_text_interaction instproc initialize {} { if {${:__state} ne "after_specs"} return # # Create component structure. @@ -461,19 +472,19 @@ ns_log notice "[self] [:info class] auto_correct=${:auto_correct}" :create_components [subst { - {text {$widget,label=#xowf.exercise-text#,plugins=OacsFs}} - {answer {text_entry_field,repeat=1..5,label=}} + {text {$widget,height=100px,label=#xowf.exercise-text#,plugins=OacsFs}} + {answer {short_text_field,repeat=1..5,label=}} }] set :__initialized 1 } - text_entry_interaction instproc convert_to_internal {} { + short_text_interaction instproc convert_to_internal {} { set intro_text [:get_named_sub_component_value text] set answerFields [:get_named_sub_component_value answer] - set shuffle_kind [${:parent_field} get_named_sub_component_value shuffle] set options {} + set render_hints {} set answer {} set count 0 @@ -486,24 +497,33 @@ set af answer[incr count] lappend options [list [dict get $value $fieldName.text] $af] lappend answer [dict get $value $fieldName.correct_when] + lappend render_hints [list \ + words [dict get $value $fieldName.options] \ + lines [dict get $value $fieldName.lines]] } - set options [::xowiki::formfield::FormField fc_encode $options] - set answer [::xowiki::formfield::FormField fc_encode $answer] + dict set fc_dict shuffle_kind [${:parent_field} get_named_sub_component_value shuffle] + dict set fc_dict show_max [${:parent_field} get_named_sub_component_value show_max] + dict set fc_dict disabled_as_div 1 + dict set fc_dict label "" + dict set fc_dict options $options + dict set fc_dict answer $answer + dict set fc_dict render_hints $render_hints append form \ "