line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package HTML::Obj2HTML::Plugin::SemanticUI; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
560
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
26
|
|
4
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
2486
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
my @semanticnumbers = qw(zero one two three four five six seven eight nine ten eleven twelve thirteen fourteen fifteen sixteen); |
7
|
|
|
|
|
|
|
HTML::Obj2HTML::register_extension("form", { |
8
|
|
|
|
|
|
|
attr => { class => "ui form" } |
9
|
|
|
|
|
|
|
});HTML::Obj2HTML::register_extension("select", { |
10
|
|
|
|
|
|
|
attr => { class => "ui dropdown" } |
11
|
|
|
|
|
|
|
}); |
12
|
|
|
|
|
|
|
HTML::Obj2HTML::register_extension("checkbox", { |
13
|
|
|
|
|
|
|
tag => "", |
14
|
|
|
|
|
|
|
before => sub { |
15
|
|
|
|
|
|
|
my $obj = shift; |
16
|
|
|
|
|
|
|
if (ref $obj ne "HASH") { return ""; } |
17
|
|
|
|
|
|
|
my $readonly = HTML::Obj2HTML::get_opt("readonly") || $obj->{readonly}; |
18
|
|
|
|
|
|
|
delete($obj->{readonly}); |
19
|
|
|
|
|
|
|
if ($readonly) { |
20
|
|
|
|
|
|
|
return HTML::Obj2HTML::gen([ div => [ |
21
|
|
|
|
|
|
|
if => { cond => $obj->{checked}, true => [ icon => 'green check' ], false => [ icon => 'red close' ]}, |
22
|
|
|
|
|
|
|
_ => " ".$obj->{label} |
23
|
|
|
|
|
|
|
]]); |
24
|
|
|
|
|
|
|
} else { |
25
|
|
|
|
|
|
|
my $label = $obj->{label}; delete($obj->{label}); |
26
|
|
|
|
|
|
|
if (!$label && $obj->{checkboxlabel}) { $label = $obj->{checkboxlabel}; delete($obj->{checkboxlabel}); } |
27
|
|
|
|
|
|
|
if (!$obj->{value}) { $obj->{value} = 1; } |
28
|
|
|
|
|
|
|
$obj->{if} = { cond => $obj->{checked}, true => { checked => 1 } }; delete($obj->{checked}); |
29
|
|
|
|
|
|
|
$obj->{type} = "checkbox"; |
30
|
|
|
|
|
|
|
return HTML::Obj2HTML::gen([ |
31
|
|
|
|
|
|
|
div => { class => 'ui checkbox', _ => [ |
32
|
|
|
|
|
|
|
input => $obj, label => $label |
33
|
|
|
|
|
|
|
] } |
34
|
|
|
|
|
|
|
]); |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
}); |
38
|
|
|
|
|
|
|
HTML::Obj2HTML::register_extension("radio", { |
39
|
|
|
|
|
|
|
tag => "", |
40
|
|
|
|
|
|
|
before => sub { |
41
|
|
|
|
|
|
|
my $obj = shift; |
42
|
|
|
|
|
|
|
if (ref $obj ne "HASH") { return ""; } |
43
|
|
|
|
|
|
|
my $readonly = HTML::Obj2HTML::get_opt("readonly") || $obj->{readonly}; |
44
|
|
|
|
|
|
|
delete($obj->{readonly}); |
45
|
|
|
|
|
|
|
if ($readonly) { |
46
|
|
|
|
|
|
|
return HTML::Obj2HTML::gen([ div => [ |
47
|
|
|
|
|
|
|
if => { cond => $obj->{checked}, true => [ icon => 'check' ] }, |
48
|
|
|
|
|
|
|
_ => " ".$obj->{label} |
49
|
|
|
|
|
|
|
]]); |
50
|
|
|
|
|
|
|
} else { |
51
|
|
|
|
|
|
|
my $label = $obj->{label}; delete($obj->{label}); |
52
|
|
|
|
|
|
|
if (!$label && $obj->{radiolabel}) { $label = $obj->{radiolabel}; delete($obj->{radiolabel}); } |
53
|
|
|
|
|
|
|
if (!$obj->{value}) { $obj->{value} = 1; } |
54
|
|
|
|
|
|
|
$obj->{if} = { cond => $obj->{checked}, true => { checked => 1 } }; delete($obj->{checked}); |
55
|
|
|
|
|
|
|
$obj->{type} = "radio"; |
56
|
|
|
|
|
|
|
return HTML::Obj2HTML::gen([ |
57
|
|
|
|
|
|
|
div => { class => 'ui radio checkbox', _ => [ |
58
|
|
|
|
|
|
|
input => $obj, label => $label |
59
|
|
|
|
|
|
|
] } |
60
|
|
|
|
|
|
|
]); |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
}); |
64
|
|
|
|
|
|
|
HTML::Obj2HTML::register_extension("labeledinput", { |
65
|
|
|
|
|
|
|
tag => "", |
66
|
|
|
|
|
|
|
before => sub { |
67
|
|
|
|
|
|
|
my $obj = shift; |
68
|
|
|
|
|
|
|
if (ref $obj ne "HASH") { return ""; } |
69
|
|
|
|
|
|
|
my $readonly = HTML::Obj2HTML::get_opt("readonly") || $obj->{readonly}; |
70
|
|
|
|
|
|
|
delete($obj->{readonly}); |
71
|
|
|
|
|
|
|
if ($readonly) { |
72
|
|
|
|
|
|
|
return [ div => $obj->{value}." ".$obj->{label} ]; |
73
|
|
|
|
|
|
|
} else { |
74
|
|
|
|
|
|
|
my $label = $obj->{label}; delete($obj->{label}); |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
# The has we were passed actually belongs to a child element, we need to copy and clear. |
77
|
|
|
|
|
|
|
my $inputobj = {}; |
78
|
|
|
|
|
|
|
for (keys %$obj) { $inputobj->{$_} = $obj->{$_}; delete $obj->{$_}; } |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
return [ div => { class => "ui right labeled input", _ => [ |
81
|
|
|
|
|
|
|
input => $inputobj, |
82
|
|
|
|
|
|
|
div => { class => "ui basic label", _ => $label } |
83
|
|
|
|
|
|
|
]}]; |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
}); |
87
|
|
|
|
|
|
|
HTML::Obj2HTML::register_extension("field", { |
88
|
|
|
|
|
|
|
tag => 'div', |
89
|
|
|
|
|
|
|
before => sub { |
90
|
|
|
|
|
|
|
my $obj = shift; |
91
|
|
|
|
|
|
|
if (ref $obj eq "HASH") { |
92
|
|
|
|
|
|
|
if (!defined $obj->{_}) { $obj->{_} = []; } |
93
|
|
|
|
|
|
|
my $label = genhelplabel($obj); |
94
|
|
|
|
|
|
|
if ($label) { |
95
|
|
|
|
|
|
|
unshift(@{$obj->{"_"}}, "label", $obj->{label}); |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
return undef; |
99
|
|
|
|
|
|
|
}, |
100
|
|
|
|
|
|
|
attr => { class => 'field' } |
101
|
|
|
|
|
|
|
}); |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
HTML::Obj2HTML::register_extension("fields", { |
104
|
|
|
|
|
|
|
tag => "div", |
105
|
|
|
|
|
|
|
before => sub { |
106
|
|
|
|
|
|
|
my $o = shift; |
107
|
|
|
|
|
|
|
if (ref $o ne "HASH") { return ""; } |
108
|
|
|
|
|
|
|
$o->{class} = "ui ".$semanticnumbers[$o->{num}]." fields"; |
109
|
|
|
|
|
|
|
delete($o->{num}); |
110
|
|
|
|
|
|
|
return ""; |
111
|
|
|
|
|
|
|
} |
112
|
|
|
|
|
|
|
}); |
113
|
|
|
|
|
|
|
HTML::Obj2HTML::register_extension("checkboxfield", { |
114
|
|
|
|
|
|
|
tag => "", |
115
|
|
|
|
|
|
|
before => sub { |
116
|
|
|
|
|
|
|
my $obj = shift; |
117
|
|
|
|
|
|
|
if (ref $obj ne "HASH") { return ""; } |
118
|
|
|
|
|
|
|
return HTML::Obj2HTML::gen(commonfield($obj, [ checkbox => $obj ])); |
119
|
|
|
|
|
|
|
} |
120
|
|
|
|
|
|
|
}); |
121
|
|
|
|
|
|
|
HTML::Obj2HTML::register_extension("radiofield", { |
122
|
|
|
|
|
|
|
tag => "", |
123
|
|
|
|
|
|
|
before => sub { |
124
|
|
|
|
|
|
|
my $obj = shift; |
125
|
|
|
|
|
|
|
if (ref $obj ne "HASH") { return ""; } |
126
|
|
|
|
|
|
|
return HTML::Obj2HTML::gen(commonfield($obj, [ radio => $obj ])); |
127
|
|
|
|
|
|
|
} |
128
|
|
|
|
|
|
|
}); |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
HTML::Obj2HTML::register_extension("inputfield", { |
131
|
|
|
|
|
|
|
tag => "", |
132
|
|
|
|
|
|
|
before => sub { |
133
|
|
|
|
|
|
|
my $obj = shift; |
134
|
|
|
|
|
|
|
if (ref $obj ne "HASH") { return ""; } |
135
|
|
|
|
|
|
|
my $readonly = HTML::Obj2HTML::get_opt("readonly") || $obj->{readonly}; |
136
|
|
|
|
|
|
|
delete($obj->{readonly}); |
137
|
|
|
|
|
|
|
if ($readonly) { |
138
|
|
|
|
|
|
|
return HTML::Obj2HTML::gen(commonfield($obj, [ span => $obj->{value} ])); |
139
|
|
|
|
|
|
|
} else { |
140
|
|
|
|
|
|
|
return HTML::Obj2HTML::gen(commonfield($obj, [ input => $obj ])); |
141
|
|
|
|
|
|
|
} |
142
|
|
|
|
|
|
|
} |
143
|
|
|
|
|
|
|
}); |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
HTML::Obj2HTML::register_extension("textareafield", { |
146
|
|
|
|
|
|
|
tag => "", |
147
|
|
|
|
|
|
|
before => sub { |
148
|
|
|
|
|
|
|
my $obj = shift; |
149
|
|
|
|
|
|
|
if (ref $obj ne "HASH") { return ""; } |
150
|
|
|
|
|
|
|
if (defined $obj->{value}) { |
151
|
|
|
|
|
|
|
my $val = $obj->{value}; |
152
|
|
|
|
|
|
|
delete($obj->{value}); |
153
|
|
|
|
|
|
|
$val =~ s/^\s+//g; |
154
|
|
|
|
|
|
|
$val =~ s/\s+$//g; |
155
|
|
|
|
|
|
|
$obj->{_} = "$val"; |
156
|
|
|
|
|
|
|
} else { |
157
|
|
|
|
|
|
|
$obj->{_} = ""; |
158
|
|
|
|
|
|
|
} |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
my $readonly = HTML::Obj2HTML::get_opt("readonly") || $obj->{readonly}; |
161
|
|
|
|
|
|
|
delete($obj->{readonly}); |
162
|
|
|
|
|
|
|
if ($readonly) { |
163
|
|
|
|
|
|
|
if ($obj->{class} =~ /editor/) { |
164
|
|
|
|
|
|
|
return HTML::Obj2HTML::gen(commonfield($obj, [ div => [ raw => $obj->{_} ] ])); |
165
|
|
|
|
|
|
|
} else { |
166
|
|
|
|
|
|
|
return HTML::Obj2HTML::gen(commonfield($obj, [ div => [ md => $obj->{_} ] ])); |
167
|
|
|
|
|
|
|
} |
168
|
|
|
|
|
|
|
} else { |
169
|
|
|
|
|
|
|
return HTML::Obj2HTML::gen(commonfield($obj, [ textarea => $obj ])); |
170
|
|
|
|
|
|
|
} |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
} |
173
|
|
|
|
|
|
|
}); |
174
|
|
|
|
|
|
|
HTML::Obj2HTML::register_extension("htmlfield", { |
175
|
|
|
|
|
|
|
tag => "", |
176
|
|
|
|
|
|
|
before => sub { |
177
|
|
|
|
|
|
|
my $obj = shift; |
178
|
|
|
|
|
|
|
if (ref $obj ne "HASH") { return ""; } |
179
|
|
|
|
|
|
|
if ($obj->{class} !~ /editor/) { |
180
|
|
|
|
|
|
|
if ($obj->{class}) { $obj->{class} .= " "; } |
181
|
|
|
|
|
|
|
$obj->{class} .= "editor"; |
182
|
|
|
|
|
|
|
} |
183
|
|
|
|
|
|
|
return [ textareafield => $obj ]; |
184
|
|
|
|
|
|
|
} |
185
|
|
|
|
|
|
|
}); |
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
HTML::Obj2HTML::register_extension("selectfield", { |
188
|
|
|
|
|
|
|
tag => "", |
189
|
|
|
|
|
|
|
before => sub { |
190
|
|
|
|
|
|
|
my $obj = shift; |
191
|
|
|
|
|
|
|
if (ref $obj ne "HASH") { return ""; } |
192
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
my $readonly = HTML::Obj2HTML::get_opt("readonly") || $obj->{readonly}; |
194
|
|
|
|
|
|
|
delete($obj->{readonly}); |
195
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
if ($obj->{class}) { $obj->{class}.=" "; } |
197
|
|
|
|
|
|
|
$obj->{class}.= "ui dropdown"; |
198
|
|
|
|
|
|
|
# if ($obj->{multiple}) { $obj->{class}.= " fluid"; } |
199
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
my $db = $obj->{db} || $HTML::Obj2HTML::db; |
201
|
|
|
|
|
|
|
delete($obj->{db}); |
202
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
if ($obj->{options} && ref $obj->{options} eq "ARRAY") { |
204
|
|
|
|
|
|
|
my @contents = (); |
205
|
|
|
|
|
|
|
if ($obj->{inclblank}) { push(@contents, option => { value => "", _ => "" }); } |
206
|
|
|
|
|
|
|
for (my $i = 0; $i <= $#{$obj->{hiddenoptions}}; $i+=2) { |
207
|
|
|
|
|
|
|
my $v = $obj->{hiddenoptions}->[$i]; |
208
|
|
|
|
|
|
|
my $t = $obj->{hiddenoptions}->[$i+1]; |
209
|
|
|
|
|
|
|
if ((!$obj->{multiple} && defined $obj->{value} && "$obj->{value}" eq "$v") || |
210
|
|
|
|
|
|
|
($obj->{multiple} && defined $obj->{value} && ($obj->{value} & $v))) { |
211
|
|
|
|
|
|
|
if ($readonly) { |
212
|
|
|
|
|
|
|
push(@contents, div => $t); |
213
|
|
|
|
|
|
|
} else { |
214
|
|
|
|
|
|
|
push(@contents, option => { value => $v, _ => $t, selected => 1 }); |
215
|
|
|
|
|
|
|
} |
216
|
|
|
|
|
|
|
} |
217
|
|
|
|
|
|
|
} |
218
|
|
|
|
|
|
|
for (my $i = 0; $i <= $#{$obj->{options}}; $i+=2) { |
219
|
|
|
|
|
|
|
my $v = $obj->{options}->[$i]; |
220
|
|
|
|
|
|
|
my $t = $obj->{options}->[$i+1]; |
221
|
|
|
|
|
|
|
my $opt = { value => $v, _ => $t }; |
222
|
|
|
|
|
|
|
if (!$obj->{multiple}) { |
223
|
|
|
|
|
|
|
if (defined $obj->{value} && "$obj->{value}" eq "$v") { $opt->{selected} = 1; } |
224
|
|
|
|
|
|
|
} else { |
225
|
|
|
|
|
|
|
if (defined $obj->{value} && ($obj->{value} & $v)) { $opt->{selected} = 1; } |
226
|
|
|
|
|
|
|
if (defined $obj->{values}) { |
227
|
|
|
|
|
|
|
if (grep {"$_" eq "$v"} @{$obj->{values}}) { $opt->{selected} = 1; } |
228
|
|
|
|
|
|
|
} |
229
|
|
|
|
|
|
|
} |
230
|
|
|
|
|
|
|
|
231
|
|
|
|
|
|
|
if ($readonly) { |
232
|
|
|
|
|
|
|
if ($opt->{selected}) { |
233
|
|
|
|
|
|
|
push(@contents, div => $opt->{_}); |
234
|
|
|
|
|
|
|
} |
235
|
|
|
|
|
|
|
} else { |
236
|
|
|
|
|
|
|
push(@contents, option => $opt); |
237
|
|
|
|
|
|
|
} |
238
|
|
|
|
|
|
|
} |
239
|
|
|
|
|
|
|
$obj->{_} = \@contents; |
240
|
|
|
|
|
|
|
delete($obj->{values}); |
241
|
|
|
|
|
|
|
delete($obj->{options}); |
242
|
|
|
|
|
|
|
delete($obj->{hiddenoptions}); |
243
|
|
|
|
|
|
|
} |
244
|
|
|
|
|
|
|
if ($obj->{optionsql} && ref $obj->{optionsql} eq "ARRAY") { |
245
|
|
|
|
|
|
|
my @contents = (); |
246
|
|
|
|
|
|
|
if ($obj->{inclblank}) { push(@contents, option => { value => "", _ => "" }); } |
247
|
|
|
|
|
|
|
if (!$obj->{valuefield}) { $obj->{valuefield} = "id"; } |
248
|
|
|
|
|
|
|
if (!$obj->{textfield}) { $obj->{textfield} = "name"; } |
249
|
|
|
|
|
|
|
for (my $r = $db->for(@{$obj->{optionsql}}); $r->more; $r->next) { |
250
|
|
|
|
|
|
|
my $opt = { value => $r->{$obj->{valuefield}}, _ => $r->{$obj->{textfield}} }; |
251
|
|
|
|
|
|
|
if (!$obj->{multiple}) { |
252
|
|
|
|
|
|
|
if (defined $obj->{value} && "$obj->{value}" eq "$r->{$obj->{valuefield}}") { $opt->{selected} = 1; } |
253
|
|
|
|
|
|
|
} else { |
254
|
|
|
|
|
|
|
if (defined $obj->{selectedfield} && $r->{$obj->{selectedfield}}) { |
255
|
|
|
|
|
|
|
$opt->{selected} = 1; |
256
|
|
|
|
|
|
|
} elsif (defined $obj->{value} && ($obj->{value} & $r->{$obj->{valuefield}})) { |
257
|
|
|
|
|
|
|
$opt->{selected} = 1; |
258
|
|
|
|
|
|
|
} |
259
|
|
|
|
|
|
|
if (defined $obj->{values}) { |
260
|
|
|
|
|
|
|
if (grep({$_ eq $r->{$obj->{valuefield}}} @{$obj->{values}})) { $opt->{selected} = 1; } |
261
|
|
|
|
|
|
|
} |
262
|
|
|
|
|
|
|
} |
263
|
|
|
|
|
|
|
if ($readonly) { |
264
|
|
|
|
|
|
|
if ($opt->{selected}) { |
265
|
|
|
|
|
|
|
push(@contents, div => $opt->{_}); |
266
|
|
|
|
|
|
|
} |
267
|
|
|
|
|
|
|
} else { |
268
|
|
|
|
|
|
|
push(@contents, option => $opt); |
269
|
|
|
|
|
|
|
} |
270
|
|
|
|
|
|
|
} |
271
|
|
|
|
|
|
|
$obj->{_} = \@contents; |
272
|
|
|
|
|
|
|
delete($obj->{values}); |
273
|
|
|
|
|
|
|
delete($obj->{optionsql}); |
274
|
|
|
|
|
|
|
delete($obj->{valuefield}); |
275
|
|
|
|
|
|
|
delete($obj->{textfield}); |
276
|
|
|
|
|
|
|
} |
277
|
|
|
|
|
|
|
if (!$obj->{_}) { $obj->{_} = []; } |
278
|
|
|
|
|
|
|
delete($obj->{value}); |
279
|
|
|
|
|
|
|
delete($obj->{inclblank}); |
280
|
|
|
|
|
|
|
|
281
|
|
|
|
|
|
|
if ($readonly) { |
282
|
|
|
|
|
|
|
return HTML::Obj2HTML::gen(commonfield($obj, $obj->{_})); |
283
|
|
|
|
|
|
|
} else { |
284
|
|
|
|
|
|
|
return HTML::Obj2HTML::gen(commonfield($obj, [ select => $obj ])); |
285
|
|
|
|
|
|
|
} |
286
|
|
|
|
|
|
|
|
287
|
|
|
|
|
|
|
} |
288
|
|
|
|
|
|
|
}); |
289
|
|
|
|
|
|
|
HTML::Obj2HTML::register_extension("dateinput", { |
290
|
|
|
|
|
|
|
tag => "", |
291
|
|
|
|
|
|
|
before => sub { |
292
|
|
|
|
|
|
|
my $o = shift; |
293
|
|
|
|
|
|
|
return HTML::Obj2HTML::gen([ |
294
|
|
|
|
|
|
|
div => { class => "ui calendar dateonly", _ => [ |
295
|
|
|
|
|
|
|
div => { class => "ui input left icon", _ => [ |
296
|
|
|
|
|
|
|
i => { class => "calendar icon", _ => [] }, |
297
|
|
|
|
|
|
|
input => $o |
298
|
|
|
|
|
|
|
]} |
299
|
|
|
|
|
|
|
]} |
300
|
|
|
|
|
|
|
]); |
301
|
|
|
|
|
|
|
} |
302
|
|
|
|
|
|
|
}); |
303
|
|
|
|
|
|
|
HTML::Obj2HTML::register_extension("datefield", { |
304
|
|
|
|
|
|
|
tag => "", |
305
|
|
|
|
|
|
|
before => sub { |
306
|
|
|
|
|
|
|
my $obj = shift; |
307
|
|
|
|
|
|
|
if (ref $obj ne "HASH") { return ""; } |
308
|
|
|
|
|
|
|
|
309
|
|
|
|
|
|
|
my $readonly = HTML::Obj2HTML::get_opt("readonly") || $obj->{readonly}; |
310
|
|
|
|
|
|
|
delete($obj->{readonly}); |
311
|
|
|
|
|
|
|
if ($readonly) { |
312
|
|
|
|
|
|
|
return HTML::Obj2HTML::gen(commonfield($obj, [ span => $obj->{value} ] )); |
313
|
|
|
|
|
|
|
} else { |
314
|
|
|
|
|
|
|
return HTML::Obj2HTML::gen(commonfield($obj, [ |
315
|
|
|
|
|
|
|
div => { class => "ui calendar ".$obj->{class}, _ => [ |
316
|
|
|
|
|
|
|
div => { class => "ui input left icon", _ => [ |
317
|
|
|
|
|
|
|
i => { class => "calendar icon", _ => [] }, |
318
|
|
|
|
|
|
|
input => { type => "text", name => $obj->{name}, placeholder => $obj->{placeholder}, value => $obj->{value} } |
319
|
|
|
|
|
|
|
]} |
320
|
|
|
|
|
|
|
]} |
321
|
|
|
|
|
|
|
])); |
322
|
|
|
|
|
|
|
} |
323
|
|
|
|
|
|
|
} |
324
|
|
|
|
|
|
|
}); |
325
|
|
|
|
|
|
|
HTML::Obj2HTML::register_extension("hiddeninput", { |
326
|
|
|
|
|
|
|
tag => "input", |
327
|
|
|
|
|
|
|
attr => { type => "hidden" } |
328
|
|
|
|
|
|
|
}); |
329
|
|
|
|
|
|
|
HTML::Obj2HTML::register_extension("submit", { |
330
|
|
|
|
|
|
|
tag => "", |
331
|
|
|
|
|
|
|
before => sub { |
332
|
|
|
|
|
|
|
my $obj = shift; |
333
|
|
|
|
|
|
|
if (ref $obj ne "HASH") { $obj = { _ => $obj }; } |
334
|
|
|
|
|
|
|
my $readonly = HTML::Obj2HTML::get_opt("readonly") || $obj->{readonly}; |
335
|
|
|
|
|
|
|
delete($obj->{readonly}); |
336
|
|
|
|
|
|
|
if ($readonly) { |
337
|
|
|
|
|
|
|
return []; |
338
|
|
|
|
|
|
|
} |
339
|
|
|
|
|
|
|
if (!ref $obj) { $obj = { value => $obj }; } else { $obj->{value} = $obj->{label}; delete($obj->{label}); } |
340
|
|
|
|
|
|
|
if (defined $obj->{class}) { $obj->{class} .= " ui button"; } else { $obj->{class}.="ui positive button"; } |
341
|
|
|
|
|
|
|
$obj->{type} = "submit"; |
342
|
|
|
|
|
|
|
return [ input => $obj ]; |
343
|
|
|
|
|
|
|
}, |
344
|
|
|
|
|
|
|
}); |
345
|
|
|
|
|
|
|
|
346
|
|
|
|
|
|
|
HTML::Obj2HTML::register_extension("cancel", { |
347
|
|
|
|
|
|
|
tag => "", |
348
|
|
|
|
|
|
|
before => sub { |
349
|
|
|
|
|
|
|
my $obj = shift; |
350
|
|
|
|
|
|
|
if (ref $obj ne "HASH") { $obj = { _ => $obj }; } |
351
|
|
|
|
|
|
|
my $readonly = HTML::Obj2HTML::get_opt("readonly") || $obj->{readonly}; |
352
|
|
|
|
|
|
|
delete($obj->{readonly}); |
353
|
|
|
|
|
|
|
if ($readonly) { |
354
|
|
|
|
|
|
|
return []; |
355
|
|
|
|
|
|
|
} |
356
|
|
|
|
|
|
|
if (!ref $obj) { $obj = { value => $obj }; } else { $obj->{value} = $obj->{label}; delete($obj->{label}); } |
357
|
|
|
|
|
|
|
if ($obj->{class}) { $obj->{class} .= " "; } |
358
|
|
|
|
|
|
|
$obj->{class}.="ui negative button"; |
359
|
|
|
|
|
|
|
return [ a => $obj ]; |
360
|
|
|
|
|
|
|
}, |
361
|
|
|
|
|
|
|
}); |
362
|
|
|
|
|
|
|
|
363
|
|
|
|
|
|
|
HTML::Obj2HTML::register_extension("helplabel", { |
364
|
|
|
|
|
|
|
tag => "label", |
365
|
|
|
|
|
|
|
before => sub { |
366
|
|
|
|
|
|
|
my $o = shift; |
367
|
|
|
|
|
|
|
if (ref $o ne "HASH") { $o = { helptext => $o }; } |
368
|
|
|
|
|
|
|
$o->{_} = [ _ => $o->{label} ]; |
369
|
|
|
|
|
|
|
if ($o->{helptext}) { |
370
|
|
|
|
|
|
|
push(@{$o->{_}}, help => { text => $o->{helptext} }); |
371
|
|
|
|
|
|
|
} |
372
|
|
|
|
|
|
|
if ($o->{helphtml}) { |
373
|
|
|
|
|
|
|
push(@{$o->{_}}, help => { html => $o->{helphtml} }); |
374
|
|
|
|
|
|
|
} |
375
|
|
|
|
|
|
|
delete($o->{label}); |
376
|
|
|
|
|
|
|
delete($o->{helptext}); |
377
|
|
|
|
|
|
|
delete($o->{helphtml}); |
378
|
|
|
|
|
|
|
return ""; |
379
|
|
|
|
|
|
|
} |
380
|
|
|
|
|
|
|
}); |
381
|
|
|
|
|
|
|
|
382
|
|
|
|
|
|
|
sub genhelplabel { |
383
|
0
|
|
|
0
|
|
|
my $obj = shift; |
384
|
0
|
0
|
|
|
|
|
if (ref $obj ne "HASH") { $obj = { _ => $obj }; } |
|
0
|
|
|
|
|
|
|
385
|
0
|
0
|
|
|
|
|
if ($obj->{label}) { |
386
|
0
|
|
|
|
|
|
my $label = $obj->{label}; |
387
|
0
|
0
|
|
|
|
|
if ($obj->{helptext}) { |
388
|
0
|
|
|
|
|
|
$label = [ _ => $label, i => { style => 'margin-left: 5px;', class => 'blue circular icon help', 'data-content' => $obj->{helptext}, _ => [] } ]; |
389
|
0
|
|
|
|
|
|
delete($obj->{helptext}); |
390
|
|
|
|
|
|
|
} |
391
|
0
|
0
|
|
|
|
|
if ($obj->{helphtml}) { |
392
|
0
|
|
|
|
|
|
$label = [ _ => $label, i => { style => 'margin-left: 5px;', class => 'blue circular icon help', 'data-html' => $obj->{helphtml}, _ => [] } ]; |
393
|
0
|
|
|
|
|
|
delete($obj->{helphtml}); |
394
|
|
|
|
|
|
|
} |
395
|
0
|
|
|
|
|
|
delete($obj->{label}); |
396
|
0
|
|
|
|
|
|
return $label; |
397
|
|
|
|
|
|
|
} |
398
|
0
|
|
|
|
|
|
return; |
399
|
|
|
|
|
|
|
} |
400
|
|
|
|
|
|
|
sub commonfield { |
401
|
0
|
|
|
0
|
|
|
my $obj = shift; |
402
|
0
|
|
|
|
|
|
my $field = shift; |
403
|
|
|
|
|
|
|
|
404
|
0
|
0
|
|
|
|
|
if (ref $obj ne "HASH") { return ""; } |
|
0
|
|
|
|
|
|
|
405
|
0
|
|
|
|
|
|
my $class = "field"; |
406
|
0
|
0
|
|
|
|
|
if ($obj->{required}) { |
407
|
0
|
|
|
|
|
|
$class .= " required"; |
408
|
0
|
|
|
|
|
|
delete($obj->{required}); |
409
|
|
|
|
|
|
|
} |
410
|
|
|
|
|
|
|
|
411
|
0
|
|
|
|
|
|
my $label = genhelplabel($obj); |
412
|
0
|
0
|
|
|
|
|
if ($label) { |
413
|
0
|
|
|
|
|
|
unshift(@{$field}, "label", $label); |
|
0
|
|
|
|
|
|
|
414
|
|
|
|
|
|
|
}; |
415
|
0
|
0
|
|
|
|
|
if ($obj->{uiwidth}) { |
416
|
0
|
|
|
|
|
|
$class .= " $semanticnumbers[$obj->{uiwidth}] wide"; |
417
|
0
|
|
|
|
|
|
delete($obj->{uiwidth}); |
418
|
|
|
|
|
|
|
} |
419
|
0
|
|
|
|
|
|
return [ div => { class => $class, _ => $field }]; |
420
|
|
|
|
|
|
|
} |
421
|
|
|
|
|
|
|
1; |