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.3 -r1.4 --- openacs-4/packages/acs-templating/tcl/data-procs.tcl 19 Jan 2002 03:55:16 -0000 1.3 +++ openacs-4/packages/acs-templating/tcl/data-procs.tcl 13 Sep 2002 10:54:05 -0000 1.4 @@ -98,3 +98,23 @@ transform::$type $value_ref } } + +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] && ![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.10 -r1.11 --- openacs-4/packages/acs-templating/tcl/widget-procs.tcl 1 Sep 2002 02:24:57 -0000 1.10 +++ openacs-4/packages/acs-templating/tcl/widget-procs.tcl 13 Sep 2002 10:54:05 -0000 1.11 @@ -383,3 +383,67 @@ 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:"] } { + # 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] + 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 +} +