-my $title = $row->{id} ? "entry <small>#$row->{id}</small>" : 'new entry';
-
-package Shiar_Sheet::FormRow {
- sub input {
- my ($row, $col, $attr) = @_;
- my $val = $row->{$col} // '';
- $val = '{'.join(',', map {s/,/\\,/gr} @{$val}).'}' if ref $val eq 'ARRAY';
- my $html = '';
- $html .= qq( $_="$attr->{$_}") for sort grep {!/^-/} keys %{$attr // {}};
-
- if (my $options = $attr->{-select}) {
- $options = { map {$_ => $options->[$_]} 0 .. $#{$options} }
- if ref $options eq 'ARRAY';
- $options->{$val} //= "unknown ($val)"; # preserve current
- return (
- sprintf('<select id="%s" name="%1$s">', $col),
- (map { sprintf('<option value="%s"%s>%s</option>',
- $_, $val eq $_ && ' selected', $options->{$_}
- ) } sort keys %{$options}),
- '</select>',
- );
- }
- elsif ($attr->{type} eq 'checkbox') {
- $html .= ' checked' if $val;
- return sprintf(
- join('',
- '<label>',
- '<input name="%1$s" value="0" type="hidden" />',
- '<input id="%s" name="%1$s" value="1"%s>',
- ' %s</label>',
- ), $col, $html, $attr->{-label}
- );
- }
- else {
- return (
- (map {
- sprintf('<label for="%s">%s</label>', $col, $_)
- } $attr->{-label} // ()),
- sprintf('<input id="%s" name="%1$s" value="%s"%s />',
- $col, PLP::Functions::EscapeHTML($val), $html
- ),
- (map {
- sprintf '<img id="%spreview" src="/%s" alt="%s"%s />',
- $col, $_, $row->{form}, $col eq 'source' ? ' hidden' : '';
- } grep { -e } $row->imagepath($col)),
- );
- }