[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.4, Thu Jun 14 16:34:57 2007 UTC revision 1.8, Thu Dec 6 16:11:19 2007 UTC
# Line 6  Line 6 
6    
7  use strict;  use strict;
8  use warnings;  use warnings;
9    use Tracer;
10    
 use Carp qw( confess );  
   
 use CGI;  
   
 1;  
11    
12  =pod  =pod
13    
# Line 62  Line 58 
58                   entries => {},                   entries => {},
59                   categories => [],                   categories => [],
60                   categories_index => {},                   categories_index => {},
61                     search => 0,
62      };      };
63      bless $self, $class;      bless $self, $class;
64    
# Line 83  Line 80 
80      $self->{entries} = {};      $self->{entries} = {};
81      $self->{categories} = [];      $self->{categories} = [];
82      $self->{categories_index} = {};      $self->{categories_index} = {};
83        $self->{search} = 0;
84      return $self;      return $self;
85  }  }
86    
# Line 120  Line 118 
118      my ($self, $category, $url, $target, $right, $order) = @_;      my ($self, $category, $url, $target, $right, $order) = @_;
119    
120      unless ($category) {      unless ($category) {
121          confess 'No category given.';          die 'No category given.';
122      }      }
123    
124      unless ($order) {      unless ($order) {
# Line 128  Line 126 
126      }      }
127    
128      if (exists($self->{categories_index}->{$category})) {      if (exists($self->{categories_index}->{$category})) {
129          confess "Trying to add category '$category' which already exists.";          die "Trying to add category '$category' which already exists.";
130      }      }
131    
132      $url = '' unless ($url);      $url = '' unless ($url);
# Line 160  Line 158 
158      my ($self, $category) = @_;      my ($self, $category) = @_;
159    
160      unless ($category) {      unless ($category) {
161          confess 'No category given.';          die 'No category given.';
162      }      }
163    
164      my $i = $self->{categories_index}->{$category};      my $i = $self->{categories_index}->{$category};
# Line 189  Line 187 
187      return keys(%{$_[0]->{categories_index}});      return keys(%{$_[0]->{categories_index}});
188  }  }
189    
190    =pod
191    
192    =item * B<search> (I<search_component>)
193    
194    Getter / Setter for the search component of the menu
195    
196    =cut
197    
198    sub search {
199      my ($self, $search) = @_;
200    
201      if (defined($search)) {
202        $self->{search} = $search;
203      }
204    
205      return $self->{search};
206    }
207    
208  =pod  =pod
209    
# Line 204  Line 219 
219  sub add_entry {  sub add_entry {
220      my ($self, $category, $entry, $url, $target) = @_;      my ($self, $category, $entry, $url, $target) = @_;
221    
222      unless ($category and $entry and $url) {      unless ($category and $entry){# and $url) {
223          confess "Missing parameter ('$category', '$entry', '$url').";          die "Missing parameter ('$category', '$entry', '$url').";
224      }      }
225    
226      unless (exists($self->{categories_index}->{$category})) {      unless (exists($self->{categories_index}->{$category})) {
227          confess "Trying to add to non-existant category '$category'.";          die "Trying to add to non-existant category '$category'.";
228      }      }
229    
230      $target = '' unless ($target);      $target = '' unless ($target);
# Line 245  Line 260 
260      # check if a right is required to see this category      # check if a right is required to see this category
261      if (defined($right)) {      if (defined($right)) {
262        unless (defined($application) && ref($application) eq 'WebApplication') {        unless (defined($application) && ref($application) eq 'WebApplication') {
263          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.";
264        }        }
265        next unless ($application->session->user && $application->session->user->has_right($application, @$right));        next unless ($application->session->user &&
266                       $application->session->user->has_right($application, @$right));
267      }      }
268    
269      my $url = ($c_url) ? qq~href="$c_url"~ : '';      my $url = ($c_url) ? qq~href="$c_url"~ : '';
# Line 262  Line 278 
278        foreach (@{$self->{entries}->{$cat}}) {        foreach (@{$self->{entries}->{$cat}}) {
279    
280          my ($entry, $e_url, $e_target) = @$_;          my ($entry, $e_url, $e_target) = @$_;
281            if ($e_url) {
282          my $target = ($e_target) ? qq~target="$e_target"~ : '';          my $target = ($e_target) ? qq~target="$e_target"~ : '';
283          $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~;
284            } else {
285              $html .= qq~\t\t\t<li>$entry</li>\n~;
286            }
287        }        }
288    
289        $html .= "\t\t</ul>\n";        $html .= "\t\t</ul>\n";
# Line 276  Line 296 
296    
297    $html .= "\t</ul>\n";    $html .= "\t</ul>\n";
298    
   # 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>~;  
   }  
   
299    $html .= "</div>\n";    $html .= "</div>\n";
300    
301    return $html;    return $html;
302    
303  }  }
304    
305    1;

Legend:
Removed from v.1.4  
changed lines
  Added in v.1.8

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3