Further work in reseller forms.

Getting closer to a first concept of handling resellers.
agranig/1_0_subfix
Andreas Granig 12 years ago
parent b87c9ea71c
commit a32be4d6f7

@ -35,8 +35,6 @@ sub reseller : Path Chained('/') CaptureArgs(0) {
{id => 6, contract_id => 6, name => 'reseller 6', status => 'active'},
];
$c->stash(resellers => $resellers);
$c->stash(template => 'reseller.tt');
}
@ -44,21 +42,41 @@ sub reseller : Path Chained('/') CaptureArgs(0) {
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 $reseller;
if($c->flash->{reseller}) {
$reseller = $c->flash->{reseller};
} else {
my @rfilter = grep { $_->{id} == $reseller_id } @{ $c->stash->{resellers} };
$reseller = shift @rfilter;
}
my $form = NGCP::Panel::Form::Reseller->new;
$form->process(
posted => ($c->req->method eq 'POST'),
params => $reseller[0],
action => $c->uri_for('/reseller/save'),
params => $reseller,
action => $c->uri_for('/reseller/save', $reseller_id),
);
$c->stash(form => $form);
$c->stash(edit => $reseller[0]);
$c->stash(edit => $reseller);
}
sub save : Path('/reseller/save') :Args(0) {
my ( $self, $c) = @_;
sub save : Path('/reseller/save') :Args(1) {
my ($self, $c, $reseller_id) = @_;
my $form = NGCP::Panel::Form::Reseller->new;
$form->process(
posted => ($c->req->method eq 'POST'),
params => $c->request->params,
);
if($form->validated) {
$c->log->debug(">>>>>> reseller data validated");
$c->response->redirect($c->uri_for('/reseller/base'));
# TODO: success message
} else {
$c->log->debug(">>>>>> reseller data NOT validated");
$c->flash(reseller => $c->request->params);
$c->response->redirect($c->uri_for('/reseller/edit', $reseller_id));
# TODO: error message
}
}
sub delete : Path('/reseller/delete') :Args(1) {

@ -4,26 +4,77 @@ use HTML::FormHandler::Moose;
extends 'HTML::FormHandler';
use Moose::Util::TypeConstraints;
with 'HTML::FormHandler::Render::Table';
sub build_render_list {[qw/fields actions/]}
has '+widget_form' => (default => 'Table');
sub build_form_tags {
{ error_class => 'label label-secondary', }
}
#sub build_form_tags {{ error_class => 'label label-secondary'}}
sub build_form_element_class {
[qw/form-horizontal/]
}
has_field 'id' => (
type 'NonEditable',
type => 'PosInteger',
wrapper_class => [qw/field control-group/],
label_class => [qw/control-label/],
error_class => [qw/error/],
required => 1,
disabled => 1,
);
has_field 'name' => (
type 'Text',
type => 'Text',
wrapper_class => [qw/field control-group/],
label_class => [qw/control-label/],
error_class => [qw/error/],
required => 1,
);
has_field 'contract_id' => (
type 'Integer',
type => 'Integer',
wrapper_class => [qw/field control-group/],
label_class => [qw/control-label/],
error_class => [qw/error/],
required => 1,
);
has_field 'status' => (
type 'Text',
type => 'Text',
wrapper_class => [qw/field control-group/],
label_class => [qw/control-label/],
error_class => [qw/error/],
required => 1,
);
has_field 'cancel' => (
type => 'Button',
value => 'Cancel',
element_class => [qw/btn/],
element_attr => {
onclick => "javascript:document.location.href='/reseller'",
},
label => '',
tags => { wrapper_tag => 'span' },
);
has_field 'save' => (
type => 'Submit',
value => 'Save',
element_class => [qw/btn btn-primary/],
label => '',
tags => { wrapper_tag => 'span' },
);
has_block 'fields' => (
tag => 'div',
class => [qw/modal-body/],
render_list => [qw/id contract_id name status/],
);
has_block 'actions' => (
tag => 'div',
class => [qw/modal-footer/],
render_list => [qw/cancel save/],
);
1;

@ -151,13 +151,7 @@
</div>
</div>
<script src="/js/libs/jquery-1.7.2.min.js"></script>
<script src="/js/libs/jquery-ui-1.8.21.custom.min.js"></script>
<script src="/js/libs/jquery.ui.touch-punch.min.js"></script>
<script src="/js/libs/bootstrap/bootstrap.min.js"></script>
<script src="/js/Theme.js"></script>
<script src="/js/plugins/validate/jquery.validate.js"></script>
<script src="/js/demos/demo.validation.js"></script>
<script>
$(function () {

@ -25,6 +25,10 @@
<link rel="stylesheet" href="/css/pages/pricing.css">
<script src="/js/libs/modernizr-2.5.3.min.js"></script>
<script src="/js/libs/jquery-1.7.2.min.js"></script>
<script src="/js/libs/jquery-ui-1.8.21.custom.min.js"></script>
<script src="/js/libs/jquery.ui.touch-punch.min.js"></script>
<script src="/js/libs/bootstrap/bootstrap.min.js"></script>
</head>
[% content %]
</html>

@ -2084,6 +2084,10 @@ Layout: Content
#content .row:first-child {
margin-top: 0;
}
#content form {
margin: 0;
}
/*------------------------------------------------------------------
Layout: Footer

@ -2,6 +2,7 @@
<div class="account-container login stacked">
<div class="content clearfix">
<h1>Sign In</h1>
<p>Sign in using your [% realm %] credentials:</p>
[% form.render %]
</div>
</div>

@ -1,44 +1,48 @@
[% 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>#</th>
<th>Name</th>
<th>Contract #</th>
<th>Status</th>
<th></th>
</tr>
</thead>
<tbody>
[% FOREACH r IN resellers -%]
<tr>
[% IF r.id == edit.id -%]
[% # form.render %]
[% ELSE -%]
<tr class="sw_action_row">
<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">
<td>[% r.status %]</td>
<td class="span3">
<div class="sw_actions pull-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>
[% IF edit.defined -%]
<div id="mod_edit" class="modal fade hide" style="display:block">
<div class="modal-header"><h3>Edit Reseller</h3></div>
[% form.render %]
</div>
<script>
$(function () {
$('#mod_edit').modal({keyboard: false, backdrop: 'static'});
});
</script>
[% END -%]
[% # vim: set tabstop=4 syntax=html expandtab: -%]

@ -15,7 +15,7 @@
</ul>
</div>
<div class="plan-actions">
<a href="javascript:;" class="btn">Configure</a>
<a href="/reseller" class="btn">Configure</a>
</div>
</div>
</div>

Loading…
Cancel
Save