word edit: null priority to inherit from parent
[sheet.git] / writer.plp
index 3c0b248bf9d859160269261912e745fa39bb16ad..a97bbfae4ec4d60e74c6a32750d311f57e72e9e8 100644 (file)
@@ -178,9 +178,14 @@ my %wordcol = (
        cat     => [{-label => 'Category'}, 'ref'],
        ref     => {-label => 'Reference'},
        prio    => [
-               {-label => 'Level', -select => [qw(
-                       essential basic common distinctive rare invisible
-               )]},
+               {-label => 'Level', -select => sub {
+                       my ($row) = @_;
+                       my @enum = qw[ essential basic common distinctive optional invisible ];
+                       return {
+                               ('' => 'parent') x (defined $row->{ref}),
+                               map { $_ => $enum[$_] } 0 .. $#enum
+                       };
+               }},
                'cover', 'grade',
        ],
        cover   => {-label => 'Highlighted', type => 'checkbox'},
@@ -250,6 +255,7 @@ elsif (defined $post{form}) {{
                                ref   => $row->{id},
                                lang  => $lang,
                                form  => $val,
+                               prio  => undef,
                        );
                        $subrow{wptitle} = $1 if $subrow{form} =~ s/\h*\[(.*)\]$//; # [Link] shorthand
                        $db->insert(word => \%subrow);
@@ -322,9 +328,9 @@ elsif (defined $post{form}) {{
        }
 }}
 else {
-       $row->{prio} //= 1;
        $row->{lang} //= $user->{editlang}->[0];
        $row->{$_} = $get{$_} for keys %get;
+       $row->{prio} = defined $row->{ref} ? undef : 1 unless exists $row->{prio};
 }
 
 my $title = $row->{id} ? "entry <small>#$row->{id}</small>" : 'new entry';
@@ -339,8 +345,7 @@ package Shiar_Sheet::FormRow {
                $html .= qq( $_="$attr->{$_}") for sort grep {!/^-/} keys %{$attr // {}};
 
                if (my $options = $attr->{-select}) {
-                       $options = { map {$_ => $options->[$_]} 0 .. $#{$options} }
-                               if ref $options eq 'ARRAY';
+                       $options = $options->(@_) if ref $options eq 'CODE';
                        $options->{$val} //= "unknown ($val)";  # preserve current
                        return (
                                sprintf('<select id="%s" name="%1$s">', $col),