From 8858c1d9a8f3c666b6aecd09413c2ceb9366d009 Mon Sep 17 00:00:00 2001 From: Michal Vaner Date: Sat, 30 Aug 2008 12:00:04 +0200 Subject: [PATCH] Menu added to editation forms --- PciIds/Address/Pci.pm | 2 +- PciIds/Address/PciClass.pm | 2 +- PciIds/Address/Toplevel.pm | 2 +- PciIds/Html/Changes.pm | 24 +++++++++++++++--------- 4 files changed, 18 insertions(+), 12 deletions(-) diff --git a/PciIds/Address/Pci.pm b/PciIds/Address/Pci.pm index 54a15af..33e4afc 100644 --- a/PciIds/Address/Pci.pm +++ b/PciIds/Address/Pci.pm @@ -49,7 +49,7 @@ sub append( $$ ) { return ( undef, 'You can not add to leaf node' ) if( $self->leaf() ); $suffix =~ s/ //g; return ( undef, "Invalid ID syntax" ) unless ( ( ( $self->get() !~ /^PC\/.*\// ) && ( $suffix =~ /^[0-9a-f]{4}$/ ) ) || ( ( $self->get() =~ /^PC\/.*\// ) && ( $suffix =~ /^[0-9a-f]{8}$/ ) ) ); - return ( PciIds::Address::Base::new( $self->{'value'} . ( ( $self->{'value'} =~ /\/$/ ) ? '' : '/' ) . $suffix ), undef ); + return ( PciIds::Address::new( $self->{'value'} . ( ( $self->{'value'} =~ /\/$/ ) ? '' : '/' ) . $suffix ), undef ); } sub path( $ ) { diff --git a/PciIds/Address/PciClass.pm b/PciIds/Address/PciClass.pm index 993efc2..46623c5 100644 --- a/PciIds/Address/PciClass.pm +++ b/PciIds/Address/PciClass.pm @@ -41,7 +41,7 @@ sub append( $$ ) { my( $self, $suffix ) = @_; return ( undef, 'You can not add to leaf node' ) if( $self->leaf() ); return ( undef, "Invalid ID syntax" ) unless ( $suffix =~ /^[0-9a-f]{2,2}$/ ); - return ( PciIds::Address::Base::new( $self->{'value'} . ( ( $self->{'value'} =~ /\/$/ ) ? '' : '/' ) . $suffix ), undef ); + return ( PciIds::Address::new( $self->{'value'} . ( ( $self->{'value'} =~ /\/$/ ) ? '' : '/' ) . $suffix ), undef ); } 1; diff --git a/PciIds/Address/Toplevel.pm b/PciIds/Address/Toplevel.pm index 6f4836b..bc66024 100644 --- a/PciIds/Address/Toplevel.pm +++ b/PciIds/Address/Toplevel.pm @@ -38,7 +38,7 @@ sub append( $$ ) { } else {#PCI Device Class return ( undef, "Invalid ID syntax" ) unless ( $suffix =~ /^[0-9a-f]{2,2}$/ ); } - return ( PciIds::Address::Base::new( $self->{'value'} . ( ( $self->{'value'} =~ /\/$/ ) ? '' : '/' ) . $suffix ), undef ); + return ( PciIds::Address::new( $self->{'value'} . ( ( $self->{'value'} =~ /\/$/ ) ? '' : '/' ) . $suffix ), undef ); } sub canDiscuss( $ ) { return 0; } diff --git a/PciIds/Html/Changes.pm b/PciIds/Html/Changes.pm index 2c8cc3a..d442744 100644 --- a/PciIds/Html/Changes.pm +++ b/PciIds/Html/Changes.pm @@ -6,15 +6,17 @@ use PciIds::Html::Util; use PciIds::Html::Forms; use PciIds::Notifications; use PciIds::Log; +use PciIds::Address; use Apache2::Const qw(:common :http); -sub genNewItemForm( $$$$$ ) { - my( $req, $args, $tables, $error, $values ) = @_; +sub genNewItemForm( $$$$$$ ) { + my( $req, $args, $auth, $tables, $error, $values ) = @_; my( $ok, $parent, $name, $note, $address ) = loadItem( $tables, $req->uri() ); return NOT_FOUND unless( $ok ); my $prettyAddr = encode( $address->pretty() ); genHtmlHead( $req, "$prettyAddr - add new item", undef ); print "

$prettyAddr - add new item

\n"; + genLocMenu( $req, $args, [ logItem( $auth ), $address->canDiscuss() ? [ 'Discuss', 'newhistory' ] : (), [ 'Notifications', 'notifications' ] ] ); print "
$error
\n" if( defined $error ); print "
\n"; genFormEx( [ [ 'input', 'Id:', 'text', 'id', 'maxlength="50"' ], @@ -31,7 +33,7 @@ sub genNewItemForm( $$$$$ ) { sub newItemForm( $$$$ ) { my( $req, $args, $tables, $auth ) = @_; if( defined $auth->{'authid'} ) {#Logged in alright - return genNewItemForm( $req, $args, $tables, undef, {} ); + return genNewItemForm( $req, $args, $auth, $tables, undef, {} ); } else { return notLoggedComplaint( $req, $args, $auth ); } @@ -58,12 +60,15 @@ sub newItemSubmit( $$$$ ) { ( $data->{'address'}, $errstr ) = $paddress->append( $data->{'id'} ); return $errstr; }, sub { return $paddress->canAddItem() ? undef : 'Can not add items here'; } ] ); - return genNewItemForm( $req, $args, $tables, $error, $data ) if( defined $error ); + return genNewItemForm( $req, $args, $auth, $tables, $error, $data ) if( defined $error ); my( $result, $comName ) = $tables->submitItem( $data, $auth ); if( $result eq 'exists' ) { genHtmlHead( $req, 'ID collision', undef ); print '

ID collision

'; - print '

This ID already exists. Have a look at it'; + my $addr = PciIds::Address::new( $req->uri() ); + genCustomMenu( $req, $addr, $args, [ logItem( $auth ), [ 'Add other item', 'newitem' ], $addr->canDiscuss() ? [ 'Discuss', 'newhistory' ] : () ] ); + genPath( $req, $data->{'address'}, 1 ); + print '

Sorry, this ID already exists.'; genHtmlTail(); return OK; } elsif( $result ) { @@ -77,13 +82,14 @@ sub newItemSubmit( $$$$ ) { } } -sub genNewHistoryForm( $$$$$ ) { - my( $req, $args, $tables, $error, $values ) = @_; +sub genNewHistoryForm( $$$$$$ ) { + my( $req, $args, $tables, $auth, $error, $values ) = @_; my( $ok, $parent, $name, $note, $address ) = loadItem( $tables, $req->uri() ); return NOT_FOUND unless( $ok ); my $prettyAddr = encode( $address->pretty() ); genHtmlHead( $req, "$prettyAddr - discuss", undef ); print "

$prettyAddr - discuss

\n"; + genLocMenu( $req, $args, [ logItem( $auth ), $address->canAddItem() ? [ 'Add item', 'newitem' ] : (), [ 'Notifications', 'notifications' ] ] ); print "
$error
\n" if( defined $error ); print "\n
"; genFormEx( [ [ 'textarea', 'Text:', undef, 'text', 'rows="5" cols="50"' ], @@ -100,7 +106,7 @@ sub genNewHistoryForm( $$$$$ ) { sub newHistoryForm( $$$$ ) { my( $req, $args, $tables, $auth ) = @_; if( defined $auth->{'authid'} ) { - return genNewHistoryForm( $req, $args, $tables, undef, {} ); + return genNewHistoryForm( $req, $args, $tables, $auth, undef, {} ); } else { return notLoggedComplaint( $req, $args, $auth ); } @@ -124,7 +130,7 @@ sub newHistorySubmit( $$$$ ) { return 'You must provide name too' if( ( length $data->{'note'} ) && ( ! length $data->{'name'} ) ); return undef; }, sub { return $address->canDiscuss() ? undef : 'You can not discuss this item'; } ] ); - return genNewHistoryForm( $req, $args, $tables, $error, $data ) if( defined $error ); + return genNewHistoryForm( $req, $args, $tables, $auth, $error, $data ) if( defined $error ); my $hid = $tables->submitHistory( $data, $auth, $address ); tulog( $auth->{'authid'}, "Discussion created $hid ".$address->get()." ".logEscape( $data->{'name'} )." ".logEscape( $data->{'description'} )." ".logEscape( $data->{'text'} ) ); notify( $tables, $address->get(), $hid, ( defined $name && ( $name ne '' ) ) ? 1 : 0, 1 ); -- 2.39.2