sub submitHistory( $$$$ ) {
my( $self, $data, $auth, $address ) = @_;
- $self->command( 'newhistory', [ $address->get(), $auth->{'authid'}, $data->{'text'}, $data->{'name'}, $data->{'note'} ], 1 );
+ if( $data->{'delete'} ) {
+ $self->command( 'newhistory', [ $address->get(), $auth->{'authid'}, $data->{'text'}, '', $data->{'note'} ], 1 );
+ } else {
+ $data->{'name'} = undef if defined $data->{'name'} && $data->{'name'} eq '';
+ $self->command( 'newhistory', [ $address->get(), $auth->{'authid'}, $data->{'text'}, $data->{'name'}, $data->{'note'} ], 1 );
+ }
return $self->last();
}
print "<div class='error'>$error</div>\n" if( defined $error );
print "<form name='newhistory' id='newhistory' method='POST' action=''>\n<table>";
genFormEx( [ [ 'textarea', 'Text:', undef, 'text', 'rows="5" cols="50"' ],
- [ 'input', 'Name*:', 'text', 'name', 'maxlength="200"' ],
- [ 'input', 'Note*:', 'text', 'note', 'maxlength="1024"' ],
+ [ 'input', 'Request deletion', 'checkbox', 'delete', 'value="delete"' ],
+ [ 'input', 'Name:', 'text', 'name', 'maxlength="200"' ],
+ [ 'input', 'Note:', 'text', 'note', 'maxlength="1024"' ],
[ 'input', '', 'submit', 'submit', 'value="Submit"' ] ], $values );
print '</table></form>';
- print '<p>Items marked with * are optional, use them only if you want to change the name and note.';
- print '<p>If you specify note, you must include name too.';
genHtmlTail();
return OK;
}
'text' => sub {
my( $expl ) = @_;
return 'Text can not be longer than 1024 characters' if ( length $expl > 1024 );
- return 'You must provide the text of comment' unless( length $expl );
+ return undef;
+ },
+ 'delete' => sub {
+ my( $delete ) = @_;
+ return ( undef, '0' ) unless defined $delete;
+ return undef if $delete eq 'delete';
+ return 'Invalid form value';
return undef;
}
}, [ sub { my( $data ) = @_;
+ return 'You must provide either name, text or request a deletion' if( ! length $data->{'name'} && ! length $data->{'text'} && ! $data->{'delete'} );
+ return undef;
+ }, sub { my( $data ) = @_;
+ return 'You can not set name and request deletion at the same time' if( length $data->{'name'} && $data->{'delete'} );
+ return undef;
+ }, sub { my( $data ) = @_;
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'; } ] );
print '<h1>'.encode( $id ).'</h1>';
genMenu( $req, $address, $args, $auth, [ [ 'Help', 'help', 'list' ], $address->helpName() ? [ 'ID syntax', 'help', $address->helpName() ] : () ] );
genPath( $req, $address, 0 );
- print htmlDiv( 'name', '<p>'.encode( $name ) ) if( defined( $name ) );
+ print htmlDiv( 'name', '<p>'.encode( $name ) ) if defined( $name );
print htmlDiv( 'note', '<p>'.encode( $note ) ) if( defined( $note ) );
my $diss = 0;
my $history;
$type = 'main-history' if( defined( $mid ) && ( $id == $mid ) );
print "<div class='$type'>\n";
print "<p class='itemname'>Name: ".encode( $name )."\n" if( defined( $name ) && ( $name ne '' ) );
+ print "<p class='itemname'>Deletion request\n" if( defined $name && $name eq '' );
print "<p class='itemnote'>Note: ".encode( $note )."\n" if( defined( $note ) && ( $note ne '' ) );
if( defined( $text ) && ( $text ne '' ) ) {
$text = encode( $text );