Move naviation to NGCP::Panel::Utils::Navigation

agranig/1_0_subfix
Andreas Granig 13 years ago
parent 1c48ba879d
commit f996d4a15e

@ -3,7 +3,7 @@ use Sipwise::Base;
use namespace::sweep;
BEGIN { extends 'Catalyst::Controller'; }
use NGCP::Panel::Form::Administrator qw();
use NGCP::Panel::Utils qw();
use NGCP::Panel::Utils::Navigation;
sub auto :Does(ACL) :ACLDetachTo('/denied_page') :AllowedRole(admin) {
my ($self, $c) = @_;
@ -52,7 +52,7 @@ sub create :Chained('list_admin') :PathPart('create') :Args(0) {
params => $c->request->params,
action => $c->uri_for('create'),
);
return if NGCP::Panel::Utils::check_form_buttons(
return if NGCP::Panel::Utils::Navigation::check_form_buttons(
c => $c,
form => $form,
fields => [qw(administrator.create)],

@ -12,9 +12,9 @@ use NGCP::Panel::Form::BillingProfile_reseller;
use NGCP::Panel::Form::BillingFee;
use NGCP::Panel::Form::BillingZone;
use NGCP::Panel::Form::BillingPeaktimeWeekdays;
use NGCP::Panel::Utils;
use NGCP::Panel::Form::BillingPeaktimeSpecial;
use NGCP::Panel::Form::BillingFeeUpload;
use NGCP::Panel::Utils::Navigation;
my @WEEKDAYS = map { langinfo($_) } (DAY_2, DAY_3, DAY_4, DAY_5, DAY_6, DAY_7, DAY_1);
#Monday Tuesday Wednesday Thursday Friday Saturday Sunday
@ -28,7 +28,7 @@ sub auto :Does(ACL) :ACLDetachTo('/denied_page') :AllowedRole(admin) :AllowedRol
sub profile_list :Chained('/') :PathPart('billing') :CaptureArgs(0) {
my ( $self, $c ) = @_;
NGCP::Panel::Utils::check_redirect_chain(c => $c);
NGCP::Panel::Utils::Navigation::check_redirect_chain(c => $c);
my $dispatch_to = '_profile_resultset_' . $c->user->auth_realm;
my $profiles_rs = $self->$dispatch_to($c);
@ -193,7 +193,7 @@ sub fees_create :Chained('fees_list') :PathPart('create') :Args(0) {
params => $c->request->params,
action => $c->uri_for($profile_id, 'fees', 'create'),
);
return if NGCP::Panel::Utils::check_form_buttons(
return if NGCP::Panel::Utils::Navigation::check_form_buttons(
c => $c, form => $form,
fields => {'billing_zone.create' => $c->uri_for("$profile_id/zones/create")},
back_uri => $c->req->uri,
@ -278,7 +278,7 @@ sub fees_edit :Chained('fees_base') :PathPart('edit') :Args(0) {
params => $posted ? $c->request->params : $c->stash->{fee},
action => $c->uri_for($profile_id,'fees',$c->stash->{fee}->{id}, 'edit'),
);
return if NGCP::Panel::Utils::check_form_buttons(
return if NGCP::Panel::Utils::Navigation::check_form_buttons(
c => $c, form => $form,
fields => {'billing_zone.create' => $c->uri_for("$profile_id/zones/create")},
back_uri => $c->req->uri,

@ -6,7 +6,7 @@ use NGCP::Panel::Utils::Contract;
use NGCP::Panel::Form::CustomerMonthlyFraud;
use NGCP::Panel::Form::CustomerDailyFraud;
use NGCP::Panel::Form::CustomerBalance;
use NGCP::Panel::Utils;
use NGCP::Panel::Utils::Navigation;
=head1 NAME
@ -32,7 +32,7 @@ sub list_customer :Chained('/') :PathPart('customer') :CaptureArgs(0) {
$c->stash(
template => 'customer/list.tt'
);
NGCP::Panel::Utils::check_redirect_chain(c => $c);
NGCP::Panel::Utils::Navigation::check_redirect_chain(c => $c);
}
sub root :Chained('list_customer') :PathPart('') :Args(0) {

@ -4,7 +4,7 @@ use namespace::autoclean;
BEGIN { extends 'Catalyst::Controller'; }
use NGCP::Panel::Utils;
use NGCP::Panel::Utils::Navigation;
use NGCP::Panel::Form::PeeringGroup;
use NGCP::Panel::Form::PeeringRule;
use NGCP::Panel::Form::PeeringServer;
@ -19,7 +19,7 @@ sub auto :Does(ACL) :ACLDetachTo('/denied_page') :AllowedRole(admin) {
sub group_list :Chained('/') :PathPart('peering') :CaptureArgs(0) {
my ( $self, $c ) = @_;
NGCP::Panel::Utils::check_redirect_chain(c => $c);
NGCP::Panel::Utils::Navigation::check_redirect_chain(c => $c);
$c->stash(template => 'peering/list.tt');
}
@ -72,7 +72,7 @@ sub edit :Chained('base') :PathPart('edit') {
params => $posted ? $c->request->params : $c->stash->{group},
action => $c->uri_for_action('/peering/edit', [$c->req->captures->[0]])
);
if (NGCP::Panel::Utils::check_form_buttons(
if (NGCP::Panel::Utils::Navigation::check_form_buttons(
c => $c, form => $form,
fields => {'contract.create' => $c->uri_for('/contract/peering/create')},
back_uri => $c->req->uri,
@ -119,7 +119,7 @@ sub create :Chained('group_list') :PathPart('create') :Args(0) {
params => $c->request->params,
action => $c->uri_for('create'),
);
if (NGCP::Panel::Utils::check_form_buttons(
if (NGCP::Panel::Utils::Navigation::check_form_buttons(
c => $c, form => $form,
fields => {'contract.create' => $c->uri_for('/contract/peering/create')},
back_uri => $c->req->uri,

@ -5,7 +5,7 @@ BEGIN { extends 'Catalyst::Controller'; }
use DateTime qw();
use HTTP::Status qw(HTTP_SEE_OTHER);
use NGCP::Panel::Form::Reseller;
use NGCP::Panel::Utils;
use NGCP::Panel::Utils::Navigation;
sub auto :Does(ACL) :ACLDetachTo('/denied_page') :AllowedRole(admin) {
my ($self, $c) = @_;
@ -21,7 +21,7 @@ sub list_reseller :Chained('/') :PathPart('reseller') :CaptureArgs(0) {
->resultset('resellers')->search_rs({}),
template => 'reseller/list.tt'
);
NGCP::Panel::Utils::check_redirect_chain(c => $c);
NGCP::Panel::Utils::Navigation::check_redirect_chain(c => $c);
}
sub root :Chained('list_reseller') :PathPart('') :Args(0) {
@ -55,7 +55,7 @@ sub create :Chained('list_reseller') :PathPart('create') :Args(0) {
params => $c->request->params,
action => $c->uri_for('create'),
);
return if NGCP::Panel::Utils::check_form_buttons(
return if NGCP::Panel::Utils::Navigation::check_form_buttons(
c => $c,
form => $form,
fields => [qw/contract.create/],
@ -176,7 +176,7 @@ sub edit :Chained('base') :PathPart('edit') :Args(0) {
params => $posted ? $c->request->params : {$c->stash->{reseller}->get_inflated_columns},
action => $c->uri_for($c->stash->{reseller}->get_column('id'), 'edit'),
);
return if NGCP::Panel::Utils::check_form_buttons(
return if NGCP::Panel::Utils::Navigation::check_form_buttons(
c => $c, form => $form, fields => [qw/contract.create/],
back_uri => $c->uri_for($c->stash->{reseller}->get_column('id'), 'edit')
);

@ -2,6 +2,7 @@ package NGCP::Panel::Controller::Subscriber;
use Sipwise::Base;
use namespace::sweep;
BEGIN { extends 'Catalyst::Controller'; }
use NGCP::Panel::Utils::Navigation;
use NGCP::Panel::Utils::Contract;
use NGCP::Panel::Utils::Subscriber;
use NGCP::Panel::Form::Subscriber;
@ -39,7 +40,7 @@ sub sub_list :Chained('/') :PathPart('subscriber') :CaptureArgs(0) {
$c->stash(
template => 'subscriber/list.tt',
);
#NGCP::Panel::Utils::check_redirect_chain(c => $c);
#NGCP::Panel::Utils::Navigation::check_redirect_chain(c => $c);
}
@ -57,7 +58,7 @@ sub create_list :Chained('sub_list') :PathPart('create') :Args(0) {
params => $c->request->params,
action => $c->uri_for('/subscriber/create'),
);
return if NGCP::Panel::Utils::check_form_buttons(
return if NGCP::Panel::Utils::Navigation::check_form_buttons(
c => $c,
form => $form,
fields => [qw/domain.create/],
@ -397,7 +398,7 @@ sub preferences_callforward :Chained('base') :PathPart('preferences/callforward'
params => $params,
);
return if NGCP::Panel::Utils::check_form_buttons(
return if NGCP::Panel::Utils::Navigation::check_form_buttons(
c => $c, form => $cf_form,
fields => {
'cf_actions.advanced' =>
@ -546,7 +547,7 @@ sub preferences_callforward_advanced :Chained('base') :PathPart('preferences/cal
);
return if NGCP::Panel::Utils::check_form_buttons(
return if NGCP::Panel::Utils::Navigation::check_form_buttons(
c => $c, form => $cf_form,
fields => {
'cf_actions.simple' =>

@ -4,59 +4,6 @@ use warnings;
use NGCP::Panel::Form::Preferences;
sub check_redirect_chain {
my %params = @_;
# TODO: check for missing fields
my $c = $params{c};
if($c->session->{redirect_targets} && @{ $c->session->{redirect_targets} }) {
my $target = ${ $c->session->{redirect_targets} }[0];
if('/'.$c->request->path eq $target->path) {
shift @{$c->session->{redirect_targets}};
$c->stash(close_target => ${ $c->session->{redirect_targets} }[0]);
} else {
$c->stash(close_target => $target);
}
}
}
sub check_form_buttons {
my %params = @_;
# TODO: check for missing fields
my $c = $params{c};
my $fields = $params{fields};
my $form = $params{form};
my $back_uri = $params{back_uri};
$fields = { map {($_, undef)} @$fields }
if (ref($fields) eq "ARRAY");
my $posted = ($c->request->method eq 'POST');
if($posted && $form->field('submitid')) {
my $val = $form->field('submitid')->value;
if(defined $val and exists($fields->{$val}) ) {
my $target;
if (defined $fields->{$val}) {
$target = $fields->{$val};
} else {
$target = '/'.$val;
$target =~ s/\./\//g;
$target = $c->uri_for($target);
}
if($c->session->{redirect_targets}) {
unshift @{ $c->session->{redirect_targets} }, $back_uri;
} else {
$c->session->{redirect_targets} = [ $back_uri ];
}
$c->response->redirect($target);
return 1;
}
}
return;
}
sub load_preference_list {
my %params = @_;
@ -333,23 +280,6 @@ Various utils to outsource common tasks in the controllers.
=head1 METHODS
=head2 check_redirect_chain
Sets close_target to the next uri in our redirect_chain if it exists.
Puts close_target to stash, which will be read by the templates.
=head2 check_form_buttons
Parameters:
c
fields - either an arrayref of fieldnames or a hashref with fieldnames
key and redirect target as value (where it should redirect to)
form
back_uri - the uri we come from
Checks the hidden field "submitid" and redirects to its "value" when it
matches a field.
=head2 load_preference_list
Parameters:

@ -0,0 +1,101 @@
package NGCP::Panel::Utils::Navigation;
use strict;
use warnings;
use Sipwise::Base;
use DBIx::Class::Exception;
sub check_redirect_chain {
my %params = @_;
# TODO: check for missing fields
my $c = $params{c};
if($c->session->{redirect_targets} && @{ $c->session->{redirect_targets} }) {
my $target = ${ $c->session->{redirect_targets} }[0];
if('/'.$c->request->path eq $target->path) {
shift @{$c->session->{redirect_targets}};
$c->stash(close_target => ${ $c->session->{redirect_targets} }[0]);
} else {
$c->stash(close_target => $target);
}
}
}
sub check_form_buttons {
my %params = @_;
# TODO: check for missing fields
my $c = $params{c};
my $fields = $params{fields};
my $form = $params{form};
my $back_uri = $params{back_uri};
$fields = { map {($_, undef)} @$fields }
if (ref($fields) eq "ARRAY");
my $posted = ($c->request->method eq 'POST');
if($posted && $form->field('submitid')) {
my $val = $form->field('submitid')->value;
if(defined $val and exists($fields->{$val}) ) {
my $target;
if (defined $fields->{$val}) {
$target = $fields->{$val};
} else {
$target = '/'.$val;
$target =~ s/\./\//g;
$target = $c->uri_for($target);
}
if($c->session->{redirect_targets}) {
unshift @{ $c->session->{redirect_targets} }, $back_uri;
} else {
$c->session->{redirect_targets} = [ $back_uri ];
}
$c->response->redirect($target);
return 1;
}
}
return;
}
1;
=head1 NAME
NGCP::Panel::Utils::Navigation
=head1 DESCRIPTION
A temporary helper to manipulate subscriber data
=head1 METHODS
=head2 check_redirect_chain
Sets close_target to the next uri in our redirect_chain if it exists.
Puts close_target to stash, which will be read by the templates.
=head2 check_form_buttons
Parameters:
c
fields - either an arrayref of fieldnames or a hashref with fieldnames
key and redirect target as value (where it should redirect to)
form
back_uri - the uri we come from
Checks the hidden field "submitid" and redirects to its "value" when it
matches a field.
=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
# vim: set tabstop=4 expandtab:

@ -24,7 +24,7 @@ sub get_usr_preference_rs {
=head1 NAME
NGCP::Panel::Utils::Contract
NGCP::Panel::Utils::Subscriber
=head1 DESCRIPTION

Loading…
Cancel
Save