Skip to content
Browse files

all page actions are under Page controller (as it should have been)

  • Loading branch information...
1 parent ddd2d3c commit a3d1ecb4c8580518c577c6563612a25eec1cf8c3 @jberger committed Feb 22, 2013
View
9 lib/Galileo.pm
@@ -157,6 +157,11 @@ sub startup {
}
);
+ $app->helper( expire => sub {
+ my ($self, $name) = @_;
+ $self->flex_memorize->{$name}{expires} = 1;
+ });
+
## Routing ##
my $r = $app->routes;
@@ -175,8 +180,8 @@ sub startup {
});
$if_author->any( '/admin/menu' )->to('edit#edit_menu');
- $if_author->any( '/edit/:name' )->to('edit#edit_page');
- $if_author->websocket( '/store/page' )->to('edit#store_page');
+ $if_author->any( '/edit/:name' )->to('page#edit');
+ $if_author->websocket( '/store/page' )->to('page#store');
$if_author->websocket( '/store/menu' )->to('edit#store_menu');
my $if_admin = $r->under( sub {
View
56 lib/Galileo/Edit.pm
@@ -3,57 +3,6 @@ use Mojo::Base 'Mojolicious::Controller';
use Mojo::JSON 'j';
-sub edit_page {
- my $self = shift;
- my $name = $self->param('name');
- $self->title( "Editing Page: $name" );
- $self->content_for( banner => "Editing Page: $name" );
-
- my $schema = $self->schema;
-
- my $page = $schema->resultset('Page')->single({name => $name});
- if ($page) {
- my $title = $page->title;
- $self->stash( title_value => $title );
- $self->stash( input => $page->md );
- } else {
- $self->stash( title_value => '' );
- $self->stash( input => "Hello World" );
- }
-
- $self->stash( sanitize => $self->config->{sanitize} // 1 ); #/# highlight fix
-
- $self->render;
-}
-
-sub store_page {
- my $self = shift;
- $self->on( text => sub {
- my ($self, $message) = @_;
- my $data = j( $message );
-
- my $schema = $self->schema;
-
- unless($data->{title}) {
- $self->send({ text => j({
- message => 'Not saved! A title is required!',
- success => \0,
- }) });
- return;
- }
- my $author = $schema->resultset('User')->single({name=>$self->session->{username}});
- $data->{author_id} = $author->id;
- $schema->resultset('Page')->update_or_create(
- $data, {key => 'pages_name'},
- );
- $self->expire('main');
- $self->send({ text => j({
- message => 'Changes saved',
- success => \1,
- }) });
- });
-}
-
sub edit_menu {
my $self = shift;
my $name = 'main';
@@ -114,10 +63,5 @@ sub store_menu {
});
}
-sub expire {
- my ($self, $name) = @_;
- $self->flex_memorize->{$name}{expires} = 1;
-}
-
1;
View
53 lib/Galileo/Page.pm
@@ -1,6 +1,8 @@
package Galileo::Page;
use Mojo::Base 'Mojolicious::Controller';
+use Mojo::JSON 'j';
+
sub show {
my $self = shift;
my $name = $self->param('name');
@@ -17,5 +19,56 @@ sub show {
}
}
+sub edit {
+ my $self = shift;
+ my $name = $self->param('name');
+ $self->title( "Editing Page: $name" );
+ $self->content_for( banner => "Editing Page: $name" );
+
+ my $schema = $self->schema;
+
+ my $page = $schema->resultset('Page')->single({name => $name});
+ if ($page) {
+ my $title = $page->title;
+ $self->stash( title_value => $title );
+ $self->stash( input => $page->md );
+ } else {
+ $self->stash( title_value => '' );
+ $self->stash( input => "Hello World" );
+ }
+
+ $self->stash( sanitize => $self->config->{sanitize} // 1 ); #/# highlight fix
+
+ $self->render;
+}
+
+sub store {
+ my $self = shift;
+ $self->on( text => sub {
+ my ($self, $message) = @_;
+ my $data = j( $message );
+
+ my $schema = $self->schema;
+
+ unless($data->{title}) {
+ $self->send({ text => j({
+ message => 'Not saved! A title is required!',
+ success => \0,
+ }) });
+ return;
+ }
+ my $author = $schema->resultset('User')->single({name=>$self->session->{username}});
+ $data->{author_id} = $author->id;
+ $schema->resultset('Page')->update_or_create(
+ $data, {key => 'pages_name'},
+ );
+ $self->expire('main');
+ $self->send({ text => j({
+ message => 'Changes saved',
+ success => \1,
+ }) });
+ });
+}
+
1;
View
0 ...eo/files/templates/edit/edit_page.html.ep → ...Galileo/files/templates/page/edit.html.ep
File renamed without changes.

0 comments on commit a3d1ecb

Please sign in to comment.
Something went wrong with that request. Please try again.