--- loncom/interface/lonhtmlcommon.pm 2009/01/12 01:37:57 1.197 +++ loncom/interface/lonhtmlcommon.pm 2009/03/31 21:09:36 1.204 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # a pile of common html routines # -# $Id: lonhtmlcommon.pm,v 1.197 2009/01/12 01:37:57 raeburn Exp $ +# $Id: lonhtmlcommon.pm,v 1.204 2009/03/31 21:09:36 kaisler Exp $ # # Copyright Michigan State University Board of Trustees # @@ -1308,14 +1308,15 @@ returns: nothing my ($component,$component_help,$menulink,$helplink,$css_class,$no_mt) = @_; # $css_class ||= 'LC_breadcrumbs'; - my $Str = "\n".''; + $Str1 .= $links.''; # if (defined($component)) { - $Str .= '
    '; + my $Str1 = '
      '; + my $Str = ''; # # Make the faq and bug data cascade my $faq = ''; my $bug = ''; my $help=''; # Crumb Symbol - my $crumbsymbol = ' ▶ '; + my $crumbsymbol = '» '; # The last breadcrumb does not have a link, so handle it separately. my $last = pop(@Crumbs); # @@ -1338,31 +1339,31 @@ returns: nothing no_mt =>$no_mt_descr, }); } - my $links .= - join($crumbsymbol, + my $links .= '
    1. '. + join('
    2. '.$crumbsymbol, map { $faq = $_->{'faq'} if (exists($_->{'faq'})); $bug = $_->{'bug'} if (exists($_->{'bug'})); $help = $_->{'help'} if (exists($_->{'help'})); - my $result = '
    3. {'href'}.'" '; if (defined($_->{'target'}) && $_->{'target'} ne '') { $result .= 'target="'.$_->{'target'}.'" '; } if ($_->{'no_mt'}) { $result .='title="'.$_->{'title'}.'">'. - $_->{'text'}.'
    4. '; + $_->{'text'}.''; } else { $result .='title="'.&mt($_->{'title'}).'">'. - &mt($_->{'text'}).''; + &mt($_->{'text'}).''; } $result; } @Crumbs - ); - $links .= $crumbsymbol if ($links ne ''); + ).''; + $links .= '
    5. '.$crumbsymbol if ($links ne ''); if ($last->{'no_mt'}) { - $links .= '
    6. '.$last->{'text'}.'
    7. '; + $links .= ''.$last->{'text'}.''; } else { - $links .= '
    8. '.&mt($last->{'text'}).'
    9. '; + $links .= ''.&mt($last->{'text'}).''; } # my $icons = ''; @@ -1382,10 +1383,11 @@ returns: nothing $faq,$bug); } # - $Str .= $links.'
'; + $Str .= "\n".'' + .''; + $Str .= '
'; if ($no_mt) { $Str .= $component; } else { @@ -1394,15 +1396,14 @@ returns: nothing if ($icons ne '') { $Str .= ' '.$icons; } - $Str .= '
'."\n"; } - $Str .= '
'."\n"; # # Return the @Crumbs stack to what we started with push(@Crumbs,$last); shift(@Crumbs); # - return $Str; + return "$Str\n$Str1"; } sub clear_breadcrumbs { @@ -1552,7 +1553,7 @@ sub role_select_row { $output = &row_title($title,$css_class); } $output .= qq| - \n|; foreach my $role (@$roles) { my $plrole; if ($role eq 'ow') { @@ -1679,7 +1680,7 @@ sub status_select_row { $output = &row_title($title,$css_class,'LC_pick_box_select'); } $output .= qq| - \n|; foreach my $status_type (sort(keys(%{$types}))) { $output .= ' '; } @@ -2031,10 +2032,11 @@ END # An array of following structure: # ({ categorytitle => 'Categorytitle', # 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(), -# must evaluate to true in order to activate the link', +# must evaluate to true in order to activate the link', # icon => 'icon filename', # alttext => 'alt text for the icon', # help => 'Name of the corresponding helpfile', @@ -2053,42 +2055,74 @@ END # subject to change during this project. # Don't rely on its current functionality as it might be # changed or removed. -# TODO: -# check for empty values # -------------------------- - sub generate_menu { my @menu = @_; - my $menu_html = qq|
|; - foreach my $category (@menu) { #FIXME: insert appropriate classnames for styles when they're finished. - $menu_html .='
-

'.mt($category->{'categorytitle'}).'

-
'; + # usage: $wrap->(element, content, {attribute => value,...}); + # output: content enclosed in html conform tags + my $wrap = sub { + return + qq|<$_[0]| + . join( '', map { qq| $_="${$_[2]}{$_}"| } keys %{ $_[2] } ) + . ($_[1] ? qq|>$_[1]| : qq|/>|). "\n"; + }; + + # subs for specific html elements + my $h3 = sub { return $wrap->( "h3", @_ ) }; + my $div = sub { return $wrap->( "div", @_ ) }; + my $ul = sub { return $wrap->( "ul", @_ ) }; + my $li = sub { return $wrap->( "li", @_ ) }; + my $a = sub { return $wrap->( "a", @_ ) }; + my $img = sub { return $wrap->( "img", @_ ) }; + + my @categories; # each element represents the entire markup for a category + + foreach my $category (@menu) { + my @links; # contains the links for the current $category + foreach my $link (@{$$category{items}}) { + 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

, concatenate with + # joined and in