word edit: columns declare nested suboptions
authorMischa POSLAWSKY <perl@shiar.org>
Sat, 30 May 2020 18:51:20 +0000 (20:51 +0200)
committerMischa POSLAWSKY <perl@shiar.org>
Sat, 6 Jun 2020 01:49:20 +0000 (03:49 +0200)
writer.plp

index ca27e214615983c44ce04cfacf2d0b5c000643fa..0e1058221ad4dc984c28c03b77d3fa15e3109968 100644 (file)
@@ -105,20 +105,25 @@ my $db = eval {
        });
 } or Abort('Database error', 501, $@);
 
-my @wordcols = (
+my @wordcols = pairkeys
+my %wordcol = (
        lang    => 'Language',
-       cat     => 'Category',
-       ref     => undef, # included with cat
-       grade   => undef, # "
-       prio    => 'Level',
-       cover   => undef, # included with prio
+       cat     => [{-label => 'Category'}, 'ref'],
+       ref     => {-label => 'Reference'},
+       prio    => [
+               {-label => 'Level', -select => [qw(
+                       essential basic common distinctive rare invisible
+               )]},
+               'cover', 'grade',
+       ],
+       cover   => {-label => 'Highlighted', type => 'checkbox'},
+       grade   => {-label => 'Order', type => 'number'},
        form    => 'Title',
        alt     => 'Synonyms',
        wptitle => 'Wikipedia',
        source  => 'Image',
        thumb   => 'Convert options',
 );
-my @prioenum = qw( essential basic common distinctive rare invisible );
 my %langflag = (
        nld => "\N{REGIONAL INDICATOR SYMBOL LETTER N}\N{REGIONAL INDICATOR SYMBOL LETTER L}",
        eng => "\N{REGIONAL INDICATOR SYMBOL LETTER G}\N{REGIONAL INDICATOR SYMBOL LETTER B}",
@@ -137,7 +142,7 @@ if (exists $get{copy}) {
 }
 elsif ($ENV{REQUEST_METHOD} eq 'POST') {{
        my $replace = $row;
-       $row = {%post{ pairkeys @wordcols }};
+       $row = {%post{keys %wordcol}};
        $_ = length ? $_ : undef for values %{$row};
 
        eval {
@@ -267,20 +272,14 @@ bless $row, 'Shiar_Sheet::FormRow';
 <input id="id" name="id" value="<:= $row->{id} // '' :>" type="hidden" />
 <ul>
 <:
-for my $colinfo (pairs @wordcols) {
-       my ($col, $title) = @{$colinfo};
-       defined $title or next;
+for my $col (@wordcols) {
+       my $info = $wordcol{$col} or next;
+       my ($attr, @span) = ref $info eq 'ARRAY' ? @{$info} : $info;
+       my $title = ref $attr ? delete $attr->{-label} : $attr;
        printf '<li><label for="%s">%s</label><p>', $col, $title;
                printf '<span class=inline>';
-       if ($col eq 'prio') {
-               print $row->input($col => {-select => \@prioenum});
-               print $row->input(cover => {type => 'checkbox', -label => 'Highlighted'});
-               print $row->input(grade => {type => 'number', -label => 'Order'});
-       }
-       else {
-               print $row->input($col);
-               print $row->input(ref => {-label => 'Reference'}) if $col eq 'cat';
-       }
+               print $row->input($col => $attr);
+               print $row->input($_ => delete $wordcol{$_}) for @span;
                print '</span>';
        say '</p></li>';
 }