MT#8299 Also properly edit pbx device.

gjungwirth/email_test
Andreas Granig 11 years ago
parent 7efc1c43d6
commit c44d28ef54

@ -13,7 +13,6 @@ use NGCP::Panel::Form::Customer::PbxExtensionSubscriberSubadmin;
use NGCP::Panel::Form::Customer::PbxGroupEdit;
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;
@ -1173,7 +1172,7 @@ sub pbx_device_edit :Chained('pbx_device_base') :PathPart('edit') :Args(0) {
},{
join => { 'config' => 'device' },
});
my $form = NGCP::Panel::Form::Customer::PbxFieldDeviceEdit->new(ctx => $c);
my $form = NGCP::Panel::Form::Customer::PbxFieldDevice->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) {
@ -1214,6 +1213,7 @@ sub pbx_device_edit :Chained('pbx_device_base') :PathPart('edit') :Args(0) {
$fdev->autoprov_field_device_lines->delete_all;
my @lines = $form->field('line')->fields;
foreach my $line(@lines) {
next unless($line->field('subscriber_id')->value);
my $prov_subscriber = $schema->resultset('provisioning_voip_subscribers')->find({
id => $line->field('subscriber_id')->value,
account_id => $c->stash->{contract}->id,
@ -1228,19 +1228,22 @@ sub pbx_device_edit :Chained('pbx_device_base') :PathPart('edit') :Args(0) {
# TODO: throw exception here!
$err = 1;
last;
} else {
my ($range_id, $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,
key_num => $key_num,
line_type => $type,
});
}
my ($range_id, $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,
key_num => $key_num,
line_type => $type,
});
}
});
unless($err) {
$c->flash(messages => [{type => 'success', text => $c->loc('PBX device successfully updated') }]);
} else {
$schema->rollback;
}
} catch ($e) {
NGCP::Panel::Utils::Message->error(

@ -14,8 +14,12 @@ sub build_form_element_class {[qw(form-horizontal)]}
has_field 'profile_id' => (
type => 'Select',
required => 1,
label => 'Device Profile',
label => 'Device',
options_method => \&build_profiles,
element_attr => {
rel => ['tooltip'],
title => ['The PBX device.']
},
);
sub build_profiles {
my ($self) = @_;
@ -33,13 +37,21 @@ sub build_profiles {
has_field 'identifier' => (
type => 'Text',
required => 1,
label => 'MAC Address / Identifier',
label => 'MAC Address',
element_attr => {
rel => ['tooltip'],
title => ['The MAC address of the device.']
},
);
has_field 'station_name' => (
type => 'Text',
required => 1,
label => 'Station Name',
element_attr => {
rel => ['tooltip'],
title => ['The name to display on the device (usually the name of the person this device belongs to).']
},
);
has_field 'line' => (

@ -1,47 +0,0 @@
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;
return [] unless $c;
my $fdev = $c->stash->{pbx_device};
my @options = ();
foreach my $range($fdev->profile->config->device->autoprov_device_line_ranges->all) {
push @options, { label => '', value => '' };
for(my $i = 0; $i < $range->num_lines; ++$i) {
push @options, {
label => $range->name . ' - Key/Line ' . $i,
value => $range->id . '.' . $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:

@ -590,7 +590,7 @@
{
position: relative;
left: -50px;
margin: 20px;
margin: 20px 20px 0 20px;
}
.annotated img
{
@ -630,6 +630,7 @@
<script>
var aaData;
function annotate_device() {
$('.annotated').remove();
var prof_id = $('div.controls #profile_id option:selected').first().attr('value');
if(!prof_id) return;
@ -650,7 +651,6 @@
var a = range.annotations[j];
[% IF create_flag == 1 -%]
var status = "unassigned";
//var action = '<i class="fa fa-plus-square fa-fw"></i> [% c.loc("Assign Subscriber") %]';
var action = '<i class="fa fa-plus-square fa-fw"></i> ' +
'<select class="subselect" name="line.' + formcnt + '.subscriber_id" id="line.' + formcnt + '.subscriber_id">' +
'<option value="0">[% c.loc("Subscriber") %]</option>' +
@ -672,6 +672,7 @@
'[% line.linerange_id %].[% line.key_num %]': {
'mode': '[% line.line_type %]',
'sub': '[% line.provisioning_voip_subscriber.username %]@[% line.provisioning_voip_subscriber.domain.domain%]',
'subid': [% line.provisioning_voip_subscriber.id %],
'ext': '[% line.provisioning_voip_subscriber.pbx_extension%]'
} [% line == pbx_device.autoprov_field_device_lines.all.last ? '' : ',' %]
[% END -%]
@ -680,26 +681,40 @@
var status, action;
var idx = aaData[i].id + '.' + a.line_index;
if(linekeys[idx]) {
status = "assigned"; // only if really; do check
var mode;
switch(linekeys[idx].mode) {
case "private":
mode = "fa-user"; break;
case "shared":
mode = "fa-users"; break;
case "blf":
mode = "fa-rss"; break;
}
action = '<i class="fa ' + mode + ' fa-fw"></i> ' + linekeys[idx].sub + ' (' + linekeys[idx].ext + ')';
status = "assigned";
//action = '<i class="fa ' + mode + ' fa-fw"></i> ' + linekeys[idx].sub + ' (' + linekeys[idx].ext + ')';
var action = '<i class="fa fa-user fa-fw"></i> ' +
'<select class="subselect" name="line.' + formcnt + '.subscriber_id" id="line.' + formcnt + '.subscriber_id">' +
'<option value="0">[% c.loc("None") %]</option>' +
[% subs = [] -%]
[% FOR sub IN subs.merge(pbx_groups.all, subscribers.all) -%]
'<option value="[% sub.provisioning_voip_subscriber.id %]"' + (linekeys[idx].subid == [% sub.provisioning_voip_subscriber.id %] ? ' selected="selected"' : '') + '>[% sub.username _ "@" _ sub.domain.domain %]</option>' +
[% END -%]
'</select>' +
'<select class="modeselect" name="line.' + formcnt + '.type" id="line.' + formcnt + '.type">' +
[% FOR opt IN ["private", "shared", "blf"] -%]
'<option value="[% opt %]"' + (linekeys[idx].mode == "[% opt %]" ? ' selected="selected"' : '') + '>[% opt %]</option>' +
[% END -%]
'</select>' +
'<input type="hidden" name="line.' + formcnt + '.line" id="line.' + formcnt + '.line" value="' + a.range_id + '.' + a.line_index + '"/>' +
'';
} else {
status = "unassigned";
//action = '<i class="fa fa-plus-square fa-fw"></i> [% c.loc("Assign Subscriber") %]';
action = '<i class="fa fa-plus-square fa-fw"></i> ' +
'<select>' +
'<option>[% c.loc("Assign Subscriber") %]</option>' +
'<option>test1@example.org</option>' +
'<option>test2@example.org</option>' +
'</select>';
var action = '<i class="fa fa-plus-square fa-fw"></i> ' +
'<select class="subselect" name="line.' + formcnt + '.subscriber_id" id="line.' + formcnt + '.subscriber_id">' +
'<option value="0">[% c.loc("Subscriber") %]</option>' +
[% subs = [] -%]
[% FOR sub IN subs.merge(pbx_groups.all, subscribers.all) -%]
'<option value="[% sub.provisioning_voip_subscriber.id %]">[% sub.username _ "@" _ sub.domain.domain %]</option>' +
[% END -%]
'</select>' +
'<select class="modeselect" name="line.' + formcnt + '.type" id="line.' + formcnt + '.type">' +
[% FOR opt IN ["private", "shared", "blf"] -%]
'<option value="[% opt %]">[% opt %]</option>' +
[% END -%]
'</select>' +
'<input type="hidden" name="line.' + formcnt + '.line" id="line.' + formcnt + '.line" value="' + a.range_id + '.' + a.line_index + '"/>' +
'';
}
[% END -%]
markup += '<div class="caption ' + status + '" style="top:' + a.y + 'px; left:' + a.x + 'px;" data-pos="' + a.position + '">' + action + '</div>';

Loading…
Cancel
Save