| CatalystX-Usul documentation | Contained in the CatalystX-Usul distribution. |
CatalystX::Usul::Plugin::Controller::ModelHelper - Convenience methods for common model calls
0.3.$Revision: 576 $
package CatalystX::Usul;
use parent qw(Catalyst::Component CatalystX::Usul::Base);
package CatalystX::Usul::Controller;
use parent qw(CatalystX::Usul
CatalystX::Usul::ModelHelper
Catalyst::Controller);
package YourApp::Controller::YourController;
use parent qw(CatalystX::Usul::Controller);
Many convenience methods for common model calls
Add a message to the results div
Creates an XML response to and Ajax call which validates a data value for a given form field. Calls check_field in CatalystX::Usul::Model
Sets stash values for the navigation menus, tools menus, the footer, quick links and recovers the keys for the current form from the session store
Calls add_header
Calls add_footer
Generates a simple page not found page. No longer called as unknown pages cause a redirect to the controllers default page
Generates a context sensitive help page by calling get_help
Generates some blurb for the Overview panel of the sidebar accordion widget
Exposes the method of the same name in the base model class
Exposes the method of the same name in the base model class
Sets the popup flag to stop the browser from caching the window size in the browser state cookie. Clears the main navigation menu and adds a close window link
None
None
There are no known incompatibilities in this module
There are no known bugs in this module. Please report problems to the address below. Patches are welcome
Peter Flanigan, <Support at RoxSoft.co.uk>
Copyright (c) 2008 Pete Flanigan. All rights reserved
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See perlartistic
This program is distributed in the hope that it will be useful, but WITHOUT WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE
| CatalystX-Usul documentation | Contained in the CatalystX-Usul distribution. |
# @(#)$Id: ModelHelper.pm 576 2009-06-09 23:23:46Z pjf $ package CatalystX::Usul::Plugin::Controller::ModelHelper; use strict; use warnings; use version; our $VERSION = qv( sprintf '0.3.%d', q$Rev: 576 $ =~ /\d+/gmx ); use parent qw(CatalystX::Usul); my $SEP = q(/); sub add_sidebar_panel { # Add an Ajax call to the side bar accordion widget my ($self, $c, @rest) = @_; my $e; my $pno = eval { $c->model( q(Base) )->add_sidebar_panel( @rest ) }; $self->error_page( $c, $e->as_string ) if ($e = $self->catch); return $pno; } sub check_field { # Process Ajax calls to validate form field values my ($self, $c) = @_; $c->model( q(Base) )->check_field_wrapper; return; } sub close_footer { # Prevent the footer div from displaying my ($self, $c) = @_; my $s = $c->stash; if ($s->{fstate}) { if ($self->can( q(set_cookies) )) { $self->set_cookie( $c, { name => $s->{cname}, key => q(footer), value => q(false) } ); } $s->{fstate} = 0; } return; } sub close_sidebar { # Prevent the side bar div from displaying my ($self, $c) = @_; my $s = $c->stash; if ($s->{sbstate}) { if ($self->can( q(delete_cookie) )) { $self->delete_cookie( $c, { name => $s->{cname}, key => q(sidebar) } ); } $s->{sbstate} = 0; } return; } sub common { # Most controllers will want to add these things to the stash my ($self, $c, $footer_model, $header_model) = @_; my $e; $footer_model ||= $c->model( q(Base) ); $header_model ||= $c->model( q(Navigation) ); eval { $header_model->add_header; $footer_model->add_footer; }; if ($e = $self->catch) { $self->error_page( $c, $e->as_string ); $c->detach; # Never returns } return; } sub default { # Award the luser a 404 my ($self, $c) = @_; my $s = $c->stash; my $e; return if ($c->res->redirect); my $model = $c->model( q(Navigation) ); eval { $model->clear_controls; $model->add_menu_back; $model->simple_page( q(default) ); }; $self->error_page( $c, $e->as_string ) if ($e = $self->catch); $s->{request_path} = $c->req->path; $c->action->reverse( q(default) ); $c->res->status( 404 ); return; } sub help { # Generate the context sensitive help from the POD in the code my ($self, $c, @args) = @_; my $e; my $model = $c->model( q(Help) ); eval { $model->add_header; $model->get_help( @args ); }; $self->error_page( $c, $e->as_string ) if ($e = $self->catch); $self->set_popup( $c ); return; } sub open_footer { # Force the footer into the open state my ($self, $c) = @_; my $s = $c->stash; if (not $s->{fstate} and $self->can( q(set_cookie) )) { $self->set_cookie( $c, { name => $s->{cname}, key => q(footer), value => q(true) } ); } return; } sub open_sidebar { # Force the side bar into an open state my ($self, $c) = @_; my $s = $c->stash; if (not $s->{sbstate} and $self->can( q(set_cookie) )) { $self->set_cookie( $c, { key => q(sidebar), name => $s->{cname}, value => $s->{assets}.q(pushedpin.gif) } ); } return; } sub overview { # Respond to the ajax call for some info about the side bar accordion my ($self, $c) = @_; my $e; eval { $c->model( q(Help) )->overview }; $self->error_page( $c, $e->as_string ) if ($e = $self->catch); return; } sub select_sidebar_panel { my ($self, $c, $pno) = @_; if ($self->can( q(set_cookie) )) { $self->set_cookie( $c, { name => $c->stash->{cname}, key => q(sidebarPanel), value => $pno } ); } return; } sub set_popup { my ($self, $c, $args) = @_; my $model = $c->model( q(Navigation) ); my $e; eval { $model->clear_controls; $model->add_menu_close( $args ); }; $self->error_page( $c, $e->as_string ) if ($e = $self->catch); $c->stash( is_popup => q(true) ); return; } 1; __END__
# Local Variables: # mode: perl # tab-width: 3 # End: