template::list::prepare_filters (private)

 template::list::prepare_filters -name name \
    [ -filter_names filter_names ]

Defined in packages/acs-templating/tcl/list-procs.tcl

Builds urls, selected_p, etc., for filters

Switches:
-name
(required)
-filter_names
(optional)

Partial Call Graph (max 5 caller/called nodes):
%3 template::list::prepare template::list::prepare (public) template::list::prepare_filters template::list::prepare_filters template::list::prepare->template::list::prepare_filters template::adp_level template::adp_level (public) template::list::prepare_filters->template::adp_level template::list::element::get_reference template::list::element::get_reference (public) template::list::prepare_filters->template::list::element::get_reference template::list::get_reference template::list::get_reference (public) template::list::prepare_filters->template::list::get_reference template::list::get_url template::list::get_url (private) template::list::prepare_filters->template::list::get_url util_sets_equal_p util_sets_equal_p (public) template::list::prepare_filters->util_sets_equal_p

Testcases:
No testcase defined.
Source code:
    set level [template::adp_level]

    # Get an upvar'd reference to list_properties
    get_reference -name $name

    if {[info exists filter_names]} {
        set filter_refs [list]
        foreach filter_name $filter_names {
            lappend filter_refs ${name}:filter:${filter_name}:properties
        }

    } else {
        set filter_refs $list_properties(filter_refs)
    }
    # Construct URLs for the filters now, while we still have access to the caller's namespace
    foreach filter_ref $list_properties(filter_refs) {
        upvar #$level $filter_ref filter_properties

        upvar $list_properties(ulevel) $filter_properties(name) current_filter_value

        # Set to default value if undefined
        if { (![info exists current_filter_value] || $current_filter_value eq "")
             && $filter_properties(default_value) ne "" } {
            set current_filter_value $filter_properties(default_value)
        }

        # Does the filter have a current value?
        if { [info exists current_filter_value] } {

            # Get the where clause
            if { $current_filter_value eq "" } {
                set search_order { null_where_clause_eval null_where_clause where_clause_eval where_clause }
            } else {
                set search_order { where_clause_eval where_clause }
            }

            foreach property $search_order {
                if { $filter_properties($property) ne "" } {
                    # We've found a where_clause to include

                    if { [string match "*_eval" $property] } {
                        # It's an _eval, subst it now
                        lappend list_properties(filter_where_clauses)  [uplevel $list_properties(ulevel) $filter_properties($property)]
                    } else {
                        # Not an eval, just add it straight
                        lappend list_properties(filter_where_clauses) $filter_properties($property)
                    }
                    break
                }
            }
            # Get the clear_url
            if { ![string is true -strict $filter_properties(has_default_p)] } {
                    set filter_properties(clear_url) [get_url  -name $name  -exclude [list $filter_properties(name)]]
                }
            # Remember the filter value
            set list_properties(filter,$filter_properties(name)$current_filter_value
            # get the from clause
            # check if there is a dynamic column
            # see if we have an element with the same name
            if {[lsearch $list_properties(elements) $filter_properties(name)] > -1} {
                template::list::element::get_reference -list_name $name -element_name $filter_properties(name)

                if {[info exists element_properties(from_clause_eval)]
                    && $element_properties(from_clause_eval) ne ""
                    && [lsearch $list_properties [string trim [uplevel $list_properties(ulevel) $filter_properties($property)]]] < 0} {
                    lappend list_properties(from_clauses)  [uplevel $list_properties(ulevel) $filter_properties($property)]
                } elseif {[info exists element_properties(from_clause)]
                          && $element_properties(from_clause) ne ""
                          && [lsearch $list_properties(from_clauses) [string trim $element_properties(from_clause)]] < 0} {
                    lappend list_properties(from_clauses) [string trim $filter_properties(from_clause)]
                }
            }
            # get the select clause
            if {$filter_properties(select_clause_eval) ne ""
                && [lsearch $list_properties(element_select_clauses) $filter_properties(select_clause_eval)] < 0} {
                lappend list_properties(filter_select_clauses)  [uplevel $list_properties(ulevel) $filter_properties(select_clause_eval)]
            } elseif {$filter_properties(select_clause) ne ""
                      && [lsearch $list_properties(element_select_clauses) $filter_properties(select_clause)] < 0} {
                lappend list_properties(filter_select_clauses) $filter_properties(select_clause)
            }
        }

        # If none was found, we may need to provide an 'other' entry below
        set found_selected_p 0

        # Now generate selected_p, urls, add_urls
        foreach elm $filter_properties(values) {

            # Set label, value and count from the list element
            lassign $elm label value count

            if { [string is space $label] } {
                set label $filter_properties(null_label)
            }
            switch -- $filter_properties(type) {
                singleval {
                    set selected_p [expr {[info exists current_filter_value] && $current_filter_value eq $value}]
                }
                multival {
                    if { ![info exists current_filter_value] || $current_filter_value eq "" } {
                        set selected_p 0
                    } else {
                        # Since here we have multiple values
                        # we set as selected_p the value that match any
                        # of the values present in the list
                        set selected_p 0
                        foreach val $current_filter_value {
                            if { [util_sets_equal_p $val $value] } {
                                set selected_p 1
                                break
                            }
                        }
                    }
                }
                multivar {
                    # Value is a list of { key value } lists
                    # We only check the value whose key matches the filter name
                    set selected_p 0
                    foreach elm $value {
                        foreach { elm_key elm_value } [lrange $elm 0 1] {}
                        if {$elm_key eq $filter_properties(name)} {
                            set selected_p [expr {[info exists current_filter_value] && $current_filter_value eq $elm_value}]
                        }
                    }
                }
            }
            # DAVEB Make multivar actually DO something
            # set the other vars according to the settings
            if {$selected_p && $filter_properties(type) eq "multivar"} {
                foreach elm $value {
                    foreach { elm_key elm_value } [lrange $elm 0 1] {}
                    if {$elm_key ne $filter_properties(name)} {
                        set list_properties(filter,$elm_key$elm_value
                    }
                }
            }

            lappend filter_properties(selected_p) $selected_p
            set found_selected_p [expr {$found_selected_p || $selected_p}]

            if { $selected_p } {
                # Remember the filter label
                set list_properties(filter_label,$filter_properties(name)$label
            }

            # Generate url and add to filter(urls)
            switch -- $filter_properties(type) {
                singleval - multival {
                    lappend filter_properties(urls) [get_url  -name $name  -override [list [list $filter_properties(var_spec) $value]]]
                }
                multivar {
                    # We just use the value-list directly
                    lappend filter_properties(urls) [get_url  -name $name  -override $value]
                }
            }

            # Generate add_url, and add to filter(add_urls)
            if { [info exists filter_properties(add_url_eval)] && $filter_properties(add_url_eval) ne "" } {
                upvar $list_properties(ulevel) __filter_value __filter_value
                set __filter_value $value
                lappend filter_properties(add_urls) [uplevel $list_properties(ulevel) subst $filter_properties(add_url_eval)]
            }


            # Handle 'other_label'
            if { [info exists current_filter_value] && $current_filter_value ne ""
                 && !$found_selected_p
                 && $filter_properties(other_label) ne ""
             } {
                # Add filter entry with the 'other_label'.
                lappend filter_properties(values) [list $filter_properties(other_label) {}]
                lappend filter_properties(urls) {}
                lappend filter_properties(selected_p) 1
            }
        }
    }
XQL Not present:
Generic, PostgreSQL, Oracle
[ hide source ] | [ make this the default ]
Show another procedure: