X-Git-Url: http://git.shiar.nl/sheet.git/blobdiff_plain/643b24914332240284adb01359c55406405a7e89..35a635c705ad1449df22a7cf5f6623b9445e40e3:/word/edit.plp diff --git a/word/edit.plp b/word/edit.plp index 31fca23..40bf8af 100644 --- a/word/edit.plp +++ b/word/edit.plp @@ -1,6 +1,8 @@ <(../common.inc.plp)><: +my $editorurl = '/word/edit'; s{\Aedit(/|\z)}{} for $Request // (); + Html({ title => 'words cheat sheet admin', version => '1.0', @@ -21,7 +23,6 @@ my $db = eval { } or Abort('Database error', 501, $@); my $user = eval { - my $rootpath = '/word/edit'; if (defined $post{username}) { $cookie{login} = EncodeURI(join ':', @post{qw( username pass )}); } @@ -30,7 +31,7 @@ my $user = eval { if (AddCookie(CGI::Cookie->new( -name => 'login', -value => '', - -path => $rootpath, + -path => $editorurl, -expires => 'now', )->as_string)) { delete $cookie{login}; @@ -50,7 +51,7 @@ my $user = eval { my $httpcookie = CGI::Cookie->new( -name => 'login', -value => join(':', @{$found}{qw( username pass )}), - -path => $rootpath, + -path => $editorurl, ) or die "prepared object is empty\n"; AddCookie($httpcookie->as_string); } or Abort(["Unable to create login cookie", $@], 403); @@ -71,6 +72,7 @@ my $user = eval { }; my %lang = ( + '' => ['(reference)'], nl => ["\N{REGIONAL INDICATOR SYMBOL LETTER N}\N{REGIONAL INDICATOR SYMBOL LETTER L}", 'nederlands'], en => ["\N{REGIONAL INDICATOR SYMBOL LETTER G}\N{REGIONAL INDICATOR SYMBOL LETTER B}", 'english'], eo => [qq'\N{BLACK STAR}', 'esperanto'], @@ -88,7 +90,9 @@ my %wordcol = ( prio => [ {-label => 'Level', -select => sub { my ($row) = @_; - my @enum = qw[ essential basic common distinctive optional invisible ]; + my @enum = qw[ + essential ubiquitous basic common distinctive specialised rare invisible + ]; return { ('' => 'parent') x (defined $row->{ref}), map { $_ => $enum[$_] } 0 .. $#enum @@ -105,17 +109,19 @@ my %wordcol = ( return "data/word/org/$_[0]->{id}.jpg"; }}, convert => {-label => 'Convert options', -json => 'image', -multiple => 1, -src => sub { - return "data/word/en/$_[0]->{id}.jpg"; + return "data/word/32/$_[0]->{id}.jpg"; }}, + crop32 => {-label => 'Crop 3:2', -json => 'image'}, story => {-label => 'Story', type => 'textarea', hidden => 'hidden'}, ); if (my $search = $fields{q}) { - my %filter = (form => {ilike => '%'.$search.'%'}); + my %filter = $search eq '^' ? (cat => undef, ref => undef) : + (form => {ilike => '%'.parseinput($search).'%'}); my $results = $db->select(word => '*', \%filter); say '

Search

\n"; @@ -156,7 +162,7 @@ elsif (defined $post{form}) {{ my $imagecol = $row->{image}; # backup image subcolumns ref $_ eq 'HASH' and $_ = encode_json($_) for values %{$row}; - if (!$row->{form}) { + if (!$row->{form} and $row->{lang}) { if ($row->{ref} ne 'delete') { Alert("Empty title", "Confirm removal by setting Reference to delete." @@ -213,7 +219,7 @@ elsif (defined $post{form}) {{ $reimage++ if $fields{rethumb}; # force refresh if ($reimage) { eval { - $image->convert($wordcol{convert}->{-src}->($row), $imagecol->{convert}); + $image->generate($wordcol{convert}->{-src}->($row), $imagecol); } or do { my ($warn, @details) = ref $@ ? @{$@} : $@; Alert([ "Thumbnail image not generated", $warn ], @details); @@ -221,13 +227,13 @@ elsif (defined $post{form}) {{ } }} else { - $row->{lang} //= $user->{editlang}->[0]; + $row->{lang} //= $user->{editlang}->[0] unless exists $row->{lang}; $row->{$_} = $get{$_} for keys %get; - $row->{prio} = defined $row->{ref} ? undef : 1 unless exists $row->{prio}; + $row->{prio} = defined $row->{ref} ? undef : 4 unless exists $row->{prio}; } eval { - my $imagerow = $row->{image} && decode_json(delete $row->{image}) || {}; + my $imagerow = $row->{image} && JSON->new->decode(delete $row->{image}) || {}; while (my ($col, $val) = each %{$imagerow}) { $row->{$col} = $val; } @@ -254,7 +260,7 @@ for my $col (@wordcols) { printf ''; print $row->input($col => $attr); if (my $imgsrc = $attr->{-src}) { - printf('%s', + printf('%s', $col, $_, $row->{form}, $col eq 'source' && ' hidden' ) for grep { -e } $imgsrc->($row); } @@ -264,7 +270,7 @@ for my $col (@wordcols) { } if (not $row->{ref}) { - printf '
    • ', + printf '
      • ', 'trans', 'Translations'; my @children = !$row->{id} ? () : $db->select(word => '*', {ref => $row->{id}}, 'lang, id')->hashes; @@ -283,7 +289,7 @@ if (not $row->{ref}) { printf( $ref->{id} ? '%s' : '', - "trans-$ref->{lang}", "/writer/$ref->{id}", Entity($ref->{form} // ''), + "trans-$ref->{lang}", "$editorurl/$ref->{id}", Entity($ref->{form} // ''), ); } say '
    • '; @@ -292,7 +298,7 @@ if (not $row->{ref}) {

    - +

    @@ -306,20 +312,24 @@ if ($row->{id}) { say '
      '; my $parents = $db->select(word => '*', [{id => $row->{cat}}, {id => $row->{ref}}]); while (my $ref = $parents->hash) { - printf '
    • %s
    • ', $ref->{id}, Entity($ref->{form}); + printf '
    • %s
    • ', $editorurl, $ref->{id}, Entity($ref->{form}); } say "
    • $_
    • " for Entity($row->{form}); my $children = $db->select(word => '*', {cat => $row->{id}, ref => undef}, 'grade, id'); while (my $ref = $children->hash) { - printf '
    • %s
    • ', $ref->{id}, Entity($ref->{form}); + printf '
    • %s
    • ', $editorurl, $ref->{id}, Entity($ref->{form}); } :> -
    • +
    + + <: }