Implement voicemail settings.

agranig/1_0_subfix
Andreas Granig 13 years ago
parent 2b966d8190
commit 4aebd6aa8b

@ -149,9 +149,12 @@ sub subscriber_create :Chained('base') :PathPart('subscriber/create') :Args(0) {
# TODO: check if we find a reseller and contract and domains
my $number;
my $number; my $cli = 0;
if(defined $c->request->params->{'e164.cc'} &&
$c->request->params->{'e164.cc'} ne '') {
$cli = $c->request->params->{'e164.cc'} .
($c->request->params->{'e164.ac'} || '') .
$c->request->params->{'e164.sn'};
$number = $reseller->voip_numbers->create({
cc => $c->request->params->{'e164.cc'},
@ -204,7 +207,7 @@ sub subscriber_create :Chained('base') :PathPart('subscriber/create') :Args(0) {
'subscriber_id' => $prov_subscriber->id,
'value' => $c->request->params->{'e164.cc'},
});
my $cli = $c->request->params->{'e164.cc'} .
$cli = $c->request->params->{'e164.cc'} .
(defined $c->request->params->{'e164.ac'} &&
length($c->request->params->{'e164.ac'}) > 0 ?
$c->request->params->{'e164.ac'} : ''
@ -216,6 +219,14 @@ sub subscriber_create :Chained('base') :PathPart('subscriber/create') :Args(0) {
'value' => $cli,
});
}
$schema->resultset('voicemail_users')->create({
customer_id => $uuid_string,
mailbox => $cli,
password => sprintf("%04d", int(rand 10000)),
email => '',
});
});
$c->flash(messages => [{type => 'success', text => 'Subscriber successfully created!'}]);
$c->response->redirect($c->uri_for_action('/customer/details', [$contract->id]));

