summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorYorhel <git@yorhel.nl>2011-12-29 16:05:31 +0100
committerYorhel <git@yorhel.nl>2011-12-29 16:05:31 +0100
commitce33c5933d9e83699fa0791d4dae72208d528953 (patch)
treef64d0b35279ad53639e523c3e559efea4675099b /lib
parent019f1424945aff4545c3a5083fb6330a942f4a3b (diff)
Added duplicate check when adding VNs
Diffstat (limited to 'lib')
-rw-r--r--lib/VNDB/DB/VN.pm4
-rw-r--r--lib/VNDB/Handler/VNEdit.pm72
-rw-r--r--lib/VNDB/Util/FormHTML.pm17
-rw-r--r--lib/VNDB/Util/LayoutHTML.pm2
4 files changed, 80 insertions, 15 deletions
diff --git a/lib/VNDB/DB/VN.pm b/lib/VNDB/DB/VN.pm
index 1b738ab4..473fa92c 100644
--- a/lib/VNDB/DB/VN.pm
+++ b/lib/VNDB/DB/VN.pm
@@ -11,7 +11,7 @@ our @EXPORT = qw|dbVNGet dbVNRevisionInsert dbVNImageId dbScreenshotAdd dbScreen
# Options: id, rev, char, search, length, lang, olang, plat, tag_inc, tag_exc, tagspoil,
-# hasani, hasshot, ul_notblack, ul_onwish, results, page, what, sort, reverse
+# hasani, hasshot, ul_notblack, ul_onwish, results, page, what, sort, reverse, inc_hidden
# What: extended anime relations screenshots relgraph rating ranking changes
# Sort: id rel pop rating title tagscore rand
sub dbVNGet {
@@ -66,7 +66,7 @@ sub dbVNGet {
$uid && defined $o{ul_onlist} ? (
'v.id !s IN(SELECT vid FROM vnlists WHERE uid = ?)' => [ $o{ul_onlist} ? '' : 'NOT', $uid ] ) : (),
# don't fetch hidden items unless we ask for an ID
- !$o{id} && !$o{rev} ? (
+ !$o{id} && !$o{rev} && !$o{inc_hidden} ? (
'v.hidden = FALSE' => 0 ) : (),
# optimize fetching random entries (only when there are no other filters present, otherwise this won't work well)
$o{sort} eq 'rand' && $o{results} <= 10 && !grep(!/^(?:results|page|what|sort|tagspoil)$/, keys %o) ? (
diff --git a/lib/VNDB/Handler/VNEdit.pm b/lib/VNDB/Handler/VNEdit.pm
index 36333cb0..56031472 100644
--- a/lib/VNDB/Handler/VNEdit.pm
+++ b/lib/VNDB/Handler/VNEdit.pm
@@ -10,13 +10,71 @@ use VNDB::Func;
TUWF::register(
qr{v(?:([1-9]\d*)(?:\.([1-9]\d*))?/edit|/new)}
=> \&edit,
+ qr{v/add} => \&addform,
qr{xml/vn\.xml} => \&vnxml,
qr{xml/screenshots\.xml} => \&scrxml,
);
+sub addform {
+ my $self = shift;
+ return $self->htmlDenied if !$self->authCan('edit');
+
+ my $frm;
+ my $l = [];
+ if($self->reqMethod eq 'POST') {
+ return if !$self->authCheckCode;
+ $frm = $self->formValidate(
+ { post => 'title', maxlength => 250 },
+ { post => 'original', required => 0, maxlength => 250, default => '' },
+ { post => 'alias', required => 0, maxlength => 500, default => '' },
+ { post => 'continue_ign',required => 0 },
+ );
+
+ # look for duplicates
+ if(!$frm->{_err} && !$frm->{continue_ign}) {
+ $l = $self->dbVNGet(search => $frm->{title}, what => 'changes', results => 50, inc_hidden => 1);
+ push @$l, @{$self->dbVNGet(search => $frm->{original}, what => 'changes', results => 50, inc_hidden => 1)} if $frm->{original};
+ $_ && push @$l, $self->dbVNGet(search => $_, what => 'changes', results => 50, inc_hidden => 1) for(split /\n/, $frm->{alias});
+ my %ids = map +($_->{id}, $_), @$l;
+ $l = [ map $ids{$_}, sort { $ids{$a}{title} cmp $ids{$b}{title} } keys %ids ];
+ }
+
+ return edit($self, undef, undef, 1) if !@$l && !$frm->{_err};
+ }
+
+ $self->htmlHeader(title => mt('_vnedit_title_add'), noindex => 1);
+ if(@$l) {
+ div class => 'mainbox';
+ h1 mt '_vnedit_dup_title';
+ div class => 'warning';
+ p; lit mt '_vnedit_dup_msg'; end;
+ end;
+ ul;
+ for(@$l) {
+ li;
+ a href => "/v$_->{id}", title => $_->{original}||$_->{title}, "v$_->{id}: ".shorten($_->{title}, 50);
+ b class => 'standout', ' deleted' if $_->{hidden};
+ end;
+ }
+ end;
+ end 'div';
+ }
+
+ $self->htmlForm({ frm => $frm, action => '/v/add', continue => @$l ? 2 : 1 },
+ vn_add => [ mt('_vnedit_title_add'),
+ [ input => short => 'title', name => mt '_vnedit_frm_title' ],
+ [ input => short => 'original', name => mt '_vnedit_original' ],
+ [ static => content => mt '_vnedit_original_msg' ],
+ [ textarea => short => 'alias', name => mt('_vnedit_alias'), rows => 4 ],
+ [ static => content => mt '_vnedit_alias_msg' ],
+ ]);
+ $self->htmlFooter;
+}
+
+
sub edit {
- my($self, $vid, $rev) = @_;
+ my($self, $vid, $rev, $nosubmit) = @_;
my $v = $vid && $self->dbVNGet(id => $vid, what => 'extended screenshots relations anime changes', $rev ? (rev => $rev) : ())->[0];
return $self->resNotFound if $vid && !$v->{id};
@@ -36,7 +94,7 @@ sub edit {
my $frm;
if($self->reqMethod eq 'POST') {
- return if !$self->authCheckCode;
+ return if !$nosubmit && !$self->authCheckCode;
$frm = $self->formValidate(
{ post => 'title', maxlength => 250 },
{ post => 'original', required => 0, maxlength => 250, default => '' },
@@ -53,16 +111,16 @@ sub edit {
{ post => 'vnrelations', required => 0, default => '', maxlength => 5000 },
{ post => 'screenshots', required => 0, default => '', maxlength => 1000 },
{ post => 'editsum', required => 0, maxlength => 5000 },
- { post => 'ihid', required => 0 },
- { post => 'ilock', required => 0 },
+ { post => 'ihid', required => 0 },
+ { post => 'ilock', required => 0 },
);
- push @{$frm->{_err}}, 'badeditsum' if !$frm->{editsum} || lc($frm->{editsum}) eq lc($frm->{desc});
+ push @{$frm->{_err}}, 'badeditsum' if !$nosubmit && (!$frm->{editsum} || lc($frm->{editsum}) eq lc($frm->{desc}));
# handle image upload
- $frm->{image} = _uploadimage($self, $frm);
+ $frm->{image} = _uploadimage($self, $frm) if !$nosubmit;
- if(!$frm->{_err}) {
+ 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} ];
diff --git a/lib/VNDB/Util/FormHTML.pm b/lib/VNDB/Util/FormHTML.pm
index 21eeb980..13ec56f9 100644
--- a/lib/VNDB/Util/FormHTML.pm
+++ b/lib/VNDB/Util/FormHTML.pm
@@ -165,10 +165,12 @@ sub htmlFormPart {
# Generates a form, first argument is a hashref with global options, keys:
-# frm => the $frm as returned by formValidate,
-# action => The location the form should POST to (also used as form id)
-# upload => 1/0, adds an enctype.
-# editsum => 1/0, adds an edit summary field before the submit button
+# frm => the $frm as returned by formValidate,
+# action => The location the form should POST to (also used as form id)
+# upload => 1/0, adds an enctype.
+# nosubmit => 1/0, hides the submit button
+# editsum => 1/0, adds an edit summary field before the submit button
+# continue => 2/1/0, replace submit button with continue buttons
# The other arguments are a list of subforms in the form
# of (subform-name => [form parts]). Each subform is shown as a
# (JavaScript-powered) tab, and has it's own 'mainbox'. This function
@@ -235,7 +237,12 @@ sub htmlForm {
textarea name => 'editsum', id => 'editsum', rows => 4, cols => 50, $options->{frm}{editsum}||'';
br;
}
- input type => 'submit', value => mt('_form_submit'), class => 'submit';
+ if(!$options->{continue}) {
+ input type => 'submit', value => mt('_form_submit'), class => 'submit';
+ } else {
+ input type => 'submit', value => mt('_form_continue'), class => 'submit';
+ input type => 'submit', name => 'continue_ign', value => mt('_form_continue_ign'), class => 'submit', style => 'width: auto' if $options->{continue} == 2;
+ }
end;
end 'div';
}
diff --git a/lib/VNDB/Util/LayoutHTML.pm b/lib/VNDB/Util/LayoutHTML.pm
index 752f6728..7507d682 100644
--- a/lib/VNDB/Util/LayoutHTML.pm
+++ b/lib/VNDB/Util/LayoutHTML.pm
@@ -100,7 +100,7 @@ sub _menu {
a href => '/g/links?u='.$self->authInfo->{id}, mt '_menu_mytags'; br;
br;
if($self->authCan('edit')) {
- a href => '/v/new', mt '_menu_addvn'; br;
+ a href => '/v/add', mt '_menu_addvn'; br;
a href => '/p/new', mt '_menu_addproducer'; br;
}
if($self->authCan('charedit')) {