summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--data/js/misc.js62
-rw-r--r--lib/VNDB/Handler/ULists.pm11
2 files changed, 52 insertions, 21 deletions
diff --git a/data/js/misc.js b/data/js/misc.js
index 23049068..85f25f10 100644
--- a/data/js/misc.js
+++ b/data/js/misc.js
@@ -7,30 +7,60 @@ function ulist_redirect(type, path, formcode, args) {
}
+function vote_validate(s) {
+ if(s < 1)
+ s = prompt('Please input your vote as a number between 1 and 10. One digit after the decimal is allowed, for example: 8.6 or 7.3.', '');
+ if(!s)
+ return 0;
+ s = s.replace(',', '.');
+ if(!s.match(/^([1-9]|10)([\.,][0-9])?$/) || s > 10 || s < 1) {
+ alert('Invalid number.');
+ return 0;
+ }
+ if(s == 1 && !confirm('You are about to give this visual novel a 1 out of 10.'+
+ ' This is a rather extreme rating, meaning this game has absolutely nothing to offer, and that it\'s the worst game you have ever played.'+
+ ' Are you really sure this visual novel matches that description?'))
+ return 0;
+ if(s == 10 && !confirm('You are about to give this visual novel a 10 out of 10.'+
+ ' This is a rather extreme rating, meaning this is one of the best visual novels you\'ve ever played and it\'s unlikely that any other game could ever be better than this one.'+
+ ' It is generally a bad idea to have more than three games in your vote list with this rating, choose carefully!'))
+ return 0;
+ return s;
+}
+
+
// VN Voting (/v+)
if(byId('votesel'))
byId('votesel').onchange = function() {
var s = this.options[this.selectedIndex].value;
+ if(s == -3)
+ return;
+ if(s != -1)
+ s = vote_validate(s);
+ if(!s)
+ this.selectedIndex = 0;
+ else
+ ulist_redirect('v', '/vote', this.name, 'v='+s);
+ };
+
+
+// VN voting from list (/u+/votes)
+if(byId('batchvotes'))
+ byId('batchvotes').onchange = function() {
+ var s = this.options[this.selectedIndex].value;
if(s == -2)
- s = prompt('Please input your vote as a number between 1 and 10. One digit after the decimal is allowed, for example: 8.6 or 7.3.', '');
- if(!s || s == -3)
return;
- if(s != -1 && (!s.match(/^([1-9]|10)([\.,][0-9])?$/) || s > 10 || s < 1)) {
- alert('Invalid number.');
+ if(s != -1)
+ s = vote_validate(s);
+ if(!s) {
this.selectedIndex = 0;
return;
}
- s = s.replace(',', '.');
- if(s == 1 && !confirm('You are about to give this visual novel a 1 out of 10.'+
- ' This is a rather extreme rating, meaning this game has absolutely nothing to offer, and that it\'s the worst game you have ever played.'+
- ' Are you really sure this visual novel matches that description?'))
- return;
- if(s == 10 && !confirm('You are about to give this visual novel a 10 out of 10.'+
- ' This is a rather extreme rating, meaning this is one of the best visual novels you\'ve ever played and it\'s unlikely that any other game could ever be better than this one.'+
- ' It is generally a bad idea to have more than three games in your vote list with this rating, choose carefully!'))
- return;
- if(s > 0 || s == -1)
- ulist_redirect('v', '/vote', this.name, 'v='+s);
+ this.options[this.selectedIndex].value = s;
+ var frm = this;
+ while(frm.nodeName.toLowerCase() != 'form')
+ frm = frm.parentNode;
+ frm.submit();
};
@@ -166,7 +196,7 @@ if(location.hostname != 'vndb.org') {
})();
-// Batch edit dropdown box (/u+/wish and /u+/votes)
+// Batch edit dropdown box (/u+/wish)
if(byId('batchedit'))
byId('batchedit').onchange = function() {
if(this.selectedIndex == 0)
diff --git a/lib/VNDB/Handler/ULists.pm b/lib/VNDB/Handler/ULists.pm
index f30397b7..5b4ea901 100644
--- a/lib/VNDB/Handler/ULists.pm
+++ b/lib/VNDB/Handler/ULists.pm
@@ -134,12 +134,12 @@ sub votelist {
return if !$self->authCheckCode;
my $frm = $self->formValidate(
{ post => 'vid', required => 1, multi => 1, template => 'id' },
- { post => 'batchedit', required => 1, enum => [ -2, -1, 1..10 ] },
+ { post => 'batchvotes', required => 1, regex => qr/^(-1|([1-9]|10)(\.[0-9])?)$/ },
);
my @vid = grep $_ && $_ > 0, @{$frm->{vid}};
- if(!$frm->{_err} && @vid && $frm->{batchedit} > -2) {
- $self->dbVoteDel($id, \@vid) if $frm->{batchedit} == -1;
- $self->dbVoteAdd(\@vid, $id, $frm->{batchedit}*10) if $frm->{batchedit} > 0;
+ if(!$frm->{_err} && @vid && $frm->{batchvotes} > -2) {
+ $self->dbVoteDel($id, \@vid) if $frm->{batchvotes} == -1;
+ $self->dbVoteAdd(\@vid, $id, $frm->{batchvotes}*10) if $frm->{batchvotes} > 0;
}
}
@@ -203,10 +203,11 @@ sub votelist {
td colspan => 3, class => 'tc1';
input type => 'checkbox', class => 'checkall', name => 'vid', value => 0;
txt ' ';
- Select name => 'batchedit', id => 'batchedit';
+ Select name => 'batchvotes', id => 'batchvotes';
option value => -2, '-- with selected --';
optgroup label => 'Change vote';
option value => $_, sprintf '%d (%s)', $_, fmtrating $_ for (reverse 1..10);
+ option value => -3, 'Other';
end;
option value => -1, 'revoke';
end;