X-Git-Url: http://git.shiar.nl/sheet.git/blobdiff_plain/5d87ef3cd8bd0104cc663a2872a87b89d1c546bb..4bd2308ef29a34a94eca8f71e924a868b9b7bb19:/writer.plp diff --git a/writer.plp b/writer.plp index 6177fcd..275819b 100644 --- a/writer.plp +++ b/writer.plp @@ -98,8 +98,12 @@ my %wordcol = ( 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'}, ); @@ -109,7 +113,7 @@ if (my $search = $fields{q}) { say '

Search

\n"; exit; @@ -183,7 +187,7 @@ elsif (defined $post{form}) {{ 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 @@ -202,8 +206,8 @@ elsif (defined $post{form}) {{ $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} // [] }; @@ -309,20 +313,9 @@ package Shiar_Sheet::FormRow { $col, $multiple ? '' : EscapeHTML($val), $html ), $multiple ? '' : (), - (map { - sprintf '%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'; :> @@ -341,6 +334,11 @@ for my $col (@wordcols) { printf '
  • ', $col, $title; printf ''; print $row->input($col => $attr); + if (my $imgsrc = $attr->{-src}) { + printf('%s', + $col, $_, $row->{form}, $col eq 'source' && ' hidden' + ) for grep { -e } $imgsrc->($row); + } print $row->input($_ => delete $wordcol{$_}) for @span; print ''; say '

  • ';