[Jifty-commit] r1088 - in jifty/branches/jifty-jsan: lib/Jifty/Web lib/Jifty/Web/Form plugins/EditInPlace share/web/templates/_elements

jifty-commit at lists.jifty.org jifty-commit at lists.jifty.org
Mon May 22 21:43:16 EDT 2006


Author: jesse
Date: Mon May 22 21:43:15 2006
New Revision: 1088

Modified:
   jifty/branches/jifty-jsan/lib/Jifty/Web.pm
   jifty/branches/jifty-jsan/lib/Jifty/Web/Form/Field.pm
   jifty/branches/jifty-jsan/lib/Jifty/Web/Form/Link.pm
   jifty/branches/jifty-jsan/lib/Jifty/Web/Menu.pm
   jifty/branches/jifty-jsan/plugins/EditInPlace/META.yml
   jifty/branches/jifty-jsan/share/web/templates/_elements/menu

Log:
* Added support for context menus (at the code level. next up, at the CSS level)


Modified: jifty/branches/jifty-jsan/lib/Jifty/Web.pm
==============================================================================
--- jifty/branches/jifty-jsan/lib/Jifty/Web.pm	(original)
+++ jifty/branches/jifty-jsan/lib/Jifty/Web.pm	Mon May 22 21:43:15 2006
@@ -707,7 +707,7 @@
 
 sub link {
     my $self = shift;
-    return Jifty::Web::Form::Clickable->new(@_)->generate->render;
+    return Jifty::Web::Form::Clickable->new(@_)->generate;
 }
 
 =head3 return PARAMHASH

Modified: jifty/branches/jifty-jsan/lib/Jifty/Web/Form/Field.pm
==============================================================================
--- jifty/branches/jifty-jsan/lib/Jifty/Web/Form/Field.pm	(original)
+++ jifty/branches/jifty-jsan/lib/Jifty/Web/Form/Field.pm	Mon May 22 21:43:15 2006
@@ -45,7 +45,7 @@
 
 use Scalar::Util;
 use HTML::Entities;
-use overload '""' => sub {shift->render};
+use overload '""' => sub { shift->render};
 
 =head2 new
 

Modified: jifty/branches/jifty-jsan/lib/Jifty/Web/Form/Link.pm
==============================================================================
--- jifty/branches/jifty-jsan/lib/Jifty/Web/Form/Link.pm	(original)
+++ jifty/branches/jifty-jsan/lib/Jifty/Web/Form/Link.pm	Mon May 22 21:43:15 2006
@@ -17,6 +17,9 @@
 
 use base qw/Jifty::Web::Form::Element Class::Accessor::Fast/;
 
+# Since we don't inherit from Form::Field, we don't otherwise stringify
+use overload '""' => sub { shift->render};
+
 =head2 accessors
 
 Link adds C<url> and C<escape_label> to the list of possible accessors

Modified: jifty/branches/jifty-jsan/lib/Jifty/Web/Menu.pm
==============================================================================
--- jifty/branches/jifty-jsan/lib/Jifty/Web/Menu.pm	(original)
+++ jifty/branches/jifty-jsan/lib/Jifty/Web/Menu.pm	Mon May 22 21:43:15 2006
@@ -3,7 +3,7 @@
 use base qw/Class::Accessor::Fast/;
 use URI;
 
-__PACKAGE__->mk_accessors(qw(label parent sort_order));
+__PACKAGE__->mk_accessors(qw(label parent sort_order link));
 
 =head2 new PARAMHASH
 
@@ -14,6 +14,14 @@
 
 =cut
 
+sub new {
+    my $package = shift;
+    # Class::Accessor only wants a hashref;
+    $package->SUPER::new( ref($_[0]) eq 'HASH' ? @_ : {@_} );
+
+}
+
+
 =head2 label [STRING]
 
 Sets or returns the string that the menu item will be displayed as.
@@ -28,6 +36,14 @@
 Gets or sets the sort order of the item, as it will be displayed under
 the parent.  This defaults to adding onto the end.
 
+
+=head2 link
+
+Gets or set a Jifty::Web::Link object that represents this menu item. If
+you're looking to do complex ajaxy things with menus, this is likely
+the option you want.
+
+
 =head2 url
 
 Gets or sets the URL that the menu's link goes to.  If the link
@@ -146,4 +162,44 @@
     return wantarray ? @kids : \@kids;
 }
 
+
+sub render_as_context_menu {
+    my $self = shift;
+    my @kids = $self->children;
+    my $id = Jifty->web->serial;
+    Jifty->web->out(
+        qq{<ul class="menu">} .qq{<li class="closed contextual">}.  qq{<span class="title">} . $self->label() . qq{</span>}
+            . (
+            @kids
+            ? qq{<span class="expand"><a href="#" onClick="Jifty.ContextMenu.hideshow('}.$id.qq{'; return false;">+</a></span>}
+            : ''
+            )
+            . qq{</dt>}
+            . qq{<dd>}
+            . qq{<ul id="}.$id.  qq{">}
+    );
+    for (@kids) {
+        Jifty->web->out("<li>");
+
+        # We should be able to get this as a string.
+        $_->as_link;
+        Jifty->web->out("</li>");
+    }
+
+    Jifty->web->out(qq{</ul></li></ul>});
+    '';
+
+}
+
+=head2 as_link
+
+Return this menu item as a C<Jifty::Web::Link>, either the one we were initialized with or a new one made from the C</label> and c</url>
+
+=cut
+
+sub as_link {
+     my $self = shift;
+     ($self->link ? $self->link : Jifty->web->link(label => $self->label, url => $self->url)); 
+}
+
 1;

Modified: jifty/branches/jifty-jsan/plugins/EditInPlace/META.yml
==============================================================================
--- jifty/branches/jifty-jsan/plugins/EditInPlace/META.yml	(original)
+++ jifty/branches/jifty-jsan/plugins/EditInPlace/META.yml	Mon May 22 21:43:15 2006
@@ -1,5 +1,7 @@
+build_requires: 
+  ExtUtils::MakeMaker: 6.11
 distribution_type: module
-generated_by: Module::Install version 0.610
+generated_by: Module::Install version 0.620
 license: unknown
 name: Jifty-Plugin-EditInPlace
 no_index: 

Modified: jifty/branches/jifty-jsan/share/web/templates/_elements/menu
==============================================================================
--- jifty/branches/jifty-jsan/share/web/templates/_elements/menu	(original)
+++ jifty/branches/jifty-jsan/share/web/templates/_elements/menu	Mon May 22 21:43:15 2006
@@ -20,11 +20,7 @@
   <%init>
     my @kids = $item->children;
   </%init>
-  <li <%  $item->active ? 'class="active"' : '' |n %>><%
-    Jifty->web->link(
-        url   => $item->url,
-        label => _($item->label),
-    ) %><% @kids ? '' : '</li>' |n %>
+  <li <%  $item->active ? 'class="active"' : '' |n %>><% $item->as_link |n %><% @kids ? '' : '</li>' |n %>
 % if (@kids) {
     <ul class="submenu">
 % $m->comp(".menu", item => $_) for @kids;


More information about the Jifty-commit mailing list