[Catalyst-commits] r12158 - in
trunk/examples/Advent09FormHandlerBlog/Blog: . lib
lib/Blog/Controller root/lib root/static/css root/static/js
alexn_org at dev.catalyst.perl.org
alexn_org at dev.catalyst.perl.org
Thu Dec 3 10:21:17 GMT 2009
Author: alexn_org
Date: 2009-12-03 10:21:16 +0000 (Thu, 03 Dec 2009)
New Revision: 12158
Modified:
trunk/examples/Advent09FormHandlerBlog/Blog/blog.conf
trunk/examples/Advent09FormHandlerBlog/Blog/lib/Blog.pm
trunk/examples/Advent09FormHandlerBlog/Blog/lib/Blog/Controller/Article.pm
trunk/examples/Advent09FormHandlerBlog/Blog/root/lib/layout.tt
trunk/examples/Advent09FormHandlerBlog/Blog/root/static/css/styles.css
trunk/examples/Advent09FormHandlerBlog/Blog/root/static/js/main.js
Log:
fixes
Modified: trunk/examples/Advent09FormHandlerBlog/Blog/blog.conf
===================================================================
--- trunk/examples/Advent09FormHandlerBlog/Blog/blog.conf 2009-12-03 09:36:52 UTC (rev 12157)
+++ trunk/examples/Advent09FormHandlerBlog/Blog/blog.conf 2009-12-03 10:21:16 UTC (rev 12158)
@@ -9,3 +9,9 @@
WRAPPER = "layout.tt"
TEMPLATE_EXTENSION = ".tt"
</View::TT>
+
+# session conf
+<session>
+ flash_to_stash = 1
+ cookie_expires = 0
+</session>
Modified: trunk/examples/Advent09FormHandlerBlog/Blog/lib/Blog/Controller/Article.pm
===================================================================
--- trunk/examples/Advent09FormHandlerBlog/Blog/lib/Blog/Controller/Article.pm 2009-12-03 09:36:52 UTC (rev 12157)
+++ trunk/examples/Advent09FormHandlerBlog/Blog/lib/Blog/Controller/Article.pm 2009-12-03 10:21:16 UTC (rev 12158)
@@ -7,37 +7,39 @@
sub articles : Chained('/') PathPart('article') CaptureArgs(0) {
my ($self, $c) = @_;
- $c->stash->{articles} = $c->model('DB::Article');
+ $c->stash->{articles} = $c->model('DB::Article')->search({}, { order_by => 'ts desc' });
}
-sub list : Chained('articles') Args(0) {}
+sub list : Chained('articles') Args(0) {
+ my ($self, $c) = @_;
+ $c->stash->{template} = 'article/list.tt';
+}
sub item : Chained('articles') PathPart('') CaptureArgs(1) {
my ($self, $c, $id) = @_;
$c->error("ID isn't valid!") unless $id =~ /^\d+$/;
$c->stash->{item} = $c->stash->{articles}->find($id)
- or $c->error("ID $id is nonexistent");
+ || $c->detach('not_found');
}
sub show : Chained('item') Args(0) {}
sub add : Chained('articles') Args(0) {
my ($self, $c) = @_;
- $c->forward_to_action('Article', 'save');
+ $c->stash->{item} = $c->model('DB::Article')->new_result({});
+ $c->forward('save');
}
sub edit : Chained('item') {
my ($self, $c) = @_;
- $c->forward_to_action('Article', 'add');
+ $c->forward('save');
}
sub save : Private {
my ($self, $c) = @_;
- # if the item doesn't exist, we'll just create a new result
- my $item = $c->stash->{item} || $c->model('DB::Article')->new_result({});
- my $form = Blog::Form::Article->new( item => $item );
+ my $form = Blog::Form::Article->new( item => $c->stash->{item} );
my $all_tags = $c->model('DB::Tag')->search({}, { order_by => 'name' });
$c->stash( form => $form, template => 'article/save.tt', tags => $all_tags );
@@ -46,19 +48,16 @@
# if it returns False, then a validation error happened
return unless $form->process( params => $c->req->params );
+ $c->stash->{template} = 'article/save.tt';
$c->flash->{info_msg} = "Article saved!";
$c->redirect_to_action('Article', 'list');
}
-sub remove : Chained('item') Args(0) FormConfig {
+sub not_found : Local {
my ($self, $c) = @_;
-
- my $form = $c->stash->{form};
- return unless $form->submitted_and_valid;
-
- $c->stash->{item}->delete;
- $c->flash->{info_msg} = "Article was deleted!";
- $c->redirect_to_action('Article', 'list');
+ $c->response->status(404);
+ $c->stash->{error_msg} = "Article not found!";
+ $c->detach('list');
}
1;
Modified: trunk/examples/Advent09FormHandlerBlog/Blog/lib/Blog.pm
===================================================================
--- trunk/examples/Advent09FormHandlerBlog/Blog/lib/Blog.pm 2009-12-03 09:36:52 UTC (rev 12157)
+++ trunk/examples/Advent09FormHandlerBlog/Blog/lib/Blog.pm 2009-12-03 10:21:16 UTC (rev 12158)
@@ -42,12 +42,6 @@
$c->detach;
}
-sub forward_to_action {
- my ($c, $controller, $action, @params) = @_;
- $c->forward($controller, $action, @params);
- $c->detach;
-}
-
sub action_uri {
my ($c, $controller, $action, @params) = @_;
return eval {$c->uri_for($c->controller($controller)->action_for($action), @params)};
Modified: trunk/examples/Advent09FormHandlerBlog/Blog/root/lib/layout.tt
===================================================================
--- trunk/examples/Advent09FormHandlerBlog/Blog/root/lib/layout.tt 2009-12-03 09:36:52 UTC (rev 12157)
+++ trunk/examples/Advent09FormHandlerBlog/Blog/root/lib/layout.tt 2009-12-03 10:21:16 UTC (rev 12158)
@@ -18,6 +18,7 @@
href="[% c.uri_for('/static/css/jquery.autocomplete.css') %]" />
</head>
<body>
+
[% IF info_msg %]<div class="info_msg">[% info_msg %]</div>[% END %]
[% IF error_msg %]<div class="error_msg">[% error_msg %]</div>[% END %]
Modified: trunk/examples/Advent09FormHandlerBlog/Blog/root/static/css/styles.css
===================================================================
--- trunk/examples/Advent09FormHandlerBlog/Blog/root/static/css/styles.css 2009-12-03 09:36:52 UTC (rev 12157)
+++ trunk/examples/Advent09FormHandlerBlog/Blog/root/static/css/styles.css 2009-12-03 10:21:16 UTC (rev 12158)
@@ -47,3 +47,22 @@
font-weight: bold;
}
+.info_msg, .error_msg {
+ position: absolute;
+ top: 0;
+ left: 0;
+ width: 98%;
+
+ border-bottom: 2px solid #334455;
+ padding: 1%;
+
+ background-color: #8899AA;
+ font-size: 24px;
+ color: white;
+}
+
+
+.error_msg {
+ border-color: #554433;
+ background-color: #AA9988;
+}
Modified: trunk/examples/Advent09FormHandlerBlog/Blog/root/static/js/main.js
===================================================================
--- trunk/examples/Advent09FormHandlerBlog/Blog/root/static/js/main.js 2009-12-03 09:36:52 UTC (rev 12157)
+++ trunk/examples/Advent09FormHandlerBlog/Blog/root/static/js/main.js 2009-12-03 10:21:16 UTC (rev 12158)
@@ -0,0 +1,5 @@
+$(function () {
+ setTimeout(function () {
+ $('.error_msg, .info_msg').fadeOut();
+ }, 5000);
+});
\ No newline at end of file
More information about the Catalyst-commits
mailing list