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 %]