From: Mischa POSLAWSKY Date: Sat, 30 May 2020 16:45:52 +0000 (+0200) Subject: word edit: common method to determine image paths X-Git-Tag: v1.13~237 X-Git-Url: http://git.shiar.nl/sheet.git/commitdiff_plain/26b42ef92dccbff26573149d6886958862455d81 word edit: common method to determine image paths --- diff --git a/writer.js b/writer.js index e21b684..e00f99e 100644 --- a/writer.js +++ b/writer.js @@ -35,6 +35,7 @@ document.addEventListener('DOMContentLoaded', () => { let imgpreview = document.getElementById('sourcepreview'); if (imgpreview) { let imginput = document.getElementById('source'); + imginput.parentNode.parentNode.append(imgpreview); // separate row let previewbutton = imginput.parentNode.appendChild(document.createElement('button')); previewbutton.type = 'button'; previewbutton.append('View'); diff --git a/writer.plp b/writer.plp index 99a9736..15a9515 100644 --- a/writer.plp +++ b/writer.plp @@ -150,7 +150,7 @@ elsif ($ENV{REQUEST_METHOD} eq 'POST') {{ next; }; - my $imgpath = "data/word/org/$row->{id}.jpg"; + my $imgpath = Shiar_Sheet::FormRow::imagepath($row, 'source'); my $reimage = eval { ($row->{source} // '') ne ($replace->{source} // '') or return; # copy changed remote url to local file @@ -169,7 +169,7 @@ elsif ($ENV{REQUEST_METHOD} eq 'POST') {{ $reimage ||= $row->{cover} ~~ $replace->{cover}; # resize $reimage++ if $fields{rethumb}; # force refresh - my $thumbpath = "data/word/eng/$row->{form}.jpg"; + my $thumbpath = Shiar_Sheet::FormRow::imagepath($row => 'thumb'); if ($reimage) { if (-e $imgpath) { my $xyres = $row->{cover} ? '600x400' : '300x200'; @@ -238,9 +238,20 @@ package Shiar_Sheet::FormRow { sprintf('', $col, PLP::Functions::EscapeHTML($val), $html ), + (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/eng/$row->{form}.jpg" if $col eq 'thumb'; + return; + } } bless $row, 'Shiar_Sheet::FormRow'; :> @@ -264,14 +275,9 @@ for my $colinfo (pairs @wordcols) { } else { print $row->input($col); - -e and printf '%s', $col, $_, $row->{form} - for $col eq 'thumb' ? "data/word/eng/$row->{form}.jpg" : (); print $row->input(ref => {}, 'Reference') if $col eq 'cat'; } print ''; - -e and printf('', - $col, $_, $row->{form} - ) for $col eq 'source' ? "data/word/org/$row->{id}.jpg" : (); say '

'; }