lib/Strehler/FormFu/Element/Category.pm

filter: Statementstmt 95.3% 41 / 43 Branchbran 56.2% 9 / 16 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 77.7% 7 / 9 Podpod 100% 3 / 3 totaltotal 84.5% 60 / 71 CC 9 SCAR 10.8
CC
9
Cov
85%
not_required
4.2
name
4.0
label
3.1
CRAP 3.0
« blib/lib/Strehler/Element/Role/Maintainer.pm ↑ Summary lib/Strehler/Element/Role/Configured.pm »
1 package Strehler::FormFu::Element::Category;
2 7 $Strehler::FormFu::Element::Category::VERSION = '1.6.8';
3 7 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 7 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 7 extends 'HTML::FormFu::Element::Fieldset';
7  
8 has _name => (
9 is => 'rw',
10 17 ▶ default => sub { [] },
Subroutine __ANON__: called CC=1 SCAR=0.0
11 7 lazy => 1,
12 );
13  
14 has _label => (
15 is => 'rw',
16 0 ▶ default => sub { [] },
Subroutine __ANON__: not called CC=1 SCAR=6.9
17 7 lazy => 1,
18 );
19  
20 has _not_required => (
21 is => 'rw',
22 0 ▶ default => sub { [] },
Subroutine __ANON__: not called CC=1 SCAR=6.9
23 7 lazy => 1,
24 );
25  
26  
27  
28  
29 40 ▶after BUILD => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
30 40 my $self = shift;
31 40 my $root_path = __FILE__;
32 40 $root_path =~ s/FormFu\/Element\/Category\.pm//;
33 40 $self->load_config_file($root_path . "forms/admin/elements/category_multi.yml");
34 40 return;
35 7 };
36  
37 22 ▶sub label { ## no critic qw(Subroutines::RequireArgUnpacking)
Subroutine label: called CC=3 SCAR=11.2
Pod documented
38 22 my ( $self, $arg ) = @_;
39  
40 22 ▶ return $self->_label if @_ == 1;
Branch: 1 branch
BranchTrueFalseTotal
if @_ == 1 0 22 22
41  
42 22 ▶ if ( defined $arg ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $arg) 22 0 22
43 22 $self->_label($arg);
44 22 $self->get_all_element({ name => 'category-name' })->label($arg);
45 }
46 22 return $self;
47 }
48 75 ▶sub name { ## no critic qw(Subroutines::RequireArgUnpacking)
Subroutine name: called CC=4 SCAR=14.0
Pod documented
49 75 my ( $self, $arg ) = @_;
50  
51 75 ▶ return $self->_name if @_ == 1;
Branch: 1 branch
BranchTrueFalseTotal
if @_ == 1 53 22 75
52  
53 22 ▶ if ( defined $arg ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $arg) 22 0 22
54 22 $self->_name($arg);
55 22 my $name_element = $self->get_element({ name => 'category' });
56 22 ▶ if($name_element)
Branch: 1 branch
BranchTrueFalseTotal
if ($name_element) 22 0 22
57 {
58 22 $name_element->name($arg);
59 22 $name_element->id($arg);
60 }
61 }
62 22 return $self;
63 }
64 22 ▶sub not_required { ## no critic qw(Subroutines::RequireArgUnpacking)
Subroutine not_required: called CC=4 SCAR=14.3
Pod documented
65 22 my ( $self, $arg ) = @_;
66 22 ▶ return $self->_not_required if @_ == 1;
Branch: 1 branch
BranchTrueFalseTotal
if @_ == 1 0 22 22
67 22 ▶ if ( defined $arg ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $arg) 22 0 22
68 22 $self->_not_required($arg);
69 22 ▶ if($arg == 1)
Branch: 1 branch
BranchTrueFalseTotal
if ($arg == 1) 22 0 22
70 {
71 22 $self->get_all_element({ name => 'category-name' })->_constraints([]);
72 }
73 }
74  
75 22 return;
76 }
77  
78 =encoding utf8
79  
80 =head1 NAME
81  
82 Strehler::FormFu::Element::Category - FormFu Element for Strehler Category Selector.
83  
84 =head1 DESCRIPTION
85  
86 A FormFu element to encapsulate all the frontend logic for category selection. It's just a Block element with a particular configuration file hard-coded in it.
87 Category selector needs to be identified in a clear way and needs a fixed structure because it has to interact with Strehler javascript library.
88  
89 This element hasn't the standard HTML::FormFu elements namespace because it makes sense only in a Strehler system.
90  
91 =head1 SYNOPSIS
92  
93 In article form:
94  
95 - type: "+Strehler::FormFu::Element::Category"
96  
97 =head1 PARAMETERS
98  
99 =over 4
100  
101 =item label
102  
103 The label displayed for the field. "Category" is the default value.
104  
105 =item name
106  
107 The name of the field containing information about the category (the ID). "category" is the default value.
108  
109 =item not_required
110  
111 Category is usually mandatory on categorized entities. If you want a category field NOT required set this parameter to 1.
112  
113 =back
114  
115 =head1 GENERATED HTML
116  
117 <fieldset class="category-widget">
118 <div class="sel-category-input">
119 <div>
120 <label>Category</label>
121 <input name="category-name" type="text" class="sel-category-name">
122 </div>
123 <button class="btn btn-warning sel-category-back" type="button">
124 &lt;
125 </button>
126 <img class="sel-category-loader"
127 src="/strehler/images/ajax-loader.gif"
128 style="display: none;">
129 </div>
130 <div>
131 <select name="category-combo" class="sel-category-combo">
132 <option value="1">cat1</option>
133 <option value="2">cat2</option>
134 </select>
135 </div>
136 <input name="category" type="hidden" value="22" class="sel-category-id" id="category">
137 <input name="category-parent" type="hidden" class="sel-category-parent" value="">
138 </fieldset>
139  
140  
141 Options are inserted dinamically during form generation.
142 Sub-category display attributed is managed by javascript.
143  
144 =head1 YAML CONFIGURATION
145  
146 For the complete configuration see in the package: forms/admin/elements/category_multi.yml
147  
148 =cut
149  
150 7 1;
« blib/lib/Strehler/Element/Role/Maintainer.pm ↑ Summary lib/Strehler/Element/Role/Configured.pm »