]> mj.ucw.cz Git - pciids.git/blob - PciIds/Html/List.pm
Output better path
[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         print htmlDiv( 'name', '<p>Name: '.encode( $name ) ) if defined $name && $name ne '';
34         print htmlDiv( 'note', '<p>Note: '.encode( $note ) ) if defined $note && $note ne '';
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, $email ) = @{$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                 ( $user ) = ( $email =~ /^(.*)@/ ) if defined $email && !defined $user;
55                 print "<p class='author'>".encode( $user )."\n" if( defined( $user ) );
56                 print "<p class='time'>".encode( $time )."\n";
57                 print "</div>\n";
58         }
59         if( $diss ) {
60                 print "<p><a href='".buildExcept( 'action', $args )."?action=newhistory'>Discuss</a>\n";
61                 print "</div>\n" if( $diss );
62         }
63         unless( $address->leaf() ) {
64                 print "<h2>".encode( $address->subName() )."</h2>\n";
65                 my $restricts = $address->defaultRestrictList();
66                 if( scalar @{$restricts} ) {
67                         print "<p>";
68                         my $url = '/read/'.$address->get().buildExcept( 'restrict', $args ).'?restrict=';
69                         foreach( @{$restricts} ) {
70                                 print "<a href='".$url.$_->[0]."'>".$_->[1]."</a> ";
71                         }
72                 }
73                 my $url = '/read/'.$address->get().buildExcept( 'sort', $args );
74                 my $sort = ( $args->{'sort'} or 'id' );
75                 my( $sort_id, $sort_name ) = ( ( $sort eq 'id' ? 'rid' : 'id' ), ( $sort eq 'name' ? 'rname' : 'name' ) );
76                 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' ] );
77                 $args->{'restrict'} = $address->defaultRestrict() unless( defined( $args->{'restrict'} ) );
78                 $tables->nodes( $address->get(), $args );
79                 genTableTail();
80                 print "<p><a href='".buildExcept( 'action', $args )."?action=newitem'>Add item</a>\n";
81         }
82         genHtmlTail();
83         return OK;
84 }
85
86 1;