« blib/lib/OpusVL/AppKit/FormFu/Constraint/AppKitPassword.pm
↑ Summary
blib/lib/OpusVL/AppKit/View/SimpleXML.pm »
| 1 | package OpusVL::AppKit::Action::AppKitForm; | ||||||||||
| 2 | |||||||||||
| 3 | ############################################################################################################################ | ||||||||||
| 4 | # use lines. | ||||||||||
| 5 | ############################################################################################################################ | ||||||||||
| 6 | 8 | ▶ | use Moose; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 8 | ▶ | use namespace::autoclean; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | 8 | ▶ | use MRO::Compat; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | 8 | extends 'Catalyst::Action'; | |||||||||
| 10 | 8 | ▶ | use File::ShareDir; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 11 | 8 | ▶ | use List::MoreUtils qw/uniq/; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 12 | |||||||||||
| 13 | ############################################################################################################################ | ||||||||||
| 14 | # Methods | ||||||||||
| 15 | ############################################################################################################################ | ||||||||||
| 16 | |||||||||||
| 17 | sub execute | ||||||||||
| 18 | 16 | ▶ | { | ||||||||
|
Subroutine
execute: called CC=9 SCAR=23.9
Pod
documented
| |||||||||||
| 19 | 16 | my $self = shift; | |||||||||
| 20 | 16 | my ($controller, $c, @args) = @_; | |||||||||
| 21 | |||||||||||
| 22 | # get the FormFu object ... | ||||||||||
| 23 | 16 | ▶ | die("Failed to pull form from controller. Ensure your Controller 'extends' Catalyst::Controller::HTML::FormFu") unless $controller->can('form'); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 24 | 16 | my $form = $controller->form; | |||||||||
| 25 | |||||||||||
| 26 | # Configure the form to generate IDs automatically | ||||||||||
| 27 | 16 | $form->auto_id("formfield_%n_%r_%c"); | |||||||||
| 28 | # The action attribute should point the path of the config file... | ||||||||||
| 29 | 16 | my $config_file = $self->attributes->{AppKitForm}->[0]; | |||||||||
| 30 | |||||||||||
| 31 | 16 | ▶ | unless ( $controller->appkit_myclass ) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 32 | { | ||||||||||
| 33 | 0 | die("Failed to load AppKitForm.. no appkit_myclass specified for $controller "); | |||||||||
| 34 | } | ||||||||||
| 35 | |||||||||||
| 36 | # build the start of config file path.. | ||||||||||
| 37 | 16 | my $path = File::ShareDir::module_dir( $controller->appkit_myclass ) . '/root/forms/'; | |||||||||
| 38 | # ... build the rest of the path.. | ||||||||||
| 39 | 16 | ▶ | if ( defined $config_file ) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 40 | { | ||||||||||
| 41 | 15 | $path .= $config_file; | |||||||||
| 42 | } | ||||||||||
| 43 | else | ||||||||||
| 44 | { | ||||||||||
| 45 | 1 | $path .= $self->reverse . '.yml'; | |||||||||
| 46 | } | ||||||||||
| 47 | |||||||||||
| 48 | 16 | ▶ | $c->log->debug("AppKitForm Loading config: $path \n" ) if $c->debug; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 49 | |||||||||||
| 50 | # .. now get the full path... | ||||||||||
| 51 | 16 | my $form_file = File::Spec->rel2abs( $path ); | |||||||||
| 52 | |||||||||||
| 53 | 16 | ▶ | if ( -r $form_file ) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 54 | { | ||||||||||
| 55 | # .. load it.. | ||||||||||
| 56 | 16 | $self->load_config_file ( $c, $form, $form_file ); | |||||||||
| 57 | 16 | my $new_formfu = $form->can('auto_container_comment_class'); | |||||||||
| 58 | 16 | ▶ | if($c->config->{no_formfu_classes}) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 59 | { | ||||||||||
| 60 | 0 | ▶ | unless($new_formfu) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 61 | { | ||||||||||
| 62 | 0 | $c->log->warn('no_formfu_classes feature will not work without upgrade to HTML::FormFu 1.0'); | |||||||||
| 63 | } | ||||||||||
| 64 | } | ||||||||||
| 65 | else | ||||||||||
| 66 | { | ||||||||||
| 67 | 16 | ▶ | if($new_formfu) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 68 | { | ||||||||||
| 69 | 16 | $form->auto_container_class('%t'); | |||||||||
| 70 | 16 | $form->auto_container_label_class('label'); | |||||||||
| 71 | 16 | $form->auto_container_comment_class('comment'); | |||||||||
| 72 | 16 | $form->auto_comment_class('comment'); | |||||||||
| 73 | 16 | $form->auto_container_error_class('error'); | |||||||||
| 74 | 16 | $form->auto_container_per_error_class('error_%s_%t'); | |||||||||
| 75 | 16 | $form->auto_error_class('error_message error_%s_%t'); | |||||||||
| 76 | } | ||||||||||
| 77 | } | ||||||||||
| 78 | |||||||||||
| 79 | 16 | my $previous_indicator = $form->indicator; | |||||||||
| 80 | $form->indicator(sub | ||||||||||
| 81 | 21 | ▶ | { | ||||||||
|
Subroutine
__ANON__: called CC=4 SCAR=16.5
| |||||||||||
| 82 | 21 | my $self = shift; | |||||||||
| 83 | 21 | my $query = shift; | |||||||||
| 84 | 21 | ▶ | if(uc $form->method eq 'POST') { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 85 | 21 | ▶ | unless(uc $c->req->method eq 'POST') | ||||||||
|
Branch: 1 branch
| |||||||||||
| 86 | { | ||||||||||
| 87 | # check form is a post, if not return false. | ||||||||||
| 88 | 7 | return 0; | |||||||||
| 89 | } | ||||||||||
| 90 | } | ||||||||||
| 91 | 14 | ▶ | if($previous_indicator) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 92 | { | ||||||||||
| 93 | 14 | return $query->param($previous_indicator); | |||||||||
| 94 | } | ||||||||||
| 95 | else | ||||||||||
| 96 | { | ||||||||||
| 97 | 0 | my @names = uniq grep {defined} map { $_->nested_name } @{ $self->get_fields }; | |||||||||
| 98 | 0 | return grep { defined $query->param($_) } @names; | |||||||||
| 99 | } | ||||||||||
| 100 | 16 | }); | |||||||||
| 101 | |||||||||||
| 102 | 16 | $self->process( $form ); | |||||||||
| 103 | |||||||||||
| 104 | # .. stash it.. | ||||||||||
| 105 | 16 | $c->stash->{ 'form' } = $form; | |||||||||
| 106 | } | ||||||||||
| 107 | else | ||||||||||
| 108 | { | ||||||||||
| 109 | 0 | die("Could not find form config: $form_file "); | |||||||||
| 110 | } | ||||||||||
| 111 | |||||||||||
| 112 | # call the next 'excute'... | ||||||||||
| 113 | 16 | my $r = $self->next::method(@_); | |||||||||
| 114 | |||||||||||
| 115 | 16 | return $r; | |||||||||
| 116 | } | ||||||||||
| 117 | |||||||||||
| 118 | sub load_config_file | ||||||||||
| 119 | 16 | ▶ | { | ||||||||
|
Subroutine
load_config_file: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 120 | 16 | my $self = shift; | |||||||||
| 121 | 16 | my $c = shift; | |||||||||
| 122 | 16 | my $form = shift; | |||||||||
| 123 | 16 | my $form_file = shift; | |||||||||
| 124 | |||||||||||
| 125 | 16 | $form->load_config_file ( $form_file ); | |||||||||
| 126 | } | ||||||||||
| 127 | |||||||||||
| 128 | sub process | ||||||||||
| 129 | 16 | ▶ | { | ||||||||
|
Subroutine
process: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 130 | 16 | my $self = shift; | |||||||||
| 131 | 16 | my $form = shift; | |||||||||
| 132 | # this is here so that other classes/roles can hook this method. | ||||||||||
| 133 | # .. process it.. | ||||||||||
| 134 | 16 | $form->process; | |||||||||
| 135 | } | ||||||||||
| 136 | |||||||||||
| 137 | 8 | 1; | |||||||||
| 138 | |||||||||||
| 139 | __END__ | ||||||||||