X-Git-Url: http://git.shiar.nl/sheet.git/blobdiff_plain/ca5f2bee8e55d51ca801ef65d25dcb03285a6b1c..94259759473e60e9fb3823864031e827f09cc607:/word/edit.plp diff --git a/word/edit.plp b/word/edit.plp index 1d766b9..2968642 100644 --- a/word/edit.plp +++ b/word/edit.plp @@ -10,8 +10,6 @@ Html({ raw => <<'EOT', - - EOT }); @@ -113,7 +111,7 @@ my %wordcol = ( convert => {-label => 'Convert options', -json => 'image', -multiple => 1, -src => sub { return "data/word/32/$_[0]->{id}.jpg"; }}, - crop32 => {-label => 'Crop 3:2', -json => 'image'}, + crop32 => {-json => 'image', type => 'hidden'}, # set by javascript interface story => {-label => 'Story', type => 'textarea', hidden => 'hidden'}, ); @@ -154,7 +152,6 @@ elsif (defined $post{form}) {{ my @val = map { parseinput($_) } $post{'@'.$col}->@*; my $val = $colinfo->{-multiple} && @val ? \@val : $val[-1]; if (my $jsoncol = $colinfo->{-json}) { - defined $val and $row->{$jsoncol}->{$col} = $val; # hash will be encoded } else { @@ -162,7 +159,13 @@ elsif (defined $post{form}) {{ } } my $imagecol = $row->{image}; # backup image subcolumns - ref $_ eq 'HASH' and $_ = encode_json($_) for values %{$row}; + while (my ($col, $val) = each %{$row}) { + # convert json subcolumns to database string + ref $val eq 'HASH' or next; + $val = { %{decode_json($_)}, %{$val} } for $replace->{$col} // (); # preserve unknown + defined $val->{$_} or delete $val->{$_} for keys %{$val}; # delete emptied + $row->{$col} = encode_json($val); + } if (!$row->{form} and $row->{lang}) { if ($row->{ref} ne 'delete') { @@ -258,17 +261,20 @@ for my $col (@wordcols) { my ($attr, @span) = ref $info eq 'ARRAY' ? @{$info} : $info; next if delete $attr->{hidden} and not $row->{$col}; my $title = ref $attr ? delete $attr->{-label} : $attr; - printf '
  • ', $col, $title; + printf '

  • ', $col, $title; printf ''; print $row->input($col => $attr); if (my $imgsrc = $attr->{-src}) { - printf('%s', - $col, $_, $row->{form}, $col eq 'source' && ' hidden' + my $hide = $col eq 'source'; + printf '
    ', $col unless $hide; + printf('%s', + $_, $row->{form}, $hide && qq( id="${col}preview" hidden) ) for grep { -e } $imgsrc->($row); + printf '
    ' unless $hide; } print $row->input($_ => delete $wordcol{$_}) for @span; print '
    '; - say '

  • '; + say ''; } if (not $row->{ref}) { @@ -328,6 +334,10 @@ while (my $ref = $children->hash) { + + <: }