@ -15,6 +15,10 @@ use NGCP::Panel::Form::SubscriberCFAdvanced;
use NGCP::Panel::Form::SubscriberCFTAdvanced;
use NGCP::Panel::Form::DestinationSet;
use NGCP::Panel::Form::TimeSet;
use NGCP::Panel::Form::Voicemail::Pin;
use NGCP::Panel::Form::Voicemail::Email;
use NGCP::Panel::Form::Voicemail::Attach;
use NGCP::Panel::Form::Voicemail::Delete;
use UUID;
use Data::Printer;
@ -126,6 +130,7 @@ sub create_list :Chained('sub_list') :PathPart('create') :Args(0) {
domain_id => $prov_domain->id,
});
my $cli = 0;
my $voip_preferences = $schema->resultset('voip_preferences')->search({
'usr_pref' => 1,
});
@ -148,7 +153,7 @@ sub create_list :Chained('sub_list') :PathPart('create') :Args(0) {
'subscriber_id' => $prov_subscriber->id,
'value' => $c->request->params->{'e164.cc'},
});
my $cli = $c->request->params->{'e164.cc'} .
$cli = $c->request->params->{'e164.cc'} .
(defined $c->request->params->{'e164.ac'} &&
length($c->request->params->{'e164.ac'}) > 0 ?
$c->request->params->{'e164.ac'} : ''
@ -160,6 +165,12 @@ sub create_list :Chained('sub_list') :PathPart('create') :Args(0) {
'value' => $cli,
});
}
$schema->resultset('voicemail_users')->create({
customer_id => $uuid_string,
mailbox => $cli,
password => sprintf("%04d", int(rand 10000)),
email => '',
});
});
$c->flash(messages => [{type => 'success', text => 'Subscriber successfully created!'}]);
$c->response->redirect($c->uri_for('/subscriber'));
@ -1310,8 +1321,8 @@ sub details :Chained('master') :PathPart('') :Args(0) {
my ($self, $c) = @_;
}
sub edit_master :Chained('master') :PathPart('edit') {
my ($self, $c, $attribute) = @_;
sub edit_master :Chained('master') :PathPart('edit') :Args(0) {
my ($self, $c) = @_;
my $form = NGCP::Panel::Form::SubscriberEdit->new;
my $posted = ($c->request->method eq 'POST');
@ -1426,6 +1437,88 @@ sub edit_master :Chained('master') :PathPart('edit') {
}
sub edit_voicebox :Chained('base') :PathPart('preferences/voicebox/edit') :Args(1) {
my ($self, $c, $attribute) = @_;
my $form;
my $posted = ($c->request->method eq 'POST');
my $vm_user = $c->stash->{subscriber}->provisioning_voip_subscriber->voicemail_user;
unless($vm_user) {
$c->log->error("no voicemail user found for subscriber uuid ".$c->stash->{subscriber}->uuid);
$c->flash(messages => [{type => 'error', text => 'Failed to find voicemail user'}]);
$c->response->redirect($c->uri_for_action('/subscriber/preferences', [$c->req->captures->[0]]));
return;
# TODO: we could create one instead?
}
my $params;
try {
given($attribute) {
when('pin') {
$form = NGCP::Panel::Form::Voicemail::Pin->new;
$params = { 'pin' => $vm_user->password };
$form->process(params => $posted ? $c->req->params : $params);
if($posted && $form->validated) {
$vm_user->update({ password => $form->field('pin')->value });
}
}
when('email') {
$form = NGCP::Panel::Form::Voicemail::Email->new;
$params = { 'email' => $vm_user->email };
$form->process(params => $posted ? $c->req->params : $params);
if($posted && $form->validated) {
$vm_user->update({ email => $form->field('email')->value });
}
}
when('attach') {
$form = NGCP::Panel::Form::Voicemail::Attach->new;
$params = { 'attach' => $vm_user->attach eq 'yes' ? 1 : 0 };
$form->process(params => $posted ? $c->req->params : $params);
if($posted && $form->validated) {
$vm_user->update({ attach => $form->field('attach')->value ? 'yes' : 'no' });
}
}
when('delete') {
$form = NGCP::Panel::Form::Voicemail::Delete->new;
$params = { 'delete' => $vm_user->get_column('delete') eq 'yes' ? 1 : 0 };
$form->process(params => $posted ? $c->req->params : $params);
if($posted && $form->validated) {
$vm_user->update({
# TODO: which accessor?
column_delete => $form->field('delete')->value ? 'yes' : 'no',
# force attach if delete flag is set, otherwise message will be lost
'attach' => $form->field('delete')->value ? 'yes' : $vm_user->attach,
});
}
}
default {
$c->log->error("trying to set invalid voicemail param '$attribute' for subscriber uuid ".$c->stash->{subscriber}->uuid);
$c->flash(messages => [{type => 'error', text => 'Invalid voicemail setting'}]);
$c->response->redirect($c->uri_for_action('/subscriber/preferences', [$c->req->captures->[0]]));
return;
}
}
if($posted && $form->validated) {
$c->flash(messages => [{type => 'success', text => 'Successfully updated voicemail setting'}]);
$c->response->redirect($c->uri_for_action('/subscriber/preferences', [$c->req->captures->[0]]));
return;
}
} catch($e) {
$c->log->error("updating voicemail setting failed: $e");
$c->flash(messages => [{type => 'error', text => 'Failed to update voicemail setting'}]);
$c->response->redirect($c->uri_for_action('/subscriber/preferences', [$c->req->captures->[0]]));
return;
}
$c->stash(
template => 'subscriber/preferences.tt',
edit_cf_flag => 1,
cf_description => $attribute,
cf_form => $form,
close_target => $c->uri_for_action('/subscriber/preferences', [$c->req->captures->[0]]),
);
}
sub ajax_calls :Chained('master') :PathPart('calls/ajax') :Args(0) {
my ($self, $c) = @_;

@ -0,0 +1,39 @@
package NGCP::Panel::Form::Voicemail::Attach;
use HTML::FormHandler::Moose;
extends 'HTML::FormHandler';
use Moose::Util::TypeConstraints;
use HTML::FormHandler::Widget::Block::Bootstrap;
has '+widget_wrapper' => ( default => 'Bootstrap' );
sub build_render_list {[qw/fields actions/]}
sub build_form_element_class { [qw/form-horizontal/] }
has_field 'attach' => (
type => 'Boolean',
label => 'Attach WAV',
required => 0,
);
has_field 'save' => (
type => 'Submit',
value => 'Save',
element_class => [qw/btn btn-primary/],
label => '',
);
has_block 'fields' => (
tag => 'div',
class => [qw/modal-body/],
render_list => [qw/attach/],
);
has_block 'actions' => (
tag => 'div',
class => [qw/modal-footer/],
render_list => [qw/save/],
);
1;
# vim: set tabstop=4 expandtab:

@ -0,0 +1,39 @@
package NGCP::Panel::Form::Voicemail::Delete;
use HTML::FormHandler::Moose;
extends 'HTML::FormHandler';
use Moose::Util::TypeConstraints;
use HTML::FormHandler::Widget::Block::Bootstrap;
has '+widget_wrapper' => ( default => 'Bootstrap' );
sub build_render_list {[qw/fields actions/]}
sub build_form_element_class { [qw/form-horizontal/] }
has_field 'delete' => (
type => 'Boolean',
label => 'Delete WAV',
required => 0,
);
has_field 'save' => (
type => 'Submit',
value => 'Save',
element_class => [qw/btn btn-primary/],
label => '',
);
has_block 'fields' => (
tag => 'div',
class => [qw/modal-body/],
render_list => [qw/delete/],
);
has_block 'actions' => (
tag => 'div',
class => [qw/modal-footer/],
render_list => [qw/save/],
);
1;
# vim: set tabstop=4 expandtab:

@ -0,0 +1,39 @@
package NGCP::Panel::Form::Voicemail::Email;
use HTML::FormHandler::Moose;
extends 'HTML::FormHandler';
use Moose::Util::TypeConstraints;
use HTML::FormHandler::Widget::Block::Bootstrap;
has '+widget_wrapper' => ( default => 'Bootstrap' );
sub build_render_list {[qw/fields actions/]}
sub build_form_element_class { [qw/form-horizontal/] }
has_field 'email' => (
type => 'Email',
label => 'Email',
required => 0,
);
has_field 'save' => (
type => 'Submit',
value => 'Save',
element_class => [qw/btn btn-primary/],
label => '',
);
has_block 'fields' => (
tag => 'div',
class => [qw/modal-body/],
render_list => [qw/email/],
);
has_block 'actions' => (
tag => 'div',
class => [qw/modal-footer/],
render_list => [qw/save/],
);
1;
# vim: set tabstop=4 expandtab:

@ -0,0 +1,39 @@
package NGCP::Panel::Form::Voicemail::Pin;
use HTML::FormHandler::Moose;
extends 'HTML::FormHandler';
use Moose::Util::TypeConstraints;
use HTML::FormHandler::Widget::Block::Bootstrap;
has '+widget_wrapper' => ( default => 'Bootstrap' );
sub build_render_list {[qw/fields actions/]}
sub build_form_element_class { [qw/form-horizontal/] }
has_field 'pin' => (
type => 'Text',
label => 'PIN',
required => 0,
);
has_field 'save' => (
type => 'Submit',
value => 'Save',
element_class => [qw/btn btn-primary/],
label => '',
);
has_block 'fields' => (
tag => 'div',
class => [qw/modal-body/],
render_list => [qw/pin/],
);
has_block 'actions' => (
tag => 'div',
class => [qw/modal-footer/],
render_list => [qw/save/],
);
1;
# vim: set tabstop=4 expandtab:

@ -108,7 +108,7 @@
<div class="sw_actions">
<a class="btn btn-primary btn-small" href="[% c.uri_for_action("/subscriber/preferences_callforward", [c.req.captures.0], cf.type) %]"><i class="icon-edit"></i> Edit</a>
[% IF cf_mappings.${cf.type}.id -%]
<a class="btn btn-secondary btn-small" data-confirm="Delete" href="[% c.uri_for_action("/subscriber/preferences_callforward_delete", [c.req.captures.0, cf_mappings.${cf.type}.id], cf.type) %]"><i class="icon-edit"></i> Delete</a>
<a class="btn btn-secondary btn-small" data-confirm="Delete" href="[% c.uri_for_action("/subscriber/preferences_callforward_delete", [c.req.captures.0, cf_mappings.${cf.type}.id], cf.type) %]"><i class="icon-delete"></i> Delete</a>
[% END -%]
</div>
@ -122,6 +122,77 @@
</div>
</div>
<div class="accordion-group">
<div class="accordion-heading">
<a class="accordion-toggle" data-toggle="collapse" data-parent="#preference_groups" href="#collapse_vm">Voicemail and Voicebox</a>
</div>
<div class="accordion-body collapse" id="collapse_vm">
<div class="accordion-inner">
<table class="table table-bordered table-striped table-highlight table-hover" id="preferences_table[% group.id %]">
<thead>
<tr>
<th>Name</th>
<th>Value</th>
[% # one for actions -%]
<th class="ngcp-actions-column"></th>
</tr>
</thead>
<tbody>
<tr class="sw_action_row">
<td>PIN</td>
<td>
[% subscriber.provisioning_voip_subscriber.voicemail_user.password %]
</td>
<td class="ngcp-actions-column">
<div class="sw_actions">
<a class="btn btn-primary btn-small" href="[% c.uri_for_action("/subscriber/edit_voicebox", [c.req.captures.0], 'pin') %]"><i class="icon-edit"></i> Edit</a>
</div>
</td>
</tr>
<tr class="sw_action_row">
<td>Email</td>
<td>
[% subscriber.provisioning_voip_subscriber.voicemail_user.email %]
</td>
<td class="ngcp-actions-column">
<div class="sw_actions">
<a class="btn btn-primary btn-small" href="[% c.uri_for_action("/subscriber/edit_voicebox", [c.req.captures.0], 'email') %]"><i class="icon-edit"></i> Edit</a>
</div>
</td>
</tr>
<tr class="sw_action_row">
<td>Delete after sending Email</td>
<td>
[% subscriber.provisioning_voip_subscriber.voicemail_user.get_column('delete') %]
</td>
<td class="ngcp-actions-column">
<div class="sw_actions">
<a class="btn btn-primary btn-small" href="[% c.uri_for_action("/subscriber/edit_voicebox", [c.req.captures.0], 'delete') %]"><i class="icon-edit"></i> Edit</a>
</div>
</td>
</tr>
<tr class="sw_action_row">
<td>Attach WAV in Email</td>
<td>
[% subscriber.provisioning_voip_subscriber.voicemail_user.attach %]
</td>
<td class="ngcp-actions-column">
<div class="sw_actions">
<a class="btn btn-primary btn-small" href="[% c.uri_for_action("/subscriber/edit_voicebox", [c.req.captures.0], 'attach') %]"><i class="icon-edit"></i> Edit</a>
</div>
</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
[%
PROCESS 'helpers/pref_table.tt';

Loading…
Cancel
Save