ad_library { Form widgets for the ArsDigita Templating System @author Karl Goldstein (karlg@arsdigita.com) @author Stanislav Freidin (sfreidin@arsdigita.com) @cvs-id $Id: widget-procs.tcl,v 1.64 2019/03/29 11:28:45 gernst Exp $ } # Copyright (C) 1999-2000 ArsDigita Corporation # This is free software distributed under the terms of the GNU Public # License. Full text of the license is available from the GNU Project: # http://www.fsf.org/copyleft/gpl.html namespace eval template {} namespace eval template::widget {} namespace eval template::data {} namespace eval template::data::transform {} ad_proc -public template::widget {} { The template::widget namespace contains the code for the various input widgets. @see template::widget::ampmFragment @see template::widget::button @see template::widget::checkbox @see template::widget::comment @see template::widget::currency @see template::widget::date @see template::widget::dateFragment @see template::widget::file @see template::widget::hidden @see template::widget::inform @see template::widget::input @see template::widget::menu @see template::widget::monthFragment @see template::widget::multiselect @see template::widget::numericRange @see template::widget::password @see template::widget::party_search @see template::widget::radio @see template::util::richtext @see template::widget::search @see template::widget::select @see template::widget::submit @see template::widget::text @see template::widget::textarea @see template::widget::block @see template::element::create @see template::widget::select_text @see template::wdiget::radio_text @see template::widget::checkbox_text } - ad_proc -public template::widget::party_search { element_reference tag_attributes } { A widget that searches for parties (persons, groups and relational_segments) and lets the user select one from the search results.
It only searches in all parties from the system currently. It should propably be extended to
allow one to restrict the search to a specific subsite, as well as searching only
for groups or persons.
@author Tilmann Singer
} {
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 {
set output ""
append output ""
if { ![info exists element(confirmed_p)] } {
append output ""
}
append output [select $element_reference $tag_attributes]
}
return $output
}
ad_proc -public template::data::validate::party_search {
value_ref
message_ref
} {
Validate the party search entry form.
@param value_ref A reference to the value input by the user.
@param message_ref A reference to the form element error field.
@return true - all input for this datatype is valid.
} {
return 1
}
ad_proc -private template::data::transform::party_search {
element_ref
} {
Do the actual search of parties using the input value and return a list of lists
consisting of (party_name, party_id).
DRB: The blank string check should actually be in the validate procedure.
@param element_ref Reference variable to the form element.
@return search result or error
} {
upvar $element_ref element
set element_id $element(id)
set value [string trim [ns_queryget $element_id]]
set is_optional [info exists element(optional)]
if { $value eq "" } {
if { [string is true $is_optional] } {
return ""
} else {
template::element::set_error $element(form_id) $element_id "Please enter a search string."
return [list]
}
}
if {$value eq ":search:"} {
# user has selected 'search again' previously
template::element::set_error $element(form_id) $element_id "Please enter a search string."
return [list]
}
if { [ns_queryexists $element_id:search_string] } {
# request comes from a page with a select widget and the
# search string has been passed as hidden value
set search_string [ns_queryget $element_id:search_string]
set element(search_string) $search_string
# the value to be returned
set value [ns_queryget $element_id]
} else {
# request is an initial search
set search_string $value
set element(search_string) $value
}
# search in persons
set persons [db_list_of_lists search_persons {}]
# search in groups and relsegs
set groups_relsegs [db_list_of_lists search_groups_relsegs {}]
# Localize the groups
set groups_relsegs [lang::util::localize_list_of_lists -list $groups_relsegs]
if { [llength $persons] == 0 && [llength $groups_relsegs] == 0 } {
# no search results so return text entry back to the user
unset -nocomplain element(options)
template::element::set_error $element(form_id) $element_id [subst {
No matches were found for "[ns_quotehtml $search_string]".
Please try again.
}]
} else {
# we need to return a select list
set options [list]
if { [llength $persons] > 0 } {
set options $persons
lappend options [list "---" ""]
}
if { [llength $groups_relsegs] > 0 } {
lappend options {*}$groups_relsegs [list "---" ""]
}
set element(options) [concat $options { { "Search again..." ":search:" } }]
if { ![info exists value] } {
# set value to first item
set value [lindex $options 0 1]
}
if { ![ns_queryexists $element_id:confirmed_p] } {
template::element::set_error $element(form_id) $element_id "Please choose an entry."
}
}
if { [info exists element(result_datatype)]
&& [ns_queryexists $element_id:select] } {
set element(datatype) $element(result_datatype)
}
return $value
}
ad_proc -public template::widget::search {
element_reference
tag_attributes
} {
Return a widget consisting of either a search box or a search pull-down list.
Here is an example of using the search widget with ad_form:
ad_form -name test -form { {user:search,optional {result_datatype integer} {label "Email"} {help_text "Search for a user by email address"} {search_query { select email from cc_users where lower(email) like '%'||lower(:value)||'%' }} } }Can be either a select widget initially if options supplied or a text box which on submit changes to a select widget. @param element_reference Reference variable to the form element @param tag_attributes If the "options" attribute is passed in, a select widget is created, otherwise a search text box. @return Form HTML for widget } { 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 \ [subst {\n}] \ [select element $tag_attributes] } return $output } ad_proc -public template::widget::textarea { element_reference tag_attributes } { A widget for the HTML form input textarea element. Includes spellchecker. @see template::util::spellcheck::spellcheck_properties @param element_reference Reference to the form element. @param tag_attributes Html attributes to set in the widget. @return Form HTML for widget } { upvar $element_reference element if { [info exists element(html)] } { array set attributes $element(html) } array set attributes $tag_attributes if { [info exists element(value)] } { set value $element(value) } else { set value {} } if { [info exists element(mode)] } { set mode $element(mode) } else { set mode {} } set attributes(id) $element(name) set output [textarea_internal $element(name) attributes $value $mode] # Spell-checker array set spellcheck [template::util::spellcheck::spellcheck_properties -element_ref element] if { $element(mode) eq "edit" && $spellcheck(render_p) } { append output "