Home | Wiki | OI 1.x Docs | OI 2.x Docs |
OpenInteract2::Action::CommonAdd - Tasks to display empty form and create an object
# Just subclass and the tasks 'display_add' and 'add' are implemented package OpenInteract2::Action::MyAction; use base qw( OpenInteract2::Action::CommonAdd );
This common action supports the following tasks:
display_add - Display a form to create a new object.
add - Add the new object.
Displays a possibly empty form to create a new object. The 'possibly' derives from your ability to pre-populate the object with default data so the user can do less typing. Because it's all about the users...
c_display_add_template: Template with a form for the user to fill in with values to create a new object.
The template gets an unsaved (likely empty) object in the keys 'object' and '$object_type'.
_display_add_customize( \%template_params )
Called just before the content is generated, giving you the ability to modify the likely empty object to display or to add more parameters.
These are in addition to the template parameters defined above.
c_object_type ($) (REQUIRED)
SPOPS key for object you'll be displaying.
c_object ($)
System will create a new instance of the object type if not previously set.
c_object_class ($)
Set to the class corresponding to c_object_type
. This has already
been validated.
Takes data from a form and creates a new object from it.
None
_add_customize( $object, \%save_options )
Called just before the save()
operation which creates the object in
your datastore. You have three opportunities to affect the operation:
Modify the object being saved by modifying or adding values to
$object
.
Modify the options passed to save()
by modifying or adding values
to \%save_options
.
Throw a die
with content from the method. This content will be sent
on to the user. This gives you an opportunity to do any necessary
validation, quota ceiling inspections, time of day checking, etc.
Here's an example of a validation check:
sub _add_customize { my ( $self, $object, $save_options ) = @_; if ( $self->widget_type eq 'Frobozz' and $self->size ne 'Large' ) {
# First set an error message to tell the user what's wrong...
$self->add_view_message( size => "Only large widgets of type Frobozz are allowed' );
# Next, provide the object with its values to the form so we # can prepopulate it...
$self->param( c_object => $object );
# ...and display the editing form again
die $self->execute({ task => 'display_add' }); } }
_add_post_action
This method is called after the object has been successfully created
-- you'll find the object in the c_object
action parameter. You can
perform any action you like in this method. Similar to
_add_customize()
, if you throw a die
with content it will be
displayed to the user rather than moving to the configured
c_add_task
.
c_object_type ($) (REQUIRED)
SPOPS key for object you'll be displaying.
c_add_task ($) (REQUIRED)
Task executed when the add is successful.
c_add_fail_task ($)
Task to run if we fail to fetch the object.
Default: 'display_add'
c_add_return_url ($)
Path we use for returning. (For example, if someone logs in on the resulting page.)
Default: the default task for this action
These configuration keys control what data will be read from the HTTP request into your object, and in some cases how it will be read.
c_add_fields ($ or \@)
List the fields you just want assigned directly from the name. So if a form variable is named 'first_name' and you list 'first_name' here we'll assign that value to the object property 'first_name'.
c_add_fields_toggled ($ or \@)
List the fields you want assigned in a toggled fashion -- if any value is specified, we set it to 'yes'; otherwise we set it to 'no'. (See OpenInteract2::Request/param_toggled.)
c_add_fields_date ($ or \@)
List the date fields you want assigned. You can have the date read
from a single field, in which case you should also specify a
strptime
format in c_add_fields_date_format
, or multiple fields
as created by the date_select
OI2 control. (See
OpenInteract2::Request/param_date.)
c_add_fields_datetime ($ or \@)
List the datetime fields you want assigned. These are just like date
fields except they also have a time component. You can have the date
and time read from a single field, in which case you should also
specify a strptime
format in c_add_fields_date_format
, or
multiple fields. (See OpenInteract2::Request/param_datetime.)
c_add_fields_date_format ($)
If you list one or more fields in c_add_fields_date
and they're
pulled from a single field, you need to let OI2 know how to parse the
date. Just specify a strptime
format as specified in
DateTime::Format::Strptime.
c_add_fields_datetime_format ($)
If you list one or more fields in c_add_fields_datetime
and they're
pulled from a single field, you need to let OI2 know how to parse the
date and time. Just specify a strptime
format as specified in
DateTime::Format::Strptime.
c_object ($)
If the add is successful this will be set to the newly-created object.
c_object_class ($)
Set to the class corresponding to c_object_type
. This has already
been validated.
Copyright (c) 2002-2003 Chris Winters. All rights reserved.
Chris Winters <chris@cwinters.com>
Generated from the OpenInteract 1.99_03 source.