MT#3977 Implement editing of PBX field device.

agranig/peering-route
Andreas Granig 13 years ago
parent ed359aacd5
commit 5730437acf

@ -12,6 +12,7 @@ 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::Form::Customer::PbxFieldDeviceEdit;
use NGCP::Panel::Form::Customer::PbxFieldDeviceSync;
use NGCP::Panel::Utils::Message;
use NGCP::Panel::Utils::Navigation;
@ -690,9 +691,20 @@ sub pbx_device_edit :Chained('pbx_device_base') :PathPart('edit') :Args(0) {
},{
join => { 'config' => 'device' },
});
my $form = NGCP::Panel::Form::Customer::PbxFieldDevice->new(ctx => $c);
say ">>>>>>>>>>>>>>>>>>> ceate NGCP::Panel::Form::Customer::PbxFieldDevice";
my $form = NGCP::Panel::Form::Customer::PbxFieldDeviceEdit->new(ctx => $c);
my $params = { $c->stash->{pbx_device}->get_inflated_columns };
my @lines = ();
foreach my $line($c->stash->{pbx_device}->autoprov_field_device_lines->all) {
push @lines, {
subscriber_id => $line->subscriber_id,
line => $line->linerange_id . '.' . $line->linerange_num . '.' . $line->key_num,
type => $line->line_type,
};
}
$params->{line} = \@lines;
$params = $params->merge($c->session->{created_objects});
say ">>>>>>>>>>>>>>>>>>>>>>> process form";
$form->process(
posted => $posted,
params => $c->request->params,
@ -706,13 +718,52 @@ sub pbx_device_edit :Chained('pbx_device_base') :PathPart('edit') :Args(0) {
);
if($posted && $form->validated) {
try {
my $err = 0;
my $schema = $c->model('DB');
$schema->txn_do( sub {
$form->params->{identifier} = lc $form->params->{identifier};
$c->stash->{pbx_device}->update($form->params);
});
my $fdev = $c->stash->{pbx_device};
my $station_name = $form->params->{station_name};
my $identifier = lc $form->params->{identifier};
my $profile_id = $form->params->{profile_id};
$fdev->update({
profile_id => $profile_id,
identifier => $identifier,
station_name => $station_name,
});
$c->flash(messages => [{type => 'success', text => 'PBX device successfully updated'}]);
$fdev->autoprov_field_device_lines->delete_all;
my @lines = $form->field('line')->fields;
foreach my $line(@lines) {
say ">>>>>>>>>> handle line, subscriber_id=".$line->field('subscriber_id').", account_id=".$c->stash->{contract}->id;
my $prov_subscriber = $schema->resultset('provisioning_voip_subscribers')->find({
id => $line->field('subscriber_id')->value,
account_id => $c->stash->{contract}->id,
});
unless($prov_subscriber) {
NGCP::Panel::Utils::Message->error(
c => $c,
error => "invalid provisioning subscriber_id '".$line->field('subscriber_id')->value.
"' for contract id '".$c->stash->{contract}->id."'",
desc => "Invalid provisioning subscriber id detected.",
);
# TODO: throw exception here!
$err = 1;
last;
}
my ($range_id, $range_num, $key_num) = split /\./, $line->field('line')->value;
my $type = $line->field('type')->value;
$fdev->autoprov_field_device_lines->create({
subscriber_id => $prov_subscriber->id,
linerange_id => $range_id,
linerange_num => $range_num,
key_num => $key_num,
line_type => $type,
});
}
});
unless($err) {
$c->flash(messages => [{type => 'success', text => 'PBX device successfully updated'}]);
}
} catch ($e) {
NGCP::Panel::Utils::Message->error(
c => $c,

@ -21,6 +21,7 @@ has_field 'profile_id' => (
);
sub build_profiles {
my ($self) = @_;
print ">>>>>>>>>>>>>> build_profiles\n";
my $c = $self->form->ctx;
my $profile_rs = $c->stash->{autoprov_profile_rs};
my @options = ();

@ -0,0 +1,48 @@
package NGCP::Panel::Form::Customer::PbxFieldDeviceEdit;
use HTML::FormHandler::Moose;
extends 'NGCP::Panel::Form::Customer::PbxFieldDevice';
use Moose::Util::TypeConstraints;
use HTML::FormHandler::Widget::Block::Bootstrap;
has_field 'line.line' => (
type => 'Select',
required => 1,
label => 'Line/Key',
options_method => \&build_lines,
no_option_validation => 1,
element_attr => {
rel => ['tooltip'],
title => ['The line/key to use'],
},
element_class => [qw/ngcp-linekey-select/],
);
sub build_lines {
my ($self) = @_;
my $c = $self->form->ctx;
my $fdev = $c->stash->{pbx_device};
my @options = ();
my $i = 0;
foreach my $range($fdev->profile->config->device->autoprov_device_line_ranges->all) {
push @options, { label => '', value => '' };
for(my $j = 0; $j < $range->num_lines; ++$j) {
push @options, {
label => $range->name . ' - Key/Line ' . $j,
value => $range->id . '.' . $i . '.' . $j,
};
}
$i++;
}
return \@options;
}
has_block 'fields' => (
tag => 'div',
class => [qw/modal-body/],
render_list => [qw/profile_id identifier station_name line line_add/],
);
1;
# vim: set tabstop=4 expandtab:

@ -538,6 +538,7 @@
function handle_add_line(line_id) {
console.log("add line_id " + line_id);
$('#line\\.' + line_id + '\\.line option').remove();
$('#line\\.' + line_id + '\\.line').append('<option value=""></option>');
for(var i = 0; i < aaData.length; ++i) {
var range = aaData[i];
@ -548,11 +549,11 @@
}
}
$('#line\\.' + line_id + '\\.line').change(function(obj) {
handle_change_line(obj);
handle_change_line(obj, 'invalid');
});
}
function handle_change_line(obj) {
function handle_change_line(obj, active_type) {
var range_id;
var range_num;
var key_num;
@ -571,19 +572,45 @@
$('#line\\.' + line_id + '\\.type option').remove();
if(range && +range.can_private) { // cast to int
$('#line\\.' + line_id + '\\.type').append('<option value="private">Private Line</option>');
$('#line\\.' + line_id + '\\.type').append('<option value="private"' + (active_type == 'private' ? ' selected="selected"' : '') + '>Private Line</option>');
}
if(range && +range.can_shared) {
$('#line\\.' + line_id + '\\.type').append('<option value="shared">Shared Line</option>');
$('#line\\.' + line_id + '\\.type').append('<option value="shared"' + (active_type == 'shared' ? ' selected="selected"' : '') + '>Shared Line</option>');
}
if(range && +range.can_blf) {
$('#line\\.' + line_id + '\\.type').append('<option value="blf">BLF Key</option>');
$('#line\\.' + line_id + '\\.type').append('<option value="blf"' + (active_type == 'blf' ? ' selected="selected"' : '') + '>BLF Key</option>');
}
}
[% IF create_flag == 1 -%]
$('.ngcp-linekey-select option').remove();
$('.ngcp-linetype-select option').remove();
$('.ngcp-linekey-select option').remove();
$('.ngcp-linetype-select option').remove();
[% ELSIF edit_flag == 1 -%]
var linekeys = {
[% FOR line IN pbx_device.autoprov_field_device_lines.all -%]
'[% line.linerange_id %].[% line.linerange_num %].[% line.key_num %]':'[% line.line_type %]'[% line == bx_device.autoprov_field_device_lines.all.last ? '' : ',' %]
[% END -%]
};
var prof_id;
$('div.controls #profile_id option:selected').each(function() {
prof_id = $(this).attr('value');
});
console.log("querying lines for profile id " + prof_id);
$.ajax({
url: "/device/profile/" + prof_id + "/lines/ajax",
}).done(function(data) {
aaData = data.aaData;
console.log("got edit data", data);
$('.ngcp-linekey-select').each(function() {
var key_val;
$(this).find('option:selected').each(function(){
key_val = $(this).attr("value");
});
console.log("key_val=" + key_val + ", type=" + linekeys[key_val]);
var obj = { currentTarget: $(this)};
handle_change_line(obj, linekeys[key_val]);
});
});
[% END -%]
$('div.controls #profile_id').change(function() {

Loading…
Cancel
Save