template::widget::table::prepare (public)

 template::widget::table::prepare statement_name name [ level ]

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

Compose the query, if necessary, and define the datasources

Parameters:
statement_name (required)
name (required)
level (optional, defaults to "1")

Partial Call Graph (max 5 caller/called nodes):
%3 template::widget::table::create template::widget::table::create (public) template::widget::table::prepare template::widget::table::prepare template::widget::table::create->template::widget::table::prepare db_multirow db_multirow (public) template::widget::table::prepare->db_multirow export_vars export_vars (public) template::widget::table::prepare->export_vars

Testcases:
No testcase defined.
Source code:

    upvar $level "tablewidget:${name}" widget

    # Get the rows
    if { ![info exists widget(rows_data)] } {
        if { ![info exists widget(query)] } {
            error "No row datasource available for tablewidget $name"
        }

        # fixme - need to get a statement name here
        set sql_query $widget(query)

        # Append the order by clause, if any
        if { [info exists widget(orderby)] } {
            if { ![regexp -nocase "order +by" $sql_query match] } {
                append sql_query "\n order by"
            }
            append sql_query $widget(orderby)"
        }

        if { [info exists widget(column_def)] } {
        # Convert the column def list to an array for extra speed
            upvar $level "tablewidget:${name}_column_def" column_arr
            array set column_arr $widget(column_def)
            set eval_code "set row(row_html) \"\"\n"

            # Process each column and append its presentation to the row html
            foreach {column_name column} $widget(column_def) {
                set presentation [lindex $column 2]
                set row_key "${column_name}_html"

                # Make sure there are no empty values that cause tables to
                # look ugly
                append eval_code "if \{ \[template::util::is_nil row($column_name) \] \} \{
                set $column_name \" \"
                \} else \{
                set $column_name \$row($column_name)
            \}
            "

            # Append to the row html
            if { $presentation ne "" } {
            # Debug !
                regsub -all -- {"} $presentation {\\"} presentation
                append eval_code "set row($row_key) \"$presentation\"\n"
            } else {
                append eval_code "set row($row_key) <td>\$$column_name</td>\n"
            }
            append eval_code "
            append row(row_html) \$row($row_key)
            "
        }

    }

    if { [info exists widget(eval)] } {
        append eval_code $widget(eval)
    }
    uplevel $level "
    db_multirow tw_${name}_rows $statement_name \{$sql_query\} \\
        \{$eval_code\}
    "

    # Get the column definition if it does not exist
    if { ![info exists widget(column_def)] } {
        template::widget::table::default_column_def widget  [expr {$level + 1}]
    }

    } else {
        uplevel $level "uplevel 0 tw_${name}_rows $widget(rows_data)"
        template::widget::table::default_column_def widget  [expr {$level + 1}]
    }

    # Process the rows datasource and get the columns
    if { ![info exists widget(columns_data)] } {
        upvar $level "tw_${name}_columns:rowcount" rowcount

        # Get the base url for the page
        set url [export_vars  -base [ns_conn url]  -entire_form  -exclude [list "tablewidget:${name}_orderby"]]

        set the_joiner [expr {[string first ? $url] >= 0 ? "&" : "?"}]

        # Convert the column def into a multirow datasource
        set rowcount 0
        foreach {column_name column} $widget(column_def) {
            incr rowcount
            upvar $level "tw_${name}_columns:$rowcount" row
            set row(rownum) $rowcount
            set row(colnum) $rowcount
            set row(name) $column_name

            lassign $column label orderby_clause
            if {$label eq ""} {
                set label $column_name
            }
            if {$orderby_clause eq ""} {
                set orderby_clause $column_name
            }

            if { [info exists widget(orderby)] && $column_name eq $widget(orderby) } {
                set row(html) "<b>$label</b>"
                set row(selected) "t"
            } else {
                set row(html)    "<a href=\"[ns_quotehtml ${url}${the_joiner}tablewidget:${name}_orderby\=$row(name)]\">"
                append row(html) "$label</a>"
                set row(selected) "f"
            }
        }
    } else {
        uplevel $level "uplevel 0 tw_${name}_columns $template(columns_data)"
    }
XQL Not present:
Generic, PostgreSQL, Oracle
[ hide source ] | [ make this the default ]
Show another procedure: