new modal to create billing zones

agranig/1_0_subfix
Gerhard Jungwirth 12 years ago
parent 9274a5c93d
commit e953697c8f

@ -6,9 +6,13 @@ BEGIN { extends 'Catalyst::Controller'; }
use NGCP::Panel::Form::BillingProfile;
use NGCP::Panel::Form::BillingFee;
use NGCP::Panel::Form::BillingZone;
use NGCP::Panel::Utils;
sub list :Chained('/') :PathPart('billing') :CaptureArgs(0) :Args(0) {
my ( $self, $c ) = @_;
NGCP::Panel::Utils::check_redirect_chain(c => $c);
$c->stash(has_edit => 1);
$c->stash(has_preferences => 0);
@ -198,6 +202,11 @@ sub fees_edit :Chained('fees_base') :PathPart('edit') :Args(0) {
params => $posted ? $c->request->params : $c->stash->{fee},
action => $c->uri_for($c->stash->{profile}->{id},'fees',$c->stash->{fee}->{id}, 'edit'),
);
return if NGCP::Panel::Utils::check_form_buttons(
c => $c, form => $form, fields => [qw/billing_zone.create/],
back_uri => $c->req->uri,
redir_uri => $c->uri_for($c->stash->{profile}->{id}, 'zones', 'create'),
);
if($posted && $form->validated) {
$c->stash->{'fee_result'}
->update($form->custom_get_values_to_update() );
@ -225,8 +234,11 @@ sub fees_delete :Chained('fees_base') :PathPart('delete') :Args(0) {
}
sub zones_list :Chained('base') :PathPart('zones') :CaptureArgs(0) {
my ($self, $c) = @_;
$c->stash(has_edit => 0);
$c->stash(has_preferences => 0);
$c->stash(template => 'billing/zones.tt');
}
sub zones_ajax :Chained('zones_list') :PathPart('ajax') :Args(0) {
@ -241,6 +253,35 @@ sub zones_ajax :Chained('zones_list') :PathPart('ajax') :Args(0) {
$c->detach( $c->view("JSON") );
}
sub zones_create :Chained('zones_list') :PathPart('create') :Args(0) {
my ($self, $c) = @_;
my $form = NGCP::Panel::Form::BillingZone->new;
$form->process(
posted => ($c->request->method eq 'POST'),
params => $c->request->params,
action => $c->uri_for($c->stash->{profile}->{id}, 'zones', 'create'),
);
if($form->validated) {
$c->stash->{'profile_result'}->billing_zones
->create(
$form->fif,
);
if($c->stash->{close_target}) {
# TODO: set created zone in flash to be selected at target
$c->response->redirect($c->stash->{close_target});
return;
}
$c->flash(messages => [{type => 'success', text => 'Billing Zone successfully created!'}]);
#$c->response->redirect($c->uri_for($c->stash->{profile}->{id}, 'fees'));
return;
}
#$c->stash(close_target => $c->uri_for($c->stash->{profile}->{id}, 'fees'));
$c->stash(form => $form);
$c->stash(create_flag => 1);
}
__PACKAGE__->meta->make_immutable;
1;

@ -15,6 +15,10 @@ has_field 'id' => (
type => 'Hidden'
);
has_field 'submitid' => (
type => 'Hidden'
);
has_field 'source' => (
type => 'Text', #Regexp
maxlength => 255,
@ -89,7 +93,8 @@ has_block 'fields' => (
render_list => [qw/id source destination direction billing_zone
onpeak_init_rate onpeak_init_interval onpeak_follow_rate
onpeak_follow_interval offpeak_init_rate offpeak_init_interval
offpeak_follow_rate offpeak_follow_interval use_free_time/],
offpeak_follow_rate offpeak_follow_interval use_free_time
submitid /],
);
has_block 'actions' => (
@ -104,15 +109,13 @@ sub custom_get_values {
foreach my $val(values %$hashvalues) {
$val = '' unless defined($val);
}
delete $hashvalues->{submitid};
return $hashvalues;
}
sub custom_get_values_to_update {
my ($self) = @_;
my $hashvalues = { %{$self->value} }; #prevents sideeffects
foreach my $val(values %$hashvalues) {
$val = '' unless defined($val);
}
my $hashvalues = $self->custom_get_values;
$hashvalues->{billing_zone_id} = defined $hashvalues->{billing_zone}->{id} ?
$hashvalues->{billing_zone}->{id}+0 :
'';

@ -0,0 +1,48 @@
package NGCP::Panel::Form::BillingZone;
use HTML::FormHandler::Moose;
extends 'HTML::FormHandler';
use Moose::Util::TypeConstraints;
use HTML::FormHandler::Widget::Block::Bootstrap;
has '+widget_wrapper' => ( default => 'Bootstrap' );
sub build_render_list {[qw/fields actions/]}
sub build_form_element_class { [qw/form-horizontal/] }
has_field 'id' => (
type => 'Hidden'
);
has_field 'zone' => (
type => 'Text',
maxlength => 127,
required => 1,
);
has_field 'detail' => (
type => 'Text',
maxlength => 127,
);
has_field 'save' => (
type => 'Submit',
value => 'Save',
element_class => [qw/btn btn-primary/],
label => '',
);
has_block 'fields' => (
tag => 'div',
class => [qw/modal-body/],
render_list => [qw/id zone detail /],
);
has_block 'actions' => (
tag => 'div',
class => [qw/modal-footer/],
render_list => [qw/save/],
);
1;
# vim: set tabstop=4 expandtab:

@ -29,6 +29,7 @@ sub check_form_buttons {
my $fields = $params{fields};
my $form = $params{form};
my $back_uri = $params{back_uri};
my $redir_uri = $params{redir_uri};
my $posted = ($c->request->method eq 'POST');
@ -43,7 +44,11 @@ sub check_form_buttons {
} else {
$c->session->{redirect_targets} = [ $back_uri ];
}
$c->response->redirect($c->uri_for($target));
if (defined $redir_uri) {
$c->response->redirect($redir_uri);
} else {
$c->response->redirect($c->uri_for($target));
}
return 1;
}
}

@ -0,0 +1,19 @@
[% META title = 'Billing Zones' -%]
[%
helper.name = 'Billing Zones';
helper.messages = messages;
helper.column_titles = [ '#', 'Zone', 'Zone Detail' ];
helper.column_fields = [ 'id', 'zone', 'detail' ];
helper.close_target = close_target;
helper.create_flag = create_flag;
helper.edit_flag = edit_fee_flag;
helper.form_object = form;
helper.has_edit = has_edit;
helper.has_preferences = has_preferences;
helper.ajax_uri = c.uri_for( c.action, c.req.captures, 'ajax' );
helper.base_uri = c.uri_for( profile.id, 'zones');
PROCESS 'helpers/datatables.tt';
-%]
[% # vim: set tabstop=4 syntax=html expandtab: -%]
Loading…
Cancel
Save