package LATMOS::Accounts::Web::Controller::NetZones;

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

=head1 NAME

LATMOS::Accounts::Web::Controller::Users - Catalyst Controller

=head1 DESCRIPTION

Catalyst Controller.

=head1 METHODS

=cut


=head2 index 

=cut

sub index : Private {
    my ( $self, $c ) = @_;
    
    $c->stash->{ofilter} = $c->model('AttrFilter', 'netzone');
    $c->stash->{page}{title} = "Liste des zones réseaux";
}

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

    my $base = $c->model('Accounts')->db;
    $c->stash->{netzone} = $base->get_object('netzone', $netzonename) or do {
        $c->forward('/no_object');
        return;
    };
    $c->stash->{page}{title} = "Zone réseau :: $netzonename";
    $c->stash->{netzonename} = $netzonename;
    $c->stash->{form} = $c->model('AttrForms', 'netzone', $c->stash->{netzone});
    $c->stash->{form}->set_attrs;

    if ($c->req->param('make_active')) {
        $c->stash->{netzone}->set_c_fields('exported' => 1);
        $base->commit;
    }
    if ($c->req->param('make_inactive')) {
        $c->stash->{netzone}->set_c_fields('exported' => 0);
        $base->commit;
    }
    if ($c->req->param('delete')) {
        $base->delete_object('netzone', $netzonename);
        $base->commit;
        $c->res->redirect('/netzones');
    }
}

=head1 AUTHOR

Thauvin Olivier

=head1 LICENSE

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

=cut

1;
