Implement fax preference handling.

agranig/1_0_subfix
Andreas Granig 13 years ago
parent 1c4fd57e19
commit 90dedaa1bc

@ -22,6 +22,13 @@ use NGCP::Panel::Form::Voicemail::Delete;
use NGCP::Panel::Form::Reminder;
use NGCP::Panel::Form::Subscriber::TrustedSource;
use NGCP::Panel::Form::Subscriber::Location;
use NGCP::Panel::Form::Faxserver::Name;
use NGCP::Panel::Form::Faxserver::Password;
use NGCP::Panel::Form::Faxserver::Active;
use NGCP::Panel::Form::Faxserver::SendStatus;
use NGCP::Panel::Form::Faxserver::SendCopy;
use NGCP::Panel::Form::Faxserver::Destination;
use NGCP::Panel::Utils::XMLDispatcher;
use UUID;
@ -1666,6 +1673,124 @@ sub edit_voicebox :Chained('base') :PathPart('preferences/voicebox/edit') :Args(
);
}
sub edit_fax :Chained('base') :PathPart('preferences/fax/edit') :Args(1) {
my ($self, $c, $attribute) = @_;
my $form;
my $posted = ($c->request->method eq 'POST');
my $prov_subscriber = $c->stash->{subscriber}->provisioning_voip_subscriber;
my $faxpref = $prov_subscriber->voip_fax_preference;
my $params = {};
my $faxpref_rs = $c->model('DB')->resultset('voip_fax_preferences')->search({
subscriber_id => $prov_subscriber->id
});
if(!$faxpref) {
$faxpref = $faxpref_rs->create({});
}
try {
given($attribute) {
when('name') {
$form = NGCP::Panel::Form::Faxserver::Name->new;
$params = { 'name' => $faxpref->name };
$form->process(params => $posted ? $c->req->params : $params);
if($posted && $form->validated) {
$faxpref->update({ name => $form->field('name')->value });
}
}
when('password') {
$form = NGCP::Panel::Form::Faxserver::Password->new;
$params = { 'password' => $faxpref->password };
$form->process(params => $posted ? $c->req->params : $params);
if($posted && $form->validated) {
$faxpref->update({ password => $form->field('password')->value });
}
}
when('active') {
$form = NGCP::Panel::Form::Faxserver::Active->new;
$params = { 'active' => $faxpref->active };
$form->process(params => $posted ? $c->req->params : $params);
if($posted && $form->validated) {
$faxpref->update({ active => $form->field('active')->value });
}
}
when('send_status') {
$form = NGCP::Panel::Form::Faxserver::SendStatus->new;
$params = { 'send_status' => $faxpref->send_status };
$form->process(params => $posted ? $c->req->params : $params);
if($posted && $form->validated) {
$faxpref->update({ send_status => $form->field('send_status')->value });
}
}
when('send_copy') {
$form = NGCP::Panel::Form::Faxserver::SendCopy->new;
$params = { 'send_copy' => $faxpref->send_copy };
$form->process(params => $posted ? $c->req->params : $params);
if($posted && $form->validated) {
$faxpref->update({ send_copy => $form->field('send_copy')->value });
}
}
when('destinations') {
$form = NGCP::Panel::Form::Faxserver::Destination->new;
unless($posted) {
my @dests = ();
for my $dest($prov_subscriber->voip_fax_destinations->all) {
push @dests, {
destination => $dest->destination,
filetype => $dest->filetype,
cc => $dest->cc,
incoming => $dest->incoming,
outgoing => $dest->outgoing,
status => $dest->status,
}
}
$params->{destination} = \@dests;
}
$form->process(params => $posted ? $c->req->params : $params);
if($posted && $form->validated) {
for my $dest($prov_subscriber->voip_fax_destinations->all) {
$dest->delete;
}
for my $dest($form->field('destination')->fields) {
$prov_subscriber->voip_fax_destinations->create({
destination => $dest->field('destination')->value,
filetype => $dest->field('filetype')->value,
cc => $dest->field('cc')->value,
incoming => $dest->field('incoming')->value,
outgoing => $dest->field('outgoing')->value,
status => $dest->field('status')->value,
});
}
}
}
default {
$c->log->error("trying to set invalid fax param '$attribute' for subscriber uuid ".$c->stash->{subscriber}->uuid);
$c->flash(messages => [{type => 'error', text => 'Invalid fax 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 fax setting'}]);
$c->response->redirect($c->uri_for_action('/subscriber/preferences', [$c->req->captures->[0]]));
return;
}
} catch($e) {
$c->log->error("updating fax setting failed: $e");
$c->flash(messages => [{type => 'error', text => 'Failed to update fax 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 edit_reminder :Chained('base') :PathPart('preferences/reminder/edit') {
my ($self, $c, $attribute) = @_;

@ -0,0 +1,39 @@
package NGCP::Panel::Form::Faxserver::Active;
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 'active' => (
type => 'Boolean',
label => 'Active',
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/active/],
);
has_block 'actions' => (
tag => 'div',
class => [qw/modal-footer/],
render_list => [qw/save/],
);
1;
# vim: set tabstop=4 expandtab:

@ -0,0 +1,113 @@
package NGCP::Panel::Form::Faxserver::Destination;
use HTML::FormHandler::Moose;
extends 'HTML::FormHandler';
use Moose::Util::TypeConstraints;
use HTML::FormHandler::Widget::Block::Bootstrap;
with 'NGCP::Panel::Render::RepeatableJs';
has '+widget_wrapper' => ( default => 'Bootstrap' );
sub build_render_list {[qw/fields actions/]}
sub build_form_element_class { [qw/form-horizontal/] }
has_field 'destination' => (
type => 'Repeatable',
setup_for_js => 1,
do_wrapper => 1,
do_label => 0,
tags => {
controls_div => 1,
},
wrapper_class => [qw/hfh-rep/],
);
has_field 'destination.id' => (
type => 'Hidden',
);
has_field 'destination.destination' => (
type => 'Text',
label => 'Destination',
required => 1,
wrapper_class => [qw/hfh-rep-field/],
);
has_field 'destination.filetype' => (
type => 'Select',
options => [
{ label => 'TIFF', value => 'TIFF' },
{ label => 'PS', value => 'PS' },
{ label => 'PDF', value => 'PDF' },
{ label => 'PDF14', value => 'PDF14' },
],
label => 'File Type',
required => 1,
wrapper_class => [qw/hfh-rep-field/],
);
has_field 'destination.cc' => (
type => 'Boolean',
label => 'Incoming Email as CC',
default => 0,
wrapper_class => [qw/hfh-rep-field/],
);
has_field 'destination.incoming' => (
type => 'Boolean',
label => 'Deliver Incoming Faxes',
default => 1,
wrapper_class => [qw/hfh-rep-field/],
);
has_field 'destination.outgoing' => (
type => 'Boolean',
label => 'Deliver Outgoing Faxes',
default => 1,
wrapper_class => [qw/hfh-rep-field/],
);
has_field 'destination.status' => (
type => 'Boolean',
label => 'Receive Reports',
default => 1,
wrapper_class => [qw/hfh-rep-field/],
);
has_field 'destination.rm' => (
type => 'RmElement',
value => 'Remove',
element_class => [qw/btn btn-primary pull-right/],
);
has_field 'destination_add' => (
type => 'AddElement',
repeatable => 'destination',
value => 'Add another destination',
element_class => [qw/btn btn-primary pull-right/],
);
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/destination destination_add/ ],
);
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::Faxserver::Name;
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 'name' => (
type => 'Text',
label => 'Name in Fax Header',
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/name/],
);
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::Faxserver::Password;
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 'password' => (
type => 'Text',
label => 'Password',
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/password/],
);
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::Faxserver::SendCopy;
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 'send_copy' => (
type => 'Boolean',
label => 'Send Copies',
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/send_copy/],
);
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::Faxserver::SendStatus;
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 'send_status' => (
type => 'Boolean',
label => 'Send Reports',
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/send_status/],
);
has_block 'actions' => (
tag => 'div',
class => [qw/modal-footer/],
render_list => [qw/save/],
);
1;
# vim: set tabstop=4 expandtab:

@ -173,7 +173,7 @@
END;
PROCESS "helpers/modal.tt";
modal_header(m.create_flag=0,
m.name = "Subscriber Master Data");
m.name = description);
form.render;
modal_footer();
modal_script(m.close_target = close_target);

@ -194,6 +194,108 @@
</div>
</div>
<div class="accordion-group">
<div class="accordion-heading">
<a class="accordion-toggle" data-toggle="collapse" data-parent="#preference_groups" href="#collapse_fax">Fax2Mail and Sendfax</a>
</div>
<div class="accordion-body collapse" id="collapse_fax">
<div class="accordion-inner">
<table class="table table-bordered table-striped table-highlight table-hover" id="preferences_table_fax">
<thead>
<tr>
<th>Name</th>
<th>Value</th>
[% # one for actions -%]
<th class="ngcp-actions-column"></th>
</tr>
</thead>
<tbody>
[%
faxpref = subscriber.provisioning_voip_subscriber.voip_fax_preference;
faxdests = subscriber.provisioning_voip_subscriber.voip_fax_destinations.all;
-%]
<tr class="sw_action_row">
<td>Name in Fax Header for Sendfax</td>
<td>
[% faxpref.name %]
</td>
<td class="ngcp-actions-column">
<div class="sw_actions">
<a class="btn btn-primary btn-small" href="[% c.uri_for_action("/subscriber/edit_fax", [c.req.captures.0], 'name') %]"><i class="icon-edit"></i> Edit</a>
</div>
</td>
</tr>
<tr class="sw_action_row">
<td>Password for Sendfax</td>
<td>
[% faxpref.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_fax", [c.req.captures.0], 'password') %]"><i class="icon-edit"></i> Edit</a>
</div>
</td>
</tr>
<tr class="sw_action_row">
<td>Active</td>
<td>
[% faxpref.active ? 'yes' : 'no' %]
</td>
<td class="ngcp-actions-column">
<div class="sw_actions">
<a class="btn btn-primary btn-small" href="[% c.uri_for_action("/subscriber/edit_fax", [c.req.captures.0], 'active') %]"><i class="icon-edit"></i> Edit</a>
</div>
</td>
</tr>
<tr class="sw_action_row">
<td>Send Reports</td>
<td>
[% faxpref.send_status ? 'yes' : 'no' %]
</td>
<td class="ngcp-actions-column">
<div class="sw_actions">
<a class="btn btn-primary btn-small" href="[% c.uri_for_action("/subscriber/edit_fax", [c.req.captures.0], 'send_status') %]"><i class="icon-edit"></i> Edit</a>
</div>
</td>
</tr>
<tr class="sw_action_row">
<td>Send Copies</td>
<td>
[% faxpref.send_copy ? 'yes' : 'no' %]
</td>
<td class="ngcp-actions-column">
<div class="sw_actions">
<a class="btn btn-primary btn-small" href="[% c.uri_for_action("/subscriber/edit_fax", [c.req.captures.0], 'send_copy') %]"><i class="icon-edit"></i> Edit</a>
</div>
</td>
</tr>
<tr class="sw_action_row">
<td>Destinations</td>
<td>
[% FOR faxdest IN faxdests -%]
[% faxdest.destination %] as [% faxdest.filetype %]<br/>
[% END -%]
</td>
<td class="ngcp-actions-column">
<div class="sw_actions">
<a class="btn btn-primary btn-small" href="[% c.uri_for_action("/subscriber/edit_fax", [c.req.captures.0], 'destinations') %]"><i class="icon-edit"></i> Edit</a>
</div>
</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
<div class="accordion-group">
<div class="accordion-heading">
<a class="accordion-toggle" data-toggle="collapse" data-parent="#preference_groups" href="#collapse_rm">Reminder</a>

Loading…
Cancel
Save