Index: openacs-4/packages/xowiki/tcl/form-field-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/xowiki/tcl/form-field-procs.tcl,v diff -u -r1.66 -r1.67 --- openacs-4/packages/xowiki/tcl/form-field-procs.tcl 10 Apr 2008 12:05:47 -0000 1.66 +++ openacs-4/packages/xowiki/tcl/form-field-procs.tcl 16 Apr 2008 10:32:38 -0000 1.67 @@ -374,15 +374,66 @@ FormField instproc pretty_value {v} { if {[my exists options]} { - foreach o [my set options] { - foreach {label value} $o break - if {$value eq $v} {return [my localize $label]} + if {[my exists multiple] && [my set multiple]} { + foreach o [my set options] { + foreach {label value} $o break + set labels($value) [my localize $label] + } + set values [list] + foreach i $v {lappend values $labels($i)} + return [join $values {, }] + } else { + foreach o [my set options] { + foreach {label value} $o break + if {$value eq $v} {return [my localize $label]} + } } } #my log "mapping $v" return [string map [list & "&" < "<" > ">" \" """ ' "'" @ "@"] $v] } + FormField instproc config_from_category_tree {tree_name} { + # Get the options of a select or rado from the specified + # category tree. + # + # We could config as well from the mapped category tree, + # and get required and multiple from there.... + # + # The usage of the label does not seem to be very useful. + # + set tree_id [category_tree::get_id $tree_name [my locale]] + if {$tree_id eq ""} { + my msg "cannot lookup category tree name '$tree_name'" + return + } + # + # In case there are multiple trees with the same named map, + # take the first one to avoid confusions. + # + #my msg tree_id=$tree_id + set tree_id [lindex $tree_id 0] + set subtree_id "" + set options [list] + + foreach category [category_tree::get_tree -subtree_id $subtree_id $tree_id] { + foreach {category_id category_name deprecated_p level} $category break + #if {[lsearch $category_ids $category_id] > -1} {lappend value $category_id} + #lappend value $category_id + set category_name [ad_quotehtml [lang::util::localize $category_name]] + if { $level>1 } { + set category_name "[string repeat { } [expr {2*$level-4}]]..$category_name" + } + lappend options [list $category_name $category_id] + } + my options $options + my set is_category_field 1 + # my msg label_could_be=$tree_name,existing=[my label] + # if {![my exists label]} { + # my label $tree_name + # } + } + ########################################################### # # helper method for extending slots: @@ -802,9 +853,11 @@ Class FormField::radio -superclass FormField -parameter { {options ""} {horizontal false} + {category_tree} } FormField::radio instproc initialize {} { my set widget_type text(radio) + if {[my exists category_tree]} {my config_from_category_tree [my category_tree]} } FormField::radio instproc render_input {} { set value [my value] @@ -828,9 +881,11 @@ Class FormField::select -superclass FormField -parameter { {options} {multiple "false"} + {category_tree} } FormField::select instproc initialize {} { my set widget_type text(select) + if {[my exists category_tree]} {my config_from_category_tree [my category_tree]} if {![my exists options]} {my options [list]} } FormField::select instproc render_input {} { Index: openacs-4/packages/xowiki/tcl/xowiki-www-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/xowiki/tcl/xowiki-www-procs.tcl,v diff -u -r1.141 -r1.142 --- openacs-4/packages/xowiki/tcl/xowiki-www-procs.tcl 2 Apr 2008 11:31:57 -0000 1.141 +++ openacs-4/packages/xowiki/tcl/xowiki-www-procs.tcl 16 Apr 2008 10:32:38 -0000 1.142 @@ -439,7 +439,7 @@ if {[lsearch $category_ids $category_id] > -1} {lappend value $category_id} set category_name [ad_quotehtml [lang::util::localize $category_name]] if { $level>1 } { - set category_name "[string repeat { } [expr {2*$level -4}]]..$category_name" + set category_name "[string repeat { } [expr {2*$level-4}]]..$category_name" } lappend options [list $category_name $category_id] } @@ -568,6 +568,7 @@ set f [my lookup_form_field -name $att $form_fields] set value [$f value [string trim [::xo::cc form_parameter $att]]] if {![string match *.* $att]} {set __ia($att) $value} + if {[$f exists is_category_field]} {foreach v $value {lappend category_ids $v}} } } if {[string match *.* $att]} { @@ -657,7 +658,7 @@ #my msg "--set instance attributes to [array get __ia]" my instance_attributes [array get __ia] my array set __ia [my instance_attributes] - return [list $validation_errors $category_ids] + return [list $validation_errors [lsort -unique $category_ids]] } FormPage instproc form_field_as_html {{-mode edit} before name form_fields} {