package Agave::C::PostAdmin::Options;

use strict;
use warnings;
use base 'Catalyst::Controller::BindLex';

use Data::Dumper::Simple;
=head1 NAME

Agave::C::PostAdmin::Options - Catalyst Controller

=head1 SYNOPSIS

See L<Agave>

=head1 DESCRIPTION

Catalyst Controller.

=head1 METHODS

=cut

#
# Uncomment and modify this or add new actions to fit your needs
#
#=head2 default
#
#=cut
#
sub default : Private {
    my ( $self, $c ) = @_;

	my $template : Stashed = 'blog/admin/options/index.tt';
	
	my @themes = $c->model('Theme')->all();
	
	my $blog : Stashed;
	
	$c->widget('blogoptions')->method('post')->action($c->uri_for($blog->urlbase . 'postadmin/options'));
	$c->widget('blogoptions')->element('Textfield','name')->label('Name')->value($blog->name);
	$c->widget('blogoptions')->element('Textfield','items_pr_page')->label('Items pr page');
	$c->widget('blogoptions')->element('Select','theme')->label('Theme')
		->options(undef => 'No theme', map { $_->dirpath => $_->name } @themes);
	
	$c->widget('blogoptions')->element('Checkbox','enable_captcha')->label('Enable captcha');
	
	$c->widget('blogoptions')->element('Checkbox','sidebar_description')->label('Sidebar description');
	$c->widget('blogoptions')->element('Textarea','description')
		->label('Description')->cols('35')->rows('8');
	
	$c->widget('blogoptions')->indicator(sub { $c->req->method eq 'POST' } );
	$c->widget('blogoptions')->element('Submit','save')->value('Save');
	
	$blog->fill_widget($c->widget('blogoptions'));
	
	my $result : Stashed = $c->widget_result('blogoptions');

	if ($c->req->method eq 'POST' and !scalar($result->has_errors())) {
		$blog->populate_from_widget($result);
		$c->res->redirect($blog->urlbase . 'postadmin/options');
	}

}


=head1 AUTHOR

Andreas Marienborg

=head1 LICENSE

This library is free software, you can redistribute it and/or modify
it under the same terms as Perl itself.

=cut

1;
