CatalystX::Usul::Plugin::Controller::ModelHelper - Convenience methods for common model calls


CatalystX-Usul documentation Contained in the CatalystX-Usul distribution.

Index


Code Index:

Name

Top

CatalystX::Usul::Plugin::Controller::ModelHelper - Convenience methods for common model calls

Version

Top

0.3.$Revision: 576 $

Synopsis

Top

   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);

Description

Top

Many convenience methods for common model calls

Subroutines/Methods

Top

add_result

Add a message to the results div

add_sidebar_panel

Calls method of the same name in the base model class to stuff the stash with the data necessary to create a panel in the accordion widget on the sidebar

check_field

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

close_sidebar

Forces the sidebar to not be displayed when the page is rendered

common

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

default

Generates a simple page not found page. No longer called as unknown pages cause a redirect to the controllers default page

help

Generates a context sensitive help page by calling get_help

open_sidebar

Sets the key/value pair in the browser state cookie that will cause the sidebar to appear in the generated page

overview

Generates some blurb for the Overview panel of the sidebar accordion widget

query_array

Exposes the method of the same name in the base model class

query_value

Exposes the method of the same name in the base model class

select_sidebar_panel

Set the cookie that controls which sidebar panel is visible

set_popup

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

Diagnostics

Top

None

Configuration and Environment

Top

None

Dependencies

Top

CatalystX::Usul

Incompatibilities

Top

There are no known incompatibilities in this module

Bugs and Limitations

Top

There are no known bugs in this module. Please report problems to the address below. Patches are welcome

Author

Top

Peter Flanigan, <Support at RoxSoft.co.uk>

License and Copyright

Top


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: