" \
@@ -290,7 +311,7 @@
#:msg "$input_field_name .correct = $value(correct)"
}
- if {![:multiple]} {
+ if {!${:multiple}} {
regexp {[.]([^.]+)$} $correct_field_name _ correct_field_value
lappend fc "radio:text,answer=$correct_field_value"
}
@@ -318,12 +339,8 @@
mc_choice instproc initialize {} {
if {${:__state} ne "after_specs"} return
- if {1} {
- test_item instvar {xinha(javascript) javascript}
- set text_config [subst {height=100px,label=Text}]
- } else {
- set text_config [subst {editor=wym,height=100px,label=Text}]
- }
+ set text_config [subst {height=100px,label=Text}]
+
if {[:feedback_level] eq "full"} {
set feedback_fields {
{feedback_correct {textarea,cols=60,label=#xowf.feedback_correct#}}
@@ -334,7 +351,7 @@
}
set widget [test_item set richtextWidget]
- if {[:multiple]} {
+ if {${:multiple}} {
# We are in a multiple-choice item; provide for editing a radio
# group per alternative.
:create_components [subst {
@@ -370,14 +387,13 @@
text_interaction instproc initialize {} {
if {${:__state} ne "after_specs"} return
- test_item instvar {xinha(javascript) javascript}
#
# Create component structure.
#
set widget [test_item set richtextWidget]
if {${:auto_correct}} {
- set autoCorrectSpec {{correct_when {text,label=#xowf.correct_when#}}}
+ set autoCorrectSpec {{correct_when {correct_when,label=#xowf.correct_when#}}}
} else {
set autoCorrectSpec ""
}
@@ -407,12 +423,14 @@
append form \
"\n"
append fc \
"@categories:off @cr_fields:hidden\n" \
- "{answer:textarea,rows=$lines,cols=$columns,$correct_when,label=Answer}"
+ "{answer:textarea,disabled_as_div=1,rows=$lines,cols=$columns,$correct_when,label=Answer}"
#ns_log notice "text_interaction $form\n$fc"
${:object} set_property -new 1 form $form
@@ -436,49 +454,54 @@
text_entry_interaction instproc initialize {} {
if {${:__state} ne "after_specs"} return
- test_item instvar {xinha(javascript) javascript}
#
# Create component structure.
#
set widget [test_item set richtextWidget]
ns_log notice "[self] [:info class] auto_correct=${:auto_correct}"
- :create_components [subst {
+ :create_components [subst {
{text {$widget,label=#xowf.exercise-text#,plugins=OacsFs}}
- {answer {text_entry_field,repeat=1..5}}
+ {answer {text_entry_field,repeat=1..5,label=}}
}]
set :__initialized 1
}
text_entry_interaction instproc convert_to_internal {} {
- set intro_text [:get_named_sub_component_value text]
- #:msg " input_field_names=${:input_field_names}"
+ set intro_text [:get_named_sub_component_value text]
set answerFields [:get_named_sub_component_value answer]
- ns_log notice "answerFields <$answerFields>"
+ set shuffle_kind [${:parent_field} get_named_sub_component_value shuffle]
+ set options {}
+ set answer {}
set count 0
- set list "\n"
+
foreach {fieldName value} $answerFields {
+ # skip template entry
if {[lindex [split $fieldName .] end] eq 0} {
continue
}
- ns_log notice ...fieldName=$fieldName->$value
+ #ns_log notice ...fieldName=$fieldName->$value
set af answer[incr count]
- append list "- [dict get $value $fieldName.text] @${af}@
\n"
- set correct_when [dict get $value $fieldName.correct_when]
- # inline=true;
- lappend fc ${af}:text,label=,[::xowiki::formfield::FormField fc_encode correct_when=$correct_when]
- #ns_log notice "correct_when <$correct_when>"
+ lappend options [list [dict get $value $fieldName.text] $af]
+ lappend answer [dict get $value $fieldName.correct_when]
}
- append list " \n"
+ set options [::xowiki::formfield::FormField fc_encode $options]
+ set answer [::xowiki::formfield::FormField fc_encode $answer]
+
append form \
"\n"
- lappend fc @categories:off @cr_fields:hidden
+ set fc {}
+ lappend fc \
+ "answer:text_fields,disabled_as_div=1,options=$options,shuffle_kind=$shuffle_kind,answer=$answer,label=" \
+ @categories:off @cr_fields:hidden
ns_log notice "text_entry_interaction $form\n$fc"
${:object} set_property -new 1 form $form
@@ -534,7 +557,103 @@
}
+namespace eval ::xowiki::formfield {
+ ###########################################################
+ #
+ # ::xowiki::formfield::mc_interaction2
+ #
+ ###########################################################
+ Class create mc_interaction2 -superclass TestItemField -parameter {
+ }
+
+ mc_interaction2 instproc initialize {} {
+ if {${:__state} ne "after_specs"} return
+ #
+ # Create component structure.
+ #
+ set widget [test_item set richtextWidget]
+ #ns_log notice "[self] [:info class] auto_correct=${:auto_correct}"
+
+ :create_components [subst {
+ {text {$widget,label=#xowf.exercise-text#,plugins=OacsFs}}
+ {answer {mc_field,repeat=1..10,label=}}
+ }]
+ set :__initialized 1
+ }
+
+ mc_interaction2 instproc convert_to_internal {} {
+
+ set intro_text [:get_named_sub_component_value text]
+ set shuffle_kind [${:parent_field} get_named_sub_component_value shuffle]
+ set answerFields [:get_named_sub_component_value answer]
+
+ set count 0
+ set options {}
+ set correct {}
+ foreach {fieldName value} $answerFields {
+ # skip template entry
+ if {[lindex [split $fieldName .] end] eq 0} {
+ continue
+ }
+ ns_log notice ...fieldName=$fieldName->$value
+ #set af answer[incr count]
+ set text [dict get $value $fieldName.text]
+ # trim leading since this causes a newline in the checkbox label
+ regexp {^\s*( )(.*)$} $text . . text
+ lappend options [list $text [incr count]]
+ lappend correct [dict get $value $fieldName.correct]
+ }
+ set options [::xowiki::formfield::FormField fc_encode $options]
+ set fc [list answer:checkbox,richtext=1,answer=$correct,shuffle_kind=$shuffle_kind,options=$options]
+
+ append form \
+ " \n"
+ lappend fc @categories:off @cr_fields:hidden
+
+ ns_log notice "mc_interaction2 $form\n$fc"
+ ${:object} set_property -new 1 form $form
+ ${:object} set_property -new 1 form_constraints $fc
+ set anon_instances true ;# TODO make me configurable
+ ${:object} set_property -new 1 anon_instances $anon_instances
+ ${:object} set_property -new 1 auto_correct ${:auto_correct}
+ ${:object} set_property -new 1 has_solution false
+ }
+
+ #
+ # ::xowiki::formfield::mc_field
+ #
+ Class create mc_field -superclass TestItemField -parameter {
+ }
+
+ mc_field instproc initialize {} {
+ if {${:__state} ne "after_specs"} return
+ #
+ # Create component structure.
+ #
+ set widget [test_item set richtextWidget]
+
+ if {${:auto_correct}} {
+ set autoCorrectSpec {{correct_when {correct_when,label=#xowf.correct_when#}}}
+ } else {
+ set autoCorrectSpec ""
+ }
+ #:msg autoCorrectSpec=$autoCorrectSpec
+ :create_components [subst {
+ {text {$widget,height=100px,label=Teilaufgabe,plugins=OacsFs}}
+ {correct {boolean,horizontal=true,label=Korrekt}}
+ }]
+ set :__initialized 1
+ }
+
+}
+
+
namespace eval ::xowiki::formfield {
###########################################################
#
@@ -561,8 +680,10 @@
set intro_text [:get_named_sub_component_value text]
append form \
"\n"
append fc \
"@categories:off @cr_fields:hidden\n" \
@@ -679,6 +800,80 @@
}
}
+namespace eval ::xowf::test_item {
+
+ nx::Object create renaming_form_loader {
+ #
+ # Form loader that renames "generic" form-field-names as provided
+ # by the test-item form-field classes (@answer@) into names based
+ # on the form name, such that multiple of these form names can be
+ # processed together without name clashes.
+ #
+
+ :object method map_form_constraints {form_constraints oldName newName} {
+ #
+ # Rename form constraints starting with $oldName into $newName.
+ # Handle as well "answer=$oldName" form constraint properties.
+ #
+ return [lmap f $form_constraints {
+ #:msg check?'$f'
+ if {[string match "${oldName}*" $f]} {
+ regsub $oldName $f $newName f
+ if {[string match "*answer=$oldName*" $f]} {
+ regsub answer=$oldName $f answer=$newName f
+ #:log "MAP VALUE=answer=$oldName => answer=$newName "
+ }
+ }
+ set f
+ }]
+ }
+
+ :public object method form_name_based_attribute_stem {formName} {
+ #
+ # Produce from the provided 'formName' an attribute stem for the
+ # input fields of this form.
+ #
+ set strippedName [lindex [split $formName :] end]
+ regsub -all {[-]} $strippedName _ stem
+ return ${stem}_
+ }
+
+ :public object method get_form_object {{-set_title:boolean true} ctx form_name} {
+ #:msg "renaming_form_loader for form_name <$form_name>"
+ set form_id [$ctx default_load_form_id $form_name]
+ set obj [$ctx object]
+ set form_obj [::xo::db::CrClass get_instance_from_db -item_id $form_id]
+
+ set form [$form_obj get_property -name form]
+ set fc [$form_obj get_property -name form_constraints]
+
+ #
+ # Map "answer" to a generic name in the form "@answer@" and in the
+ # form constraints.
+ #
+ set newName [:form_name_based_attribute_stem [$form_obj name]]
+
+ regsub -all {@answer} $form @$newName form
+ set fc [:map_form_constraints $fc "answer" $newName]
+ set disabled_fc [lmap f $fc {
+ if {[string match "$newName*" $f]} { append f ,disabled=true }
+ set f
+ }]
+
+ lappend fc @cr_fields:hidden
+ lappend disabled_fc @cr_fields:hidden
+ #:msg fc=$fc
+
+ $form_obj set_property form $form
+ $form_obj set_property -new 1 form_constraints $fc
+ $form_obj set_property -new 1 disabled_form_constraints $disabled_fc
+
+ return $form_obj
+ }
+
+ }
+}
+
#
# Local variables:
# mode: tcl
Index: openacs-4/packages/xowf/www/resources/myform.css
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/xowf/www/resources/myform.css,v
diff -u -N
--- openacs-4/packages/xowf/www/resources/myform.css 28 Aug 2014 08:24:57 -0000 1.1
+++ /dev/null 1 Jan 1970 00:00:00 -0000
@@ -1,11 +0,0 @@
-.xowiki-content fieldset {
- border: 1px solid #ccc;
-}
-.xowiki-content .margin-form fieldset .form-item-wrapper .form-label {
- width: 10em;
-}
-.xowiki-content .margin-form fieldset .form-item-wrapper .form-widget,
-.xowiki-content .margin-form fieldset .form-button,
-.xowiki-content .margin-form fieldset div.form-help-text {
- margin-left: 11em;
-}
\ No newline at end of file
Index: openacs-4/packages/xowf/www/resources/test-item.css
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/xowf/www/resources/Attic/test-item.css,v
diff -u -N -r1.1.2.2 -r1.1.2.3
--- openacs-4/packages/xowf/www/resources/test-item.css 27 Oct 2019 23:35:51 -0000 1.1.2.2
+++ openacs-4/packages/xowf/www/resources/test-item.css 4 Nov 2019 10:24:39 -0000 1.1.2.3
@@ -41,7 +41,7 @@
display: none;
}
-div.mc_interaction, div.sc_interaction, div.text_entry_interaction {
+div.mc_interaction, div.sc_interaction, div.text_entry_interaction, div.text_interaction {
padding: 15px 0px 0px 15px;
}
div.mc_interaction label, div.sc_interaction label {
@@ -56,10 +56,11 @@
div.mc_interaction label input[type="checkbox"],
div.sc_interaction label input[type="radio"] {
vertical-align: top;
+ margin: 0px 0px 0px 10px;
}
div.text_entry_interaction li {
- padding: 0px 0px 15px 0px;
+ padding: 0px 0px 10px 0px;
}
/*
@@ -71,9 +72,32 @@
div.text_entry_interaction div.incorrect input:disabled {
background: #ffdddd;
}
-div.mc_interaction label.correct, div.sc_interaction label.correct {
- background: #ccffcc;
+div.text_interaction div.textarea,
+div.text_entry_interaction div.text {
+ background: #eee;
+ white-space: pre-wrap;
+ padding: 10px 10px 10px 10px;
}
-div.mc_interaction label.incorrect, div.sc_interaction label.incorrect {
- background: #ffdddd;
+
+div.text_interaction div.correct,
+div.text_entry_interaction div.correct,
+div.mc_interaction label.correct,
+div.sc_interaction label.correct
+{
+ border-width: 0px 0px 0px 4px;
+ border-style: solid;
+ border-color: green;
}
+div.text_interaction div.incorrect,
+div.text_entry_interaction div.incorrect,
+div.mc_interaction label.incorrect,
+div.sc_interaction label.incorrect
+{
+ border-width: 0px 0px 0px 4px;
+ border-style: solid;
+ border-color: red;
+}
+div.text_interaction div.textarea span.match,
+div.text_entry_interaction div.text span.match {
+ background: #FFFF2F; /*#FFFFAA;*/
+}
|