MT#8299 Successfully create new pbx device.

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

@ -1087,6 +1087,7 @@ sub pbx_device_create :Chained('base') :PathPart('pbx/device/create') :Args(0) {
my @lines = $form->field('line')->fields; my @lines = $form->field('line')->fields;
foreach my $line(@lines) { foreach my $line(@lines) {
next unless($line->field('subscriber_id')->value);
my $prov_subscriber = $schema->resultset('provisioning_voip_subscribers')->find({ my $prov_subscriber = $schema->resultset('provisioning_voip_subscribers')->find({
id => $line->field('subscriber_id')->value, id => $line->field('subscriber_id')->value,
account_id => $c->stash->{contract}->id, account_id => $c->stash->{contract}->id,
@ -1098,10 +1099,9 @@ sub pbx_device_create :Chained('base') :PathPart('pbx/device/create') :Args(0) {
"' for contract id '".$c->stash->{contract}->id."'", "' for contract id '".$c->stash->{contract}->id."'",
desc => $c->loc('Invalid provisioning subscriber id detected.'), desc => $c->loc('Invalid provisioning subscriber id detected.'),
); );
# TODO: throw exception here!
$err = 1; $err = 1;
last; last;
} } else {
my ($range_id, $key_num) = split /\./, $line->field('line')->value; my ($range_id, $key_num) = split /\./, $line->field('line')->value;
my $type = $line->field('type')->value; my $type = $line->field('type')->value;
$fdev->autoprov_field_device_lines->create({ $fdev->autoprov_field_device_lines->create({
@ -1111,9 +1111,12 @@ sub pbx_device_create :Chained('base') :PathPart('pbx/device/create') :Args(0) {
line_type => $type, line_type => $type,
}); });
} }
}
}); });
unless($err) { unless($err) {
$c->flash(messages => [{type => 'success', text => $c->loc('PBX device successfully created') }]); $c->flash(messages => [{type => 'success', text => $c->loc('PBX device successfully created') }]);
} else {
$schema->rollback;
} }
} catch ($e) { } catch ($e) {
NGCP::Panel::Utils::Message->error( NGCP::Panel::Utils::Message->error(
@ -1127,6 +1130,7 @@ sub pbx_device_create :Chained('base') :PathPart('pbx/device/create') :Args(0) {
} }
$c->stash( $c->stash(
device_flag => 1,
create_flag => 1, create_flag => 1,
form => $form, form => $form,
description => $c->loc('PBX Device'), description => $c->loc('PBX Device'),
@ -1250,6 +1254,7 @@ sub pbx_device_edit :Chained('pbx_device_base') :PathPart('edit') :Args(0) {
} }
$c->stash( $c->stash(
device_flag => 1,
edit_flag => 1, edit_flag => 1,
form => $form, form => $form,
description => $c->loc('PBX Device'), description => $c->loc('PBX Device'),

@ -6,8 +6,6 @@ use Moose::Util::TypeConstraints;
use HTML::FormHandler::Widget::Block::Bootstrap; use HTML::FormHandler::Widget::Block::Bootstrap;
with 'NGCP::Panel::Render::RepeatableJs';
has '+widget_wrapper' => ( default => 'Bootstrap' ); has '+widget_wrapper' => ( default => 'Bootstrap' );
has_field 'submitid' => ( type => 'Hidden' ); has_field 'submitid' => ( type => 'Hidden' );
sub build_render_list {[qw/submitid fields actions/]} sub build_render_list {[qw/submitid fields actions/]}
@ -47,58 +45,18 @@ has_field 'station_name' => (
has_field 'line' => ( has_field 'line' => (
type => 'Repeatable', type => 'Repeatable',
label => 'Lines/Keys', label => 'Lines/Keys',
setup_for_js => 1, do_wrapper => 0,
do_wrapper => 1, do_label => 0,
do_label => 1,
required => 1,
tags => {
controls_div => 1,
},
wrapper_class => [qw/hfh-rep-block/],
);
has_field 'line.id' => (
type => 'Hidden',
); );
has_field 'line.subscriber_id' => ( has_field 'line.subscriber_id' => (
type => 'Select', type => 'Hidden',
required => 1, required => 1,
label => 'Subscriber',
options_method => \&build_subscribers,
element_attr => {
rel => ['tooltip'],
title => ['The subscriber to use on this line/key'],
},
); );
sub build_subscribers {
my ($self) = @_;
my $c = $self->form->ctx;
return unless $c;
my $sub_rs = $c->stash->{contract}->voip_subscribers;
my @options = ();
foreach my $s($sub_rs->all) {
next unless($s->status eq 'active');
push @options, {
label => $s->username . '@' . $s->domain->domain,
value => $s->provisioning_voip_subscriber->id
};
}
return \@options;
}
has_field 'line.line' => ( has_field 'line.line' => (
type => 'Select', type => 'Hidden',
required => 1, required => 1,
label => 'Line/Key',
options => [],
no_option_validation => 1,
element_attr => {
rel => ['tooltip'],
title => ['The line/key to use'],
},
element_class => [qw/ngcp-linekey-select/],
); );
sub validate_line_line { sub validate_line_line {
my ($self, $field) = @_; my ($self, $field) = @_;
@ -111,16 +69,8 @@ sub validate_line_line {
} }
has_field 'line.type' => ( has_field 'line.type' => (
type => 'Select', type => 'Hidden',
required => 1, required => 1,
label => 'Line/Key Type',
options => [],
no_option_validation => 1,
element_attr => {
rel => ['tooltip'],
title => ['The type of feature to use on this line/key'],
},
element_class => [qw/ngcp-linetype-select/],
); );
sub validate_line_type { sub validate_line_type {
my ($self, $field) = @_; my ($self, $field) = @_;
@ -134,21 +84,6 @@ sub validate_line_type {
return; return;
} }
has_field 'line.rm' => (
type => 'RmElement',
value => 'Remove',
order => 100,
element_class => [qw/btn btn-primary pull-right/],
);
has_field 'line_add' => (
type => 'AddElement',
repeatable => 'line',
value => 'Add another Line/Key',
element_class => [qw/btn btn-primary pull-right/],
);
has_field 'save' => ( has_field 'save' => (
type => 'Submit', type => 'Submit',
value => 'Save', value => 'Save',
@ -159,7 +94,7 @@ has_field 'save' => (
has_block 'fields' => ( has_block 'fields' => (
tag => 'div', tag => 'div',
class => [qw/modal-body/], class => [qw/modal-body/],
render_list => [qw/profile_id identifier station_name line line_add/], render_list => [qw/profile_id identifier station_name line/],
); );
has_block 'actions' => ( has_block 'actions' => (

@ -584,12 +584,12 @@
}); });
</script> </script>
[% END -%] [% END -%]
[% IF c.config.features.cloudpbx -%] [% IF c.config.features.cloudpbx && device_flag -%]
<style> <style>
.annotated .annotated
{ {
position: relative; position: relative;
left: -150px; left: -50px;
margin: 20px; margin: 20px;
} }
.annotated img .annotated img
@ -607,13 +607,28 @@
{ {
white-space: nowrap; white-space: nowrap;
} }
.annotated select
{
height: 15px;
line-height: 15px;
padding: 0;
margin: 0;
font-size: 11px;
}
.annotated select.subselect
{
width: 180px;
}
.annotated select.modeselect
{
width: 60px;
}
</style> </style>
<link rel="stylesheet" href="/css/ngcp-annotate.css"> <link rel="stylesheet" href="/css/ngcp-annotate.css">
<script src="/js/libs/ngcp-annotate.js"></script> <script src="/js/libs/ngcp-annotate.js"></script>
<link rel="stylesheet" type="text/css" href="/font/font-awesome/css/font-awesome.min.css"/> <link rel="stylesheet" type="text/css" href="/font/font-awesome/css/font-awesome.min.css"/>
<script> <script>
var aaData; var aaData;
alert("TODO: implement sub/mode selection and post result on save");
function annotate_device() { function annotate_device() {
var prof_id = $('div.controls #profile_id option:selected').first().attr('value'); var prof_id = $('div.controls #profile_id option:selected').first().attr('value');
if(!prof_id) return; if(!prof_id) return;
@ -625,13 +640,32 @@
console.log("got data", data); console.log("got data", data);
var markup = '<div class="annotated">' + var markup = '<div class="annotated">' +
'<img src="/device/profile/' + prof_id + '/frontimage" />'; '<img src="/device/profile/' + prof_id + '/frontimage" />';
var formcnt = -1;
for(var i = 0; i < aaData.length; ++i) { for(var i = 0; i < aaData.length; ++i) {
var range = aaData[i]; var range = aaData[i];
for(var j = 0; j < aaData[i].annotations.length; ++j) { for(var j = 0; j < range.annotations.length; ++j) {
var a = aaData[i].annotations[j]; formcnt++;
$('#line\\.' + formcnt).remove();
var a = range.annotations[j];
[% IF create_flag == 1 -%] [% IF create_flag == 1 -%]
var status = "unassigned"; 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> [% 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>' +
[% 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 + '"/>' +
'';
[% ELSIF edit_flag == 1 -%] [% ELSIF edit_flag == 1 -%]
var linekeys = { var linekeys = {
[% FOR line IN pbx_device.autoprov_field_device_lines.all -%] [% FOR line IN pbx_device.autoprov_field_device_lines.all -%]
@ -658,20 +692,23 @@
} }
action = '<i class="fa ' + mode + ' fa-fw"></i> ' + linekeys[idx].sub + ' (' + linekeys[idx].ext + ')'; action = '<i class="fa ' + mode + ' fa-fw"></i> ' + linekeys[idx].sub + ' (' + linekeys[idx].ext + ')';
} else { } else {
status = "unassigned"; // only if really; do check 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> [% 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>';
} }
[% END -%] [% END -%]
markup += '<div class="caption ' + status + '" style="top:' + a.y + 'px; left:' + a.x + 'px;" data-pos="' + a.position + '"><a href="#">' + action + '</a></div>'; markup += '<div class="caption ' + status + '" style="top:' + a.y + 'px; left:' + a.x + 'px;" data-pos="' + a.position + '">' + action + '</div>';
} }
} }
markup += '</div>'; markup += '</div>';
$('#station_name').after(markup); $('div.control-group').last().after(markup);
$("div.annotated").each(function(){ $("div.annotated").each(function(){
$(this).find("div.caption").annotate(this).click(function(event) { $(this).find("div.caption").annotate(this);
event.preventDefault();
//dialog.dialog("open"); TODO: subscriber/type selection here
});
}); });
}); });
} }

Loading…
Cancel
Save