});
} 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}",
}
elsif ($ENV{REQUEST_METHOD} eq 'POST') {{
my $replace = $row;
- $row = {%post{ pairkeys @wordcols }};
+ $row = {%post{keys %wordcol}};
$_ = length ? $_ : undef for values %{$row};
eval {
<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>';
}