summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYorhel <git@yorhel.nl>2009-02-28 14:54:56 +0100
committerYorhel <git@yorhel.nl>2009-02-28 14:54:56 +0100
commit82a66074209f8cc2e23f9fb738aa869894cb83c9 (patch)
tree41ca227195e4ffc520509b46ca1e649968843ce3
parente3e3f7b3c9556375702703aadb4faa6db695631a (diff)
Improvements in vntagmod table layout, and saving votes in the DB works
And a "Don't forget to submit" text, and various important bugfixes, and... geez, time for a coke with some cookies!
-rw-r--r--data/style.css6
-rw-r--r--lib/VNDB/DB/Tags.pm12
-rw-r--r--lib/VNDB/Handler/Tags.pm38
-rw-r--r--lib/VNDB/Util/FormHTML.pm2
-rw-r--r--static/f/forms.js9
5 files changed, 53 insertions, 14 deletions
diff --git a/data/style.css b/data/style.css
index cc008631..0b719a91 100644
--- a/data/style.css
+++ b/data/style.css
@@ -974,7 +974,11 @@ ul#catselect li li.exc { background-position: 0px -33px; color: $statnok$; }
/***** VN tagmod *****/
#jt_box_tags .formtable table td { padding: 1px 5px }
-#tagtable tfoot { text-align: right }
+#tagtable tfoot td { padding-top: 20px!important; }
+#tagtable .tc2_1 { border-right: 1px solid $border$; border-left: 1px solid $border$; width: 150px; text-align: center }
+#tagtable .tc3_1 { border-left: 1px solid $border$; width: 150px; text-align: center }
+#tagtable .tc1 { min-width: 200px; border-right: 1px solid $border$ }
+#tagtable .tc3 { border-right: 1px solid $border$ }
a.taglvl { display: block; float: left; width: 8px; height: 12px; border: 1px solid $border$; font-size: 1px; color: $maintext$!important }
a.taglvl0 { width: 15px; border: none!important; font-size: 10px; text-align: center; }
a.taglvl:hover { border-bottom: 1px solid transparent!important }
diff --git a/lib/VNDB/DB/Tags.pm b/lib/VNDB/DB/Tags.pm
index aca87677..2250ff90 100644
--- a/lib/VNDB/DB/Tags.pm
+++ b/lib/VNDB/DB/Tags.pm
@@ -5,7 +5,7 @@ use strict;
use warnings;
use Exporter 'import';
-our @EXPORT = qw|dbTagGet dbTagEdit dbTagAdd dbTagDel dbTagLinks dbVNTags|;
+our @EXPORT = qw|dbTagGet dbTagEdit dbTagAdd dbTagDel dbTagLinks dbTagLinkEdit dbVNTags|;
# %options->{ id name search page results order what }
@@ -100,6 +100,15 @@ sub dbTagLinks {
}
+# Change a user's tags for a VN entry
+# Arguments: uid, vid, [ [ tag, vote ], .. ]
+sub dbTagLinkEdit {
+ my($self, $uid, $vid, $tags) = @_;
+ $self->dbExec('DELETE FROM tags_vn WHERE vid = ? AND uid = ?', $vid, $uid);
+ $self->dbExec('INSERT INTO tags_vn (tag, vid, uid, vote) VALUES (?, ?, ?, ?)', $_->[0], $vid, $uid, $_->[1]) for (@$tags);
+}
+
+
# Fetch all tags related to a VN
# Argument: vid
sub dbVNTags {
@@ -114,6 +123,5 @@ sub dbVNTags {
);
}
-
1;
diff --git a/lib/VNDB/Handler/Tags.pm b/lib/VNDB/Handler/Tags.pm
index 2991ed9d..667b302f 100644
--- a/lib/VNDB/Handler/Tags.pm
+++ b/lib/VNDB/Handler/Tags.pm
@@ -215,6 +215,15 @@ sub vntagmod {
return $self->htmlDenied if !$self->authCan('tag');
+ if($self->reqMethod eq 'POST') {
+ my $frm = $self->formValidate(
+ { name => 'taglinks', required => 0, default => '', maxlength => 10240, regex => [ qr/^[1-9][0-9]*,-?[1-3]( [1-9][0-9]*,-?[1-3])*$/, 'meh' ] }
+ );
+ use Data::Dumper; warn Dumper $frm;
+ return 404 if $frm->{_err};
+ $self->dbTagLinkEdit($self->authInfo->{id}, $vid, [ map [ split /,/ ], split / /, $frm->{taglinks}]);
+ }
+
my $my = $self->dbTagLinks(vid => $vid, uid => $self->authInfo->{id});
my $tags = $self->dbVNTags($vid);
@@ -233,13 +242,21 @@ sub vntagmod {
end;
end;
end;
- $self->htmlForm({ frm => $frm, action => "/v$vid/tagmod" }, 'Tags' => [
+ $self->htmlForm({ frm => $frm, action => "/v$vid/tagmod", hitsubmit => 1 }, 'Tags' => [
[ hidden => short => 'taglinks', value => '' ],
[ static => nolabel => 1, content => sub {
table id => 'tagtable';
- thead; Tr;
- td $_ for('Tag', 'Rating', 'Spoiler', 'Your vote', 'Your spoiler');
- end; end;
+ thead;
+ Tr;
+ td '';
+ td colspan => 2, class => 'tc2_1', 'Others';
+ td colspan => 2, class => 'tc3_1', 'You';
+ end;
+ Tr;
+ my $i=0;
+ td class => 'tc'.++$i, $_ for(qw|Tag Rating Spoiler Rating Spoiler|);
+ end;
+ end;
tfoot; Tr;
td colspan => 5;
input type => 'text', class => 'text', name => 'addtag', value => '';
@@ -250,14 +267,15 @@ sub vntagmod {
for my $t (sort { $a->{name} cmp $b->{name} } @$tags) {
my $m = (grep $_->{tag} == $t->{id}, @$my)[0] || {};
Tr;
- td;
+ td class => 'tc1';
a href => "/g$t->{id}", $t->{name};
end;
- td sprintf '%.2f (%d)',
- $m->{vote} ? ($t->{rating}/$t->{users} - $m->{vote}) * ($t->{users}-1) : $t->{rating}, $t->{users} - ($m->{vote} ? 1 : 0);
- td $t->{spoiler};
- td $m->{vote}||0;
- td $m->{spoiler}||'-';
+ td class => 'tc2', sprintf '%.2f (%d)',
+ !$m->{vote} ? $t->{rating} : $t->{users} == 1 ? 0 : ($t->{rating}*$t->{users} - $m->{vote}) / ($t->{users}-1),
+ $t->{users} - ($m->{vote} ? 1 : 0);
+ td class => 'tc3', $t->{spoiler};
+ td class => 'tc4', $m->{vote}||0;
+ td class => 'tc5', $m->{spoiler}||'-';
end;
}
end;
diff --git a/lib/VNDB/Util/FormHTML.pm b/lib/VNDB/Util/FormHTML.pm
index 95b51553..ecaf1183 100644
--- a/lib/VNDB/Util/FormHTML.pm
+++ b/lib/VNDB/Util/FormHTML.pm
@@ -253,7 +253,9 @@ sub htmlForm {
end;
br;
}
+ b "Don't forget! -> " if $options->{hitsubmit};
input type => 'submit', value => 'Submit', class => 'submit';
+ b ' <-' if $options->{hitsubmit};
end;
end;
diff --git a/static/f/forms.js b/static/f/forms.js
index 389da140..65f9efc0 100644
--- a/static/f/forms.js
+++ b/static/f/forms.js
@@ -886,7 +886,7 @@ function tglLoad() {
var l = x('tagtable').getElementsByTagName('tbody')[0].getElementsByTagName('tr');
for(var i=0; i<l.length;i++) {
var o = l[i].getElementsByTagName('td')[3];
- tglVoteBar(o, o.innerHTML);
+ tglVoteBar(o, parseInt(o.innerHTML));
}
}
@@ -927,6 +927,7 @@ function tglAdd() {
ajax('/xml/tags.xml?q=name:'+encodeURIComponent(n[0].value), function(hr) {
n[0].disabled = n[1].disabled = false;
n[1].value = 'Add tag';
+ n[0].value = '';
var items = hr.responseXML.getElementsByTagName('item');
if(items.length < 1)
@@ -942,21 +943,27 @@ function tglAdd() {
var tr = document.createElement('tr');
var td = document.createElement('td');
td.innerHTML = '<a href="/g'+items[0].getAttribute('id')+'">'+name+'</a>';
+ td.className = 'tc1';
tr.appendChild(td);
td = document.createElement('td');
+ td.className = 'tc2';
td.innerHTML = '0.00 (0)';
tr.appendChild(td);
td = document.createElement('td');
td.innerHTML = '0';
+ td.className = 'tc3';
tr.appendChild(td);
td = document.createElement('td');
tglVoteBar(td, 2);
+ td.className = 'tc4';
tr.appendChild(td);
td = document.createElement('td');
td.innerHTML = '-';
+ td.className = 'tc5';
tr.appendChild(td);
x('tagtable').getElementsByTagName('tbody')[0].appendChild(tr);
tglStripe();
+ tglSerialize();
});
}