[Jifty-commit] r3288 - in jifty/trunk: lib/Jifty/View/Declare
jifty-commit at lists.jifty.org
jifty-commit at lists.jifty.org
Tue May 22 20:31:46 EDT 2007
Author: jesse
Date: Tue May 22 20:31:45 2007
New Revision: 3288
Modified:
jifty/trunk/ (props changed)
jifty/trunk/lib/Jifty/View/Declare/CRUD.pm
Log:
r57048 at pinglin: jesse | 2007-05-22 20:30:50 -0400
* Better factored CRUD library, ready for local overriding
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 Tue May 22 20:31:45 2007
@@ -4,34 +4,34 @@
package Jifty::View::Declare::CRUD;
use Jifty::View::Declare -base;
use base 'Exporter';
-our @EXPORT = qw(object_type fragment_for get_record);
-
+our @EXPORT = qw(object_type fragment_for get_record current_collection);
sub object_type {
my $self = shift;
- return $self->package_variable('object_type')|| get('object_type');
+ return $self->package_variable('object_type') || get('object_type');
}
sub fragment_for {
- my $self = shift;
+ my $self = shift;
my $fragment = shift;
-
- if (my $coderef = $self->can('fragment_for_'.$fragment) ) {
+
+ if ( my $coderef = $self->can( 'fragment_for_' . $fragment ) ) {
return $coderef->($self);
}
- return $self->package_variable('fragment_for_'.$fragment)||$self->fragment_base_path ."/". $fragment;
+ return $self->package_variable( 'fragment_for_' . $fragment )
+ || $self->fragment_base_path . "/" . $fragment;
}
sub fragment_base_path {
my $self = shift;
- return $self->package_variable('base_path')|| '/crud';
+ return $self->package_variable('base_path') || '/crud';
}
sub get_record {
- my ($self, $id) = @_;
+ my ( $self, $id ) = @_;
- my $record_class = Jifty->app_class("Model", $self->object_type);
+ my $record_class = Jifty->app_class( "Model", $self->object_type );
my $record = $record_class->new();
$record->load($id);
@@ -135,16 +135,12 @@
}
};
-template 'list' => sub {
- my $self = shift;
- my $object_type = $self->object_type ;
+sub current_collection {
+ my $self =shift;
my ( $page, $search_collection ) = get(qw(page search_collection));
- 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_class = Jifty->app_class( "Model", $object_type . "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 ) {
@@ -154,8 +150,35 @@
$collection = $search->content('search');
}
- $collection->set_page_info( current_page => $page, per_page => 25);
- my $search_region = Jifty::Web::PageRegion->new( name => 'search', path => '/__jifty/empty',);
+ $collection->set_page_info( current_page => $page, per_page => 25 );
+
+ return $collection;
+}
+
+template 'list' => sub {
+ my $self = shift;
+
+ my ( $page, $search_collection ) = get(qw(page search_collection));
+ 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();
+ show('./search_region');
+ show( './paging_top', $collection, $page );
+ show( './list_items', $collection, $item_path );
+ show( './paging_bottom', $collection, $page );
+ show( './new_item_region', $fragment_for_new_item );
+
+};
+
+private template 'search_region' => sub {
+ my $self = shift;
+ my $object_type = $self->object_type;
+
+ my $search_region = Jifty::Web::PageRegion->new(
+ name => 'search',
+ path => '/__jifty/empty'
+ );
hyperlink(
onclick => [
@@ -169,17 +192,26 @@
);
outs( $search_region->render );
+};
+private template 'new_item_region' => sub {
+ my $self = shift;
+ my $fragment_for_new_item = shift;
+ my $object_type = $self->object_type;
-
- if ( $collection->pager->last_page > 1 ) {
- span {
- { class is 'page-count' };
- outs(
- _( "Page %1 of %2", $page, $collection->pager->last_page ) );
- }
+ if ($fragment_for_new_item) {
+ render_region(
+ name => 'new_item',
+ path => $fragment_for_new_item,
+ defaults => { object_type => $object_type },
+ );
}
+};
-
+private template 'list_items' => sub {
+ my $self = shift;
+ my $collection = shift;
+ my $item_path = shift;
+ my $object_type = $self->object_type;
if ( $collection->pager->total_entries == 0 ) {
outs( _("No items found") );
}
@@ -195,40 +227,53 @@
}
};
+};
- show ('./paging', $collection);
+private template 'paging_top' => sub {
+ my $self = shift;
+ my $collection = shift;
+ my $page = shift;
- if ($fragment_for_new_item) {
- render_region(
- name => 'new_item',
- path => $fragment_for_new_item,
- defaults => { object_type => $object_type },
- );
+ if ( $collection->pager->last_page > 1 ) {
+ span {
+ { class is 'page-count' };
+ outs(
+ _( "Page %1 of %2", $page, $collection->pager->last_page ) );
+ }
}
+
};
-private template paging => sub {
- my $self = shift;
+private template paging_bottom => sub {
+ my $self = shift;
my $collection = shift;
+ my $page = shift;
div {
{ class is 'paging' };
if ( $collection->pager->previous_page ) {
span {
{ class is 'prev-page' };
- hyperlink( label => "Previous Page", onclick => { args => { page => $collection->pager->previous_page } });
+ hyperlink(
+ label => "Previous Page",
+ onclick => {
+ args => { page => $collection->pager->previous_page }
+ }
+ );
}
}
if ( $collection->pager->next_page ) {
span {
{ class is 'next-page' };
- hyperlink( label => "Next Page", onclick => { args => { page => $collection->pager->next_page } });
+ hyperlink(
+ label => "Next Page",
+ onclick =>
+ { args => { page => $collection->pager->next_page } }
+ );
}
}
};
};
-
-
template 'new_item' => sub {
my $self = shift;
my ( $object_type, $id ) = ( $self->object_type, get('id') );
@@ -246,7 +291,9 @@
onclick => [
{ submit => $create },
{ refresh_self => 1 },
- { element => Jifty->web->current_region->parent->get_element('div.list'),
+ { element =>
+ Jifty->web->current_region->parent->get_element(
+ 'div.list'),
append => $self->fragment_for('view'),
args => {
object_type => $object_type,
More information about the Jifty-commit
mailing list