summaryrefslogtreecommitdiff
path: root/lib/VNDB
diff options
context:
space:
mode:
authorYorhel <git@yorhel.nl>2008-12-08 17:28:11 +0100
committerYorhel <git@yorhel.nl>2008-12-08 17:28:11 +0100
commitcffa6de2fb050c7546a043c93a741d42e7405ff6 (patch)
treee3c00ff21cf051f073e45d49ce78009f20d57a1f /lib/VNDB
parentc6409639e1fea3ae63ec2689bdeb66489816de69 (diff)
Batch edit user VN list
Diffstat (limited to 'lib/VNDB')
-rw-r--r--lib/VNDB/DB/VNList.pm35
-rw-r--r--lib/VNDB/Handler/ULists.pm63
2 files changed, 90 insertions, 8 deletions
diff --git a/lib/VNDB/DB/VNList.pm b/lib/VNDB/DB/VNList.pm
index 40ff20c7..4120e775 100644
--- a/lib/VNDB/DB/VNList.pm
+++ b/lib/VNDB/DB/VNList.pm
@@ -6,7 +6,7 @@ use warnings;
use Exporter 'import';
-our @EXPORT = qw|dbVNListGet|;
+our @EXPORT = qw|dbVNListGet dbVNListAdd dbVNListDel|;
# %options->{ uid order char voted page results }
@@ -68,6 +68,39 @@ sub dbVNListGet {
}
+# %options->{ uid rid rstat vstat }
+sub dbVNListAdd {
+ my($self, %o) = @_;
+
+ my %s = (
+ defined $o{rstat} ? ( 'rstat = ?', $o{rstat} ) : (),
+ defined $o{vstat} ? ( 'vstat = ?', $o{vstat} ) : (),
+ );
+ $o{rstat}||=0;
+ $o{vstat}||=0;
+
+ $self->dbExec(
+ 'UPDATE rlists !H WHERE uid = ? AND rid IN(!l)',
+ \%s, $o{uid}, ref($o{rid}) eq 'ARRAY' ? $o{rid} : [ $o{rid} ]
+ )
+ ||
+ $self->dbExec(
+ 'INSERT INTO rlists (uid, rid, rstat, vstat) VALUES(!l)',
+ [@o{qw| uid rid rstat vstat |}]
+ );
+}
+
+
+# Arguments: uid, rid
+sub dbVNListDel {
+ my($self, $uid, $rid) = @_;
+ $self->dbExec(
+ 'DELETE FROM rlists WHERE uid = ? AND rid IN(!l)',
+ $uid, ref($rid) eq 'ARRAY' ? $rid : [ $rid ]
+ );
+}
+
+
1;
diff --git a/lib/VNDB/Handler/ULists.pm b/lib/VNDB/Handler/ULists.pm
index fcb8d6c0..3cfbedeb 100644
--- a/lib/VNDB/Handler/ULists.pm
+++ b/lib/VNDB/Handler/ULists.pm
@@ -69,11 +69,11 @@ sub wishlist {
if($own && $self->reqMethod eq 'POST') {
my $frm = $self->formValidate(
{ name => 'sel', required => 0, default => 0, multi => 1, template => 'int' },
- { name => 'wishbatch', required => 1, enum => [ -1..$#{$self->{wishlist_status}} ] },
+ { name => 'batchedit', required => 1, enum => [ -1..$#{$self->{wishlist_status}} ] },
);
if(!$frm->{_err} && @{$frm->{sel}} && $frm->{sel}[0]) {
- $self->dbWishListDel($uid, $frm->{sel}) if $frm->{wishbatch} == -1;
- $self->dbWishListAdd($frm->{sel}, $uid, $frm->{wishbatch}) if $frm->{wishbatch} >= 0;
+ $self->dbWishListDel($uid, $frm->{sel}) if $frm->{batchedit} == -1;
+ $self->dbWishListAdd($frm->{sel}, $uid, $frm->{batchedit}) if $frm->{batchedit} >= 0;
}
}
@@ -134,7 +134,7 @@ sub wishlist {
return if !$own;
Tr;
td colspan => 3;
- Select name => 'wishbatch', id => 'wishbatch';
+ Select name => 'batchedit', id => 'batchedit';
option '-- with selected --';
optgroup label => 'Change priority';
option value => $_, $self->{wishlist_status}[$_]
@@ -167,6 +167,22 @@ sub vnlist {
);
return 404 if $f->{_err};
+ if($own && $self->reqMethod eq 'POST') {
+ my $frm = $self->formValidate(
+ { name => 'sel', required => 0, default => 0, multi => 1, template => 'int' },
+ { name => 'batchedit', required => 1, enum => [ 'del', map("r$_", 0..$#{$self->{vn_rstat}}), map("v$_", 0..$#{$self->{vn_vstat}}) ] },
+ );
+ if(!$frm->{_err} && @{$frm->{sel}} && $frm->{sel}[0]) {
+ $self->dbVNListDel($uid, $frm->{sel}) if $frm->{batchedit} eq 'del';
+ $self->dbVNListAdd(
+ rid => $frm->{sel},
+ uid => $uid,
+ $frm->{batchedit} =~ /^([rv])(\d+)$/ && $1 eq 'r' ? (rstat => $2) : (vstat => $2)
+ ) if $frm->{batchedit} ne 'del';
+ }
+ }
+
+
my($list, $np) = $self->dbVNListGet(
uid => $uid,
results => 50,
@@ -208,6 +224,16 @@ sub vnlist {
end;
end;
+ _vnlist_browse($self, $own, $list, $np, $f, $url);
+ $self->htmlFooter;
+}
+
+sub _vnlist_browse {
+ my($self, $own, $list, $np, $f, $url) = @_;
+
+ form action => $url->(), method => 'post'
+ if $own;
+
$self->htmlBrowse(
class => 'rlist',
items => $list,
@@ -221,6 +247,7 @@ sub vnlist {
[ Vote => 'vote' ],
],
row => sub {
+
my($s, $n, $i) = @_;
Tr $n % 2 == 0 ? (class => 'odd') : ();
td class => 'tc1', colspan => 3;
@@ -237,9 +264,12 @@ sub vnlist {
end;
td class => 'tc3', $i->{vote} || '-';
end;
+
for (@{$i->{rels}}) {
Tr class => "relhid vid$i->{vid} ";
- td class => 'tc1';
+ td class => 'tc1'.($own ? ' own' : '');
+ input type => 'checkbox', name => 'sel', value => $_->{rid}
+ if $own;
lit datestr $_->{released};
end;
td class => 'tc2';
@@ -253,10 +283,29 @@ sub vnlist {
end;
}
},
+
+ footer => sub {
+ Tr;
+ td class => 'tc1', colspan => 3;
+ Select id => 'batchedit', name => 'batchedit';
+ option '- with selected -';
+ optgroup label => 'Change release status';
+ option value => "r$_", $self->{vn_rstat}[$_]
+ for (0..$#{$self->{vn_rstat}});
+ end;
+ optgroup label => 'Change play status';
+ option value => "v$_", $self->{vn_vstat}[$_]
+ for (0..$#{$self->{vn_vstat}});
+ end;
+ option value => 'del', 'remove from list';
+ end;
+ end;
+ end;
+ }
);
- $self->htmlFooter;
-}
+ end if $own;
+}
1;