template::list::prepare_filter_form (private)
template::list::prepare_filter_form [ -name name ] \ [ -filter_exclude_from_key_extra filter_exclude_from_key_extra ]
Defined in packages/acs-templating/tcl/list-procs.tcl
Documentation goes here
- Switches:
- -name (optional)
- -filter_exclude_from_key_extra (optional)
- Partial Call Graph (max 5 caller/called nodes):
- Testcases:
- No testcase defined.
Source code: set level [template::adp_level] # Provide a reference to the list properties for use by the list template # Get an upvar'd reference to list_properties get_reference -name $name set filter_names_options_tmp [list] set filter_names_options [list] set filter_hidden_filters [list] set filter_key_filters [list] set filter_exclude_from_key [list orderby groupby format page __list_view] if {[llength $filter_exclude_from_key_extra]} { lappend filter_exclude_from_key {*}$filter_exclude_from_key_extra } set filter_hidden_filters_url_vars [list] # loop through all the filters in this list foreach filter_ref $list_properties(filter_refs) { upvar #$level $filter_ref filter_properties if {$filter_properties(label) ne "" && $filter_properties(name) ni $filter_exclude_from_key} { # filters with a label will be added to the form for the user # to choose from lappend filter_names_options_tmp [list $filter_properties(label) $filter_properties(name)] } # filters without a label are added as hidden elements # to the form so that quer params for the list # and group by/order by are preserved when the filter # form is used # Grab the current value of the filter out of the list if # it exists. upvar $list_properties(ulevel) $filter_properties(name) current_filter_value if {[info exists current_filter_value] && $current_filter_value ne ""} { if {[lsearch $filter_exclude_from_key $filter_properties(name)] > -1} { lappend filter_hidden_filters $filter_properties(name) } else { lappend filter_key_filters $filter_properties(name) $current_filter_value } } } upvar #[template::adp_level] __list_filter_form_client_property_key list_filter_form_client_property_key # To save the client property name, it is hashed with ns_sha1 hash # to fit it into toe attribute. We don't extract the data from the # property name so this should work fine. set list_filter_form_client_property_key [ns_sha1 [list [ad_conn url] $name]] upvar \#[template::adp_level] __client_property_filters client_property_filters set client_property_filters [ad_get_client_property acs-templating $list_filter_form_client_property_key] # take out filters we already applied... set i 0 foreach option_list $filter_names_options_tmp { lassign $option_list option_label option_name if {"${name}:filter:${option_name}:properties" ni $client_property_filters} { lappend filter_names_options [list $option_label $option_name] } } # build an ad_form form based on the chosen filters set filters_form_name list-filters-$name set add_filter_form_name list-filter-add-$name ad_form -name $add_filter_form_name -form { {choose_filter:text(select) {label "Add Filter"} {options {$filter_names_options}} } {name:text(hidden) {value $name}} {add_filter:text(submit) {label "Add"}} {clear_all:text(submit) {label "Clear All"}} {clear_one:text(hidden),optional} } foreach fhf $filter_hidden_filters { ad_form -extend -name $add_filter_form_name -form { {$fhf:text(hidden),optional} } } ad_form -extend -name $add_filter_form_name -on_request { # setup little Xs to click to clear one field # pass the name of the field in the clear_one variable set clear_one [ns_queryget clear_one] if {$clear_one ne ""} { # # Loop through the saved filters and remove the filter # from the client property if its specified in clear_one. # set __old_client_property_filters [ad_get_client_property acs-templating $__list_filter_form_client_property_key] set __client_property_filters [list] foreach {__ref __value} $__old_client_property_filters { if {[set ${__ref}(name)] ne $clear_one} { lappend __client_property_filters $__ref $__value } } # # If we changed the list of filters, save it in the # client property, we read it later on to build the # form of selected filters # set client_property_filters $__client_property_filters ad_set_client_property acs-templating $__list_filter_form_client_property_key $__client_property_filters # # Now reload the form, excluding variable clear_one. # set pattern [ns_urlencode "clear_one"]=[ns_urlencode "$clear_one"] regsub "${pattern}&?" [ad_return_url] {} url ad_returnredirect $url ad_script_abort } } -on_submit { if {[info exists clear_all] && $clear_all ne ""} { set __client_property_filters {} ad_set_client_property acs-templating $__list_filter_form_client_property_key $__client_property_filters break } template::list::get_reference -name $name foreach filter_ref $list_properties(filter_refs) { upvar \#[template::adp_level] $filter_ref filter_properties if {$filter_properties(name) eq $choose_filter} { lappend __client_property_filters $filter_ref "" } } ad_set_client_property acs-templating $__list_filter_form_client_property_key $__client_property_filters } # Create the form that holds the actual filter values ad_form -name $filters_form_name -has_submit 1 -form { {name:text(hidden) {value $name}} } # we need to pass the hidden list filters in this form too # since we need to preserve the other variables if either # the add filter or the apply filter form is submitted foreach fhf $filter_hidden_filters { ad_form -extend -name $filters_form_name -form { {$fhf:text(hidden),optional} } upvar \#[template::adp_level] $name:filter:${fhf}:properties filter_properties set filter_properties(widget) hidden set filter_properties(selected_p) t } # we need to extract the values of the hidden filters out of the # form elements, there is some magic here where ad_form # grabs the elements out of the form/url vars and # sets them, we want to pull them out of the form instead of # setting local variables to prevent collisions foreach fhf $filter_hidden_filters { lappend filter_hidden_filters_url_vars [list $fhf [template::element::get_value $add_filter_form_name $fhf]] } set visible_filters_p 0 # add a select box for filters with a list of valid values # otherwise add a regular text box foreach {f_ref f_value} $client_property_filters { upvar \#[template::adp_level] $f_ref filter_properties if {$filter_properties(label) ne "" && $filter_properties(hide_p) eq 0 && $filter_properties(name) ni $filter_exclude_from_key} { incr visible_filters_p } if {![template::element::exists $filters_form_name $filter_properties(name)]} { # extract options set options [list] foreach elm $filter_properties(values) url $filter_properties(urls) selected_p $filter_properties(selected_p) add_url $filter_properties(add_urls) { # Loop over 'values' and 'url' simultaneously # 'label' is the first element, 'value' the second # We do an lrange here, otherwise values would be set wrong # in case someone accidentally supplies a list with too many elements, # because then the foreach loop would run more than once foreach { label value count } [lrange $elm 0 2] {} if { [string is space $label] } { set label $filter_properties(null_label) } lappend options [list $label $value] } set clear_url_vars [concat [list [list clear_one $filter_properties(name)]] $filter_hidden_filters_url_vars] set filter_properties(clear_one_url) [export_vars -base [ad_conn url] $clear_url_vars] set form_element(element_name) $filter_properties(name) set form_element(widget) text set form_element(datatype) text if {[llength $options]} { set form_element(widget) select set form_element(options) $options } set form_element(label) "$filter_properties(label)" if {[info exists filter_properties(form_element_properties)]} { foreach {var value} $filter_properties(form_element_properties) { set form_element($var) $value } } set ad_form_element [list ${form_element(element_name)}:${form_element(datatype)}(${form_element(widget)}),optional] if {$filter_properties(type) eq "multival"} { set ad_form_element [list "[lindex $ad_form_element 0],multiple"] } foreach {var value} [array get form_element] { if {$var ni {name widget datatype}} { lappend ad_form_element [list $var $value] } } ad_form -extend -name $filters_form_name -form [list $ad_form_element] set filter_properties(widget) $form_element(widget) set filter_properties(selected_p) t array unset form_element } } ad_form -extend -name $filters_form_name -on_request { foreach {f_ref f_value} $__client_property_filters { upvar \#[template::adp_level] $f_ref filter_properties set $filter_properties(name) $f_value } } -on_submit { # set the values of the filters, the creator of the list # still has to process the values to generate a valid # where clause template::list::get_reference -name $name set templist [list] foreach {f_ref f_value} $__client_property_filters { upvar \#[template::adp_level] $f_ref filter_properties set filter_properties(value) [set $filter_properties(name)] lappend templist $f_ref $filter_properties(value) # hack in elements?? if {$filter_properties(name) in [template::multirow columns $list_properties(multirow)]} { # FIXME Don't do this where, don't allow filters for # matching element/filter names if element does not exist # check if its a dynamic element...(has select_clause) list::element::create -list_name $name -element_name $filter_properties(name) -spec [list label $filter_properties(label)] } } set __client_property_filters $templist ad_set_client_property acs-templating $__list_filter_form_client_property_key $__client_property_filters } # only show the submit button for the apply filters form if # there are filters selected by the user if {$visible_filters_p} { ad_form -extend -name $filters_form_name -form { {submit:text(submit) {label "Apply Filters"}} } } else { # hard to figure out how to conditionally handle this in the # ad_form -extend -name $filters_form_name -form { {submit:text(hidden),optional} } }XQL Not present: Generic, PostgreSQL, Oracle