From 51e7c5fb93f1dec94c534e28e9e5cbf5ad5a988f Mon Sep 17 00:00:00 2001 From: Irina Peshinskaya Date: Mon, 22 Sep 2014 08:14:52 +0300 Subject: [PATCH] MT#8627 Add empty destination check into callforward forms --- lib/NGCP/Panel/Form/DestinationSet.pm | 19 ++++++++++++++++++- lib/NGCP/Panel/Form/SubscriberCFAdvanced.pm | 13 ++++++------- lib/NGCP/Panel/Form/SubscriberCFSimple.pm | 12 +++++++++++- 3 files changed, 35 insertions(+), 9 deletions(-) diff --git a/lib/NGCP/Panel/Form/DestinationSet.pm b/lib/NGCP/Panel/Form/DestinationSet.pm index e838875765..a4726c0008 100644 --- a/lib/NGCP/Panel/Form/DestinationSet.pm +++ b/lib/NGCP/Panel/Form/DestinationSet.pm @@ -109,7 +109,6 @@ has_field 'destination.rm' => ( # }, ); - has_field 'destination_add' => ( type => 'AddElement', repeatable => 'destination', @@ -136,6 +135,24 @@ has_block 'actions' => ( render_list => [qw(save)], ); +sub validate_destination{ + my ( $self, $field ) = @_; + my $value = $field->value || []; + my $result = 1; + if( $#$value < 0 ){ + $field->add_error($field->label . " is empty"); + $result = 0; + }else{ + foreach my $destination($field->fields()){ + (my($uri_field)) = grep {'destination' eq $_->name} $destination->field('uri')->fields; + if('uri' eq $destination->field('destination')->value && !$uri_field->value){ + $uri_field->add_error($uri_field->label . " is empty"); + $result = 0; + } + } + } + return $result; +} 1; # vim: set tabstop=4 expandtab: diff --git a/lib/NGCP/Panel/Form/SubscriberCFAdvanced.pm b/lib/NGCP/Panel/Form/SubscriberCFAdvanced.pm index d260b75cde..4f7f42fa73 100644 --- a/lib/NGCP/Panel/Form/SubscriberCFAdvanced.pm +++ b/lib/NGCP/Panel/Form/SubscriberCFAdvanced.pm @@ -105,21 +105,20 @@ has_block 'actions' => ( ); sub validate_active_callforward{ my ( $self, $field ) = @_; - my $value = $field->value || []; my $result = 1; + my $value = $field->value || []; if( $#$value < 0 ){ + $field->add_error($field->label . ' is empty.'); $result = 0; }else{ - foreach my $map (@$value){ - if(! defined $map->{destination_set}){ + foreach my $callforward_spec($field->fields()){ + my $destination_set_field = $callforward_spec->field('destination_set'); + if(!$destination_set_field->value){ + $destination_set_field->add_error($destination_set_field->label . ' is empty.'); $result = 0; - last; } } } - if(!$result){ - $field->add_error($field->label . " is invalid"); - } return $result; } 1; diff --git a/lib/NGCP/Panel/Form/SubscriberCFSimple.pm b/lib/NGCP/Panel/Form/SubscriberCFSimple.pm index 88323c7e68..baa8f3fc29 100644 --- a/lib/NGCP/Panel/Form/SubscriberCFSimple.pm +++ b/lib/NGCP/Panel/Form/SubscriberCFSimple.pm @@ -103,7 +103,17 @@ has_block 'fields' => ( render_list => [qw(destination)], ); has_block 'actions' => (tag => 'div', class => [qw(modal-footer)], render_list => [qw(cf_actions)],); - +sub validate_destination{ + my ( $self, $field ) = @_; + my $result = 0; + (my($uri_field)) = grep {'destination' eq $_->name} ($field->field('uri')->fields); + if( 'uri' eq $field->field('destination')->value + && !$uri_field->value ){ + $uri_field->add_error($uri_field->label . " is empty"); + $result = 0; + } + return $result; +} 1; # vim: set tabstop=4 expandtab: