diff --git a/lib/NGCP/Panel/Controller/Subscriber.pm b/lib/NGCP/Panel/Controller/Subscriber.pm index d644b03cce..abe9130b53 100644 --- a/lib/NGCP/Panel/Controller/Subscriber.pm +++ b/lib/NGCP/Panel/Controller/Subscriber.pm @@ -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) = @_; diff --git a/lib/NGCP/Panel/Form/Faxserver/Active.pm b/lib/NGCP/Panel/Form/Faxserver/Active.pm new file mode 100644 index 0000000000..56a93f066e --- /dev/null +++ b/lib/NGCP/Panel/Form/Faxserver/Active.pm @@ -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: diff --git a/lib/NGCP/Panel/Form/Faxserver/Destination.pm b/lib/NGCP/Panel/Form/Faxserver/Destination.pm new file mode 100644 index 0000000000..70ff22b15f --- /dev/null +++ b/lib/NGCP/Panel/Form/Faxserver/Destination.pm @@ -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: diff --git a/lib/NGCP/Panel/Form/Faxserver/Name.pm b/lib/NGCP/Panel/Form/Faxserver/Name.pm new file mode 100644 index 0000000000..929e2a234b --- /dev/null +++ b/lib/NGCP/Panel/Form/Faxserver/Name.pm @@ -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: diff --git a/lib/NGCP/Panel/Form/Faxserver/Password.pm b/lib/NGCP/Panel/Form/Faxserver/Password.pm new file mode 100644 index 0000000000..7249490031 --- /dev/null +++ b/lib/NGCP/Panel/Form/Faxserver/Password.pm @@ -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: diff --git a/lib/NGCP/Panel/Form/Faxserver/SendCopy.pm b/lib/NGCP/Panel/Form/Faxserver/SendCopy.pm new file mode 100644 index 0000000000..75ada5a4e7 --- /dev/null +++ b/lib/NGCP/Panel/Form/Faxserver/SendCopy.pm @@ -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: diff --git a/lib/NGCP/Panel/Form/Faxserver/SendStatus.pm b/lib/NGCP/Panel/Form/Faxserver/SendStatus.pm new file mode 100644 index 0000000000..5b60e31800 --- /dev/null +++ b/lib/NGCP/Panel/Form/Faxserver/SendStatus.pm @@ -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: diff --git a/share/templates/subscriber/master.tt b/share/templates/subscriber/master.tt index 382646d14c..2cb9615357 100644 --- a/share/templates/subscriber/master.tt +++ b/share/templates/subscriber/master.tt @@ -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); diff --git a/share/templates/subscriber/preferences.tt b/share/templates/subscriber/preferences.tt index 6abca50d86..6d5a2ce9e8 100644 --- a/share/templates/subscriber/preferences.tt +++ b/share/templates/subscriber/preferences.tt @@ -194,6 +194,108 @@ +
+
+ Fax2Mail and Sendfax +
+
+
+ + + + + + + [% # one for actions -%] + + + + + [% + faxpref = subscriber.provisioning_voip_subscriber.voip_fax_preference; + faxdests = subscriber.provisioning_voip_subscriber.voip_fax_destinations.all; + -%] + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameValue
Name in Fax Header for Sendfax + [% faxpref.name %] + +
+ Edit +
+ +
Password for Sendfax + [% faxpref.password %] + +
+ Edit +
+ +
Active + [% faxpref.active ? 'yes' : 'no' %] + +
+ Edit +
+ +
Send Reports + [% faxpref.send_status ? 'yes' : 'no' %] + +
+ Edit +
+ +
Send Copies + [% faxpref.send_copy ? 'yes' : 'no' %] + +
+ Edit +
+ +
Destinations + [% FOR faxdest IN faxdests -%] + [% faxdest.destination %] as [% faxdest.filetype %]
+ [% END -%] +
+
+ Edit +
+ +
+ +
+
+
+
Reminder