Implement proper destination selection for CF.

agranig/1_0_subfix
Andreas Granig 13 years ago
parent 076d7a8963
commit 71f5e663dc

@ -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)

@ -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 => '<div class="ngcp-destination-row">',
after_element => '</div>',
},
);
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 <input type="text" class="ngcp-destination-field" name="destination.'.$self->parent->name.'.uri_destination" value="'.$uri_d.'"/>'.
'<span> for </span>'.
'<input type="text" class="ngcp-destination-field" name="destination.'.$self->parent->name.'.uri_timeout" value="'.$uri_t.'"/>'.
'<span> seconds</span>',
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' => (

@ -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 {

@ -168,7 +168,7 @@
<td>[% set.name %]</td>
<td>
[% FOREACH d IN set.destinations -%]
[% d.destination %] <span class="pull-right">after [% d.timeout %]s</span><br/>
[% d.destination %] <span class="pull-right">for [% d.timeout %]s</span><br/>
[% END -%]
</td>
<td class="ngcp-actions-column">

Loading…
Cancel
Save