form => {-label => 'Title'},
alt => {-label => 'Synonyms', -multiple => 1},
wptitle => {-label => 'Wikipedia'},
- source => {-label => 'Image'},
- thumb => {-label => 'Convert options', -multiple => 1},
+ source => {-label => 'Image', -src => sub {
+ return "data/word/org/$_[0]->{id}.jpg";
+ }},
+ thumb => {-label => 'Convert options', -multiple => 1, -src => sub {
+ return "data/word/en/$_[0]->{id}.jpg";
+ }},
story => {-label => 'Story', type => 'textarea'},
);
say '<h1>Search</h1><ul>';
printf("<li><small>%s</small> %s %s</li>\n",
$_->{id}, showlink($_->{form}, "/writer/$_->{id}"),
- sprintf('<img src="/%s" style="height:3ex; width:auto" />', Shiar_Sheet::FormRow::imagepath($_ => 'thumb')) x defined $_->{thumb}
+ sprintf('<img src="/%s" style="height:3ex; width:auto" />', $wordcol{thumb}->{-src}->($_)) x defined $_->{thumb}
) for $results->hashes;
say "</ul>\n";
exit;
return 1;
} or Alert('Error creating translation entries', $@);
- my $imgpath = Shiar_Sheet::FormRow::imagepath($row, 'source');
+ my $imgpath = $wordcol{source}->{-src}->($row);
my $reimage = eval {
($row->{source} // '') ne ($replace->{source} // '') or return;
# copy changed remote url to local file
$reimage ||= $row->{cover} ~~ $replace->{cover}; # resize
$reimage++ if $fields{rethumb}; # force refresh
- my $thumbpath = Shiar_Sheet::FormRow::imagepath($row => 'thumb');
if ($reimage) {
+ my $thumbpath = $wordcol{thumb}->{-src}->($row);
if (-e $imgpath) {
my $xyres = $row->{cover} ? '600x400' : '300x200';
my @cmds = @{ $row->{thumb} // [] };
$col, $multiple ? '' : EscapeHTML($val), $html
),
$multiple ? '</span>' : (),
- (map {
- sprintf '<img id="%spreview" src="/%s" alt="%s"%s />',
- $col, $_, $row->{form}, $col eq 'source' ? ' hidden' : '';
- } grep { -e } $row->imagepath($col)),
);
}
}
-
- sub imagepath {
- my ($row, $col) = @_;
- return "data/word/org/$row->{id}.jpg" if $col eq 'source';
- return "data/word/en/$row->{id}.jpg" if $col eq 'thumb';
- return;
- }
}
bless $row, 'Shiar_Sheet::FormRow';
:>
printf '<li><label for="%s">%s</label><p>', $col, $title;
printf '<span class=inline>';
print $row->input($col => $attr);
+ if (my $imgsrc = $attr->{-src}) {
+ printf('<img id="%spreview" src="/%s" alt="%s"%s />',
+ $col, $_, $row->{form}, $col eq 'source' && ' hidden'
+ ) for grep { -e } $imgsrc->($row);
+ }
print $row->input($_ => delete $wordcol{$_}) for @span;
print '</span>';
say '</p></li>';