Add system options to subscriber CF simple view.

agranig/1_0_subfix
Andreas Granig 12 years ago
parent af28876437
commit 579d5cc1e2

@ -399,18 +399,8 @@ sub preferences_callforward :Chained('base') :PathPart('preferences/callforward'
}
my $params = {};
if($destination) {
$params->{destination} = $destination->destination;
if($cf_type eq 'cft') {
my $rt = $ringtimeout_preference->first;
if($rt) {
$params->{ringtimeout} = $rt->value;
} else {
$params->{ringtimeout} = 15;
}
}
}
if($posted) {
# TODO: normalize
$params = $c->request->params;
if(length($params->{destination}) &&
(!$c->request->params->{submitid} ||
@ -423,13 +413,50 @@ sub preferences_callforward :Chained('base') :PathPart('preferences/callforward'
$params->{destination} = 'sip:' . $params->{destination};
}
}
} else {
my $ringtimeout = 15;
if($cf_type eq 'cft') {
my $rt = $ringtimeout_preference->first;
if($rt) {
$ringtimeout = $rt->value;
}
}
my $d = $destination ? $destination->destination : "";
my $duri = undef;
my $t = $destination ? ($destination->timeout || 300) : 300;
if($d =~ /\@voicebox\.local$/) {
$d = 'voicebox';
} elsif($d =~ /\@fax2mail\.local$/) {
$d = 'fax2mail';
} elsif($d =~ /\@conference\.local$/) {
$d = 'conference';
} elsif($d =~ /\@fax2mail\.local$/) {
$d = 'fax2mail';
} elsif($d =~ /^sip:callingcard\@app\.local$/) {
$d = 'callingcard';
} elsif($d =~ /^sip:callthrough\@app\.local$/) {
$d = 'callthrough';
} elsif($d =~ /^sip:localuser\@.+\.local$/) {
$d = 'localuser';
} else {
$duri = $d;
$d = 'uri';
$c->stash->{cf_tmp_params} = {
uri_destination => $duri,
uri_timeout => $t,
id => $destination ? $destination->id : undef,
};
}
$params = $c->stash->{cf_tmp_params};
$params->{destination} = { destination => $d };
$params->{ringtimeout} = $ringtimeout;
}
my $cf_form;
if($cf_type eq "cft") {
$cf_form = NGCP::Panel::Form::SubscriberCFTSimple->new;
$cf_form = NGCP::Panel::Form::SubscriberCFTSimple->new(ctx => $c);
} else {
$cf_form = NGCP::Panel::Form::SubscriberCFSimple->new;
$cf_form = NGCP::Panel::Form::SubscriberCFSimple->new(ctx => $c);
}
$cf_form->process(
@ -465,10 +492,48 @@ sub preferences_callforward :Chained('base') :PathPart('preferences/callforward'
$dest->delete;
}
}
my $dest = $dest_set->voip_cf_destinations->create({
my $numberstr = "";
my $number = $c->stash->{subscriber}->primary_number;
if(defined $number) {
$numberstr .= $number->cc;
$numberstr .= $number->ac if defined($number->ac);
$numberstr .= $number->sn;
} else {
$numberstr = $c->stash->{subscriber}->uuid;
}
my $dest = $cf_form->field('destination');
my $d = $dest->field('destination')->value;
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
}
$dest_set->voip_cf_destinations->create({
destination => $d,
timeout => $t,
priority => 1,
timeout => 300,
destination => $c->request->params->{destination},
});
$cf_mapping = $cf_mapping->first;
@ -844,8 +909,8 @@ sub preferences_callforward_destinationset_edit :Chained('preferences_callforwar
$d = 'fax2mail';
} elsif($d =~ /^sip:callingcard\@app\.local$/) {
$d = 'callingcard';
} elsif($d =~ /^sip:callingthrough\@app\.local$/) {
$d = 'callingcard';
} elsif($d =~ /^sip:callthrough\@app\.local$/) {
$d = 'callthrough';
} elsif($d =~ /^sip:localuser\@.+\.local$/) {
$d = 'localuser';
} else {

@ -16,14 +16,72 @@ has_field 'submitid' => (
);
has_field 'destination' => (
type => 'Text',
required => 1,
element_attr => {
rel => ['tooltip'],
title => ['Either a number (e.g. “431234”), a SIP user (e.g. “peter” or a full SIP URI (e.g. “sip:peter@example.org”)']
type => 'Compound',
);
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 => 'Select',
widget => 'RadioGroup',
label => 'Destination',
do_label => 1,
options_method => \&set_destination_groups,
tags => {
before_element => '<div class="ngcp-destination-row-simple">',
after_element => '</div>',
},
);
sub set_destination_groups {
my($self) = @_;
my @options = ();
my $uri_d = "";
my $uri_t = 300;
if(defined $self->form->ctx &&
defined $self->form->ctx->stash->{cf_tmp_params}) {
print ">>>>>>>>>>>>>>>>>>>>>>> we have cf_tmp_params\n";
use Data::Printer;
p $self->form->ctx->stash->{cf_tmp_params};
my $d = $self->form->ctx->stash->{cf_tmp_params};
p $d;
$uri_d = $d->{uri_destination} if defined($d);
$uri_t = $d->{uri_timeout} if defined($d);
print ">>>>>>>>>>>>>>>>>>>>>>> uri_destination=$uri_d, uri_timeout=$uri_t\n";
}
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.uri_destination" value="'.$uri_d.'"/>'.
'<span> for </span>'.
'<input type="text" class="ngcp-destination-field" name="destination.uri_timeout" value="'.$uri_t.'"/>'.
'<span> seconds</span>',
value => 'uri',
selected => 1,
};
return \@options;
}
has_field 'cf_actions' => (
type => 'Compound',
do_label => 0,
@ -62,15 +120,6 @@ sub build_form_element_class {
return [qw(form-horizontal)];
}
sub validate_destination {
my ($self, $field) = @_;
# TODO: proper SIP URI check!
if($field->value !~ /^sip:.+\@.+$/) {
my $err_msg = 'Destination must be a valid SIP URI in format "sip:user@domain"';
$field->add_error($err_msg);
}
}
1;
# vim: set tabstop=4 expandtab:

@ -113,6 +113,10 @@ div.ngcp-destination-row {
margin-left: 180px !important;
}
div.ngcp-destination-row-simple {
margin-left: 0px !important;
}
input.ngcp-destination-field {
width: 30%;
}

Loading…
Cancel
Save