diff --git a/lib/NGCP/Panel/Controller/Customer.pm b/lib/NGCP/Panel/Controller/Customer.pm
index 320c53ad09..3fcc6fc440 100644
--- a/lib/NGCP/Panel/Controller/Customer.pm
+++ b/lib/NGCP/Panel/Controller/Customer.pm
@@ -891,11 +891,27 @@ sub subscriber_ajax :Chained('base') :PathPart('subscriber/ajax') :Args(0) {
sub pbx_group_ajax :Chained('base') :PathPart('pbx/group/ajax') :Args(0) {
my ($self, $c) = @_;
+ my $subscriber_id = $c->req->params->{subscriber_id} // 0;
+
+ my $subscriber;
+ if($subscriber_id && $subscriber_id->is_integer) {
+ $subscriber = $c->model('DB')->resultset('voip_subscribers')->search({
+ 'me.status' => { '!=' => 'terminated' },
+ })->find( { id => $subscriber_id } );
+ }
my $res = $c->stash->{contract}->voip_subscribers->search({
'provisioning_voip_subscriber.is_pbx_group' => 1,
-
},{
- join => 'provisioning_voip_subscriber',
+ 'join' => 'provisioning_voip_subscriber',
+ ( defined $subscriber ? (
+ '+select' => [
+ {'' => \['select voip_pbx_groups.id from provisioning.voip_pbx_groups where voip_pbx_groups.group_id=provisioning_voip_subscriber.id and subscriber_id=?', [ {} => $subscriber->provisioning_voip_subscriber->id ] ], '-as' => 'sort_field' },
+ {'' => \['(select voip_pbx_groups.id from provisioning.voip_pbx_groups where voip_pbx_groups.group_id=provisioning_voip_subscriber.id and subscriber_id=?) is null', [ {} => $subscriber->provisioning_voip_subscriber->id ] ], '-as' => 'sort_field_is_null' },
+ ],
+ '+as' => ['sort_field','sort_field_is_null'],
+ 'order_by' => ['sort_field_is_null','sort_field'], )
+ : (),
+ ),
});
NGCP::Panel::Utils::Datatables::process($c, $res, $c->stash->{pbxgroup_dt_columns});
$c->detach( $c->view("JSON") );
diff --git a/lib/NGCP/Panel/Field/DataTable.pm b/lib/NGCP/Panel/Field/DataTable.pm
index 43b8f64d2b..4707c0506b 100644
--- a/lib/NGCP/Panel/Field/DataTable.pm
+++ b/lib/NGCP/Panel/Field/DataTable.pm
@@ -13,6 +13,7 @@ has 'template' => ( isa => 'Str',
has 'ajax_src' => ( isa => 'Str', is => 'rw', default => '/emptyajax' );
has 'table_fields' => ( isa => 'ArrayRef', is => 'rw' );
has 'table_titles' => ( isa => 'ArrayRef', is => 'rw' );
+has 'no_ordering' => ( isa => 'Bool', is => 'rw' );
has 'language_file' => (isa => 'Str', is => 'rw', default => 'dataTables.default.js' );
sub render_element {
@@ -36,6 +37,7 @@ sub render_element {
ajax_src => $self->ajax_src,
table_fields => $self->table_fields,
table_titles => $self->table_titles,
+ no_ordering => $self->no_ordering,
errors => $self->errors,
language_file => $self->language_file,
wrapper_class => ref $self->wrapper_class eq 'ARRAY' ? join (' ', @{$self->wrapper_class}) : $self->wrapper_class,
diff --git a/lib/NGCP/Panel/Form/Customer/PbxSubscriber.pm b/lib/NGCP/Panel/Form/Customer/PbxSubscriber.pm
index f380facb8b..099fecd564 100644
--- a/lib/NGCP/Panel/Form/Customer/PbxSubscriber.pm
+++ b/lib/NGCP/Panel/Form/Customer/PbxSubscriber.pm
@@ -35,6 +35,7 @@ has_field 'group_select' => (
required => 0,
template => 'helpers/datatables_multifield.tt',
ajax_src => '/invalid',
+ no_ordering => 1,
table_titles => ['#', 'Name', 'Extension'],
table_fields => ['id', 'username', 'provisioning_voip_subscriber_pbx_extension'],
);
@@ -202,17 +203,20 @@ sub field_list {
}
}
if($self->field('group_select')) {
- my $sub;
+ my $sub_contract;
+ my $sub_id = 0;
if($c->stash->{pilot}) {
- $sub = $c->stash->{pilot};
+ $sub_contract = $c->stash->{pilot};
} elsif($c->stash->{subscriber}) {
- $sub = $c->stash->{subscriber};
+ $sub_contract = $c->stash->{subscriber};
}
-
- if($sub) {
+ if($c->stash->{subscriber}) {
+ $sub_id = $c->stash->{subscriber}->id;
+ }
+ if($sub_contract) {
$self->field('group_select')->ajax_src(
- $c->uri_for_action("/customer/pbx_group_ajax", [$sub->contract_id])->as_string
- );
+ $c->uri_for_action("/customer/pbx_group_ajax", [$sub_contract->contract_id], { 'subscriber_id' => $sub_id } )->as_string
+ );
}
}
diff --git a/lib/NGCP/Panel/Utils/Subscriber.pm b/lib/NGCP/Panel/Utils/Subscriber.pm
index 506eb05420..ed7e249dac 100644
--- a/lib/NGCP/Panel/Utils/Subscriber.pm
+++ b/lib/NGCP/Panel/Utils/Subscriber.pm
@@ -1123,6 +1123,8 @@ sub prepare_group_select {
my @group_options = ();
my $group_rs = $c->model('DB')->resultset('voip_pbx_groups')->search({
'subscriber_id' => $subscriber->provisioning_voip_subscriber->id,
+ },{
+ 'order_by' => 'me.id',
});
unless($unselect) {
@group_options = map { $_->group->voip_subscriber->id } $group_rs->all;
diff --git a/share/templates/helpers/datatables_field.tt b/share/templates/helpers/datatables_field.tt
index 06689bc6c1..713386b927 100644
--- a/share/templates/helpers/datatables_field.tt
+++ b/share/templates/helpers/datatables_field.tt
@@ -14,29 +14,29 @@ $(document).ready(function() {
});
- $('#[% table_id %]')
- .dataTable( {
+ $('#[% table_id %]')
+ .dataTable( {
"sDom": "<'row-fluid'<'pull-left'r><'pull-right'f>>t<'row-fluid'<'pull-left'i><'pull-right'p>>",
- "bProcessing": true,
- "bServerSide": true,
- "bPaginate": true,
+ "bProcessing": true,
+ "bServerSide": true,
+ "bPaginate": true,
"sPaginationType": "bootstrap",
- "bLengthChange": false,
- "bSort": true,
- "bInfo": true,
- "iDisplayLength": 4,
- 'iShowPages': 5,
+ "bLengthChange": false,
+ "bSort": true,
+ "bInfo": true,
+ "iDisplayLength": 4,
+ "iShowPages": 5,
"oLanguage": {
"sUrl": "/js/i18n/[% language_file %]"
},
- "sAjaxSource": "[% ajax_src %]",
-
- "aoColumns": [
+ "sAjaxSource": "[% ajax_src %]",
+
+ "aoColumns": [
[% FOREACH f IN table_fields -%]
[%index = loop.count - 1%]
[%IF table_titles.${index} %]
[% f = f.replace('\.','_');%]
- {
+ {
"mData": "[% f %]",
"mRender": function ( data, type, full ) {
if(data == null)
@@ -46,13 +46,13 @@ $(document).ready(function() {
},
[% END -%]
[% END -%]
- { "mRender": function ( data, type, full ) {
+ { "mRender": function ( data, type, full ) {
return '';
},
"mData": null,
"bSortable": false
}
- ],
+ ],
"fnRowCallback": function(nRow, aData, iDisplayIndex) {
nRow.className = "sw_action_row";
if($(nRow).find("td:first").text() == $("#[% hidden_id %]").val())
@@ -64,7 +64,7 @@ $(document).ready(function() {
"fnServerParams": function ( aoData ) {
aoData.push( {"name":"iIdOnTop","value":"[% value %]"} );
},
- } );
+ } );
} );
diff --git a/share/templates/helpers/datatables_multifield.tt b/share/templates/helpers/datatables_multifield.tt
index 9d3a000425..d8410db40a 100644
--- a/share/templates/helpers/datatables_multifield.tt
+++ b/share/templates/helpers/datatables_multifield.tt
@@ -1,46 +1,50 @@
diff --git a/share/templates/subscriber/master.tt b/share/templates/subscriber/master.tt
index 0bf3c3b2fe..d429735303 100644
--- a/share/templates/subscriber/master.tt
+++ b/share/templates/subscriber/master.tt
@@ -85,17 +85,6 @@
IF (c.user.roles == "admin" || c.user.roles == "reseller") && c.user.show_passwords;
elements.push({ value = subscriber.provisioning_voip_subscriber.password, desc = c.loc('SIP Password') });
END;
- IF subscriber.provisioning_voip_subscriber.voip_pbx_groups.count;
- group_subs = subscriber.provisioning_voip_subscriber.voip_pbx_groups.all;
- group_str = '';
- FOR group IN group_subs;
- group_str = group_str _ group.group.username;
- IF !loop.last;
- group_str = group_str _ '
';
- END;
- END;
- elements.push({ value = group_str, desc = c.loc('PBX Groups') });
- END;
IF c.user.roles == "admin" || c.user.roles == "reseller";
elements.push({ value = subscriber.provisioning_voip_subscriber.admin ? 'yes' : 'no', desc = c.loc('Administrative') });
elements.push({ value = subscriber.external_id, desc = c.loc('External #')});