Move Field e164 (Compound) and alias_number (Repeatable) to own Files because of multiple occurence.agranig/rest
parent
86600a6a23
commit
7a20e3fc70
@ -0,0 +1,32 @@
|
|||||||
|
package NGCP::Panel::Field::AliasNumber;
|
||||||
|
use HTML::FormHandler::Moose;
|
||||||
|
extends 'HTML::FormHandler::Field::Repeatable';
|
||||||
|
|
||||||
|
|
||||||
|
has 'label' => ( default => 'E164 Number');
|
||||||
|
|
||||||
|
has_field 'id' => (
|
||||||
|
type => 'Hidden',
|
||||||
|
);
|
||||||
|
|
||||||
|
has_field 'e164' => (
|
||||||
|
type => '+NGCP::Panel::Field::E164',
|
||||||
|
order => 99,
|
||||||
|
required => 0,
|
||||||
|
label => 'Alias Number',
|
||||||
|
do_label => 1,
|
||||||
|
do_wrapper => 1,
|
||||||
|
wrapper_class => [qw/hfh-rep-field/],
|
||||||
|
);
|
||||||
|
|
||||||
|
has_field 'rm' => (
|
||||||
|
type => 'RmElement',
|
||||||
|
value => 'Remove',
|
||||||
|
order => 100,
|
||||||
|
element_class => [qw/btn btn-primary pull-right/],
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
1;
|
||||||
|
|
||||||
|
# vim: set tabstop=4 expandtab:
|
@ -0,0 +1,70 @@
|
|||||||
|
package NGCP::Panel::Field::E164;
|
||||||
|
use HTML::FormHandler::Moose;
|
||||||
|
extends 'HTML::FormHandler::Field::Compound';
|
||||||
|
|
||||||
|
|
||||||
|
has 'label' => ( default => 'E164 Number');
|
||||||
|
|
||||||
|
has_field 'cc' => (
|
||||||
|
type => '+NGCP::Panel::Field::PosInteger',
|
||||||
|
element_attr => {
|
||||||
|
class => ['ngcp_e164_cc'],
|
||||||
|
rel => ['tooltip'],
|
||||||
|
title => ['Country Code, e.g. 1 for US or 43 for Austria']
|
||||||
|
},
|
||||||
|
do_label => 0,
|
||||||
|
do_wrapper => 0,
|
||||||
|
);
|
||||||
|
|
||||||
|
has_field 'ac' => (
|
||||||
|
type => '+NGCP::Panel::Field::PosInteger',
|
||||||
|
element_attr => {
|
||||||
|
class => ['ngcp_e164_ac'],
|
||||||
|
rel => ['tooltip'],
|
||||||
|
title => ['Area Code, e.g. 212 for NYC or 1 for Vienna']
|
||||||
|
},
|
||||||
|
do_label => 0,
|
||||||
|
do_wrapper => 0,
|
||||||
|
);
|
||||||
|
|
||||||
|
has_field 'sn' => (
|
||||||
|
type => '+NGCP::Panel::Field::PosInteger',
|
||||||
|
element_attr => {
|
||||||
|
class => ['ngcp_e164_sn'],
|
||||||
|
rel => ['tooltip'],
|
||||||
|
title => ['Subscriber Number, e.g. 12345678']
|
||||||
|
},
|
||||||
|
do_label => 0,
|
||||||
|
do_wrapper => 0,
|
||||||
|
);
|
||||||
|
|
||||||
|
sub validate {
|
||||||
|
my $self = shift;
|
||||||
|
my $cc = $self->field('cc')->value;
|
||||||
|
my $sn = $self->field('sn')->value;
|
||||||
|
|
||||||
|
my %sub_errors = map {$_, 1} (
|
||||||
|
@{ $self->field('cc')->errors },
|
||||||
|
@{ $self->field('ac')->errors },
|
||||||
|
@{ $self->field('sn')->errors } );
|
||||||
|
for my $sub_error( keys %sub_errors ) {
|
||||||
|
$self->add_error($sub_error);
|
||||||
|
}
|
||||||
|
$self->field('cc')->clear_errors;
|
||||||
|
$self->field('ac')->clear_errors;
|
||||||
|
$self->field('sn')->clear_errors;
|
||||||
|
|
||||||
|
if ($self->has_errors) {
|
||||||
|
#dont add more errors
|
||||||
|
} elsif (defined $cc && $cc ne '' && (!defined $sn || $sn eq '')) {
|
||||||
|
my $err_msg = 'Subscriber Number required if Country Code is set';
|
||||||
|
$self->add_error($err_msg);
|
||||||
|
} elsif(defined $sn && $sn ne '' && (!defined $cc || $cc eq '')) {
|
||||||
|
my $err_msg = 'Country Code required if Subscriber Number is set';
|
||||||
|
$self->add_error($err_msg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
1;
|
||||||
|
|
||||||
|
# vim: set tabstop=4 expandtab:
|
Loading…
Reference in new issue