Index: openacs-4/packages/assessment/www/admin/item-add-display-cb.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/assessment/www/admin/Attic/item-add-display-cb.tcl,v diff -u -r1.3 -r1.4 --- openacs-4/packages/assessment/www/admin/item-add-display-cb.tcl 29 Dec 2004 09:07:39 -0000 1.3 +++ openacs-4/packages/assessment/www/admin/item-add-display-cb.tcl 14 Jan 2005 13:13:37 -0000 1.4 @@ -49,7 +49,7 @@ ad_form -name item_add_display_cb -action item-add-display-cb -export { assessment_id section_id after } -form { {as_item_id:key} - {html_options:text,optional {label "[_ assessment.Html_Options]"} {html {size 80 maxlength 1000}} {help_text "[_ assessment.Html_Options_help]"}} + {html_options:text,optional,nospell {label "[_ assessment.Html_Options]"} {html {size 80 maxlength 1000}} {help_text "[_ assessment.Html_Options_help]"}} {choice_orientation:text(select) {label "[_ assessment.Choice_Orientation]"} {options $choice_or_types} {help_text "[_ assessment.Choice_Orientation_help]"}} {label_orientation:text(select) {label "[_ assessment.Label_Orientation]"} {options $label_or_types} {help_text "[_ assessment.Label_Orientation_help]"}} {order_type:text(select) {label "[_ assessment.Order_Type]"} {options $order_types} {help_text "[_ assessment.Order_Type_help]"}} @@ -60,23 +60,55 @@ set label_orientation "top" set order_type "order_of_entry" set answer_alignment "besideright" +} -validate { + {html_options {[as::assessment::check_html_options -options $html_options]} "[_ assessment.error_html_options]"} } -edit_data { db_transaction { - set as_item_display_id [as::item_display_cb::new \ - -html_display_options $html_options \ - -choice_orientation $choice_orientation \ - -choice_label_orientation $label_orientation \ - -sort_order_type $order_type \ - -item_answer_alignment $answer_alignment] - - as::item_rels::new -item_rev_id $as_item_id -target_rev_id $as_item_display_id -type as_item_display_rel - set new_assessment_rev_id [as::assessment::new_revision -assessment_id $assessment_id] + set section_id [as::section::latest -section_id $section_id -assessment_rev_id $new_assessment_rev_id] set new_section_id [as::section::new_revision -section_id $section_id] db_dml update_section_in_assessment {} - db_dml move_down_items {} - incr after - db_dml insert_new_item {} + set old_item_id $as_item_id + + if {![db_0or1row item_display {}] || $object_type != "as_item_display_cb"} { + set as_item_display_id [as::item_display_cb::new \ + -html_display_options $html_options \ + -choice_orientation $choice_orientation \ + -choice_label_orientation $label_orientation \ + -sort_order_type $order_type \ + -item_answer_alignment $answer_alignment] + + if {![info exists object_type]} { + # first item display mapped + as::item_rels::new -item_rev_id $as_item_id -target_rev_id $as_item_display_id -type as_item_display_rel + } else { + # old item display existing + set as_item_id [as::item::new_revision -as_item_id $as_item_id] + db_dml update_item_display {} + } + } else { + # old cb item display existing + set as_item_id [as::item::new_revision -as_item_id $as_item_id] + set as_item_display_id [as::item_display_cb::edit \ + -as_item_display_id $as_item_display_id \ + -html_display_options $html_options \ + -choice_orientation $choice_orientation \ + -choice_label_orientation $label_orientation \ + -sort_order_type $order_type \ + -item_answer_alignment $answer_alignment] + + db_dml update_item_display {} + } + + set old_item_id [as::item::latest -as_item_id $old_item_id -section_id $new_section_id -default 0] + if {$old_item_id == 0} { + db_dml move_down_items {} + incr after + db_dml insert_new_item {} + } else { + db_1row item_data {} + db_dml update_item {} + } } } -after_submit { # now go to assessment-page