summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorYorhel <git@yorhel.nl>2015-10-01 20:00:02 +0200
committerYorhel <git@yorhel.nl>2015-10-01 20:00:02 +0200
commit4cebc475aa4cd045d16e91616f148454d06d3c7d (patch)
tree4d56e894c7a50648246e730a0f104fc7b61331b0 /lib
parent423a37af953817b59879f2d3013a44a54006ec3b (diff)
VNEdit: Give error on duplicate alias + improved msg on id/page error
Diffstat (limited to 'lib')
-rw-r--r--lib/VNDB/Handler/VNEdit.pm16
-rw-r--r--lib/VNDB/Util/FormHTML.pm3
2 files changed, 10 insertions, 9 deletions
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
@@ -167,6 +167,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} };
my $relations = [ map { /^([a-z]+),([0-9]+),([01]),(.+)$/ && (!$vid || $2 != $vid) ? [ $1, $2, $3, $4 ] : () } split /\|\|\|/, $frm->{vnrelations} ];
@@ -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') {