X-Git-Url: http://git.shiar.net/sheet.git/blobdiff_plain/08a379d96eaacbc1268c3f7aff9fb2bfcee80115..cf8d01da2735d21735d562e73009546d64125d4a:/writer.plp diff --git a/writer.plp b/writer.plp index 226aa4b..99a9736 100644 --- a/writer.plp +++ b/writer.plp @@ -205,6 +205,44 @@ else { } my $title = $row->{id} ? "entry #$row->{id}" : 'new entry'; + +package Shiar_Sheet::FormRow { + sub input { + my ($row, $col, $type, $label) = @_; + my $val = $row->{$col} // ''; + $val = '{'.join(',', map {s/,/\\,/gr} @{$val}).'}' if ref $val eq 'ARRAY'; + if (ref $type eq 'ARRAY') { + return ( + sprintf('', + ); + } + elsif ($type eq 'checkbox') { + return sprintf( + join('', + '', + ), $col, $type, !!$val && ' checked', $label + ); + } + else { + my $html = ''; + $html .= qq( $_="$type->{$_}") for sort keys %{$type // {}}; + return ( + $label ? sprintf('', $col, $label) : (), + sprintf('', + $col, PLP::Functions::EscapeHTML($val), $html + ), + ); + } + } +} +bless $row, 'Shiar_Sheet::FormRow'; :>
', $col, $title;
printf '';
if ($col eq 'prio') {
- printf '';
- printf(
- join('',
- '',
- ),
- 'cover', !!$row->{cover} && ' checked', 'Highlighted'
- );
- printf('',
- 'grade', 'Order', Entity($row->{grade})
- );
+ print $row->input($col => \@prioenum);
+ print $row->input(cover => 'checkbox', 'Highlighted');
+ print $row->input(grade => {type => 'number'}, 'Order');
}
else {
- printf '', $col, Entity($val);
+ print $row->input($col);
-e and printf '', $col, $_, $row->{form}
for $col eq 'thumb' ? "data/word/eng/$row->{form}.jpg" : ();
- printf('',
- 'ref', 'Reference', Entity($row->{ref})
- ) if $col eq 'cat';
+ print $row->input(ref => {}, 'Reference') if $col eq 'cat';
}
print '';
-e and printf('
',