Add skeleton for reseller management.

agranig/1_0_subfix
Andreas Granig 13 years ago
parent 51969bc880
commit b87c9ea71c

@ -0,0 +1,83 @@
package NGCP::Panel::Controller::Reseller;
use Moose;
use namespace::autoclean;
BEGIN { extends 'Catalyst::Controller'; }
use NGCP::Panel::Form::Reseller;
=head1 NAME
NGCP::Panel::Controller::Reseller - Catalyst Controller
=head1 DESCRIPTION
Catalyst Controller.
=head1 METHODS
=cut
=head2 index
=cut
sub reseller : Path Chained('/') CaptureArgs(0) {
my ( $self, $c ) = @_;
my $resellers = [
{id => 1, contract_id => 1, name => 'reseller 1', status => 'active'},
{id => 2, contract_id => 2, name => 'reseller 2', status => 'active'},
{id => 3, contract_id => 3, name => 'reseller 3', status => 'active'},
{id => 4, contract_id => 4, name => 'reseller 4', status => 'locked'},
{id => 5, contract_id => 5, name => 'reseller 5', status => 'terminated'},
{id => 6, contract_id => 6, name => 'reseller 6', status => 'active'},
];
$c->stash(resellers => $resellers);
$c->stash(template => 'reseller.tt');
}
sub edit : Chained('reseller') PathPart('edit') :Args(1) {
my ( $self, $c, $reseller_id ) = @_;
my @reseller = grep { $_->{id} == $reseller_id } @{ $c->stash->{resellers} };
use Data::Printer;
p @reseller;
my $form = NGCP::Panel::Form::Reseller->new;
$form->process(
posted => ($c->req->method eq 'POST'),
params => $reseller[0],
action => $c->uri_for('/reseller/save'),
);
$c->stash(form => $form);
$c->stash(edit => $reseller[0]);
}
sub save : Path('/reseller/save') :Args(0) {
my ( $self, $c) = @_;
}
sub delete : Path('/reseller/delete') :Args(1) {
my ( $self, $c, $reseller_id) = @_;
}
=head1 AUTHOR
Andreas Granig,,,
=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;
# vim: set tabstop=4 expandtab:

@ -0,0 +1,30 @@
package NGCP::Panel::Form::Reseller;
use HTML::FormHandler::Moose;
extends 'HTML::FormHandler';
use Moose::Util::TypeConstraints;
with 'HTML::FormHandler::Render::Table';
has '+widget_form' => (default => 'Table');
#sub build_form_tags {{ error_class => 'label label-secondary'}}
has_field 'id' => (
type 'NonEditable',
);
has_field 'name' => (
type 'Text',
);
has_field 'contract_id' => (
type 'Integer',
);
has_field 'status' => (
type 'Text',
);
1;
# vim: set tabstop=4 expandtab:

@ -0,0 +1,44 @@
[% META title = 'Resellers' -%]
<div class="row">
[% UNLESS edit.defined -%]
<a class="btn btn-primary btn-large" data-toggle="modal" href="#mod_create" ><i class="icon-star"></i> Create Reseller</a>
<a href="#" class="btn btn-primary btn-large"><i class="icon-search"></i> Search Reseller</a>
[% ELSE -%]
<a href="[% c.uri_for_action('/reseller/reseller') %]" class="btn btn-primary btn-large"><i class="icon-remove"></i> Cancel Edit</a>
[% END -%]
</div>
<div class="row">
<table class="table table-bordered table-striped table-highlight table-hover">
<thead>
<tr>
<th class="span2">#</th>
<th>Name</th>
<th>Contract #</th>
<th>Status</th>
</tr>
</thead>
<tbody>
[% FOREACH r IN resellers -%]
<tr>
[% IF r.id == edit.id -%]
[% # form.render %]
[% ELSE -%]
<td>[% r.id %]</td>
<td>[% r.name %]</td>
<td>[% r.contract_id %]</td>
<td>
<span>[% r.status %]</span>
[% UNLESS edit.defined -%]
<div style="float:right">
<a class="btn btn-small btn-primary" href="[% c.uri_for_action('/reseller/edit', r.id) %]"><i class="icon-edit" style="line-height:1em;margin-top:2px"></i> Edit</a>
<a class="btn btn-small btn-secondary" href="[% c.uri_for_action('/reseller/delete', r.id) %]" data-confirm="Delete"><i class="icon-trash" style="line-height:1em;margin-top:2px"></i> Delete</a>
</div>
[% END -%]
</td>
[% END -%]
</tr>
[% END -%]
</tbody>
</table>
</div>
[% # vim: set tabstop=4 syntax=html expandtab: -%]

@ -0,0 +1,10 @@
use strict;
use warnings;
use Test::More;
use Catalyst::Test 'NGCP::Panel';
use NGCP::Panel::Controller::Reseller;
ok( request('/reseller')->is_success, 'Request should succeed' );
done_testing();
Loading…
Cancel
Save