} or Abort('Database error', 501, $@);
my %lang = (
- nld => ["\N{REGIONAL INDICATOR SYMBOL LETTER N}\N{REGIONAL INDICATOR SYMBOL LETTER L}", 'dutch'],
- eng => ["\N{REGIONAL INDICATOR SYMBOL LETTER G}\N{REGIONAL INDICATOR SYMBOL LETTER B}", 'english'],
- epo => ['<span style="color:green">★</span>', 'esperanto'],
+ 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 => ['<span style="color:green">★</span>', 'esperanto'],
+ ru => ["\N{REGIONAL INDICATOR SYMBOL LETTER R}\N{REGIONAL INDICATOR SYMBOL LETTER U}", 'русский'],
);
my @wordcols = pairkeys
my %wordcol = (
$row = {%post{keys %wordcol}};
$_ = length ? $_ : undef for values %{$row};
+ if (!$row->{form}) {
+ if ($row->{ref} ne 'delete') {
+ Alert("Empty title",
+ "Confirm removal by setting <em>Reference</em> to <q>delete</q>."
+ );
+ }
+ else {
+ $db->delete(word => $find);
+ Alert("Entry removed");
+ }
+ next;
+ }
+
eval {
my %res = (returning => '*');
my $query = $find ? $db->update(word => $row, $find, \%res) :
next;
};
+ eval {
+ while (my ($lang, $val) = each %post) {
+ my $field = $lang;
+ $lang =~ s/^trans-// or next;
+ $db->insert(word => {
+ ref => $row->{id},
+ lang => $lang,
+ form => $val,
+ });
+ delete $fields{$field};
+ }
+ return 1;
+ } or Alert('Error creating translation entries', $@);
+
my $imgpath = Shiar_Sheet::FormRow::imagepath($row, 'source');
my $reimage = eval {
($row->{source} // '') ne ($replace->{source} // '') or return;
sub imagepath {
my ($row, $col) = @_;
return "data/word/org/$row->{id}.jpg" if $col eq 'source';
- return "data/word/eng/$row->{form}.jpg" if $col eq 'thumb';
+ return "data/word/en/$row->{form}.jpg" if $col eq 'thumb';
return;
}
}
say '</p></li>';
}
-if ($row->{id}) {
- my $children = $db->select(word => '*', {ref => $row->{id}}, 'lang, id');
- printf '<li><label>%s</label><div><ul class="inline">', 'Translations';
- while (my $row = $children->hash) {
+if ($row->{id} and not $row->{ref}) {
+ printf '<li><label for="%s">%s</label><div><ul class="inline" id="%1$s">',
+ 'trans', 'Translations';
+ my @children = $db->select(word => '*', {ref => $row->{id}}, 'lang, id')->hashes;
+ while (my ($lang, $val) = each %fields) {
+ $lang =~ s/^trans-// or next;
+ push @children, { lang => $lang, form => $val };
+ }
+ for my $ref (@children) {
+ printf(
+ '<li><label for="%s" title="%3$s">%s </label>',
+ "trans-$ref->{lang}", @{$lang{ $ref->{lang} }}, # flag, name
+ );
printf(
- '<li><label for="%1$s" title="%5$s">%4$s</label>' .
- ' <a id="%s" href="%s">%s</a></li>',
- "trans-$row->{lang}", "/writer/$row->{id}", Entity($row->{form}),
- @{$lang{ $row->{lang} }}, # flag, name
+ $ref->{id} ? '<a id="%s" href="%s">%s</a></li>' :
+ '<input id="%s" name="%1$s" value="%3$s" />',
+ "trans-$ref->{lang}", "/writer/$ref->{id}", Entity($ref->{form}),
);
}
say '</ul></div></li>';
<:
say '<ul>';
-my $parents = $db->select(word => '*', {id => $row->{cat}});
+my $parents = $db->select(word => '*', [{id => $row->{cat}}, {id => $row->{ref}}]);
while (my $ref = $parents->hash) {
printf '<li><a href="/writer/%d">%s</a></li>', $ref->{id}, Entity($ref->{form});
}
say "<li><strong>$row->{form}</strong></li>";
-my $children = $db->select(word => '*', {cat => $row->{id}}, 'grade, id');
+my $children = $db->select(word => '*', {cat => $row->{id}, ref => undef}, 'grade, id');
while (my $ref = $children->hash) {
printf '<li><a href="/writer/%d">%s</a></li>', $ref->{id}, Entity($ref->{form});
}