diff --git a/lib/NGCP/Panel/Controller/Reseller.pm b/lib/NGCP/Panel/Controller/Reseller.pm index 1ea17651ba..75270d8f6b 100644 --- a/lib/NGCP/Panel/Controller/Reseller.pm +++ b/lib/NGCP/Panel/Controller/Reseller.pm @@ -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) { diff --git a/lib/NGCP/Panel/Form/Reseller.pm b/lib/NGCP/Panel/Form/Reseller.pm index c807700682..bfaf664e4f 100644 --- a/lib/NGCP/Panel/Form/Reseller.pm +++ b/lib/NGCP/Panel/Form/Reseller.pm @@ -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; diff --git a/share/layout/body.tt b/share/layout/body.tt index 242493d942..c6ef93f91c 100644 --- a/share/layout/body.tt +++ b/share/layout/body.tt @@ -151,13 +151,7 @@ - - - - - - + + + + [% content %] diff --git a/share/static/css/application.css b/share/static/css/application.css index f7268386aa..ca8a95fbaf 100644 --- a/share/static/css/application.css +++ b/share/static/css/application.css @@ -2084,6 +2084,10 @@ Layout: Content #content .row:first-child { margin-top: 0; } + +#content form { + margin: 0; +} /*------------------------------------------------------------------ Layout: Footer diff --git a/share/templates/login.tt b/share/templates/login.tt index 00f521618f..88923e8564 100644 --- a/share/templates/login.tt +++ b/share/templates/login.tt @@ -2,6 +2,7 @@

Sign In

+

Sign in using your [% realm %] credentials:

[% form.render %]
diff --git a/share/templates/reseller.tt b/share/templates/reseller.tt index 8dfe823261..e160817991 100644 --- a/share/templates/reseller.tt +++ b/share/templates/reseller.tt @@ -1,44 +1,48 @@ [% META title = 'Resellers' -%]
- [% UNLESS edit.defined -%] Create Reseller Search Reseller - [% ELSE -%] - Cancel Edit - [% END -%]
- + + [% FOREACH r IN resellers -%] - - [% IF r.id == edit.id -%] - [% # form.render %] - [% ELSE -%] + - + - [% END -%] [% END -%]
## Name Contract # Status
[% r.id %] [% r.name %] [% r.contract_id %] - [% r.status %] - [% UNLESS edit.defined -%] -
+
[% r.status %] + - [% END -%]
+ +[% IF edit.defined -%] + + +[% END -%] + [% # vim: set tabstop=4 syntax=html expandtab: -%] diff --git a/share/templates/widgets/reseller_overview.tt b/share/templates/widgets/reseller_overview.tt index 38f549b207..cd0cd9c5b4 100644 --- a/share/templates/widgets/reseller_overview.tt +++ b/share/templates/widgets/reseller_overview.tt @@ -15,7 +15,7 @@
- Configure + Configure