[Jifty-commit] r3982 - jifty/trunk/lib/Jifty/Plugin/TabView

jifty-commit at lists.jifty.org jifty-commit at lists.jifty.org
Sun Aug 26 06:21:05 EDT 2007


Author: clkao
Date: Sun Aug 26 06:21:03 2007
New Revision: 3982

Modified:
   jifty/trunk/lib/Jifty/Plugin/TabView/View.pm

Log:
Allow a more flexible way to use tabview, such using custom labels.


Modified: jifty/trunk/lib/Jifty/Plugin/TabView/View.pm
==============================================================================
--- jifty/trunk/lib/Jifty/Plugin/TabView/View.pm	(original)
+++ jifty/trunk/lib/Jifty/Plugin/TabView/View.pm	Sun Aug 26 06:21:03 2007
@@ -19,6 +19,12 @@
   template 'index.html' => page {
      my $self = shift;
      $self->render_tabs('foo', [qw(id)], qw( foo bar_tab ) );
+
+     # more flexible tabs
+     $self->render_tabs('foo', [qw(id)],
+                        { label => 'This is foo 1', path => 'foo', name => 'foo 1', args => { id => 1}},
+                        { label => 'This is foo 2', path => 'foo', name => 'foo 2', args => { id => 2}});
+
   };
   template 'foo' => sub { ... };
   template 'bar' => sub { ... };
@@ -43,35 +49,42 @@
 	var myTabs = new YAHOO.widget.TabView("$divname");
 	</script>'  );
 
+    @tabs = map { return $_ if ref($_);
+		  my $path = $_;
+		  my $defer = $path =~ s/_tab$//;
+		  { path => $path,
+		    name => $path,
+		    defer => $defer,
+		    label => $path };
+	      } @tabs;
 
     div { { id is $divname, class is 'yui-navset'}
 	  ul { { class is 'yui-nav'};
 	       my $i = 0;
-	       for (@tabs) {
-		   my $tab = $_;
+	       for my $tab (@tabs) {
 		   li { { class is 'selected' unless $i };
-			hyperlink(url => '#tab'.++$i, label => $tab,
-				  $tab =~ s/_tab$// ? 
+			hyperlink(url => '#tab'.++$i, label => $tab->{label},
+				  $tab->{defer} ?
 				  (onclick =>
-				  { region       => Jifty->web->current_region ? Jifty->web->current_region->qualified_name."-$tab-tab" : "$tab-tab",
-				    replace_with => _tab_path($self, $tab), # XXX: should have higher level function handling mount point
-				    args => { map { $_ => get($_)} @$args },
+				  { region       => Jifty->web->current_region ? Jifty->web->current_region->qualified_name."-$tab->{name}-tab" : "$tab->{path}-tab",
+				    replace_with => _tab_path($self, $tab->{path}), # XXX: should have higher level function handling mount point
+				    args => { (map { $_ => get($_)} @$args ), %{$tab->{args} || {}} },
 				  }) : ()
 				 ) }
 	       }
 	   };
 	  div { {class is 'yui-content' };
 		my $default_shown;
-		for (@tabs) {
-		    div { 
-			if (s/_tab$//) {
-			    render_region(name => $_.'-tab', 
-                          ($default_shown++)? () : ( path => _tab_path($self, $_),
-						     args =>  { map { $_ => get($_)} @$args })
+		for my $tab (@tabs) {
+		    div {
+			if ($tab->{defer}) {
+			    render_region(name => $tab->{name}.'-tab',
+                          ($default_shown++)? () : ( path => _tab_path($self, $tab->{path}),
+						     force_arguments => { ( map { $_ => get($_)} @$args ), %{$tab->{args} || {}} } )
                           )
 			}
 			else {
-			    show( _tab_path($self,$_) );
+			    show( _tab_path($self, $tab->{path}) );
 			}
 		    }
 		}


More information about the Jifty-commit mailing list