version 1.200, 2009/01/22 14:44:40
|
version 1.202, 2009/02/19 18:01:37
|
Line 2032 END
|
Line 2032 END
|
# An array of following structure: |
# An array of following structure: |
# ({ categorytitle => 'Categorytitle', |
# ({ categorytitle => 'Categorytitle', |
# items => [ |
# items => [ |
# { linktext => 'Text to be displayed', |
# { |
# url => 'URL the link is pointing to, i.e. /adm/site?action=dosomething', |
# linktext => 'Text to be displayed', |
|
# url => 'URL the link is pointing to, i.e. /adm/site?action=dosomething', |
# permission => 'Contains permissions as returned from lonnet::allowed(), |
# permission => 'Contains permissions as returned from lonnet::allowed(), |
# must evaluate to true in order to activate the link', |
# must evaluate to true in order to activate the link', |
# icon => 'icon filename', |
# icon => 'icon filename', |
# alttext => 'alt text for the icon', |
# alttext => 'alt text for the icon', |
# help => 'Name of the corresponding helpfile', |
# help => 'Name of the corresponding helpfile', |
Line 2054 END
|
Line 2055 END
|
# subject to change during this project. |
# subject to change during this project. |
# Don't rely on its current functionality as it might be |
# Don't rely on its current functionality as it might be |
# changed or removed. |
# changed or removed. |
# TODO: |
|
# check for empty values |
|
# -------------------------- |
# -------------------------- |
|
|
sub generate_menu { |
sub generate_menu { |
my @menu = @_; |
my @menu = @_; |
my $menu_html = qq|<div class="LC_columnSection">|; |
|
|
|
foreach my $category (@menu) { #FIXME: insert appropriate classnames for styles when they're finished. |
# usage: $wrap->(element, content, {attribute => value,...}); |
$menu_html .='<div class="LC_ContentBoxSpecial"> |
# output: content enclosed in html conform tags |
<h3 class="LC_hcell">'.mt($category->{'categorytitle'}).'</h3> |
my $wrap = sub { |
<ul class="LC_ListStyleNormal">'; |
return |
foreach my $item ( @{ $category->{items} } ) { |
qq|<$_[0]| |
next unless $item->{'permission'}; |
. join( '', map { qq| $_="${$_[2]}{$_}"| } keys %{ $_[2] } ) |
$menu_html .= qq|<li class="LC_menubuttons_inline_text"><a href="$item->{'url'}" title="|.mt($item->{'linktitle'}).'">'; |
. ($_[1] ? qq|>$_[1]</$_[0]>| : qq|/>|). "\n"; |
if($item->{'icon'}){ |
}; |
$menu_html .= qq|<img class ="LC_noBorder LC_middle" src="/res/adm/pages/$item->{'icon'}" alt="|; |
|
if($item->{'alttext'}){ |
# subs for specific html elements |
$menu_html .= $item->{'alttext'}.'"/></a>'; |
my $h3 = sub { return $wrap->( "h3", @_ ) }; |
} else { #use linktext as alt text for the icon |
my $div = sub { return $wrap->( "div", @_ ) }; |
$menu_html .= qq|$item->{'linktext'}"/></a>|; |
my $ul = sub { return $wrap->( "ul", @_ ) }; |
} |
my $li = sub { return $wrap->( "li", @_ ) }; |
} |
my $a = sub { return $wrap->( "a", @_ ) }; |
$menu_html .= qq|<a href="$item->{'url'}" title="|.mt($item->{'linktitle'}).'">'; |
my $img = sub { return $wrap->( "img", @_ ) }; |
$menu_html .= mt($item->{'linktext'}).'</a>'; |
|
if (exists($item->{'help'})) { |
my @categories; # each element represents the entire markup for a category |
$menu_html .= Apache::loncommon::help_open_topic($item->{'help'}); |
|
} |
foreach my $category (@menu) { |
$menu_html .= '</li>'; |
my @links; # contains the links for the current $category |
} |
foreach my $link (@{$$category{items}}) { |
$menu_html .= '</ul></div>'; |
next unless $$link{permission}; |
|
|
|
# create the markup for the current $link and push it into @links. |
|
# each entry consists of an image and a text optionally followed |
|
# by a help link. |
|
push @links, $li->( |
|
$a->( |
|
$img->("", { |
|
class => "LC_noBorder LC_middle", |
|
src => "/res/adm/pages/$$link{icon}", |
|
alt => mt(defined($$link{alttext}) ? |
|
$$link{alttext} : $$link{linktext}) |
|
}), { |
|
href => $$link{url}, |
|
title => mt($$link{linktitle}) |
|
}). |
|
$a->(mt($$link{linktext}), { |
|
href => $$link{url}, |
|
title => mt($$link{linktitle}), |
|
class => "LC_menubuttons_link" |
|
}). |
|
(defined($$link{help}) ? |
|
Apache::loncommon::help_open_topic($$link{help}) : ''), |
|
{class => "LC_menubuttons_inline_text"}); |
|
} |
|
|
|
# wrap categorytitle in <h3>, concatenate with |
|
# joined and in <ul> tags wrapped @links |
|
# and wrap everything in an enclosing <div> and push it into |
|
# @categories |
|
# such that each element looks like: |
|
# <div><h3>title</h3><ul><li>...</li>...</ul></div> |
|
# the category won't be added if there aren't any links |
|
push @categories, |
|
$div->($h3->(mt($$category{categorytitle}), {class=>"LC_hcell"}). |
|
$ul->(join('' ,@links), {class =>"LC_ListStyleNormal" }), |
|
{class=>"LC_ContentBoxSpecial"}) if scalar(@links); |
} |
} |
$menu_html .= qq|</div>|; |
|
return $menu_html; |
|
} |
|
|
|
|
# wrap the joined @categories in another <div> (column layout) |
|
return $div->(join('', @categories), {class => "LC_columnSection"}); |
|
} |
|
|
1; |
1; |
|
|