Index: openacs-4/packages/xowiki/tcl/category-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/xowiki/tcl/category-procs.tcl,v diff -u -r1.3 -r1.4 --- openacs-4/packages/xowiki/tcl/category-procs.tcl 3 Mar 2006 18:58:16 -0000 1.3 +++ openacs-4/packages/xowiki/tcl/category-procs.tcl 18 Apr 2006 00:06:14 -0000 1.4 @@ -1,64 +1,112 @@ namespace eval ::xowiki { - Class CatTree -superclass ::xo::OrderedComposite -parameter order_items_by + # + # ::xowiki::CatTree (category tree) + # + Class CatTree -superclass ::xo::OrderedComposite -parameter {name ""} + CatTree instproc add_to_category { - -category_id - -itemobj - {-pos 0} + -category + -orderby + -itemobj + {-increasing:boolean true} {-open_item:boolean false} } { - set catobj [self]::$category_id - if {![my isobject $catobj]} { - ::xo::OrderedComposite create $catobj - if {[my exists order_items_by]} { - $catobj orderby [my set order_items_by] + set items ${category}::items + if {![my isobject $items]} { + ::xo::OrderedComposite create $items + if {[info exists orderby]} { + set direction [expr {$increasing?"increasing":"decreasing"}] + $items orderby -order $direction $orderby } - $catobj set pos $pos - $catobj set open_requests 0 - my add $catobj } + $items add $itemobj if {$open_item} { - $catobj incr open_requests + $category openTree $itemobj set open_item 1 } - $catobj add $itemobj } + CatTree instproc openTree {} {;} - CatTree instproc render {} { + CatTree instproc render {{-tree_style:boolean false}} { + if {$tree_style} { + #::xowiki::Page requireCSS "/resources/acs-templating/mktree.css" + ::xowiki::Page requireCSS "/resources/xowiki/cattree.css" + ::xowiki::Page requireJS "/resources/acs-templating/mktree.js" + + foreach c [my children] {append content [$c render] \n} + return "" + } else { + Category instmixin Category::section_style + foreach c [my children] {append content [$c render] \n} + Category instmixin "" + return $content + } + } + + # + # ::xowiki::Category + # + + Class Category -superclass ::xo::OrderedComposite -parameter { + level label pos category_id {open_requests 0} + } + Category instproc destroy {} { + my log -- + next + } + Category instproc openTree {} { + my set open_requests 1 + if {[my exists __parent]} {[my set __parent] openTree} + } + + Category instproc render {} { set content "" - foreach c [my children] { - set cat_content "" - foreach i [$c children] { - $i instvar title page_title prefix open_item - set openProps [expr {[info exists open_item] ? [list ] : {}}] - append cat_content [lindex $openProps 0] $prefix " $page_title" [lindex $openProps 1] "
\n" + if {[my isobject [self]::items]} { + foreach i [[self]::items children] { + $i instvar title page_title prefix suffix + set entry "$prefix$page_title$suffix" + append cat_content [my render_item -highlight [$i exists open_item] $entry] } - append content "

[category::get_name [namespace tail $c]]

" \ - $cat_content "
\n" + foreach c [my children] {append cat_content [$c render] \n} + append content [my render_category -open [expr {[my set open_requests]>0}] $cat_content] } return $content } - CatTree instproc render-li {} { - ::xowiki::Page requireCSS "/resources/acs-templating/mktree.css" - ::xowiki::Page requireJS "/resources/acs-templating/mktree.js" - set content "" } + Category instproc render_category {{-open:boolean false} cat_content} { + set open_state [expr {[my set open_requests]>0?"class='liOpen'" : "class='liClosed'"}] + return "
  • [my label]\n \n" + } + # + # These are the section-specific rendering functions + # + + Class Category::section_style + Category::section_style instproc render_item {{-highlight:boolean false} item} { + if {$highlight} { + return "$item
    \n" + } else { + return "$item
    \n" + } + } + Category::section_style instproc render_category {{-open:boolean false} cat_content} { + set section [expr {[my level] + 2}] + return "[my label]\n

    \ +

    $cat_content
    \n" + } + + }