Implement form for remarking to threads
This commit is contained in:
parent
e0b7ab4a7d
commit
e73170c1f2
80
PostText.pl
80
PostText.pl
|
@ -62,35 +62,73 @@ group {
|
||||||
};
|
};
|
||||||
|
|
||||||
# Post
|
# Post
|
||||||
any [qw{GET POST}], '/post', sub ($c) {
|
group {
|
||||||
my $v;
|
under '/post';
|
||||||
|
|
||||||
$v = $c->validation() if $c->req->method eq 'POST';
|
any [qw{GET POST}], '/', sub ($c) {
|
||||||
|
my $v;
|
||||||
|
|
||||||
if ($v && $v->has_data) {
|
$v = $c->validation() if $c->req->method eq 'POST';
|
||||||
my $thread_author = $c->param('name' ) || 'Anonymous';
|
|
||||||
my $thread_title = $c->param('title');
|
|
||||||
my $thread_body = $c->param('post' );
|
|
||||||
|
|
||||||
$v->required('name' )->size(1, 63 );
|
if ($v && $v->has_data) {
|
||||||
$v->required('title')->size(1, 127 );
|
my $thread_author = $c->param('name' ) || 'Anonymous';
|
||||||
$v->required('post' )->size(2, 4000);
|
my $thread_title = $c->param('title');
|
||||||
|
my $thread_body = $c->param('post' );
|
||||||
|
|
||||||
if ($v->has_error) {
|
$v->required('name' )->size(1, 63 );
|
||||||
$c->stash(status => 400)
|
$v->required('title')->size(1, 127 );
|
||||||
|
$v->required('post' )->size(2, 4000);
|
||||||
|
|
||||||
|
if ($v->has_error) {
|
||||||
|
$c->stash(status => 400)
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$c->thread->create_thread(
|
||||||
|
$thread_author,
|
||||||
|
$thread_title,
|
||||||
|
$thread_body
|
||||||
|
);
|
||||||
|
|
||||||
|
return $c->redirect_to('view');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
$c->thread->create_thread(
|
|
||||||
$thread_author,
|
|
||||||
$thread_title,
|
|
||||||
$thread_body
|
|
||||||
);
|
|
||||||
|
|
||||||
return $c->redirect_to('view');
|
return $c->render(template => 'post_thread');
|
||||||
|
};
|
||||||
|
|
||||||
|
any [qw{GET POST}], '/:thread_id', [thread_id => qr/[0-9]+/], sub ($c) {
|
||||||
|
my $v;
|
||||||
|
|
||||||
|
$v = $c->validation() if $c->req->method eq 'POST';
|
||||||
|
|
||||||
|
if ($v && $v->has_data) {
|
||||||
|
my $thread_id = $c->param('thread_id');
|
||||||
|
my $remark_name = $c->param('name');
|
||||||
|
my $remark_body = $c->param('post');
|
||||||
|
|
||||||
|
$v->required('name' )->size(1, 63 );
|
||||||
|
$v->required('post' )->size(2, 4000);
|
||||||
|
|
||||||
|
if ($v->has_error) {
|
||||||
|
$c->stash(status => 400)
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$c->remark->create_remark(
|
||||||
|
$thread_id,
|
||||||
|
$remark_name,
|
||||||
|
$remark_body
|
||||||
|
);
|
||||||
|
|
||||||
|
# Gotta be a better way to name this route...
|
||||||
|
return $c->redirect_to(
|
||||||
|
'thread_idremark_page',
|
||||||
|
{thread_id => $thread_id}
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return $c->render();
|
return $c->render(template => 'post_remark');
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
# Thread
|
# Thread
|
||||||
|
|
|
@ -12,7 +12,7 @@ Install dependencies
|
||||||
|
|
||||||
Run it in development mode
|
Run it in development mode
|
||||||
|
|
||||||
morbo PostText.pl
|
morbo -w assets/css/ -w lib/ -w migrations/ -w t/ -w templates/ PostText.pl
|
||||||
|
|
||||||
Now try requesting http://localhost:3000
|
Now try requesting http://localhost:3000
|
||||||
|
|
||||||
|
@ -24,10 +24,11 @@ Run the tests locally (against development environment)
|
||||||
|
|
||||||
## TODOs
|
## TODOs
|
||||||
|
|
||||||
1. Form to create new remarks
|
1. Hyperlink to remarks form
|
||||||
|
1. Is there something I can do about route names?
|
||||||
1. I'm kinda hardcoding the single-thread view `link_to` in the
|
1. I'm kinda hardcoding the single-thread view `link_to` in the
|
||||||
templates because I cannot for the life of me figure out how to use
|
templates because I cannot for the life of me figure out how to use
|
||||||
`url_for` to populate the `thread_id` placeholder. Probably need to
|
`url_for` to populate the `thread_id` placeholder. Probably need to
|
||||||
clean-up the HTML too, just used `<span>` cuz I didn't know what
|
clean-up the HTML too, just used `<span>` cuz I didn't know what
|
||||||
else to use
|
else to use
|
||||||
1. Just clean stuff up in general lol
|
1. Tests for remark form
|
||||||
|
|
25
templates/post_remark.html.ep
Normal file
25
templates/post_remark.html.ep
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
% layout 'main';
|
||||||
|
% title 'New Remark';
|
||||||
|
<h2><%= title %></h2>
|
||||||
|
<form method="post">
|
||||||
|
<div class="name field">
|
||||||
|
<%= label_for name => 'Author' %>
|
||||||
|
<%= text_field name =>'Anonymous', maxlength => 63, minlength => 1 %>
|
||||||
|
<% if (my $error = validation->error('name')) { =%>
|
||||||
|
<p class="field-with-error">Invalid name: 1 to 63 characters please.</p>
|
||||||
|
<% } =%>
|
||||||
|
</div>
|
||||||
|
<div class="text field">
|
||||||
|
<%= label_for post => 'Text' %>
|
||||||
|
<%= text_area 'post', (
|
||||||
|
maxlength => 4000,
|
||||||
|
minlength => 2,
|
||||||
|
required => 'true',
|
||||||
|
rows => 6
|
||||||
|
) %>
|
||||||
|
<% if (my $error = validation->error('post')) { =%>
|
||||||
|
<p class="field-with-error">Invalid post: Up to 4,000 characters only.</p>
|
||||||
|
<% } =%>
|
||||||
|
</div>
|
||||||
|
<%= submit_button 'Post', class => 'post button' %>
|
||||||
|
</form>
|
Loading…
Reference in a new issue