Add PBX device skeleton.

agranig/peering-route
Andreas Granig 13 years ago
parent b2f7e00612
commit fef88b9ed3

@ -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,,,

@ -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:

@ -242,6 +242,45 @@
</div>
</div>
</div>
<div class="accordion-group">
<div class="accordion-heading">
<a class="accordion-toggle" data-toggle="collapse" data-parent="#customer_details" href="#collapse_pbxdevs">PBX Devices</a>
</div>
<div class="accordion-body collapse" id="collapse_pbxdevs">
<div class="accordion-inner">
<a class="btn btn-large btn-primary" href="[% c.uri_for_action('/customer/pbx_device_create', [ c.req.captures.0 ]) %]"><i class="icon-star"></i> Create PBX Device</a>
<div class="ngcp-separator"></div>
<table class="table table-bordered table-striped table-highlight table-hover" id="subscribers_table">
<thead>
<tr>
<th>SIP URI</th>
<th>MAC Address / Identifier</th>
<th>Device Profile</th>
<th class="ngcp-actions-column"></th>
</tr>
</thead>
<tbody>
[% FOR dev IN pbx_devices -%]
<tr class="sw_action_row">
<td>[% dev.subscriber.username %]@[% dev.subscriber.domain %]</td>
<td>[% dev.token %]</td>
<td>[% dev.profile.name %]</td>
<td class="ngcp-actions-column">
<div class="sw_actions">
[% UNLESS c.user.readonly -%]
<a class="btn btn-secondary btn-small" href="[% c.uri_for_action("/subscriber/terminate", [subscriber.id]) %]" data-confirm="Terminate"><i class="icon-remove"></i> Terminate</a>
<a class="btn btn-primary btn-small" href="[% c.uri_for_action("/customer/pbx_group_edit", [contract.id, subscriber.voip_pbx_group.id]) %]"><i class="icon-edit"></i> Edit</a>
[% END -%]
</div>
</td>
</tr>
[% END -%]
</tbody>
</table>
</div>
</div>
</div>
[% END -%]
<div class="accordion-group">

Loading…
Cancel
Save