diff --git a/lib/NGCP/Panel/Controller/Subscriber.pm b/lib/NGCP/Panel/Controller/Subscriber.pm index ba8f1ac217..e6cde7e093 100644 --- a/lib/NGCP/Panel/Controller/Subscriber.pm +++ b/lib/NGCP/Panel/Controller/Subscriber.pm @@ -500,6 +500,27 @@ sub preferences_callforward_advanced :Chained('base') :PathPart('preferences/cal } } + my $billing_subscriber = $c->stash->{subscriber}; + my $prov_subscriber = $billing_subscriber->provisioning_voip_subscriber; + my $cf_mapping = $prov_subscriber->voip_cf_mappings->find({ type => $cf_type }); + if($cf_mapping) { + $c->stash->{cf_active_destination_set} = $cf_mapping->destination_set + if($cf_mapping->destination_set); + $c->stash->{cf_destination_sets} = $prov_subscriber->voip_cf_destination_sets; + $c->stash->{cf_active_time_set} = $cf_mapping->time_set + if($cf_mapping->time_set); + $c->stash->{cf_time_sets} = $prov_subscriber->voip_cf_time_sets; + } + + my $destination; + if($cf_mapping && + $cf_mapping->destination_set && + $cf_mapping->destination_set->voip_cf_destinations->first) { + + $destination = $cf_mapping->destination_set->voip_cf_destinations->first; + } + + my $posted = ($c->request->method eq 'POST'); my $cf_form; @@ -507,7 +528,7 @@ sub preferences_callforward_advanced :Chained('base') :PathPart('preferences/cal # if($cf_type eq "cft") { # $cf_form = NGCP::Panel::Form::SubscriberCFTAdvanced->new; # } else { - $cf_form = NGCP::Panel::Form::SubscriberCFAdvanced->new; + $cf_form = NGCP::Panel::Form::SubscriberCFAdvanced->new(ctx => $c); # } $cf_form->process( params => $posted ? $c->request->params : {} diff --git a/lib/NGCP/Panel/Field/SubscriberDestinationSet.pm b/lib/NGCP/Panel/Field/SubscriberDestinationSet.pm new file mode 100644 index 0000000000..ad4cd1a7f0 --- /dev/null +++ b/lib/NGCP/Panel/Field/SubscriberDestinationSet.pm @@ -0,0 +1,31 @@ +package NGCP::Panel::Field::SubscriberDestinationSet; +use Moose; +use Data::Printer; +extends 'HTML::FormHandler::Field::Select'; + +sub build_options { + my ($self) = @_; + + my $form = $self->form; + + my $active_destination_set = $form->ctx->stash->{cf_active_destination_set}; + my $destination_sets = $form->ctx->stash->{cf_destination_sets}; + + my @all; + foreach my $set($destination_sets->all) { + my $entry = {}; + $entry->{label} = $set->name; + $entry->{value} = $set->id; + if($active_destination_set && + $set->id == $active_destination_set->id) { + $entry->{active} = 1; + } + push @all, $entry; + } + + return \@all; +} + +1; + +# vim: set tabstop=4 expandtab: diff --git a/lib/NGCP/Panel/Field/SubscriberTimeSet.pm b/lib/NGCP/Panel/Field/SubscriberTimeSet.pm new file mode 100644 index 0000000000..db01ecf28a --- /dev/null +++ b/lib/NGCP/Panel/Field/SubscriberTimeSet.pm @@ -0,0 +1,31 @@ +package NGCP::Panel::Field::SubscriberTimeSet; +use Moose; +use Data::Printer; +extends 'HTML::FormHandler::Field::Select'; + +sub build_options { + my ($self) = @_; + + my $form = $self->form; + + my $active_time_set = $form->ctx->stash->{cf_active_time_set}; + my $time_sets = $form->ctx->stash->{cf_time_sets}; + + my @all = ({label => '', value => undef}); + foreach my $set($time_sets->all) { + my $entry = {}; + $entry->{label} = $set->name; + $entry->{value} = $set->id; + if($active_time_set && + $set->id == $active_time_set->id) { + $entry->{active} = 1; + } + push @all, $entry; + } + + return \@all; +} + +1; + +# vim: set tabstop=4 expandtab: diff --git a/lib/NGCP/Panel/Form/SubscriberCFAdvanced.pm b/lib/NGCP/Panel/Form/SubscriberCFAdvanced.pm index ae274350cd..c5482f010a 100644 --- a/lib/NGCP/Panel/Form/SubscriberCFAdvanced.pm +++ b/lib/NGCP/Panel/Form/SubscriberCFAdvanced.pm @@ -16,7 +16,6 @@ has_field 'submitid' => ( has_field 'active_callforward' => ( type => 'Repeatable', setup_for_js => 1, - #do_wrapper => 0, do_wrapper => 1, do_label => 0, tags => { @@ -26,65 +25,36 @@ has_field 'active_callforward' => ( ); has_field 'active_callforward.destination_set' => ( - type => 'Select', + type => '+NGCP::Panel::Field::SubscriberDestinationSet', label => 'Destination Set', wrapper_class => [qw/hfh-rep-field/], ); has_field 'active_callforward.time_set' => ( - type => 'Select', + type => '+NGCP::Panel::Field::SubscriberTimeSet', label => 'during Time Set', wrapper_class => [qw/hfh-rep-field/], ); -has_field 'add_active_callforward' => ( - type => 'AddElement', - repeatable => 'active_callforward', - value => 'Add more', +has_field 'active_callforward.rm' => ( + type => 'RmElement', + value => 'Remove', element_class => [qw/btn btn-primary pull-right/], ); -#has_field 'rm_active_callforward' => ( -# type => 'RmElement', -# repeatable => 'active_callforward', -# value => 'Remove last', -# element_class => [qw/btn btn-primary pull-right/], -#); - -=pod -has_field 'destination_set.foo' => ( - type => 'Select', - label => 'Destination Set', -); - -has_field 'add_element' => ( - type => '+NGCP::Panel::Field::AddElement', - repeatable => 'destination_set.foo', - value => 'Add more', -); -has_field 'destination_set' => ( - type => 'Repeatable', -); - -has_field 'destination_set.foo' => ( - type => 'Select', - label => 'Destination Set', -); - -has_field 'add_element' => ( - type => '+NGCP::Panel::Field::AddElement', - repeatable => 'destination_set.foo', +has_field 'callforward_controls_add' => ( + type => 'AddElement', + repeatable => 'active_callforward', value => 'Add more', + element_class => [qw/btn btn-primary pull-right/], ); -=cut has_block 'fields' => ( tag => 'div', class => [qw(modal-body)], - #render_list => [qw(submitid active_callforward add_active_callforward rm_active_callforward)], - render_list => [qw(submitid active_callforward add_active_callforward )], + render_list => [qw(submitid active_callforward callforward_controls_add)], ); has_field 'simple' => (