| 1 | package Strehler::FormFu::Element::SubmitBlockMulti; | ||||||||||||||
| 2 | 5 | $Strehler::FormFu::Element::SubmitBlockMulti::VERSION = '1.6.8'; | |||||||||||||
| 3 | 5 | ▶ | use strict; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 4 | 5 | ▶ | use Moose; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 5 | |||||||||||||||
| 6 | 5 | extends 'HTML::FormFu::Element::Fieldset'; | |||||||||||||
| 7 | |||||||||||||||
| 8 | has _actions => ( | ||||||||||||||
| 9 | is => 'rw', | ||||||||||||||
| 10 | 0 | ▶ | default => sub { [] }, | ||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||
| 11 | 5 | lazy => 1, | |||||||||||||
| 12 | ); | ||||||||||||||
| 13 | |||||||||||||||
| 14 | 17 | ▶ | after BUILD => sub { | ||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||
| 15 | 17 | my $self = shift; | |||||||||||||
| 16 | 17 | $self->name("save"); | |||||||||||||
| 17 | 17 | return; | |||||||||||||
| 18 | 5 | }; | |||||||||||||
| 19 | |||||||||||||||
| 20 | 17 | ▶ | sub actions { ## no critic qw(Subroutines::RequireArgUnpacking) | ||||||||||||
|
Subroutine
actions: called CC=6 SCAR=18.1
Pod
documented
| |||||||||||||||
| 21 | 17 | my ( $self, $arg ) = @_; | |||||||||||||
| 22 | |||||||||||||||
| 23 | 17 | ▶ | return $self->_label if @_ == 1; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 24 | |||||||||||||||
| 25 | 17 | ▶ | if ( defined $arg ) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 26 | 17 | my @actions = @{$arg}; | |||||||||||||
| 27 | 17 | my $length; | |||||||||||||
| 28 | 17 | ▶ | if($#actions == 2) | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 29 | { | ||||||||||||||
| 30 | 14 | $length = 2; | |||||||||||||
| 31 | } | ||||||||||||||
| 32 | elsif($#actions < 2) | ||||||||||||||
| 33 | { | ||||||||||||||
| 34 | 3 | $length = 3; | |||||||||||||
| 35 | } | ||||||||||||||
| 36 | 17 | my $index = 1; | |||||||||||||
| 37 | 17 | foreach my $b (@actions) | |||||||||||||
| 38 | { | ||||||||||||||
| 39 | 48 | $self->element($self->button_conf($b, $index, $length)); | |||||||||||||
| 40 | 48 | $index++; | |||||||||||||
| 41 | } | ||||||||||||||
| 42 | } | ||||||||||||||
| 43 | 17 | return $self; | |||||||||||||
| 44 | } | ||||||||||||||
| 45 | |||||||||||||||
| 46 | |||||||||||||||
| 47 | sub button_conf | ||||||||||||||
| 48 | 48 | ▶ | { | ||||||||||||
|
Subroutine
button_conf: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||
| 49 | 48 | my $self = shift; | |||||||||||||
| 50 | 48 | my $action = shift; | |||||||||||||
| 51 | 48 | my $index = shift; | |||||||||||||
| 52 | 48 | my $length = shift; | |||||||||||||
| 53 | |||||||||||||||
| 54 | 48 | my %labels = ( 'submit-go' => 'Submit', | |||||||||||||
| 55 | 'submit-continue' => 'Submit and Continue', | ||||||||||||||
| 56 | 'submit-publish' => 'Submit and Publish'); | ||||||||||||||
| 57 | |||||||||||||||
| 58 | #YAML: | ||||||||||||||
| 59 | #name: savebutton1 | ||||||||||||||
| 60 | #tag: button | ||||||||||||||
| 61 | #content: Submit | ||||||||||||||
| 62 | #attributes: | ||||||||||||||
| 63 | #name: strehl-action | ||||||||||||||
| 64 | #value: submit-go | ||||||||||||||
| 65 | #type: submit | ||||||||||||||
| 66 | #class: btn btn-primary span3 | ||||||||||||||
| 67 | |||||||||||||||
| 68 | 48 | my $conf; | |||||||||||||
| 69 | 48 | $conf->{'type'} = 'Block'; | |||||||||||||
| 70 | 48 | $conf->{'name'} = 'savebutton' . $index; | |||||||||||||
| 71 | 48 | $conf->{'tag'} = 'button'; | |||||||||||||
| 72 | 48 | $conf->{'content'} = $labels{$action}; | |||||||||||||
| 73 | 48 | my $attributes; | |||||||||||||
| 74 | 48 | $attributes->{'name'} = 'strehl-action'; | |||||||||||||
| 75 | 48 | $attributes->{'value'} = $action; | |||||||||||||
| 76 | 48 | $attributes->{'type'} = 'submit'; | |||||||||||||
| 77 | 48 | $attributes->{'class'} = 'btn btn-primary span' . $length; | |||||||||||||
| 78 | 48 | $conf->{'attributes'} = $attributes; | |||||||||||||
| 79 | 48 | return $conf; | |||||||||||||
| 80 | } | ||||||||||||||
| 81 | |||||||||||||||
| 82 | =encoding utf8 | ||||||||||||||
| 83 | |||||||||||||||
| 84 | =head1 NAME | ||||||||||||||
| 85 | |||||||||||||||
| 86 | Strehler::FormFu::Element::SubmitBlockMulti - FormFu Element for Strehler generic submit buttons. | ||||||||||||||
| 87 | |||||||||||||||
| 88 | =head1 DESCRIPTION | ||||||||||||||
| 89 | |||||||||||||||
| 90 | Extension for L<Strehler::FormFu::Element::SubmitBlock>. | ||||||||||||||
| 91 | |||||||||||||||
| 92 | Allow configurations with one, two or three buttons, chosen from the actions available in Strehler forms: | ||||||||||||||
| 93 | |||||||||||||||
| 94 | =over 4 | ||||||||||||||
| 95 | |||||||||||||||
| 96 | =item | ||||||||||||||
| 97 | |||||||||||||||
| 98 | submit-go: submit and return to list page | ||||||||||||||
| 99 | |||||||||||||||
| 100 | =item | ||||||||||||||
| 101 | |||||||||||||||
| 102 | submit-continue: submit and stay on the edit page | ||||||||||||||
| 103 | |||||||||||||||
| 104 | =item | ||||||||||||||
| 105 | |||||||||||||||
| 106 | submit-publish: submit and return to list page publishing the content | ||||||||||||||
| 107 | |||||||||||||||
| 108 | =back | ||||||||||||||
| 109 | |||||||||||||||
| 110 | =head1 SYNOPSIS | ||||||||||||||
| 111 | |||||||||||||||
| 112 | In article form: | ||||||||||||||
| 113 | |||||||||||||||
| 114 | - type: "+Strehler::FormFu::Element::SubmitBlockMulti" | ||||||||||||||
| 115 | |||||||||||||||
| 116 | =head1 PARAMETERS | ||||||||||||||
| 117 | |||||||||||||||
| 118 | =over 4 | ||||||||||||||
| 119 | |||||||||||||||
| 120 | =item actions | ||||||||||||||
| 121 | |||||||||||||||
| 122 | A list of actions. Each action will be a button. | ||||||||||||||
| 123 | |||||||||||||||
| 124 | =back | ||||||||||||||
| 125 | |||||||||||||||
| 126 | =head1 GENERATED HTML | ||||||||||||||
| 127 | |||||||||||||||
| 128 | <fieldset> | ||||||||||||||
| 129 | <button value="submit-go" type="submit" name="strehl-action" class="btn btn-primary span3"> | ||||||||||||||
| 130 | Submit | ||||||||||||||
| 131 | </button> | ||||||||||||||
| 132 | <button value="submit-continue" type="submit" name="strehl-action" class="btn btn-info span3"> | ||||||||||||||
| 133 | Submit and Continue | ||||||||||||||
| 134 | </button> | ||||||||||||||
| 135 | </fieldset> | ||||||||||||||
| 136 | |||||||||||||||
| 137 | =head1 YAML CONFIGURATION | ||||||||||||||
| 138 | |||||||||||||||
| 139 | There isn't a YAML configuration. Button configuration is hard-coded in the class | ||||||||||||||
| 140 | |||||||||||||||
| 141 | =cut | ||||||||||||||
| 142 | |||||||||||||||
| 143 | 5 | 1; | |||||||||||||