diff --git a/lib/NGCP/Panel/Controller/Customer.pm b/lib/NGCP/Panel/Controller/Customer.pm index aee55dcc6d..2fb6e7238b 100644 --- a/lib/NGCP/Panel/Controller/Customer.pm +++ b/lib/NGCP/Panel/Controller/Customer.pm @@ -9,6 +9,7 @@ use NGCP::Panel::Form::CustomerBalance; use NGCP::Panel::Form::Customer::Subscriber; use NGCP::Panel::Form::Customer::PbxAdminSubscriber; use NGCP::Panel::Form::Customer::PbxExtensionSubscriber; +use NGCP::Panel::Form::Customer::PbxGroupBase; use NGCP::Panel::Form::Customer::PbxGroup; use NGCP::Panel::Utils::Message; use NGCP::Panel::Utils::Navigation; @@ -479,12 +480,92 @@ sub pbx_group_create :Chained('base') :PathPart('pbx/group/create') :Args(0) { } $c->stash( - close_target => $c->uri_for, create_flag => 1, form => $form ); } +sub pbx_group_base :Chained('base') :PathPart('pbx/group') :CaptureArgs(1) { + my ($self, $c, $group_id) = @_; + + my $group = $c->model('DB')->resultset('voip_pbx_groups')->find($group_id); + unless($group) { + NGCP::Panel::Utils::Message->error( + c => $c, + error => "invalid voip pbx group id $group_id", + desc => "PBX group with id $group_id does not exist.", + ); + NGCP::Panel::Utils::Navigation::back_or($c, $c->uri_for_action('/customer/details', [$c->req->captures->[0]])); + } + + $c->stash( + pbx_group => $group, + ); +} + +sub pbx_group_edit :Chained('pbx_group_base') :PathPart('edit') :Args(0) { + my ($self, $c) = @_; + + my $posted = ($c->request->method eq 'POST'); + my $form; + $form = NGCP::Panel::Form::Customer::PbxGroupBase->new; + my $params = { $c->stash->{pbx_group}->get_inflated_columns }; + $params = $params->merge($c->session->{created_objects}); + $form->process( + posted => $posted, + params => $c->request->params, + item => $params, + ); + NGCP::Panel::Utils::Navigation::check_form_buttons( + c => $c, + form => $form, + fields => {}, + back_uri => $c->req->uri, + ); + if($posted && $form->validated) { + try { + my $schema = $c->model('DB'); + $schema->txn_do(sub { + $c->stash->{pbx_group}->update($form->params); + my $hunt_policy = NGCP::Panel::Utils::Subscriber::get_usr_preference_rs( + c => $c, + prov_subscriber => $c->stash->{pbx_group}->provisioning_voip_subscriber, + attribute => 'cloud_pbx_hunt_policy' + ); + if($hunt_policy->first) { + $hunt_policy->first->update({ value => $form->params->{hunt_policy} }); + } else { + $hunt_policy->create({ value => $form->params->{hunt_policy} }); + } + my $hunt_timeout = NGCP::Panel::Utils::Subscriber::get_usr_preference_rs( + c => $c, + prov_subscriber => $c->stash->{pbx_group}->provisioning_voip_subscriber, + attribute => 'cloud_pbx_hunt_timeout' + ); + if($hunt_timeout->first) { + $hunt_timeout->first->update({ value => $form->params->{hunt_policy_timeout} }); + } else { + $hunt_timeout->create({ value => $form->params->{hunt_policy_timeout} }); + } + }); + + $c->flash(messages => [{type => 'success', text => 'PBX group successfully updated.'}]); + } catch ($e) { + NGCP::Panel::Utils::Message->error( + c => $c, + error => $e, + desc => "Failed to update PBX group.", + ); + } + + NGCP::Panel::Utils::Navigation::back_or($c, $c->uri_for_action('/customer/details', [$c->req->captures->[0]])); + } + + $c->stash( + edit_flag => 1, + form => $form + ); +} =head1 AUTHOR Andreas Granig,,, diff --git a/lib/NGCP/Panel/Form/Customer/PbxGroup.pm b/lib/NGCP/Panel/Form/Customer/PbxGroup.pm index 093a072a61..e899c19ec7 100644 --- a/lib/NGCP/Panel/Form/Customer/PbxGroup.pm +++ b/lib/NGCP/Panel/Form/Customer/PbxGroup.pm @@ -1,15 +1,7 @@ package NGCP::Panel::Form::Customer::PbxGroup; use HTML::FormHandler::Moose; -extends 'HTML::FormHandler'; -use Moose::Util::TypeConstraints; - -use HTML::FormHandler::Widget::Block::Bootstrap; - -has '+widget_wrapper' => ( default => 'Bootstrap' ); -has_field 'submitid' => ( type => 'Hidden' ); -sub build_render_list {[qw/submitid fields actions/]} -sub build_form_element_class {[qw(form-horizontal)]} +extends 'NGCP::Panel::Form::Customer::PbxGroupBase'; has_field 'name' => ( type => 'Text', @@ -23,43 +15,12 @@ has_field 'extension' => ( label => 'Extension', ); -has_field 'hunt_policy' => ( - type => 'Select', - required => 1, - label => 'Hunting Policy', - options => [ - { label => 'Serial Ringing', value => 'serial' }, - { label => 'Parallel Ringing', value => 'parallel' }, - ], - default => 'serial', -); - -has_field 'hunt_policy_timeout' => ( - type => 'PosInteger', - required => 1, - label => 'Serial Ringing Timeout', - default => 10, -); - -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 extension hunt_policy hunt_policy_timeout/], ); -has_block 'actions' => ( - tag => 'div', - class => [qw/modal-footer/], - render_list => [qw/save/], -); - sub validate_name { my ($self, $field) = @_; diff --git a/lib/NGCP/Panel/Form/Customer/PbxGroupBase.pm b/lib/NGCP/Panel/Form/Customer/PbxGroupBase.pm new file mode 100644 index 0000000000..59438ffe17 --- /dev/null +++ b/lib/NGCP/Panel/Form/Customer/PbxGroupBase.pm @@ -0,0 +1,52 @@ +package NGCP::Panel::Form::Customer::PbxGroupBase; + +use HTML::FormHandler::Moose; +extends 'HTML::FormHandler'; +use Moose::Util::TypeConstraints; + +use HTML::FormHandler::Widget::Block::Bootstrap; + +has '+widget_wrapper' => ( default => 'Bootstrap' ); +has_field 'submitid' => ( type => 'Hidden' ); +sub build_render_list {[qw/submitid fields actions/]} +sub build_form_element_class {[qw(form-horizontal)]} + +has_field 'hunt_policy' => ( + type => 'Select', + required => 1, + label => 'Hunting Policy', + options => [ + { label => 'Serial Ringing', value => 'serial' }, + { label => 'Parallel Ringing', value => 'parallel' }, + ], + default => 'serial', +); + +has_field 'hunt_policy_timeout' => ( + type => 'PosInteger', + required => 1, + label => 'Serial Ringing Timeout', + default => 10, +); + +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/hunt_policy hunt_policy_timeout/], +); + +has_block 'actions' => ( + tag => 'div', + class => [qw/modal-footer/], + render_list => [qw/save/], +); + +1; +# vim: set tabstop=4 expandtab: diff --git a/share/templates/customer/details.tt b/share/templates/customer/details.tt index cf0b675f57..554b1fb02b 100644 --- a/share/templates/customer/details.tt +++ b/share/templates/customer/details.tt @@ -227,6 +227,7 @@