[Bio] / WebApplication / WebMenu.pm Repository:
ViewVC logotype

Diff of /WebApplication/WebMenu.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.2, Wed Mar 14 20:19:03 2007 UTC revision 1.3, Fri Apr 27 16:02:14 2007 UTC
# Line 107  Line 107 
107    
108  =pod  =pod
109    
110  =item * B<add_category> (I<category>, I<url>, I<target>)  =item * B<add_category> (I<category>, I<url>, I<target>, I<right>)
111    
112  Adds a category to the menu. I<category> is mandatory and expects the name of the  Adds a category to the menu. I<category> is mandatory and expects the name of the
113  menu category. I<url> is optional and will add a link to the category name in the menu.  menu category. I<url> is optional and will add a link to the category name in the menu.
114  I<target> is optional and defines a href target for that link.  I<target> is optional and defines a href target for that link. The optional I<right>
115    parameter specifies the right a user must have to be able to see this category.
116    
117  =cut  =cut
118    
119  sub add_category {  sub add_category {
120      my ($self, $category, $url, $target) = @_;      my ($self, $category, $url, $target, $right) = @_;
121    
122      unless ($category) {      unless ($category) {
123          confess 'No category given.';          confess 'No category given.';
# Line 133  Line 134 
134      $self->{categories_index}->{$category} = scalar(@{$self->{categories}});      $self->{categories_index}->{$category} = scalar(@{$self->{categories}});
135    
136      # add the category and link      # add the category and link
137      push @{$self->{categories}}, [ $category, $url, $target ];      push @{$self->{categories}}, [ $category, $url, $target, $right ];
138    
139      # init the entries array for that category      # init the entries array for that category
140      $self->{entries}->{$category} = [];      $self->{entries}->{$category} = [];
# Line 216  Line 217 
217    
218  =pod  =pod
219    
220  =item * B<output> ()  =item * B<output> (I<application>)
221    
222  Returns the html output of the menu.  Returns the html output of the menu. I<application> must be a reference to the
223    application this menu is being printed in. This is only neccessary if rights
224    are required for any category to be displayed.
225    
226  =cut  =cut
227    
228  sub output {  sub output {
229    my $self = shift;    my ($self, $application) = @_;
230    
231      return '' unless scalar(@{$self->{categories}});
232    
233    my $html = "<div id='menu'>\n";    my $html = "<div id='menu'>\n";
234    $html .= "\t<ul id='nav'>\n";    $html .= "\t<ul id='nav'>\n";
235    
236    foreach (@{$self->{categories}}) {    foreach (@{$self->{categories}}) {
237    
238      my ($cat, $c_url, $c_target) = @$_;      my ($cat, $c_url, $c_target, $right) = @$_;
239    
240        # check if a right is required to see this category
241        if (defined($right)) {
242          unless (defined($application) && ref($application) eq 'WebApplication') {
243            confess "When using rights for a menu category, an application reference must be passed.";
244          }
245          next unless ($application->session->user && $application->session->user->has_right($application, @$right));
246        }
247    
248      my $url = ($c_url) ? qq~href="$c_url"~ : '';      my $url = ($c_url) ? qq~href="$c_url"~ : '';
249      my $target = ($c_target) ? qq~target="$c_target"~ : '';      my $target = ($c_target) ? qq~target="$c_target"~ : '';
250    
# Line 256  Line 270 
270    }    }
271    
272    $html .= "\t</ul>\n";    $html .= "\t</ul>\n";
273    
274      # display user string
275      if ($application->session->user) {
276        $html .= qq~<div id="user" style="padding-top: 4px; padding-right: 5px; text-align: right;">
277                    <img height="15px" src="./Html/user.gif" title="Current User" />
278                    <strong>~ . $application->session->user->firstname . " " . $application->session->user->lastname . qq~</strong></div>~;
279      }
280    
281    $html .= "</div>\n";    $html .= "</div>\n";
282    
283    return $html;    return $html;

Legend:
Removed from v.1.2  
changed lines
  Added in v.1.3

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3