The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Jifty::View::Declare::CRUD - Provides typical CRUD views to a model

SYNOPSIS

  package App::View::User;
  use Jifty::View::Declare -base;
  use base qw/ Jifty::View::Declare::CRUD /;

  template 'view' => sub {
      # customize the view
  };

  1;

  package App::View::Tag;
  use Jifty::View::Declare -base;
  use base qw/ Jifty::View::Declare::CRUD /;

  template 'view' => sub {
      # customize the view
  };

  1;

  package App::View;
  use Jifty::View::Declare -base;

  use Jifty::View::Declare::CRUD;

  # If you have customizations, this is a good way...
  Jifty::View::Declare::CRUD->mount_view('User');
  Jifty::View::Declare::CRUD->mount_view('Category', 'App::View::Tag', '/tag');

  # Another way to do the above, good for quick and dirty
  alias Jifty::View::Declare::CRUD under '/admin/blog', {
      object_type => 'BlogPost',
  };

DESCRIPTION

This class provides a set of views that may be used by a model to display Create/Read/Update/Delete views using the Template::Declare templating language.

Basically, you can use this class to do most (and maybe all) of the work you need to manipulate and view your records.

METHODS

mount_view MODELCASS VIEWCLASS /path

Call this method in your appliation's view class to add the CRUD views you're looking for. Only the first argument is required.

Arguments:

MODELCLASS

This is the name of the model that you want to generate the CRUD views for. This is the only required parameter. Leave off the parts of the class name prior to and including the "Model" part. (I.e., App::Model::User should be passed as just User).

VIEWCLASS

This is the name of the class that will be generated to hold the CRUD views of your model. If not given, it will be set to: App::View::MODELCLASS. If given, it should be the full name of the view class.

/path

This is the path where you can reach the CRUD views for this model in your browser. If not given, this will be set to the model class name in lowercase letters. (I.e., User would be found at /user if not passed explicitly).

object_type

This method returns the type of object this CRUD view has been generated for. This is normally the model class parameter that was passed to "mount_view".

record_class

This is the full name of the model class these CRUD views are for. The default implementation returns:

  Jifty->app_class('Model', $self->object_type);

You will want to override this if (in addition to "object_type") if you want to provide CRUD views in a plugin, or from an external model class, or for one of the Jifty built-in models.

fragment_for

This is a helper that returns the path to a given fragment. The only argument is the name of the fragment. It returns a absolute base path to the fragment page.

This will attempt to lookup a method named fragment_for_FRAGMENT, where FRAGMENT is the argument passed. If that method exists, it's result is used as the returned path.

Otherwise, the "fragment_base_path" is joined to the passed fragment name to create the return value.

If you really want to mess with this, you may need to read the source code of this class.

fragment_base_path

This is a helper for "fragment_for". It looks up the current template using "current_template" in Template::Declare::Tags, finds it's parent path and then returns that.

If you really want to mess with this, you may need to read the source code of this class.

_get_record $id

Given an $id, returns a record object for the CRUD view's model class.

display_columns

Returns a list of all the columns that this REST view should display

TEMPLATES

index.html

Contains the master form and page region containing the list of items. This is mainly a wrapper for the "list" fragment.

The search fragment displays a search screen connected to the search action of the module.

See Jifty::Action::Record::Search.

view

This fragment displays the data held by a single model record.

private template view_item_controls

Used by the view fragment to show the edit link for each record.

update

The update fragment displays a form for editing the data held within a single model record.

See Jifty::Action::Record::Update.

edit_item_controls $record $action

The controls we should be rendering in the 'edit' region for a given fragment

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.

per_page

This routine returns how many items should be shown on each page of a listing. The default is 25.

search_region

This private template renders a region to show an expandable region for a search widget.

new_item_region

This private template renders a region to show a the new_item template.

no_items_found

Prints "No items found."

list_items $collection $item_path

Renders a div of class list with a region per item.

paging_top $collection $page_number

Paging for your list, rendered at the top of the list

paging_bottom $collection $page_number

Paging for your list, rendered at the bottom of the list

new_item $action

Renders the action $Action, handing it the array ref returned by "display_columns".

edit_item $action

Renders the action $Action, handing it the array ref returned by "display_columns".

new_item

The new_item template provides a form for creating new model records. See Jifty::Action::Record::Create.

SEE ALSO

Jifty::Action::Record::Create, Jifty::Action::Record::Search, Jifty::Action::Record::Update, Jifty::Action::Record::Delete, Template::Declare, Jifty::View::Declare::Helpers, Jifty::View::Declare

LICENSE

Jifty is Copyright 2005-2007 Best Practical Solutions, LLC. Jifty is distributed under the same terms as Perl itself.