[Jifty-commit] r3501 - in jifty/trunk:
lib/Jifty/Plugin/Authentication/Password lib/Jifty/View/Declare
jifty-commit at lists.jifty.org
jifty-commit at lists.jifty.org
Fri Jun 15 00:17:10 EDT 2007
Author: jesse
Date: Fri Jun 15 00:17:09 2007
New Revision: 3501
Modified:
jifty/trunk/ (props changed)
jifty/trunk/lib/Jifty/Plugin/Authentication/Password/View.pm
jifty/trunk/lib/Jifty/View/Declare/CRUD.pm
Log:
r58389 at pinglin: jesse | 2007-06-15 00:16:54 -0400
* CRUD plugin cleanup and refactoring
Modified: jifty/trunk/lib/Jifty/Plugin/Authentication/Password/View.pm
==============================================================================
--- jifty/trunk/lib/Jifty/Plugin/Authentication/Password/View.pm (original)
+++ jifty/trunk/lib/Jifty/Plugin/Authentication/Password/View.pm Fri Jun 15 00:17:09 2007
@@ -17,7 +17,7 @@
use Jifty::View::Declare -base;
{ no warnings 'redefine';
-sub page (&) {
+sub page (&;$) {
no strict 'refs';
BEGIN {Jifty::Util->require(Jifty->app_class('View'))};
Jifty->app_class('View')->can('page')->(@_);
Modified: jifty/trunk/lib/Jifty/View/Declare/CRUD.pm
==============================================================================
--- jifty/trunk/lib/Jifty/View/Declare/CRUD.pm (original)
+++ jifty/trunk/lib/Jifty/View/Declare/CRUD.pm Fri Jun 15 00:17:09 2007
@@ -3,8 +3,7 @@
package Jifty::View::Declare::CRUD;
use Jifty::View::Declare -base;
-use base 'Exporter';
-our @EXPORT = qw(object_type fragment_for get_record current_collection display_columns);
+
=head1 NAME
@@ -65,7 +64,7 @@
|| $self->fragment_base_path . "/" . $fragment;
}
-=sub fragment_base_path
+=head2 fragment_base_path
=cut
@@ -74,11 +73,13 @@
return $self->package_variable('base_path') || '/crud';
}
-=sub get_record
+=head2 _get_record $id
+
+Given an $id, returns a record object for the CRUD view's model class.
=cut
-sub get_record {
+sub _get_record {
my ( $self, $id ) = @_;
my $record_class = Jifty->app_class( "Model", $self->object_type );
@@ -103,6 +104,30 @@
=head1 TEMPLATES
+
+=cut
+
+=head2 index.html
+
+
+=cut
+
+
+template 'index.html' => page {
+ my $self = shift;
+ title is $self->object_type;
+ form {
+ render_region(
+ name => $self->object_type.'-list',
+ path => $self->fragment_base_path.'/list');
+ }
+
+};
+
+
+
+
+
=head2 search
The search view displays a search screen connected to the search action of the module. See L<Jifty::Action::Record::Search>.
@@ -144,29 +169,41 @@
template 'view' => sub {
my $self = shift;
my ( $object_type, $id ) = ( $self->object_type, get('id') );
+ my $record = $self->_get_record($id);
my $update = new_action(
class => 'Update' . $object_type,
moniker => "update-" . Jifty->web->serial,
- record => $self->get_record($id)
+ record => $record
);
div {
{ class is 'crud read item inline' };
my @fields =$self->display_columns($update);
render_action( $update, \@fields, { render_mode => 'read' } );
+
+ show ('./view_item_controls', $record, $update);
+
+ hr {};
+ };
+
+};
+
+private template view_item_controls => sub {
+
+ my $self = shift;
+ my $record = shift;
+ my $action = shift;
hyperlink(
label => "Edit",
class => "editlink",
onclick => {
replace_with => $self->fragment_for('update'),
- args => { object_type => $object_type, id => $id }
+ args => { object_type => $self->object_type, id => $record->id }
},
);
-
- hr {};
};
-};
+
=head2 update
@@ -191,6 +228,27 @@
{ class is "crud update item inline " . $object_type }
show('./edit_item', $update);
+ show('./edit_item_controls', $record, $update);
+
+ hr {};
+ }
+};
+
+
+
+=head2 edit_item_controls $record $action
+
+The controls we should be rendering in the 'edit' region for a given fragment
+
+=cut
+
+private template edit_item_controls => sub {
+ my $self = shift;
+ my $record = shift;
+ my $update = shift;
+
+ my $object_type = $self->object_type;
+ my $id = $record->id;
div {
{ class is 'crud editlink' };
hyperlink(
@@ -212,30 +270,8 @@
);
};
- hr {};
- }
};
-
-sub current_collection {
- my $self =shift;
- my ( $page, $search_collection ) = get(qw(page search_collection));
-
- my $collection_class = Jifty->app_class( "Model", $self->object_type . "Collection" );
- my $search = $search_collection || Jifty->web->response->result('search');
- my $collection;
- if ( $search ) {
- $collection = $search;
- } else {
- $collection = $collection_class->new();
- $collection->unlimit();
- }
-
- $collection->set_page_info( current_page => $page, per_page => 25 );
-
- return $collection;
-}
-
=head2 list
The list template provides an interactive list for showing a list of records in the record collection, adding new records, deleting records, and updating records.
@@ -248,7 +284,7 @@
my ( $page ) = get(qw(page ));
my $fragment_for_new_item = get('fragment_for_new_item') || $self->fragment_for('new_item');
my $item_path = get('item_path') || $self->fragment_for("view");
- my $collection = $self->current_collection();
+ my $collection = $self->_current_collection();
show('./search_region');
show( './paging_top', $collection, $page );
@@ -259,6 +295,26 @@
};
+sub _current_collection {
+ my $self =shift;
+ my ( $page, $search_collection ) = get(qw(page search_collection));
+
+ my $collection_class = Jifty->app_class( "Model", $self->object_type . "Collection" );
+ my $search = $search_collection || Jifty->web->response->result('search');
+ my $collection;
+ if ( $search ) {
+ $collection = $search;
+ } else {
+ $collection = $collection_class->new();
+ $collection->unlimit();
+ }
+
+ $collection->set_page_info( current_page => $page, per_page => 25 );
+
+ return $collection;
+}
+
+
=head2 search_region
This I<private> template renders a region to show an expandable region for a search widget.
More information about the Jifty-commit
mailing list