%3 ::xowiki::Includelet ::xowiki::Includelet → html_encode ::xo::Context ::xo::Context exists_query_parameter export_vars get_parameters original_url_and_query process_query_parameter ::xowiki::Includelet->::xo::Context ::xotcl::Object ::xotcl::Object ::xo::Context->::xotcl::Object ::xowiki::includelet::toc ::xowiki::includelet::toc build_toc initialize render render_list render_yui_list ::xowiki::includelet::toc->::xowiki::Includelet ::xowiki::includelet::PageReorderSupport ::xowiki::includelet::PageReorderSupport ::xowiki::includelet::toc->::xowiki::includelet::PageReorderSupport

Class ::xowiki::includelet::toc

::xowiki::includelet::toc[i] create ... \
           [ -__decoration (default "plain") ] \
           [ -id id ] \
           [ -parameter_declaration (default " {-style ""} {-renderer ""} {-open_page ""} {-book_mode false} {-folder_mode false} {-ajax false} {-expand_all false} {-remove_levels 0} {-category_id} {-locale ""} {-orderby ""} {-source ""} {-range ""} {-allow_reorder ""} {-include_in_foldertree "true"} {-CSSclass_top_ul ""} {-CSSclass_ul ""} ") ]

Show table of contents of the current wiki. The "toc" includelet renders the page titles of the current files based on the value of the "page_order" attributes. Only those pages are rendered that have a nonempty "page_order" field.
Defined in /var/www/openacs.org/packages/xowiki/tcl/includelet-procs.tcl

Class Relations

  • class: ::xowiki::IncludeletClass[i]
  • superclass: ::xowiki::Includelet[i]
  • instmixin: ::xowiki::includelet::PageReorderSupport[i]
::xowiki::IncludeletClass create ::xowiki::includelet::toc \
     -superclass ::xowiki::Includelet \
     -instmixin ::xowiki::includelet::PageReorderSupport

