Index: openacs-4/packages/acs-tcl/tcl/widgets-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-tcl/tcl/widgets-procs.tcl,v diff -u -N -r1.21 -r1.22 --- openacs-4/packages/acs-tcl/tcl/widgets-procs.tcl 18 Sep 2018 15:19:22 -0000 1.21 +++ openacs-4/packages/acs-tcl/tcl/widgets-procs.tcl 18 Sep 2018 15:21:29 -0000 1.22 @@ -4,8 +4,8 @@ @cvs-id $Id$ } -ad_proc us_state_widget { - {default ""} +ad_proc us_state_widget { + {default ""} {select_name "usps_abbrev"} } { Returns a state selection box. @@ -20,18 +20,18 @@ select state_name, abbrev from states order by state_name } { if { $default == $abbrev } { - append widget_value "\n" - } else { + append widget_value "\n" + } else { append widget_value "\n" } } append widget_value "\n" return $widget_value } -ad_proc country_widget { - {default ""} - {select_name "country_code"} +ad_proc country_widget { + {default ""} + {select_name "country_code"} {size_subtag "size='4'"} } { Returns a country selection box. @@ -40,18 +40,18 @@ set widget_value "\n" # take care of cases like 09 for month regsub "^0" $month "" month for {set i 0} {$i < 12} {incr i} { - if { $month ne "" && $i == $month - 1 } { - append output "\n" - } else { - append output "\n" - } + if { $month ne "" && $i == $month - 1 } { + append output "\n" + } else { + append output "\n" + } } append output [subst {  - }] + }] - return $output + return $output } ad_proc ad_db_select_widget { @@ -212,38 +212,38 @@ {-blank_if_no_db 0} {-hidden_if_one_db 0} {-bind {}} - statement_name - sql_qry - name -} { + statement_name + sql_qry + name +} { given a sql query this generates a select group. If there is only one value it returns the text and a hidden variable setting that value. The first selected column should contain the optionlist items. The - second selected column should contain the optionlist values. + second selected column should contain the optionlist values.

option_list is a list in the same format (i.e. {{str val} {str2 val2}...}) which is prepended to the list

if sql_qry is null then the list is constructed from option_list only. -

+

if there is only one item the select is not generated and the value is passed in hidden form variable. -

+

if -multiple is given then a multi select is returned.

- if -blank_if_no_db is true, then do not return a select widget unless + if -blank_if_no_db is true, then do not return a select widget unless there are rows from the database -} { +} { set retval {} set count 0 set dbcount 0 if {$option_list ne ""} { - foreach opt $option_list { + foreach opt $option_list { incr count - lassign $opt value item - if { (!$multiple && $value eq $default ) - || ($multiple && $value in $default) - } { + lassign $opt value item + if { (!$multiple && $value eq $default ) + || ($multiple && $value in $default) + } { append retval "\n" } else { append retval "\n" @@ -256,38 +256,38 @@ } if {$sql_qry ne ""} { - set columns [ns_set create] - - db_foreach $statement_name $sql_qry -column_set selection -bind $bind { - incr count - incr dbcount - set item [ns_set value $selection 0] - set value [ns_set value $selection 1] - if { (!$multiple && $value eq $default ) - || ($multiple && $value in $default) - } { - append retval "\n" - } else { - append retval "\n" - } - } if_no_rows { - if {$default ne ""} { - return "\n" - } else { - return {} - } - } + set columns [ns_set create] + + db_foreach $statement_name $sql_qry -column_set selection -bind $bind { + incr count + incr dbcount + set item [ns_set value $selection 0] + set value [ns_set value $selection 1] + if { (!$multiple && $value eq $default ) + || ($multiple && $value in $default) + } { + append retval "\n" + } else { + append retval "\n" + } + } if_no_rows { + if {$default ne ""} { + return "\n" + } else { + return {} + } + } } if { $count == 1 || ($dbcount == 1 && $hidden_if_one_db) } { return "$item\n" } elseif {!$count && !$dbcount && $blank_if_no_db} { - return {} - } else { + return {} + } else { set select "\n" if { ![regexp {^([0-9]+),([0-9]+),([0-9]+)$} $default all c1 c2 c3] } { - set c1 "" - set c2 "" - set c3 "" + set c1 "" + set c2 "" + set c3 "" } foreach component { c1 c2 c3 } { - append out [subst { " + } + append out ">" } if { $use_js == 1 } { - if { $c1 eq "" } { - set c1 255 - set c2 255 - set c3 255 - } - append out [subst {  - + if { $c1 eq "" } { + set c1 255 + set c2 255 + set c3 255 + } + append out [subst {  + }] } append out "\n" return $out } -ad_proc ad_process_color_widgets args { - Sets variables corresponding to the color widgets named in $args. +ad_proc ad_process_color_widgets args { + Sets variables corresponding to the color widgets named in $args. } { foreach field $args { - upvar $field var - set var [ns_queryget "$field.list"] - if { $var eq "custom" } { - set var "[ns_queryget "$field.c1"],[ns_queryget "$field.c2"],[ns_queryget "$field.c3"]" - } - if { ![regexp {^([0-9]+),([0-9]+),([0-9]+)$} $var "" r g b] || $r > 255 || $g > 255 || $b > 255 } { - set var "" - } + upvar $field var + set var [ns_queryget "$field.list"] + if { $var eq "custom" } { + set var "[ns_queryget "$field.c1"],[ns_queryget "$field.c2"],[ns_queryget "$field.c3"]" + } + if { ![regexp {^([0-9]+),([0-9]+),([0-9]+)$} $var "" r g b] || $r > 255 || $g > 255 || $b > 255 } { + set var "" + } } } -ad_proc ad_color_to_hex { triplet } { - Converts a string of the form 0,192,255 to a string of the form #00C0FF. +ad_proc ad_color_to_hex { triplet } { + Converts a string of the form 0,192,255 to a string of the form #00C0FF. } { if { [regexp {^([0-9]+),([0-9]+),([0-9]+)$} $triplet all r g b] } { - return "#[format "%02x%02x%02x" $r $g $b]" + return "#[format "%02x%02x%02x" $r $g $b]" } else { - return "" + return "" } }