ad_table_sort_form

one of the documented procedures in this installation of the ACS
Usage:
ad_table_sort_form   datadef   { type "select" }   { return_url "" }   { item_group "" }   { item "" }   { sort_spec "" }   { allowed "" }
What it does:
builds a form for setting up custom sorts.

An example from the ticket system:

      ad_table_sort_form $tabledef select $return_url ticket_tracker_main_sort $ticket_sort $orderby
    
Defined in: /web/philip/packages/acs-core/table-display-procs.tcl

Source code:


    # first build a map of all available columns 
    set sel_list [ad_table_column_list -sortable t $datadef $allowed]
    
    # build the map of currently selected columns 
    set full_column [split $sort_spec ","]
    set sel_columns [list]
    set direction [list]
    foreach col $full_column {
        regexp {([^*,]+)([*])?} $col match coln dirn
        if {$dirn == "*"} {
            set dirn desc
        } else {
            set dirn asc
        }
        lappend sel_columns $coln
        lappend direction $dirn
    }
    
    set max_columns 4
    set n_sel_columns [llength $sel_columns]

    set html {}
    if {[string compare $item "CreateNewCustom"] == 0} {
        set item {} 
    }
    # now spit out the form fragment.
    if {![empty_string_p $item]} {
        append html "<h2>Editing <strong>$item</strong></h2>"
        append html "<form method=get action=\"/tools/sort-custom\">"
        append html "<input type=submit value=\"Delete this sort\">"
        append html "<input type=hidden name=delete_the_sort value=\"1\">"
        append html "[export_form_vars item_group item]"
        if {![empty_string_p $return_url]} {
            append html "[export_form_vars return_url]"
        }
        append html "</form>"
    }

    append html "<form method=get action=\"/tools/sort-custom\">" 
    if {![empty_string_p $return_url]} {
        append html "[export_form_vars return_url]"
    }
    if {[empty_string_p $item_group]} {
        set item_group [ns_conn url]
    }

    append html "[export_form_vars item_group]"
    if {![empty_string_p $item]} {
        set item_original $item
        append html "[export_form_vars item_original]"
        append html "<input type=submit value=\"Save changes\">"
    } else {
        append html "<input type=submit value=\"Save new sort\">"
    }

    append html "<table>"
    append html "<tr><th>Name:</th><td><input type=text size=60 name=item [export_form_value item]></td></tr>"
    if {![empty_string_p $item]} {
        set item_original item
        append html "[export_form_vars item_original]"
        append html "<tr><td>&nbsp;</td><td><em>Editing the name will rename the sort</em></td></tr>"
    }

    set options "<option value=\"\">---"
    foreach opt $sel_list { 
        append options " <option value=\"[lindex [lindex $datadef $opt] 0]\">[lindex [lindex $datadef $opt] 1]"
    }
    
    for {set i 0} { $i < $max_columns} {incr i} {
        if {$i < $n_sel_columns} {
            set match [lindex $sel_columns $i]
            regsub "(<option )(value=\"$match\">)" $options "\\1 selected \\2" out
        } else { 
            set out $options
        }
        append html "<tr><th>[expr $i + 1]</th><td><select name=\"col\">$out</select>"
        switch [lindex $direction $i] {
            asc {
                append html "<select name=\"dir\"><option value=\"asc\" selected>increasing<option value=\"desc\">decreasing</select>"
            }
            default {
                append html "<select name=\"dir\"><option value=\"asc\">increasing<option value=\"desc\" selected>decreasing</select>"
         
            }
        }
        append html "\n</td></tr>\n"
    }
    append html "</table></form>"

    return $html


philg@mit.edu