MT#3977 Prepare line/key in PBX field dev.

agranig/peering-route
Andreas Granig 12 years ago
parent fba3998657
commit 03e4d574b6

@ -759,6 +759,23 @@ sub devprof_base :Chained('base') :PathPart('profile') :CaptureArgs(1) :Does(ACL
}
}
sub devprof_get_lines :Chained('devprof_base') :PathPart('lines/ajax') :Args(0) :Does(ACL) :ACLDetachTo('/denied_page') :AllowedRole(admin) :AllowedRole(reseller) :AllowedRole(subscriberadmin) {
my ($self, $c) = @_;
# fooooo
my $resultset = $c->stash->{devprof}->config->device->autoprov_device_line_ranges;
my $cols = NGCP::Panel::Utils::Datatables::set_columns($c, [
{ name => 'name', search => 1, title => 'Name' },
{ name => 'num_lines', search => 1, title => 'Number of Lines/Keys' },
{ name => 'can_private', search => 1, title => 'Private Line' },
{ name => 'can_shared', search => 1, title => 'Shared Line' },
{ name => 'can_blf', search => 1, title => 'BLF Key' },
]);
NGCP::Panel::Utils::Datatables::process($c, $resultset, $cols);
$c->detach( $c->view("JSON") );
}
sub devprof_delete :Chained('devprof_base') :PathPart('delete') :Args(0) {
my ($self, $c) = @_;

@ -6,6 +6,8 @@ use Moose::Util::TypeConstraints;
use HTML::FormHandler::Widget::Block::Bootstrap;
with 'NGCP::Panel::Render::RepeatableJs';
has '+widget_wrapper' => ( default => 'Bootstrap' );
has_field 'submitid' => ( type => 'Hidden' );
sub build_render_list {[qw/submitid fields actions/]}
@ -22,6 +24,7 @@ sub build_profiles {
my $c = $self->form->ctx;
my $profile_rs = $c->stash->{autoprov_profile_rs};
my @options = ();
push @options, { label => '', value => undef };
foreach my $p($profile_rs->all) {
push @options, { label => $p->name, value => $p->id };
}
@ -34,12 +37,58 @@ has_field 'identifier' => (
label => 'MAC Address / Identifier',
);
has_field 'subscriber_id' => (
has_field 'line' => (
type => 'Repeatable',
label => 'Lines/Keys',
setup_for_js => 1,
do_wrapper => 1,
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' => (
type => 'Select',
required => 1,
label => 'Subscriber',
options_method => \&build_subscribers,
element_attr => {
rel => ['tooltip'],
title => ['The subscriber to use on this line/key'],
},
);
has_field 'line.line' => (
type => 'Select',
required => 1,
label => 'Line/Key',
options => [],
element_attr => {
rel => ['tooltip'],
title => ['The line/key to use'],
},
);
has_field 'line.type' => (
type => 'Select',
required => 1,
label => 'Line/Key Type',
options => [],
element_attr => {
rel => ['tooltip'],
title => ['The type of feature to use on this line/key'],
},
);
sub build_subscribers {
my ($self) = @_;
my $c = $self->form->ctx;
@ -55,6 +104,21 @@ sub build_subscribers {
return \@options;
}
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' => (
type => 'Submit',
value => 'Save',
@ -65,7 +129,7 @@ has_field 'save' => (
has_block 'fields' => (
tag => 'div',
class => [qw/modal-body/],
render_list => [qw/profile_id identifier subscriber_id/],
render_list => [qw/profile_id identifier line line_add/],
);
has_block 'actions' => (

@ -415,6 +415,9 @@
[% IF create_flag == 1 -%]
[%
IF form.has_for_js;
form.render_repeatable_js;
END;
PROCESS "helpers/modal.tt";
modal_header(m.create_flag = create_flag,
m.name = description.defined ? description : "Subscriber");
@ -424,6 +427,9 @@
-%]
[% ELSIF edit_flag == 1 -%]
[%
IF form.has_for_js;
form.render_repeatable_js;
END;
PROCESS "helpers/modal.tt";
modal_header(m.create_flag=0,
m.name = "Settings");
@ -508,5 +514,61 @@
});
</script>
[% END -%]
[% IF c.config.features.cloudpbx -%]
<script>
var aaData;
$('#line\\.0\\.line option').remove();
$('#line\\.0\\.type option').remove();
$('div.controls #profile_id').change(function() {
$('#line\\.0\\.line option').remove();
$('#line\\.0\\.type option').remove();
console.log("profile_id changed");
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 data", data);
for(var i = 0; i < aaData.length; ++i) {
var range = aaData[i];
// TODO: do it for all line.$id.line/type
$('#line\\.0\\.line').append('<option value=""></option>');
for(var j = 0; j < range.num_lines; ++j) {
$('#line\\.0\\.line').append('<option id="line.' + i + '.line.' + j + '" value="' + i + '.' + j + '">' + range.name + ' - Key/Line ' + j + '</option>');
}
}
// TODO: do this based on line.$id.line being selected!
$('#line\\.0\\.line').change(function() {
var line_id;
$('#line\\.0\\.line option:selected').each(function() {
line_id = $(this).attr('value'); // e.g. "2.1"
});
console.log("selected line_id " + line_id);
var range_id = Math.floor(line_id);
var range = aaData[range_id];
console.log("range for range_id " + range_id + " is ", range);
$('#line\\.0\\.type option').remove();
if(+range.can_private) { // cast to int
$('#line\\.0\\.type').append('<option value="private">Private Line</option>');
}
if(+range.can_shared) {
$('#line\\.0\\.type').append('<option value="shared">Shared Line</option>');
}
if(+range.can_blf) {
$('#line\\.0\\.type').append('<option value="blf">BLF Key</option>');
}
});
});
});
</script>
[% END -%]
[% # vim: set tabstop=4 syntax=html expandtab: -%]

Loading…
Cancel
Save