[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.3, Fri Apr 27 16:02:14 2007 UTC revision 1.9, Wed Jan 16 22:17:51 2008 UTC
# Line 7  Line 7 
7  use strict;  use strict;
8  use warnings;  use warnings;
9    
 use Carp qw( confess );  
   
 use CGI;  
   
 1;  
10    
11  =pod  =pod
12    
# Line 62  Line 57 
57                   entries => {},                   entries => {},
58                   categories => [],                   categories => [],
59                   categories_index => {},                   categories_index => {},
60                     search => 0,
61      };      };
62      bless $self, $class;      bless $self, $class;
63    
# Line 83  Line 79 
79      $self->{entries} = {};      $self->{entries} = {};
80      $self->{categories} = [];      $self->{categories} = [];
81      $self->{categories_index} = {};      $self->{categories_index} = {};
82        $self->{search} = 0;
83      return $self;      return $self;
84  }  }
85    
# Line 117  Line 114 
114  =cut  =cut
115    
116  sub add_category {  sub add_category {
117      my ($self, $category, $url, $target, $right) = @_;      my ($self, $category, $url, $target, $right, $order) = @_;
118    
119      unless ($category) {      unless ($category) {
120          confess 'No category given.';          die 'No category given.';
121        }
122    
123        unless ($order) {
124          $order = scalar(@{$self->{categories}});
125      }      }
126    
127      if (exists($self->{categories_index}->{$category})) {      if (exists($self->{categories_index}->{$category})) {
128          confess "Trying to add category '$category' which already exists.";          die "Trying to add category '$category' which already exists.";
129      }      }
130    
131      $url = '' unless ($url);      $url = '' unless ($url);
# Line 134  Line 135 
135      $self->{categories_index}->{$category} = scalar(@{$self->{categories}});      $self->{categories_index}->{$category} = scalar(@{$self->{categories}});
136    
137      # add the category and link      # add the category and link
138      push @{$self->{categories}}, [ $category, $url, $target, $right ];      push @{$self->{categories}}, [ $category, $url, $target, $right, $order ];
139    
140      # init the entries array for that category      # init the entries array for that category
141      $self->{entries}->{$category} = [];      $self->{entries}->{$category} = [];
# Line 156  Line 157 
157      my ($self, $category) = @_;      my ($self, $category) = @_;
158    
159      unless ($category) {      unless ($category) {
160          confess 'No category given.';          die 'No category given.';
161      }      }
162    
163      my $i = $self->{categories_index}->{$category};      my $i = $self->{categories_index}->{$category};
# Line 185  Line 186 
186      return keys(%{$_[0]->{categories_index}});      return keys(%{$_[0]->{categories_index}});
187  }  }
188    
189    =pod
190    
191    =item * B<search> (I<search_component>)
192    
193    Getter / Setter for the search component of the menu
194    
195    =cut
196    
197    sub search {
198      my ($self, $search) = @_;
199    
200      if (defined($search)) {
201        $self->{search} = $search;
202      }
203    
204      return $self->{search};
205    }
206    
207  =pod  =pod
208    
# Line 200  Line 218 
218  sub add_entry {  sub add_entry {
219      my ($self, $category, $entry, $url, $target) = @_;      my ($self, $category, $entry, $url, $target) = @_;
220    
221      unless ($category and $entry and $url) {      unless ($category and $entry){# and $url) {
222          confess "Missing parameter ('$category', '$entry', '$url').";          die "Missing parameter ('$category', '$entry', '$url').";
223      }      }
224    
225      unless (exists($self->{categories_index}->{$category})) {      unless (exists($self->{categories_index}->{$category})) {
226          confess "Trying to add to non-existant category '$category'.";          die "Trying to add to non-existant category '$category'.";
227      }      }
228    
229      $target = '' unless ($target);      $target = '' unless ($target);
# Line 233  Line 251 
251    my $html = "<div id='menu'>\n";    my $html = "<div id='menu'>\n";
252    $html .= "\t<ul id='nav'>\n";    $html .= "\t<ul id='nav'>\n";
253    
254    foreach (@{$self->{categories}}) {    my @ordered_categories = sort { $a->[4] <=> $b->[4] } @{$self->{categories}};
255      foreach (@ordered_categories) {
256    
257      my ($cat, $c_url, $c_target, $right) = @$_;      my ($cat, $c_url, $c_target, $right, $order) = @$_;
258    
259      # check if a right is required to see this category      # check if a right is required to see this category
260      if (defined($right)) {      if (defined($right)) {
261        unless (defined($application) && ref($application) eq 'WebApplication') {        unless (defined($application) && ref($application) eq 'WebApplication') {
262          confess "When using rights for a menu category, an application reference must be passed.";          die "When using rights for a menu category, an application reference must be passed.";
263        }        }
264        next unless ($application->session->user && $application->session->user->has_right($application, @$right));        next unless ($application->session->user &&
265                       $application->session->user->has_right($application, @$right));
266      }      }
267    
268      my $url = ($c_url) ? qq~href="$c_url"~ : '';      my $url = ($c_url) ? qq~href="$c_url"~ : '';
# Line 257  Line 277 
277        foreach (@{$self->{entries}->{$cat}}) {        foreach (@{$self->{entries}->{$cat}}) {
278    
279          my ($entry, $e_url, $e_target) = @$_;          my ($entry, $e_url, $e_target) = @$_;
280            if ($e_url) {
281          my $target = ($e_target) ? qq~target="$e_target"~ : '';          my $target = ($e_target) ? qq~target="$e_target"~ : '';
282          $html .= qq~\t\t\t<li><a href="$e_url" $target>$entry</a></li>\n~;          $html .= qq~\t\t\t<li><a href="$e_url" $target>$entry</a></li>\n~;
283            } else {
284              $html .= qq~\t\t\t<li>$entry</li>\n~;
285            }
286        }        }
287    
288        $html .= "\t\t</ul>\n";        $html .= "\t\t</ul>\n";
# Line 271  Line 295 
295    
296    $html .= "\t</ul>\n";    $html .= "\t</ul>\n";
297    
   # display user string  
   if ($application->session->user) {  
     $html .= qq~<div id="user" style="padding-top: 4px; padding-right: 5px; text-align: right;">  
                 <img height="15px" src="./Html/user.gif" title="Current User" />  
                 <strong>~ . $application->session->user->firstname . " " . $application->session->user->lastname . qq~</strong></div>~;  
   }  
   
298    $html .= "</div>\n";    $html .= "</div>\n";
299    
300    return $html;    return $html;
301    
302  }  }
303    
304    1;

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

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3