]> mj.ucw.cz Git - pciids.git/blob - PciIds/Html/List.pm
Make the h1 titles little lower
[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->top()->pretty();
26         genHtmlHead( $req, $id, "<style type='text/css' media='screen,print'>col.id-col { width: ".$address->subIdSize()*1.25."ex; }</style>\n" );
27         print "<div class='top'>\n";
28         genMenu( $req, $address, $args, $auth, [ [ 'Help', 'help', 'list' ], $address->helpName() ? [ 'ID syntax', 'help', $address->helpName() ] : (), [ '', 'jump' ] ] );
29         print '<h1>'.encode( $id ).'</h1>';
30         print "<div class='clear'></div>\n";
31         print "</div\n>";
32         genPath( $req, $address, 0 );
33         if( defined $name ) {
34                 print '<h2>'.encode( $id ).'</h2>';
35                 print htmlDiv( 'name', '<p>Name: '.encode( $name ) );
36         }
37         print htmlDiv( 'note', '<p>Note: '.encode( $note ) ) if defined $note && $note ne '';
38         my $diss = 0;
39         my $history;
40         foreach $history ( @{$tables->history( $address->get() )} ) {
41                 unless( $diss ) {
42                         print "<div class='discussion'>\n<h2>Discussion</h2>";
43                         $diss = 1;
44                 }
45                 my( $id, $text, $time, $name, $note, $seen, $user, $email ) = @{$history};
46                 my $type = $seen ? 'history' : 'unseen-history';
47                 $type = 'main-history' if( defined( $mid ) && ( $id == $mid ) );
48                 print "<div class='$type'>\n";
49                 print "<p class='itemname'>Name: ".encode( $name )."\n" if( defined( $name ) && ( $name ne '' ) );
50                 print "<p class='itemname'>Deletion request\n" if( defined $name && $name eq '' );
51                 print "<p class='itemnote'>Note: ".encode( $note )."\n" if( defined( $note ) && ( $note ne '' ) );
52                 if( defined( $text ) && ( $text ne '' ) ) {
53                         $text = encode( $text );
54                         $text =~ s/\n/<br>/g;
55                         print "<p class='discussion-text'>$text\n";
56                 }
57                 ( $user ) = ( $email =~ /^(.*)@/ ) if defined $email && !defined $user;
58                 print "<p class='author'>".encode( $user )."\n" if( defined( $user ) );
59                 print "<p class='time'>".encode( $time )."\n";
60                 print "</div>\n";
61         }
62         if( $diss ) {
63                 print "<p><a href='".buildExcept( 'action', $args )."?action=newhistory'>Discuss</a>\n";
64                 print "</div>\n" if( $diss );
65         }
66         unless( $address->leaf() ) {
67                 print "<h2>".encode( $address->subName() )."</h2>\n";
68                 my $restricts = $address->defaultRestrictList();
69                 if( scalar @{$restricts} ) {
70                         print "<p>";
71                         my $url = '/read/'.$address->get().buildExcept( 'restrict', $args ).'?restrict=';
72                         foreach( @{$restricts} ) {
73                                 print "<a href='".$url.$_->[0]."'>".$_->[1]."</a> ";
74                         }
75                 }
76                 my $url = '/read/'.$address->get().buildExcept( 'sort', $args );
77                 my $sort = ( $args->{'sort'} or 'id' );
78                 my( $sort_id, $sort_name ) = ( ( $sort eq 'id' ? 'rid' : 'id' ), ( $sort eq 'name' ? 'rname' : 'name' ) );
79                 genTableHead( 'subnodes', [ '<a href="'.$url.'?sort='.$sort_id.'">Id</a>', '<a href="'.$url.'?sort='.$sort_name.'">Name</a>', 'Note' ], [ 'id-col', 'name-col', 'note-col' ] );
80                 $args->{'restrict'} = $address->defaultRestrict() unless( defined( $args->{'restrict'} ) );
81                 $tables->nodes( $address->get(), $args );
82                 genTableTail();
83                 print "<p><a href='".buildExcept( 'action', $args )."?action=newitem'>Add item</a>\n";
84         }
85         genHtmlTail();
86         return OK;
87 }
88
89 1;