Class ::xowiki::formfield::reorder_box
::xowiki::formfield::reorder_box
create ... \
[ -shuffle:boolean (default "true") ]
Class Relations
- class: ::xotcl::Class
![[i]](/resources/acs-subsite/ZoomIn16.gif)
- superclass: ::xowiki::formfield::select
![[i]](/resources/acs-subsite/ZoomIn16.gif)
::xotcl::Class create ::xowiki::formfield::reorder_box \
-superclass ::xowiki::formfield::select
Methods (to be applied on instances)
answer_is_correct (scripted)
if {![info exists :answer]} {
set result 0
} else {
set value [:value]
if {[llength $value] != [llength ${:answer}]} {
error "list length of value <$value> and answer <${:answer}> must be equal (${:name})"
}
set result 1
set :correction {}
set R 0; set W 0
foreach v $value a ${:answer} {
set ok [expr {$v eq $a}]
lappend :correction $ok
if {$ok} {
incr R
} else {
set result -1
incr W
}
}
ns_log notice "${:name}: correction? have grading [info exists :grading]"
set correct_relative {}
set Rr 0; set Wr 0
for {set i 1} {$i < [llength $value]} {incr i} {
if {[lindex $value $i-1] < [lindex $value $i]} {
incr Rr
lappend correction_relative 1
} else {
set result -1
incr Wr
lappend correction_relative 0
}
}
set exact [expr {$result == 1 ? 1.0 : 0.0}]
set scores {}
lappend scores exact $exact "" $exact position [:ggw $R $W] relative [:ggw $Rr $Wr]
dict set :correction_data scores $scores
}
return $resultinitialize (scripted)
set :multiple 1
next
render_input (scripted)
if {${:value} eq ""} {
if {${:shuffle}} {
set :value [::xowiki::randomized_indices -seed [xo::cc user_id] [llength ${:options}]]
} else {
set :value [lmap o ${:options} {lindex $o 1}]
}
}
set c -1; set indices [lmap o ${:options} {incr c}]
if {[lsort -integer ${:value}] ne $indices} {
error "internal representation of options ${:options} must be subsequent integers starting with 0\nwe have: ${:value}\noptions: ${:options}"
}
regsub -all -- {[.]} "${:id}.sortable" - jqID
set textAreaID ${:id}.text
if {![:is_disabled]} {
::xo::Page requireCSS urn:ad:css:jquery-ui
::xo::Page requireJS urn:ad:js:jquery-ui
if {[::xo::cc mobile]} {
::xo::Page requireJS urn:ad:js:jquery-ui-touch-punch
}
template::add_body_script -script [subst {
\$("#$jqID").sortable();
\$("#$jqID").on( "sortupdate", function( event, ui ) {
var ul = event.target;
var textarea = document.getElementById('$textAreaID');
var items = ul.getElementsByTagName('LI');
var internalRep = "";
for (var j = 0; j < items.length; j++) {
internalRep += items\[j\].dataset.value + "\\n";
}
textarea.value = internalRep;
} );
}]
}
if {![info exists :correction]} {
set :correction {}
}
html::div -class reorder_box -id ${:id} {
::html::textarea -id $textAreaID -name ${:name} {
::html::t [join ${:value} \n]
}
::html::div -class workarea {
::html::ul -class "list-group" -id $jqID {
foreach v ${:value} c ${:correction} {
set cl "list-group-item"
lappend cl [expr {$c eq "1" ? "correct" : $c eq "0" ? "incorrect" : ""} ]
::html::li -class $cl -style "min-width:200px;" -data-value $v {
::html::t [lindex ${:options} $v 0]
}
}
}
}
}shuffle (setter)