added: DataForm can now trigger workflow when adding an entry
This commit is contained in:
parent
91812b74eb
commit
5e967d9b82
5 changed files with 156 additions and 4 deletions
|
|
@ -314,6 +314,15 @@ sub definition {
|
|||
label => $i18n->get('editForm useCaptcha label'),
|
||||
hoverHelp => $i18n->get('editForm useCaptcha description'),
|
||||
},
|
||||
workflowIdAddEntry => {
|
||||
tab => "properties",
|
||||
fieldType => "workflow",
|
||||
defaultValue => undef,
|
||||
type => "WebGUI::AssetCollateral::DataForm::Entry",
|
||||
none => 1,
|
||||
label => $i18n->get('editForm workflowIdAddEntry label'),
|
||||
hoverHelp => $i18n->get('editForm workflowIdAddEntry description'),
|
||||
},
|
||||
fieldConfiguration => {
|
||||
fieldType => 'hidden',
|
||||
},
|
||||
|
|
@ -1164,12 +1173,16 @@ sub www_editFieldSave {
|
|||
my $fieldName = $form->process('fieldName');
|
||||
my $newName = $self->session->url->urlize($form->process('newName') || $form->process('label'));
|
||||
$newName =~ tr{-/}{};
|
||||
|
||||
# Make sure we don't rename special fields
|
||||
if ($fieldName) {
|
||||
my $field = $self->getFieldConfig($fieldName);
|
||||
if ($field->{isMailField}) {
|
||||
$newName = $fieldName;
|
||||
}
|
||||
}
|
||||
|
||||
# Make sure our field name is unique
|
||||
if (!$fieldName || $fieldName ne $newName) {
|
||||
my $i = '';
|
||||
while ($self->getFieldConfig($newName . $i)) {
|
||||
|
|
@ -1178,6 +1191,7 @@ sub www_editFieldSave {
|
|||
}
|
||||
$newName .= $i;
|
||||
}
|
||||
|
||||
my %field = (
|
||||
width => $form->process("width", 'integer'),
|
||||
label => $form->process("label"),
|
||||
|
|
@ -1191,6 +1205,7 @@ sub www_editFieldSave {
|
|||
vertical => $form->process("vertical", 'yesNo'),
|
||||
extras => $form->process("extras"),
|
||||
);
|
||||
|
||||
my $newSelf = $self->addRevision;
|
||||
if ($fieldName) {
|
||||
if ($fieldName ne $newName) {
|
||||
|
|
@ -1231,6 +1246,8 @@ sub setField {
|
|||
my $self = shift;
|
||||
my $fieldName = shift;
|
||||
my $field = shift;
|
||||
|
||||
$field->{ name } = $fieldName;
|
||||
|
||||
my $fieldConfig = $self->getFieldConfig;
|
||||
if (!$fieldConfig->{$fieldName}) {
|
||||
|
|
@ -1528,18 +1545,47 @@ sub www_process {
|
|||
};
|
||||
}
|
||||
|
||||
$var->{error_loop} = \@errors;
|
||||
# Prepare template variables
|
||||
$var = $self->getRecordTemplateVars($var, $entry);
|
||||
|
||||
# If errors, show error page
|
||||
if (@errors) {
|
||||
$self->prepareFormView;
|
||||
$var->{error_loop} = \@errors;
|
||||
$self->prepareViewForm;
|
||||
return $self->processStyle($self->viewForm($var, $entry));
|
||||
}
|
||||
|
||||
# Send email
|
||||
if ($self->get("mailData") && !$entryId) {
|
||||
$self->sendEmail($var, $entry);
|
||||
}
|
||||
|
||||
# Save entry to database
|
||||
if ($self->get('storeData')) {
|
||||
$entry->save;
|
||||
}
|
||||
|
||||
# Run the workflow
|
||||
if ( $self->get("workflowIdAddEntry") ) {
|
||||
my $instanceVar = {
|
||||
workflowId => $self->get( "workflowIdAddEntry" ),
|
||||
className => "WebGUI::AssetCollateral::DataForm::Entry",
|
||||
};
|
||||
|
||||
# If we've saved the entry, we only need the ID
|
||||
if ( $self->get( 'storeData' ) ) {
|
||||
$instanceVar->{ methodName } = "new";
|
||||
$instanceVar->{ parameters } = $entry->getId;
|
||||
}
|
||||
# We haven't saved the entry, we need the whole thing
|
||||
else {
|
||||
$instanceVar->{ methodName } = "newFromHash";
|
||||
$instanceVar->{ parameters } = [ $self->getId, $entry->getHash ];
|
||||
}
|
||||
|
||||
WebGUI::Workflow::Instance->create( $self->session, $instanceVar )->start;
|
||||
}
|
||||
|
||||
return $self->processStyle($self->processTemplate($var,$self->get("acknowlegementTemplateId")))
|
||||
if $self->defaultViewForm;
|
||||
return '';
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
package WebGUI::AssetCollateral::DataForm::Entry;
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
our $VERSION = '0.0.1';
|
||||
|
||||
|
|
@ -60,6 +59,41 @@ sub fields {
|
|||
return { %{ $entryData } };
|
||||
}
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
=head2 getHash ( )
|
||||
|
||||
Gets a hash reference of data for this entry, which looks like this:
|
||||
|
||||
{
|
||||
DataForm_entryId => "entryId",
|
||||
userId => "userId",
|
||||
username => "username",
|
||||
ipAddress => "0.0.0.0",
|
||||
assetId => "assetId",
|
||||
submissionDate => "2008-00-00 00:00:00", # in UTC
|
||||
entryData => { name => value, name => value, ... },
|
||||
}
|
||||
|
||||
=cut
|
||||
|
||||
sub getHash {
|
||||
my $self = shift;
|
||||
my $id = id $self;
|
||||
|
||||
my $var = {
|
||||
DataForm_entryId => $entryId{$id},
|
||||
userId => $userId{$id},
|
||||
username => $username{$id},
|
||||
ipAddress => $ipAddress{$id},
|
||||
assetId => $assetId{$id},
|
||||
submissionDate => $submissionDate{$id}->toDatabase,
|
||||
entryData => $entryData{$id},
|
||||
};
|
||||
|
||||
return $var;
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
sub getCount {
|
||||
my $class = shift;
|
||||
|
|
@ -102,6 +136,16 @@ sub iterateAll {
|
|||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 new ( asset [, entryId ] )
|
||||
|
||||
=head2 new ( session, entryId )
|
||||
|
||||
Instantiate an object. If C<entryId> is defined, will pull the correct entry
|
||||
from the database. If C<entryId> is not defined, will create a new entry.
|
||||
|
||||
=cut
|
||||
|
||||
sub new {
|
||||
my ($class, $asset, $entryId) = @_;
|
||||
my $self = register($class);
|
||||
|
|
@ -124,7 +168,6 @@ sub new {
|
|||
if (! defined $properties->{'DataForm_entryId'}) {
|
||||
WebGUI::Error::ObjectNotFound->throw(error => 'no such DataForm_entryId', id => $entryId);
|
||||
}
|
||||
$session = $session{$id} = $asset->session;
|
||||
if (! $assetId{$id}) {
|
||||
$assetId{$id} = $properties->{assetId};
|
||||
$asset{$id} = WebGUI::Asset::Wobject::DataForm->new($session, $properties->{assetId});
|
||||
|
|
@ -140,6 +183,38 @@ sub new {
|
|||
return $self;
|
||||
}
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
=head2 newFromHash ( asset, properties )
|
||||
|
||||
=head2 newFromHash ( session, assetId, properties )
|
||||
|
||||
Create a new DataForm entry from the given properties.
|
||||
|
||||
=cut
|
||||
|
||||
sub newFromHash {
|
||||
my $class = shift;
|
||||
my $asset = shift;
|
||||
my $self;
|
||||
|
||||
if ( defined $asset && ref $asset && $asset->isa( 'WebGUI::Asset::Wobject::DataForm' ) ) {
|
||||
my $properties = shift;
|
||||
$self = $class->new( $asset );
|
||||
$self->setFromHash( $properties );
|
||||
}
|
||||
elsif ( defined $asset && ref $asset && $asset->isa( 'WebGUI::Session' ) ) {
|
||||
my $session = $asset;
|
||||
my $assetId = shift;
|
||||
my $properties = shift;
|
||||
$asset = WebGUI::Asset->newByDynamicClass( $session, $assetId );
|
||||
$self = $class->new( $asset );
|
||||
$self->setFromHash( $properties );
|
||||
}
|
||||
|
||||
return $self;
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
sub purgeAssetEntries {
|
||||
my $class = shift;
|
||||
|
|
|
|||
|
|
@ -1001,6 +1001,18 @@ be useful, others may not.|,
|
|||
lastUpdated => 0,
|
||||
context => q{Description of template variable},
|
||||
},
|
||||
|
||||
'editForm workflowIdAddEntry label' => {
|
||||
message => q{Add Entry Workflow},
|
||||
lastUpdated => 0,
|
||||
context => q{Label for asset property},
|
||||
},
|
||||
|
||||
'editForm workflowIdAddEntry description' => {
|
||||
message => q{Workflow to be run when an entry is added to the DataForm},
|
||||
lastUpdated => 0,
|
||||
context => q{Description of asset property},
|
||||
},
|
||||
};
|
||||
|
||||
1;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue