summaryrefslogtreecommitdiff
path: root/lib/VNDB/Handler
diff options
context:
space:
mode:
authorYorhel <git@yorhel.nl>2011-02-13 12:06:47 +0100
committerYorhel <git@yorhel.nl>2011-02-13 12:06:47 +0100
commit359627f10128f36f10b1d4714601fc33c3ce3c8a (patch)
treee800c67207f4156315c9b2343cbca4bc7f9b9a0f /lib/VNDB/Handler
parent5829b57d55b4173592af1a75f3f014f9a9ae2594 (diff)
chardb: Added notes file and started implementing the traits
Diffstat (limited to 'lib/VNDB/Handler')
-rw-r--r--lib/VNDB/Handler/Tags.pm68
-rw-r--r--lib/VNDB/Handler/Traits.pm82
2 files changed, 85 insertions, 65 deletions
diff --git a/lib/VNDB/Handler/Tags.pm b/lib/VNDB/Handler/Tags.pm
index cff5d980..6e48cc26 100644
--- a/lib/VNDB/Handler/Tags.pm
+++ b/lib/VNDB/Handler/Tags.pm
@@ -78,18 +78,7 @@ sub tagpage {
a class => 'addnew', href => "/g$tag/add", mt '_tagp_addchild' if $self->authCan('tag') && $t->{state} != 1;
h1 $title;
- p;
- my @p = _parenttags(@{$t->{parents}});
- for my $p (@p ? @p : []) {
- a href => '/g', mt '_tagp_indexlink';
- for (reverse @$p) {
- txt ' > ';
- a href => "/g$_->{id}", $_->{name};
- }
- txt " > $t->{name}";
- br;
- }
- end 'p';
+ parenttags($t, mt('_tagp_indexlink'), 'g');
if($t->{description}) {
p class => 'description';
@@ -110,7 +99,7 @@ sub tagpage {
}
end 'div';
- _childtags($self, $t) if @{$t->{childs}};
+ childtags($self, mt('_tagp_childs'), 'g', $t) if @{$t->{childs}};
if(!$t->{meta} && $t->{state} == 2) {
form action => "/g$t->{id}", 'accept-charset' => 'UTF-8', method => 'get';
@@ -142,57 +131,6 @@ sub tagpage {
}
-# arg: tag hashref
-# returns: [ [ tag1, tag2, tag3 ], [ tag1, tag2, tag5 ] ]
-sub _parenttags {
- my @r;
- for my $t (@_) {
- for (@{$t->{'sub'}}) {
- push @r, [ $t, @$_ ] for _parenttags($_);
- }
- push @r, [$t] if !@{$t->{'sub'}};
- }
- return @r;
-}
-
-
-# used for on both /g and /g+
-sub _childtags {
- my($self, $t, $index) = @_;
-
- div class => 'mainbox';
- h1 mt $index ? '_tagp_tree' : '_tagp_childs';
- ul class => 'tagtree';
- for my $p (sort { @{$b->{'sub'}} <=> @{$a->{'sub'}} } @{$t->{childs}}) {
- li;
- a href => "/g$p->{id}", $p->{name};
- b class => 'grayedout', " ($p->{c_vns})" if $p->{c_vns};
- end, next if !@{$p->{'sub'}};
- ul;
- for (0..$#{$p->{'sub'}}) {
- last if $_ >= 5 && @{$p->{'sub'}} > 6;
- li;
- txt '> ';
- a href => "/g$p->{sub}[$_]{id}", $p->{'sub'}[$_]{name};
- b class => 'grayedout', " ($p->{sub}[$_]{c_vns})" if $p->{'sub'}[$_]{c_vns};
- end;
- }
- if(@{$p->{'sub'}} > 6) {
- li;
- txt '> ';
- a href => "/g$p->{id}", style => 'font-style: italic', mt '_tagp_moretags', @{$p->{'sub'}}-5;
- end;
- }
- end;
- end 'li';
- }
- end 'ul';
- clearfloat;
- br;
- end 'div';
-}
-
-
sub tagedit {
my($self, $tag, $act) = @_;
@@ -687,7 +625,7 @@ sub tagindex {
end;
my $t = $self->dbTagTree(0, 2);
- _childtags($self, {childs => $t}, 1);
+ childtags($self, mt('_tagp_tree'), 'g', {childs => $t});
table class => 'mainbox threelayout';
Tr;
diff --git a/lib/VNDB/Handler/Traits.pm b/lib/VNDB/Handler/Traits.pm
new file mode 100644
index 00000000..640af81e
--- /dev/null
+++ b/lib/VNDB/Handler/Traits.pm
@@ -0,0 +1,82 @@
+
+package VNDB::Handler::Traits;
+
+use strict;
+use warnings;
+use TUWF ':html';
+use VNDB::Func;
+
+
+TUWF::register(
+ qr{i([1-9]\d*)}, \&traitpage,
+);
+
+
+sub traitpage {
+ my($self, $trait) = @_;
+
+ my $t = $self->dbTraitGet(id => $trait, what => 'parents(0) childs(2) aliases')->[0];
+ return $self->resNotFound if !$t;
+
+ my $title = mt '_traitp_title', $t->{meta}?0:1, $t->{name};
+ $self->htmlHeader(title => $title, noindex => $t->{state} != 2);
+
+ if($t->{state} != 2) {
+ div class => 'mainbox';
+ h1 $title;
+ if($t->{state} == 1) {
+ div class => 'warning';
+ h2 mt '_traitp_del_title';
+ p;
+ lit mt '_traitp_del_msg';
+ end;
+ end;
+ } else {
+ div class => 'notice';
+ h2 mt '_traitp_pending_title';
+ p mt '_traitp_pending_msg';
+ end;
+ }
+ end 'div';
+ }
+
+ div class => 'mainbox';
+ h1 $title;
+
+ parenttags($t, mt('_traitp_indexlink'), 'i');
+
+ if($t->{description}) {
+ p class => 'description';
+ lit bb2html $t->{description};
+ end;
+ }
+ if(@{$t->{aliases}}) {
+ p class => 'center';
+ b mt('_traitp_aliases');
+ br;
+ lit xml_escape($_).'<br />' for (@{$t->{aliases}});
+ end;
+ }
+ end 'div';
+
+ childtags($self, mt('_traitp_childs'), 'i', $t) if @{$t->{childs}};
+
+ # TODO: list of characters
+
+ $self->htmlFooter;
+}
+
+
+1;
+
+__END__
+
+Simple test database:
+
+ INSERT INTO traits (name, description, state, meta, addedby) VALUES
+ ('Blood Type', 'Describes the blood type of the character', 2, true, 2),
+ ('Blood Type O', '', 2, true, 2),
+ ('Blood Type B', '', 2, true, 2);
+ INSERT INTO traits_parents (trait, parent) VALUES (2, 1), (3, 1);
+
+