Index: openacs-4/packages/assessment/www/asm-admin/item-edit-mc.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/assessment/www/asm-admin/item-edit-mc.tcl,v diff -u -N -r1.8 -r1.9 --- openacs-4/packages/assessment/www/asm-admin/item-edit-mc.tcl 5 May 2005 19:25:08 -0000 1.8 +++ openacs-4/packages/assessment/www/asm-admin/item-edit-mc.tcl 12 Jun 2006 02:49:51 -0000 1.9 @@ -10,7 +10,6 @@ choice:optional,array correct:optional,array {num_choices:integer,optional 5} - {old_choices:optional} } -properties { context:onevalue page_title:onevalue @@ -38,13 +37,28 @@ set boolean_options [list [list "[_ assessment.yes]" t] [list "[_ assessment.no]" f]] set correct_options [list [list "[_ assessment.yes]" t]] +set type $assessment_data(type) + ad_form -name item_edit_mc -action item-edit-mc -export { assessment_id section_id num_choices } -form { {as_item_id:key} {title:text {label "[_ assessment.Title]"} {html {size 80 maxlength 1000}} {help_text "[_ assessment.mc_Title_help]"}} +} + +if {$type > 1} { + ad_form -extend -name item_edit_mc -form { {increasing_p:text(select) {label "[_ assessment.Increasing]"} {options $boolean_options} {help_text "[_ assessment.Increasing_help]"}} {negative_p:text(select) {label "[_ assessment.Allow_Negative]"} {options $boolean_options} {help_text "[_ assessment.Allow_Negative_help]"}} {num_correct_answers:text,optional,nospell {label "[_ assessment.num_Correct_Answer]"} {html {size 5 maxlength 5}} {help_text "[_ assessment.num_Correct_help]"}} + } +} else { + ad_form -extend -name item_edit_mc -form { + {increasing_p:text(hidden) {value ""}} + {negative_p:text(hidden) {value ""}} + {num_correct_answers:text(hidden) {value ""}} + } +} +ad_form -extend -name item_edit_mc -form { {num_answers:text,optional,nospell {label "[_ assessment.num_Answers]"} {html {size 5 maxlength 5}} {help_text "[_ assessment.num_Answers_help]"}} } @@ -55,7 +69,6 @@ set count 0 set validate_list [list] set count_correct [array exists correct] -set old_choices [list] foreach one_choice $choices { util_unlist $one_choice choice_title choice_id choice_correct_p incr count @@ -67,40 +80,41 @@ } append ad_form_code "\{choice.$choice_id:text,optional,nospell \{label \"[_ assessment.Choice] $count\"\} \{html \{size 80 maxlength 1000\}\} \{value \"\$choice($choice_id)\"\} \{help_text \"[_ assessment.Choice_help]\"\}\}\n" + if { $type > 1} { if {[info exists correct($choice_id)]} { append ad_form_code "\{correct.$choice_id:text(checkbox),optional \{label \"[_ assessment.Correct_Answer_Choice] $count\"\} \{options \$correct_options\} \{values t\} \{help_text \"[_ assessment.Correct_Answer_help]\"\}\}\n" } else { append ad_form_code "\{correct.$choice_id:text(checkbox),optional \{label \"[_ assessment.Correct_Answer_Choice] $count\"\} \{options \$correct_options\} \{help_text \"[_ assessment.Correct_Answer_help]\"\}\}\n" } - lappend validate_list "correct.$choice_id {\$count_correct > 0} \"\[_ assessment.one_correct_choice_req\]\"" - lappend old_choices $choice_id + # lappend validate_list "correct.$choice_id {\$count_correct > 0} \"\[_ assessment.one_correct_choice_req\]\"" + } } -append ad_form_code "\{old_choices:text(hidden) \{value $old_choices\}\}\n" -if {[template::form get_action item_show_mc] == "more"} { - # add new empty form entries for new choices - for {set i 1} {$i <= $num_choices} {incr i} { - incr count - if {[info exists choice($i)]} { - append ad_form_code "\{choice.$i:text,optional,nospell \{label \"[_ assessment.Choice] $count\"\} \{html \{size 80 maxlength 1000\}\} \{value \"\$choice($i)\"\} \{help_text \"[_ assessment.Choice_help]\"\}\}\n" - } else { - append ad_form_code "\{choice.$i:text,optional,nospell \{label \"[_ assessment.Choice] $count\"\} \{html \{size 80 maxlength 1000\}\} \{help_text \"[_ assessment.Choice_help]\"\}\}\n" - } - if {[info exists correct($i)]} { - append ad_form_code "\{correct.$i:text(checkbox),optional \{label \"[_ assessment.Correct_Answer_Choice] $count\"\} \{options \$correct_options\} \{values t\} \{help_text \"[_ assessment.Correct_Answer_help]\"\}\}\n" - } else { - append ad_form_code "\{correct.$i:text(checkbox),optional \{label \"[_ assessment.Correct_Answer_Choice] $count\"\} \{options \$correct_options\} \{help_text \"[_ assessment.Correct_Answer_help]\"\}\}\n" - } +# add new empty form entries for new choices +for {set i 1} {$i <= $num_choices} {incr i} { + incr count + if {[info exists choice(_$i)]} { + append ad_form_code "\{choice._$i:text,optional,nospell \{label \"[_ assessment.Choice] $count\"\} \{html \{size 80 maxlength 1000\}\} \{value \"\$choice(_$i)\"\} \{help_text \"[_ assessment.Choice_help]\"\}\}\n" + } else { + append ad_form_code "\{choice._$i:text,optional,nospell \{label \"[_ assessment.Choice] $count\"\} \{html \{size 80 maxlength 1000\}\} \{help_text \"[_ assessment.Choice_help]\"\}\}\n" } + if { $type > 1} { + if {[info exists correct(_$i)]} { + append ad_form_code "\{correct._$i:text(checkbox),optional \{label \"[_ assessment.Correct_Answer_Choice] $count\"\} \{options \$correct_options\} \{values t\} \{help_text \"[_ assessment.Correct_Answer_help]\"\}\}\n" + } else { + append ad_form_code "\{correct._$i:text(checkbox),optional \{label \"[_ assessment.Correct_Answer_Choice] $count\"\} \{options \$correct_options\} \{help_text \"[_ assessment.Correct_Answer_help]\"\}\}\n" + } + } } append ad_form_code "\}" eval ad_form -extend -name item_edit_mc $ad_form_code + set edit_request "{ db_1row item_type_data {} }" -set on_submit "{ +set on_submit "{ if {\[template::form get_action item_add_mc\] == \"more\"} { # add 5 more choice entries and redirect to this form incr num_choices 5 @@ -110,7 +124,6 @@ }" set edit_data "{ - db_transaction { set new_item_id \[as::item::new_revision -as_item_id \$as_item_id\] set as_item_type_id \[db_string item_type_id {}\] @@ -132,21 +145,24 @@ db_dml update_item_in_section {} db_dml update_item_type {} - set count 0 - set new_count \[llength \$old_choices\] - foreach i \[array names choice\] { - if {\[lsearch \$old_choices \$i\] != -1 } { - # old_choices preserves the prior order - set count \[expr \[lsearch \$old_choices \$i\] + 1\] - # edit existing choices + # edit existing choices + set count 0 + foreach i \[lsort \[array names choice\]\] { + if {\[string range \$i 0 0\] != \"_\" && !\[empty_string_p \$choice(\$i)\]} { + incr count set new_choice_id \[as::item_choice::new_revision -choice_id \$i -mc_id \$new_item_type_id\] set title \$choice(\$i) set correct_answer_p \[ad_decode \[info exists correct(\$i)\] 0 f t\] db_dml update_title {} db_dml update_correct_and_sort_order {} - } elseif { !\[empty_string_p \$choice(\$i)\] } { - # add new choices - incr new_count + } + } + + # add new choices + foreach i \[lsort \[array names choice\]\] { + + if {\[string range \$i 0 0\] == \"_\" && !\[empty_string_p \$choice(\$i)\]} { + incr count set new_choice_id \[as::item_choice::new -mc_id \$new_item_type_id \\ -title \$choice(\$i) \\ -numeric_value \"\" \\ @@ -155,7 +171,7 @@ -feedback_text \"\" \\ -selected_p \"\" \\ -correct_answer_p \[ad_decode \[info exists correct(\$i)\] 0 f t\] \\ - -sort_order \$new_count \\ + -sort_order \$count \\ -percent_score \"\"\] } } @@ -171,7 +187,6 @@ ad_script_abort }" -#eval ad_form -extend -name item_edit_mc -validate "{$validate_list}" -edit_request $edit_request -on_submit $on_submit -edit_data $edit_data -after_submit $after_submit -eval ad_form -extend -name item_edit_mc -validate "{$validate_list}" -edit_request $edit_request -edit_data $edit_data -after_submit $after_submit +eval ad_form -extend -name item_edit_mc -validate "{$validate_list}" -edit_request $edit_request -on_submit $on_submit -edit_data $edit_data -after_submit $after_submit ad_return_template