From fef88b9ed3e66f644457cfe9602df518a33cfbe2 Mon Sep 17 00:00:00 2001 From: Andreas Granig Date: Wed, 11 Sep 2013 18:08:44 +0200 Subject: [PATCH] Add PBX device skeleton. --- lib/NGCP/Panel/Controller/Customer.pm | 55 +++++++++++++ .../Panel/Form/Customer/PbxFieldDevice.pm | 77 +++++++++++++++++++ share/templates/customer/details.tt | 39 ++++++++++ 3 files changed, 171 insertions(+) create mode 100644 lib/NGCP/Panel/Form/Customer/PbxFieldDevice.pm diff --git a/lib/NGCP/Panel/Controller/Customer.pm b/lib/NGCP/Panel/Controller/Customer.pm index a51a17fbe2..6a2ea6a95d 100644 --- a/lib/NGCP/Panel/Controller/Customer.pm +++ b/lib/NGCP/Panel/Controller/Customer.pm @@ -11,6 +11,7 @@ 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::Form::Customer::PbxFieldDevice; use NGCP::Panel::Utils::Message; use NGCP::Panel::Utils::Navigation; use NGCP::Panel::Utils::DateTime; @@ -550,6 +551,60 @@ sub pbx_group_edit :Chained('pbx_group_base') :PathPart('edit') :Args(0) { form => $form ); } + +sub pbx_device_create :Chained('base') :PathPart('pbx/device/create') :Args(0) { + my ($self, $c) = @_; + + my $posted = ($c->request->method eq 'POST'); + unless($posted) { + $c->stash->{autoprov_profile_rs} = $c->model('DB')->resultset('autoprov_profiles') + ->search({ + 'device.reseller_id' => $c->stash->{contract}->contact->reseller_id, + },{ + join => { 'config' => 'device' }, + }); + } + my $form = NGCP::Panel::Form::Customer::PbxFieldDevice->new(ctx => $c); + my $params = {}; + $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->flash(messages => [{type => 'success', text => 'PBX device successfully created'}]); + } catch ($e) { + NGCP::Panel::Utils::Message->error( + c => $c, + error => $e, + desc => "Failed to create PBX device", + ); + } + + NGCP::Panel::Utils::Navigation::back_or($c, $c->uri_for_action('/customer/details', $c->req->captures)); + } + + $c->stash( + create_flag => 1, + form => $form, + description => 'PBX Device', + ); +} + + =head1 AUTHOR Andreas Granig,,, diff --git a/lib/NGCP/Panel/Form/Customer/PbxFieldDevice.pm b/lib/NGCP/Panel/Form/Customer/PbxFieldDevice.pm new file mode 100644 index 0000000000..ccaafd3221 --- /dev/null +++ b/lib/NGCP/Panel/Form/Customer/PbxFieldDevice.pm @@ -0,0 +1,77 @@ +package NGCP::Panel::Form::Customer::PbxFieldDevice; + +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 'profile' => ( + type => 'Select', + required => 1, + label => 'Device Profile', + options_method => \&build_profiles, +); +sub build_profiles { + my ($self) = @_; + my $c = $self->form->ctx; + my $profile_rs = $c->stash->{autoprov_profile_rs}; + my @options = (); + foreach my $p($profile_rs->all) { + push @options, { label => $p->name, value => $p->id }; + } + return \@options; +} + +has_field 'identifier' => ( + type => 'Text', + required => 1, + label => 'MAC Address / Identifier', +); + +has_field 'subscriber' => ( + type => 'Select', + required => 1, + label => 'Subscriber', + options_method => \&build_subscribers, +); +sub build_subscribers { + my ($self) = @_; + my $c = $self->form->ctx; + my $sub_rs = $c->stash->{contract}->voip_subscribers; + my @options = (); + foreach my $s($sub_rs->all) { + push @options, { + label => $s->username . '@' . $s->domain->domain, + value => $s->provisioning_voip_subscriber->id + }; + } + return \@options; +} + +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/profile identifier subscriber/], +); + +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 f2b693742a..79025d7794 100644 --- a/share/templates/customer/details.tt +++ b/share/templates/customer/details.tt @@ -242,6 +242,45 @@ + +
+ +
+
+ Create PBX Device +
+ + + + + + + + + + + [% FOR dev IN pbx_devices -%] + + + + + + + [% END -%] + +
SIP URIMAC Address / IdentifierDevice Profile
[% dev.subscriber.username %]@[% dev.subscriber.domain %][% dev.token %][% dev.profile.name %] +
+ [% UNLESS c.user.readonly -%] + Terminate + Edit + [% END -%] +
+
+
+
+
[% END -%]