package LATMOS::Accounts::Web::Controller::Templates;
use Moose;
use namespace::autoclean;

BEGIN { extends 'Catalyst::Controller'; }

=head1 NAME

LATMOS::Accounts::Web::Controller::Templates - Catalyst Controller

=head1 DESCRIPTION

Catalyst Controller.

=head1 METHODS

=cut


=head2 index

=cut

sub index :Path :Args(0) {
    my ( $self, $c ) = @_;

    $c->stash->{ofilter} = $c->model('AttrFilter', 'templates');
}

sub default :LocalPath {
    my ( $self, $c, undef, $template) = @_;

    my $db = $c->model('Accounts')->db;

    my $otemplate = $db->get_object('templates', $template);
    $c->stash->{templatesname} = $template;
    $c->stash->{templates} = $otemplate;
    $c->stash->{page}{title} = "Gestion des templates";

    $c->stash->{form} = $c->model('AttrForms', 'templates', $otemplate);

    if ($c->req->param('make_active')) {
        $c->stash->{templates}->set_c_fields('exported' => 1);
        $db->commit;
    }
    elsif ($c->req->param('make_inactive')) {
        $c->stash->{templates}->set_c_fields('exported' => 0);
        $db->commit;
    }
    elsif ($c->req->param('delete')) {
        $db->delete_object('templates', $template);
        $db->commit;
        $c->res->redirect('/templates');
        return;
    }
    else {
        $c->stash->{form}->set_attrs;
    }
}



=encoding utf8

=head1 AUTHOR

Olivier Thauvin,Guyancourt-B1428,+33 1 80285052,

=head1 LICENSE

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

=cut

__PACKAGE__->meta->make_immutable;

1;
