]> mj.ucw.cz Git - pciids.git/blob - PciIds/Html/List.pm
bcd55257226864e85c5eb69bd8de12c03f5c576f
[pciids.git] / PciIds / Html / List.pm
1 package PciIds::Html::List;
2 use strict;
3 use warnings;
4 use PciIds::Address;
5 use PciIds::Html::Util;
6 use Apache2::Const qw(:common :http);
7 use base 'Exporter';
8
9 our @EXPORT = qw(&loadItem);
10
11 sub loadItem( $$ ) {
12         my( $tables, $uri ) = @_;
13         my $address = PciIds::Address::new( $uri );
14         return ( 0 ) unless( defined $address );
15         my $item = $tables->item( $address->get() );
16         return ( 0 ) unless( defined $item );
17         my( $parent, $name, $note, $mainhistory ) = @{$item};
18         return ( 1, $parent, $name, $note, $address, $mainhistory );
19 }
20
21 sub list( $$$$ ) {
22         my( $req, $args, $tables, $auth ) = @_;
23         my( $ok, $parent, $name, $note, $address, $mid ) = loadItem( $tables, $req->uri() );
24         return NOT_FOUND unless( $ok );
25         my $id = $address->pretty();
26         genHtmlHead( $req, $id, undef );
27         print "<div class='top'>\n";
28         print '<h1>'.encode( $id ).'</h1>';
29         genMenu( $req, $address, $args, $auth, [ [ 'Help', 'help', 'list' ], $address->helpName() ? [ 'ID syntax', 'help', $address->helpName() ] : () ] );
30         genPath( $req, $address, 0 );
31         print "<div class='clear'></div>\n";
32         print "</div\n>";
33         print htmlDiv( 'name', '<p>'.encode( $name ) ) if defined( $name );
34         print htmlDiv( 'note', '<p>'.encode( $note ) ) if( defined( $note ) );
35         my $diss = 0;
36         my $history;
37         foreach $history ( @{$tables->history( $address->get() )} ) {
38                 unless( $diss ) {
39                         print "<div class='discussion'>\n<h2>Discussion</h2>";
40                         $diss = 1;
41                 }
42                 my( $id, $text, $time, $name, $note, $seen, $user ) = @{$history};
43                 my $type = $seen ? 'history' : 'unseen-history';
44                 $type = 'main-history' if( defined( $mid ) && ( $id == $mid ) );
45                 print "<div class='$type'>\n";
46                 print "<p class='itemname'>Name: ".encode( $name )."\n" if( defined( $name ) && ( $name ne '' ) );
47                 print "<p class='itemname'>Deletion request\n" if( defined $name && $name eq '' );
48                 print "<p class='itemnote'>Note: ".encode( $note )."\n" if( defined( $note ) && ( $note ne '' ) );
49                 if( defined( $text ) && ( $text ne '' ) ) {
50                         $text = encode( $text );
51                         $text =~ s/\n/<br>/g;
52                         print "<p class='discussion-text'>$text\n";
53                 }
54                 print "<p class='author'>".encode( $user )."\n" if( defined( $user ) );
55                 print "<p class='time'>".encode( $time )."\n";
56                 print "</div>\n";
57         }
58         print "</div>\n" if( $diss );
59         my $url_prefix = $args->{'full_links'} ? 'http://'.$req->hostname() : '';
60         unless( $address->leaf() ) {
61                 print "<h2>Sub-items</h2>\n";
62                 my $restricts = $address->defaultRestrictList();
63                 if( scalar @{$restricts} ) {
64                         print "<p>";
65                         my $url = '/read/'.$address->get().buildExcept( 'restrict', $args ).'?restrict=';
66                         foreach( @{$restricts} ) {
67                                 print "<a href='".$url_prefix.$url.$_->[0]."'>".$_->[1]."</a> ";
68                         }
69                 }
70                 my $url = '/read/'.$address->get().buildExcept( 'sort', $args );
71                 my $sort = ( $args->{'sort'} or 'id' );
72                 my( $sort_id, $sort_name ) = ( ( $sort eq 'id' ? 'rid' : 'id' ), ( $sort eq 'name' ? 'rname' : 'name' ) );
73                 genTableHead( 'subnodes', [ '<a href="'.$url_prefix.$url.'?sort='.$sort_id.'">Id</a>', '<a href="'.$url_prefix.$url.'?sort='.$sort_name.'">Name</a>', 'Note' ], [ 'id-col', 'name-col', 'note-col' ] );
74                 $args->{'restrict'} = $address->defaultRestrict() unless( defined( $args->{'restrict'} ) );
75                 $tables->nodes( $address->get(), $args, $url_prefix );
76                 genTableTail();
77         }
78         genHtmlTail();
79         return OK;
80 }
81
82 1;