Index: openacs-4/packages/acs-templating/tcl/data-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-templating/tcl/data-procs.tcl,v diff -u -r1.5 -r1.6 --- openacs-4/packages/acs-templating/tcl/data-procs.tcl 15 Sep 2002 07:54:42 -0000 1.5 +++ openacs-4/packages/acs-templating/tcl/data-procs.tcl 15 Sep 2002 20:48:59 -0000 1.6 @@ -99,25 +99,3 @@ } } -ad_proc -public template::data::validate::user { value_ref message_ref } { - A data type that works with the 'user' widget. It allows you to - search for a particular user when a dropdown would get too big. -} { - - upvar 2 $message_ref message $value_ref value - - if { [info exists value] && [string equal $value ":other:"] } { - set result 0 - set message "Please search for user by name, email, or screen name." - } elseif { [info exists value] && [string equal $value ":noresult:"] } { - set result 0 - set message "Your search didn't find any users, please search again." - } elseif { [info exists value] && ![regexp {^[0-9]*$} $value] } { - set result 0 - set message "Please pick a user from the result of your search." - } else { - set result 1 - } - - return $result -} Index: openacs-4/packages/acs-templating/tcl/widget-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-templating/tcl/widget-procs.tcl,v diff -u -r1.13 -r1.14 --- openacs-4/packages/acs-templating/tcl/widget-procs.tcl 15 Sep 2002 07:54:42 -0000 1.13 +++ openacs-4/packages/acs-templating/tcl/widget-procs.tcl 15 Sep 2002 20:48:59 -0000 1.14 @@ -15,20 +15,22 @@ upvar $element_reference element if { ! [info exists element(options)] } { - + # initial submission or no data (no options): a text box set output [input text element $tag_attributes] } else { - + # options provided so use a select list # include an extra hidden element to indicate that the # value is being selected as opposed to entered set output "" append output [select element $tag_attributes] + } + return $output } @@ -267,6 +269,13 @@ # is submitted with no search criteria (text box blank) if { [string equal $value {}] } { return [list] } + if { [string equal $value ":search:"] } { + unset element(options) + template::element::set_error $element(form_id) $element_id " + Please enter a search string." + return [list] + } + # check for a value that has been entered rather than selected if { ! [ns_queryexists $element_id:select] } { @@ -275,17 +284,23 @@ error "No search query specified for search widget" } - # FIXME: need to get a statement name here set query $element(search_query) + if { [info exists element(search_query_name)] } { + set query_name $element(search_query_name) + } else { + set query_name "get_options" + } - set options [db_list_of_lists get_options $query] + set options [db_list_of_lists $query_name $query] set option_count [llength $options] if { $option_count == 0 } { # no search results so return text entry back to the user + unset element(options) + template::element::set_error $element(form_id) $element_id " No matches were found for \"$value\".
Please try again." @@ -298,7 +313,7 @@ } else { # need to return a select list - set element(options) $options + set element(options) [concat $options { { "Search again..." ":search:" } }] template::element::set_error $element(form_id) $element_id " More than one match was found for \"$value\".
Please choose one from the list." @@ -389,79 +404,3 @@ return $output } -ad_proc -public template::widget::user { element_reference tag_attributes } { - This widget is used to allow users to pick a user from a - drop-down, and then, when the user can't be found in that list, - offers a text widget to enter a search string, the results of - which are then displayed on the next screen. - - You may optionally provide a query to use with a -search_sql "select ..." - property on the element. -} { - - upvar $element_reference element - - if { [info exists element(html)] } { - array set attributes $element(html) - } - - array set attributes $tag_attributes - - set output {} - - if { [info exists element(value)] && ([string equal $element(value) ":other:"] || [string equal $element(value) ":noresult:"]) } { - # input widget to search for users - - append output "" - } elseif { [info exists element(value)] && ![regexp {^[0-9]*$} $element(value)] } { - # it's not :other: and it's not a number -- it's a search - - set query "%${element(value)}%" - if { [info exists element(search_sql)] } { - set sql $element(search_sql) - } else { - set sql { - select distinct - u.first_names || ' ' || u.last_name as name, - u.user_id - from cc_users u - where upper(coalesce(u.first_names || ' ', '') || coalesce(u.last_name || ' ', '') || u.email || ' ' || coalesce(u.screen_name, '')) like upper(:query) - order by name - } - } - - set users_list [db_list_of_lists users $sql] - if { [llength $users_list] == 0 } { - append output "" - - } else { - lappend users_list { "Search again..." ":other:" } - set output [template::widget::menu $element(name) $users_list "" attributes] - } - } else { - # select widget to pick a known user - set options $element(options) - lappend options { "Search for other user..." ":other:" } - set output [template::widget::menu $element(name) $options $element(values) attributes] - } - - return $output -} -