--- Webpacus/lib/Webpacus/Controller/Editor.pm 2005/11/24 22:29:29 135 +++ Webpacus/lib/Webpacus/Controller/Editor.pm 2005/11/26 20:21:54 165 @@ -4,13 +4,15 @@ use warnings; use base 'Catalyst::Controller'; +use Data::Dumper; + =head1 NAME -Webpacus::Controller::Editor - Catalyst Controller +Webpacus::Controller::Editor - AJAX template and CSS editor =head1 SYNOPSIS -See L +See L, L =head1 DESCRIPTION @@ -25,46 +27,110 @@ =cut sub default : Private { - my ( $self, $c ) = @_; + my ( $self, $c ) = @_; + + my $webpac = $c->comp('Model::WebPAC'); + my $params = $c->req->params; + my $log = $c->log; - my $webpac = $c->comp('Model::WebPAC'); - my $params = $c->req->params; - my $log = $c->log; + my $template_filename = + $c->req->params->{template_filename} || + $c->config->{webpac}->{default_template} || + $c->log->fatal("need default_template"); - $c->stash->{template} = 'editor.tt'; + $c->stash->{template_filename} = $template_filename; + + $c->stash->{template} = 'editor.tt'; } +=item template + +fetch template using C in request or +C<< webpac->default_template >>. + +=cut + sub template : Local { my ( $self, $c ) = @_; - my $template_file = $c->config->{webpac}->{default_template} || die("need default_template"); + my $template_file = + $c->req->params->{template_filename} || + $c->config->{webpac}->{default_template} || + $c->log->fatal("need default_template"); my $webpac = $c->comp('Model::WebPAC'); my $template_full_path = $webpac->{template_path} . "/$template_file"; + $c->log->debug("loading $template_full_path"); + + if (! -r $template_full_path) { + $c->log->warn("can't find '$template_full_path': $!"); + $c->res->output("can't find template '$template_full_path'"); + return; + } + $c->stash->{'template_content'} = $webpac->load_html( $template_full_path ); $c->stash->{template} = 'editor/template.tt'; } +=item css + +=cut + sub css : Local { my ( $self, $c ) = @_; my $css_file = $c->config->{webpac}->{default_css} || die("need default_css"); my $css_path = $c->config->{webpac}->{css_path} || die("need css_path"); my $webpac = $c->comp('Model::WebPAC'); - $c->stash->{'css_content'} = $webpac->load_html( "$css_path/$css_file" ); + + my $css_full_path = "$css_path/$css_file"; + + $c->log->debug("loading $css_full_path"); + + $c->stash->{'css_content'} = $webpac->load_html( $css_full_path ); + $c->stash->{template} = 'editor/css.tt'; } +=item record + +=cut + +sub record : Local { + my ( $self, $c ) = @_; + + $c->log->debug('record params '.Dumper($c->req->params)); + + my $mfn = $c->req->params->{mfn}; + + if (! $mfn) { + $c->log->warn("no mfn, using 1"); + $mfn = 1; + } + + my $template_filename = $c->req->params->{template_filename}; + if (! $template_filename) { + $template_filename = $c->config->{webpac}->{default_template} || $c->log->fatal("no webpac->default_template in configuration!"); + $c->log->warn("no template_filename using $template_filename"); + } + + my $webpac = $c->comp('Model::WebPAC'); + + $c->res->output( + $webpac->record( mfn => $mfn, template => $template_filename ) + ); +} + =back =head1 AUTHOR -Dobrica Pavlinusic,,, +Dobrica Pavlinusic, C<< >> =head1 LICENSE