Methods (to be applied on instances)

  • build_toc (scripted)

     <instance of xowiki::includelet::toc[i]> build_toc

    Testcases:
    includelet_toc, xowiki
    :get_parameters
    array set :navigation {parent "" position 0 current ""}
    
    set extra_where_clause ""
    if {[info exists :category_id]} {
      lassign [:category_clause ${:category_id}] cnames extra_where_clause
    }
    lassign [::xowiki::Includelet locale_clause -revisions p -items p $package_id $locale]  locale locale_clause
    #:msg locale_clause=$locale_clause
    set order_direction asc
    set order_attribute page_order
    
    if {$source ne ""} {
      :get_page_order -source $source
      set page_order_clause "and name in ([ns_dbquotelist [array names :page_order]])"
      set page_order_att ""
    } elseif {$orderby ne ""} {
      lassign [split $orderby ,] order_attribute order_direction
      if {$order_attribute ni {page_order title}} {
        ns_log warning "toc includelet: ignore invalid page order '$orderby'"
        set order_attribute page_order
        set order_direction asc
        set page_order_att "page_order,"
        set page_order_clause "and not page_order is NULL"
      } else {
        set page_order_att "page_order,"
        set page_order_clause ""
        append extra_where_clause " and page_id != [${:__including_page} revision_id]"
      }
    } else {
      set page_order_clause "and not page_order is NULL"
      set page_order_att "page_order,"
    }
    
    if {$folder_mode} {
      # TODO just needed for Michael Aram?
      set parent_id [${:__including_page} item_id]
    } else {
      #set parent_id [::$package_id folder_id]
      set parent_id [${:__including_page} parent_id]
    }
    
    set sql [::xo::dc select  -vars "page_id, $page_order_att name, title"  -from "xowiki_page_live_revision p"  -where "parent_id = :parent_id  $page_order_clause  $extra_where_clause $locale_clause"]
    set pages [::xowiki::Page instantiate_objects -sql $sql]
    
    #
    # Set the mixin for page-order before the call of __value_compare.
    # Probably, we should use here a different approach to support as well
    # sorting by different attributes.
    #
    $pages orderby  -order [expr {$order_direction in {asc ""} ? "increasing" : "decreasing"}]  -type [ad_decode $order_attribute page_order index dictionary]  $order_attribute
    
    if {$range ne "" && $page_order_att ne ""} {
      lassign [split $range -] from to
      foreach p [$pages children] {
        if {[$pages __value_compare [$p set page_order] $from 0] == -1
            || [$pages __value_compare [$p set page_order] $to 0] > 0} {
          $pages delete $p
        }
      }
    }
    
    if {$source ne ""} {
      # add the page_order to the objects
      foreach p [$pages children] {
        $p set page_order [set :page_order([$p set name])]
      }
    }
    
    return $pages
  • initialize (scripted)

     <instance of xowiki::includelet::toc[i]> initialize

    Testcases:
    includelet_toc, xowiki
    :get_parameters
    array set :navigation {count 0 position 0 current ""}
    set list_mode 0
    dict set :render_properties CSSclass_ul $CSSclass_ul
    dict set :render_properties CSSclass_top_ul $CSSclass_top_ul
    
    #
    # If there is no renderer specified, determine the renderer from
    # the (provided) style. When the render is explicitly specified,
    # use it for rendering.
    #
    if {$renderer eq ""} {
      switch -- $style {
        "menu"    {set renderer yuitree}
        "folders" {set renderer yuitree}
        "yuitree" {set renderer "yuitree"}
        "list"    {set style ""set list_mode 1; set renderer list}
        "none"    {set style ""set renderer none}
        "default" {set style ""set list_mode 1; set renderer list
          #
          # Fall back to "xowiki-tree" for "CSSclass_ul" only when
          # value was not specified as a parameter.
          #
          if {$CSSclass_ul eq ""} {
            dict set :render_properties CSSclass_ul xowiki-tree
          }
        }
      }
      set :use_tree_renderer 0
    } else {
      set :use_tree_renderer 1
    }
    
    set :include_in_foldertree $include_in_foldertree
    set :renderer $renderer
    set :style $style
    set :list_mode $list_mode
    set :book_mode $book_mode
  • render (scripted)

     <instance of xowiki::includelet::toc[i]> render

    Testcases:
    includelet_toc, xowiki
    :get_parameters
    
    if {![info exists :id]} {
      set :id [::xowiki::Includelet html_id [self]]
    }
    if {[info exists category_id]} {
      set :category_id $category_id
    }
    
    #
    # Collect the pages which are either children of the page, or
    # children of the parent of the page depending on "folder_mode".
    #
    set pages [:build_toc $package_id $locale $source $range]
    
    #foreach p [$pages children] {
    #  ns_log notice "... [$p set page_order] [$p set name]"
    #}
    
    #
    # Build the general navigation structure using associative arrays
    #
    :build_navigation $pages
    #
    # Call a render on the created structure
    #
    if {[nsf::is object ::__xowiki__MenuBar] && ${:include_in_foldertree}} {
      ::__xowiki__MenuBar additional_sub_menu -kind folder -pages $pages -owner [self]
    }
    #
    # TODO: We should call here the appropriate tree-renderer instead
    # of the toc-specific renderers, but first we have to check, if
    # these are fully feature-compatible.
    #
    #:log "=== toc render with <${:renderer}> treerenderer ${:use_tree_renderer} list_mode <${:list_mode}>"
    if {${:renderer} eq "none"} {
    } elseif {${:use_tree_renderer}} {
      return [:render_tree -full 1 $pages]
    } elseif {${:list_mode}} {
      return [:render_list $pages]
    } else {
      return [:render_yui_list -full true $pages]
    }
  • render_list (scripted)

     <instance of xowiki::includelet::toc[i]> render_list

    Testcases:
    includelet_toc, xowiki
    :get_parameters
    
    #
    # Build a reduced toc tree based on pure HTML (no JavaScript or
    # AJAX involved).  If an open_page is specified, produce an as
    # small as possible tree and omit all non-visible nodes.
    #
    if {$open_page ne ""} {
      # TODO: can we allow open_page and reorder?
      set allow_reorder ""
    } else {
      set allow_reorder [:page_reorder_check_allow -with_head_entries false $allow_reorder]
    }
    set tree [::xowiki::Tree new -id [:id] -destroy_on_cleanup]
    $tree array set open_node [array get :open_node]
    $tree add_pages -full $full  -remove_levels $remove_levels  -book_mode $book_mode -open_page $open_page -expand_all $expand_all  -owner [self]  -properties ${:render_properties}  $pages
    
    if {$allow_reorder ne ""} {
      :page_reorder_init_vars -allow_reorder $allow_reorder js last_level ID min_level
      #set js "\nYAHOO.xo_page_order_region.DDApp.package_url = '[::$package_id package_url]';"
      set HTML [$tree render -style listdnd -context [list min_level $min_level]]
    } else {
      set HTML [$tree render -style list -properties ${:render_properties}]
    }
    
    return $HTML
  • render_yui_list (scripted)

     <instance of xowiki::includelet::toc[i]> render_yui_list

    Testcases:
    includelet_toc, xowiki
    :get_parameters
    
    #
    # Render the tree with the yui widget (with or without ajax)
    #
    if {$book_mode} {
      #:log "--warn: cannot use bookmode with ajax, resetting ajax"
      set ajax 0
    }
    set :ajax $ajax
    
    if {$ajax} {
      set :js [:yui_ajax]
    } else {
      set :js [:yui_non_ajax]
    }
    
    set tree [::xowiki::Tree new -id [:id] -destroy_on_cleanup]
    $tree array set open_node [array get :open_node]
    $tree add_pages -full $full -remove_levels $remove_levels  -book_mode $book_mode -open_page $open_page -expand_all $expand_all  -owner [self]  $pages
    
    set HTML [$tree render -style yuitree -js ${:js}]
    return $HTML