summaryrefslogtreecommitdiff
path: root/lib/VNDB/Handler/Chars.pm
blob: 353ee37fe68f4f95feb280b432cd92ff42affcac (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111

package VNDB::Handler::Chars;

use strict;
use warnings;
use TUWF ':html', 'uri_escape';
use Exporter 'import';
use VNDB::Func;
use VNDB::Types;

our @EXPORT = ('charBrowseTable');

TUWF::register(
  qr{c/([a-z0]|all)} => \&list,
);


sub list {
  my($self, $fch) = @_;

  my $f = $self->formValidate(
    { get => 'p',   required => 0, default => 1, template => 'page' },
    { get => 'q',   required => 0, default => '' },
    { get => 'fil', required => 0, default => '' },
  );
  return $self->resNotFound if $f->{_err};

  my($list, $np) = $self->filFetchDB(char => $f->{fil}, {
    tagspoil => $self->authPref('spoilers')||0,
  }, {
    $fch ne 'all' ? ( char => $fch ) : (),
    $f->{q} ? ( search => $f->{q} ) : (),
    results => 50,
    page => $f->{p},
    what => 'vns',
  });

  $self->htmlHeader(title => 'Browse characters');

  my $quri = uri_escape($f->{q});
  form action => '/c/all', 'accept-charset' => 'UTF-8', method => 'get';
  div class => 'mainbox';
   h1 'Browse characters';
   $self->htmlSearchBox('c', $f->{q});
   p class => 'browseopts';
    for ('all', 'a'..'z', 0) {
      a href => "/c/$_?q=$quri;fil=$f->{fil}", $_ eq $fch ? (class => 'optselected') : (), $_ eq 'all' ? 'ALL' : $_ ? uc $_ : '#';
    }
   end;

   p class => 'filselect';
    a id => 'filselect', href => '#c';
     lit '<i>&#9656;</i> Filters<i></i>';
    end;
   end;
   input type => 'hidden', class => 'hidden', name => 'fil', id => 'fil', value => $f->{fil};
  end;
  end 'form';

  if(!@$list) {
    div class => 'mainbox';
     h1 'No results';
     p 'No characters found that matched your criteria.';
    end;
  }

  @$list && $self->charBrowseTable($list, $np, $f, "/c/$fch?q=$quri;fil=$f->{fil}");

  $self->htmlFooter;
}


# Also used on Handler::Traits
sub charBrowseTable {
  my($self, $list, $np, $f, $uri) = @_;

  $self->htmlBrowse(
    class    => 'charb',
    items    => $list,
    options  => $f,
    nextpage => $np,
    pageurl  => $uri,
    sorturl  => $uri,
    header   => [ [ '' ], [ '' ] ],
    row      => sub {
      my($s, $n, $l) = @_;
      Tr;
       td class => 'tc1';
        cssicon "gen $l->{gender}", $GENDER{$l->{gender}} if $l->{gender} ne 'unknown';
       end;
       td class => 'tc2';
        a href => "/c$l->{id}", title => $l->{original}||$l->{name}, shorten $l->{name}, 50;
        b class => 'grayedout';
         my $i = 1;
         my %vns;
         for (@{$l->{vns}}) {
           next if $_->{spoil} || $vns{$_->{vid}}++;
           last if $i++ > 4;
           txt ', ' if $i > 2;
           a href => "/v$_->{vid}/chars", title => $_->{vntitle}, shorten $_->{vntitle}, 30;
         }
        end;
       end;
      end;
    }
  )
}


1;