From 4cebc475aa4cd045d16e91616f148454d06d3c7d Mon Sep 17 00:00:00 2001 From: Yorhel Date: Thu, 1 Oct 2015 20:00:02 +0200 Subject: VNEdit: Give error on duplicate alias + improved msg on id/page error --- data/lang.txt | 12 ++++++++++++ lib/VNDB/Handler/VNEdit.pm | 16 ++++++++-------- lib/VNDB/Util/FormHTML.pm | 3 ++- 3 files changed, 22 insertions(+), 9 deletions(-) diff --git a/data/lang.txt b/data/lang.txt index fb56f0a4..1fcc2103 100644 --- a/data/lang.txt +++ b/data/lang.txt @@ -16298,6 +16298,18 @@ tr : Yanlış pano: [_1] uk : Неправильна дошка: [_1] it : Area sbagliata: [_1] +:_formerr_existingalias +en : Duplicate alias '[_1]', or the alias is already used as a release title +ru*: +cs*: +hu*: +nl*: +de*: +es*: +tr*: +uk*: +it*: + :_formerr_tagexists en : Tag [url,_1,_2] already exists! ru : Тег [url,_1,_2] уже существует! diff --git a/lib/VNDB/Handler/VNEdit.pm b/lib/VNDB/Handler/VNEdit.pm index 4ec25605..b1e3a548 100644 --- a/lib/VNDB/Handler/VNEdit.pm +++ b/lib/VNDB/Handler/VNEdit.pm @@ -166,6 +166,14 @@ sub edit { } } } + if(!$nosubmit && !$frm->{_err}) { + # normalize aliases + $frm->{alias} = join "\n", map { s/^ +//g; s/ +$//g; $_?($_):() } split /\n/, $frm->{alias}; + # throw error on duplicate/existing aliases + my %alias = map +(lc($_),1), $frm->{title}, $frm->{original}, map +($_->{title}, $_->{original}), @$r; + my @e = map $alias{ lc($_) }++ ? [ 'alias', 'existingalias', $_ ] : (), split /\n/, $frm->{alias}; + $frm->{_err} = \@e if @e; + } if(!$nosubmit && !$frm->{_err}) { # parse and re-sort fields that have multiple representations of the same information my $anime = { map +($_=>1), grep /^[0-9]+$/, split /[ ,]+/, $frm->{anime} }; @@ -183,14 +191,6 @@ sub edit { $frm->{credits} = json_encode \@credits; $frm->{seiyuu} = json_encode \@seiyuu; - # weed out duplicate aliases - my %alias; - $frm->{alias} = join "\n", grep { - my $a = lc $_; - $a && !$alias{$a}++ && $a ne lc($frm->{title}) && $a ne lc($frm->{original}) - && !grep $a eq lc($_->{title}) || $a eq lc($_->{original}), @$r; - } map { s/^ +//g; s/ +$//g; $_ } split /\n/, $frm->{alias}; - # nothing changed? just redirect return $self->resRedirect("/v$vid", 'post') if $vid && !grep $frm->{$_} ne $b4{$_}, keys %b4; diff --git a/lib/VNDB/Util/FormHTML.pm b/lib/VNDB/Util/FormHTML.pm index a319ba42..611fdf46 100644 --- a/lib/VNDB/Util/FormHTML.pm +++ b/lib/VNDB/Util/FormHTML.pm @@ -38,9 +38,10 @@ sub htmlFormError { li mt '_formerr_maxlength', $field, $rule if $type eq 'maxlength'; li mt '_formerr_enum', $field, join ', ', @$rule if $type eq 'enum'; li mt '_formerr_wrongboard', $rule if $type eq 'wrongboard'; + li mt '_formerr_existingalias', $rule if $type eq 'existingalias'; li $rule->[1] if $type eq 'func' || $type eq 'regex'; if($type eq 'template') { - $rule = 'int' if $rule eq 'num' || $rule eq 'uint'; + $rule = 'int' if $rule eq 'num' || $rule eq 'uint' || $rule eq 'page' || $rule eq 'id'; li; lit mt "_formerr_tpl_$rule", $field; end; } if($type eq 'tagexists') { -- cgit v1.2.3