From 71f5e663dca31cb103e538891bf46b8140bb68dc Mon Sep 17 00:00:00 2001 From: Andreas Granig Date: Wed, 17 Jul 2013 15:05:43 +0200 Subject: [PATCH] Implement proper destination selection for CF. --- lib/NGCP/Panel/Controller/Subscriber.pm | 116 +++++++++++++++++++--- lib/NGCP/Panel/Form/DestinationSet.pm | 64 ++++++++++-- share/static/css/main.css | 12 +++ share/templates/subscriber/preferences.tt | 2 +- 4 files changed, 168 insertions(+), 26 deletions(-) diff --git a/lib/NGCP/Panel/Controller/Subscriber.pm b/lib/NGCP/Panel/Controller/Subscriber.pm index 233b842911..e6f696d2dd 100644 --- a/lib/NGCP/Panel/Controller/Subscriber.pm +++ b/lib/NGCP/Panel/Controller/Subscriber.pm @@ -677,6 +677,11 @@ sub preferences_callforward_destinationset_create :Chained('base') :PathPart('pr my $posted = ($c->request->method eq 'POST'); + if($posted) { + say ">>>>>>>>>>>>>>>>> posted"; + + } + $form->process( posted => $posted, params => $c->req->params, @@ -691,17 +696,46 @@ sub preferences_callforward_destinationset_create :Chained('base') :PathPart('pr my $set = $prov_subscriber->voip_cf_destination_sets->create({ name => $form->field('name')->value, }); + my $number = $c->stash->{subscriber}->primary_number; + my $numberstr = ""; + if(defined $number) { + $numberstr .= $number->cc; + $numberstr .= $number->ac if defined($number->ac); + $numberstr .= $number->sn; + } else { + $numberstr = $c->stash->{subscriber}->uuid; + } foreach my $dest(@fields) { my $d = $dest->field('destination')->value; - if($d !~ /\@/) { - $d .= '@'.$c->stash->{subscriber}->domain->domain; - } - if($d !~ /^sip:/) { - $d = 'sip:' . $d; + my $t = 300; + if($d eq "voicebox") { + $d = "sip:vmu$numberstr\@voicebox.local"; + } elsif($d eq "fax2mail") { + $d = "sip:$numberstr\@fax2mail.local"; + } elsif($d eq "conference") { + $d = "sip:conf=$numberstr\@conference.local"; + } elsif($d eq "callingcard") { + $d = "sip:callingcard\@app.local"; + } elsif($d eq "callthrough") { + $d = "sip:callthrough\@app.local"; + } elsif($d eq "localuser") { + $d = "sip:localuser\@app.local"; + } elsif($d eq "uri") { + $d = $dest->field('uri_destination')->value->[1]; + # TODO: check for valid dest here + if($d !~ /\@/) { + $d .= '@'.$c->stash->{subscriber}->domain->domain; + } + if($d !~ /^sip:/) { + $d = 'sip:' . $d; + } + $t = $dest->field('uri_timeout')->value->[1]; + # TODO: check for valid timeout here } + $set->voip_cf_destinations->create({ destination => $d, - timeout => $dest->field('timeout')->value, + timeout => $t, priority => $dest->field('priority')->value, }); } @@ -749,8 +783,6 @@ sub preferences_callforward_destinationset_base :Chained('base') :PathPart('pref sub preferences_callforward_destinationset_edit :Chained('preferences_callforward_destinationset_base') :PathPart('edit') :Args(1) { my ($self, $c, $cf_type) = @_; - my $form = NGCP::Panel::Form::DestinationSet->new; - my $posted = ($c->request->method eq 'POST'); my $cf_preference = NGCP::Panel::Utils::Subscriber::get_usr_preference_rs( @@ -768,9 +800,27 @@ sub preferences_callforward_destinationset_edit :Chained('preferences_callforwar $params->{name} = $set->name; my @destinations; for my $dest($set->voip_cf_destinations->all) { + my $d = $dest->destination; + my $duri = undef; + my $t = $dest->timeout; + if($d =~ /\@voicebox\.local$/) { + $d = 'voicebox'; + } elsif($d =~ /\@conference\.local$/) { + $d = 'conference'; + } elsif($d =~ /^sip:callingcard\@app\.local$/) { + $d = 'callingcard'; + } elsif($d =~ /^sip:callingthrough\@app\.local$/) { + $d = 'callingcard'; + } elsif($d =~ /^sip:localuser\@.+\.local$/) { + $d = 'localuser'; + } else { + $duri = $d; + $d = 'uri'; + } push @destinations, { - destination => $dest->destination, - timeout => $dest->timeout, + destination => $d, + uri_timeout => $t, + uri_destination => $duri, priority => $dest->priority, id => $dest->id, }; @@ -778,9 +828,12 @@ sub preferences_callforward_destinationset_edit :Chained('preferences_callforwar $params->{destination} = \@destinations; } + $c->stash->{cf_tmp_params} = $params; + my $form = NGCP::Panel::Form::DestinationSet->new(ctx => $c); $form->process( params => $posted ? $c->req->params : $params ); + delete $c->stash->{cf_tmp_params}; if($posted && $form->validated) { try { @@ -810,20 +863,51 @@ sub preferences_callforward_destinationset_edit :Chained('preferences_callforwar foreach my $dest($set->voip_cf_destinations->all) { $dest->delete; } + + my $number = $c->stash->{subscriber}->primary_number; + my $numberstr = ""; + if(defined $number) { + $numberstr .= $number->cc; + $numberstr .= $number->ac if defined($number->ac); + $numberstr .= $number->sn; + } else { + $numberstr = $c->stash->{subscriber}->uuid; + } foreach my $dest($form->field('destination')->fields) { my $d = $dest->field('destination')->value; - if($d !~ /\@/) { - $d .= '@'.$c->stash->{subscriber}->domain->domain; - } - if($d !~ /^sip:/) { - $d = 'sip:' . $d; + my $t = 300; + if($d eq "voicebox") { + $d = "sip:vmu$numberstr\@voicebox.local"; + } elsif($d eq "fax2mail") { + $d = "sip:$numberstr\@fax2mail.local"; + } elsif($d eq "conference") { + $d = "sip:conf=$numberstr\@conference.local"; + } elsif($d eq "callingcard") { + $d = "sip:callingcard\@app.local"; + } elsif($d eq "callthrough") { + $d = "sip:callthrough\@app.local"; + } elsif($d eq "localuser") { + $d = "sip:localuser\@app.local"; + } elsif($d eq "uri") { + $d = $dest->field('uri_destination')->value->[1]; + # TODO: check for valid dest here + if($d !~ /\@/) { + $d .= '@'.$c->stash->{subscriber}->domain->domain; + } + if($d !~ /^sip:/) { + $d = 'sip:' . $d; + } + $t = $dest->field('uri_timeout')->value->[1]; + # TODO: check for valid timeout here } + $set->voip_cf_destinations->create({ destination => $d, - timeout => $dest->field('timeout')->value, + timeout => $t, priority => $dest->field('priority')->value, }); } + $c->response->redirect( $c->uri_for_action('/subscriber/preferences_callforward_destinationset', [$c->req->captures->[0]], $cf_type) diff --git a/lib/NGCP/Panel/Form/DestinationSet.pm b/lib/NGCP/Panel/Form/DestinationSet.pm index cbdcacc853..f7f9870bd5 100644 --- a/lib/NGCP/Panel/Form/DestinationSet.pm +++ b/lib/NGCP/Panel/Form/DestinationSet.pm @@ -33,23 +33,69 @@ has_field 'destination' => ( has_field 'destination.id' => ( type => 'Hidden', ); + +# dummy fields to provide accessors for our manually created ones +# in &set_destination_groups below +has_field 'destination.uri_destination' => ( + type => 'Hidden', + value => undef, +); +has_field 'destination.uri_timeout' => ( + type => 'Hidden', + value => undef, +); + has_field 'destination.destination' => ( - type => 'Text', + type => 'Select', + widget => 'RadioGroup', label => 'Destination', - wrapper_class => [qw/hfh-rep-field/], - required => 1, -); -has_field 'destination.timeout' => ( - type => 'PosInteger', - label => 'Ring for (sec)', - wrapper_class => [qw/hfh-rep-field/], - default => 300, + do_label => 1, + options_method => \&set_destination_groups, + tags => { + before_element => '
', + after_element => '
', + }, ); + +sub set_destination_groups { + my($self) = @_; + my @options = (); + + my $parent_id = $self->parent->name; + my $uri_d = ""; + my $uri_t = 300; + if($parent_id =~ /^\d+$/ && + defined $self->form->ctx && + defined $self->form->ctx->stash->{cf_tmp_params}) { + my $d = $self->form->ctx->stash->{cf_tmp_params}->{destination}->[$parent_id]; + $uri_d = $d->{uri_destination} if defined($d); + $uri_t = $d->{uri_timeout} if defined($d); + } + + push @options, { label => 'Voicemail', value => 'voicebox' }; + push @options, { label => 'Conference', value => 'conference' }; + push @options, { label => 'Fax2Mail', value => 'fax2mail' }; + push @options, { label => 'Calling Card', value => 'callingcard' }; + push @options, { label => 'Call Trough', value => 'callthrough' }; + push @options, { label => 'Local Subscriber', value => 'localuser' }; + push @options, { + label => 'URI/Number '. + ' for '. + ''. + ' seconds', + value => 'uri', + selected => 1, + }; + + return \@options; +} + has_field 'destination.priority' => ( type => 'PosInteger', label => 'Priority', wrapper_class => [qw/hfh-rep-field/], default => 1, + required => 1, ); has_field 'destination.rm' => ( diff --git a/share/static/css/main.css b/share/static/css/main.css index 88491d6ebe..ab80cb8abc 100644 --- a/share/static/css/main.css +++ b/share/static/css/main.css @@ -90,6 +90,18 @@ div.ngcp-timeset-field div.controls { margin: 0 !important; } +/* align cf destination radio group */ + +div.ngcp-destination-row { + margin-left: 180px !important; +} + +input.ngcp-destination-field { + width: 30%; +} + + + /* align buttons in one row in modal-footer */ div.modal-footer div.control-group div.controls { diff --git a/share/templates/subscriber/preferences.tt b/share/templates/subscriber/preferences.tt index 1f487ca2fe..4eb324a642 100644 --- a/share/templates/subscriber/preferences.tt +++ b/share/templates/subscriber/preferences.tt @@ -168,7 +168,7 @@ [% set.name %] [% FOREACH d IN set.destinations -%] - [% d.destination %] after [% d.timeout %]s
+ [% d.destination %] for [% d.timeout %]s
[% END -%]