MT#12939 Preserve groups order while edit subscriber

Change-Id: I2a2c1cf89e72c3345b3abcf3367301e4487ba083
changes/78/1978/6
Irina Peshinskaya 10 years ago
parent 558bb1c2fc
commit 7ba2dbd0d3

@ -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") );

@ -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,

@ -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
);
}
}

@ -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;

@ -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 '<input type="checkbox" value="' + full.id + '"/>';
},
"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 %]"} );
},
} );
} );
} );
</script>

@ -1,46 +1,50 @@
<!-- datatables_multifield -->
<script type="text/javascript">
var checked_fields = {};
var checked_fields = [];
$(document).ready(function() {
[%IF value%]
JSON.parse('[% value %]').map( function (val) {
checked_fields[val] = 1;
checked_fields.push(val);
});
[%END%]
$('#[% table_id %] tr td input[type="checkbox"]').live( "click", function() {
var my_id = $(this).parents("tr").find("td:first").text();
var indexOfId = checked_fields.indexOf(my_id)
if($(this).attr("checked") == "checked") {
checked_fields[my_id] = 1;
if(indexOfId < 0){
checked_fields.push(my_id);
}
} else {
delete checked_fields[my_id];
if( indexOfId >= 0){
checked_fields.splice(indexOfId,1);
}
}
$("#[% hidden_id %]").val( JSON.stringify(Object.keys(checked_fields)) );
$("#[% hidden_id %]").val( JSON.stringify(checked_fields) );
});
$('#[% 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,
"bLengthChange": false,
"bSort": [%IF no_ordering; 'false'; ELSE; 'true'; END%],
"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 -%]
{
{
"mData": "[% f %]",
"mRender": function ( data, type, full ) {
if(data == null)
@ -49,16 +53,16 @@ $(document).ready(function() {
}
},
[% END -%]
{ "mRender": function ( data, type, full ) {
{ "mRender": function ( data, type, full ) {
return '<input type="checkbox" value="' + full.id + '"/>';
},
"mData": null,
"bSortable": false
}
],
],
"fnRowCallback": function(nRow, aData, iDisplayIndex) {
nRow.className = "sw_action_row";
if($(nRow).find("td:first").text() in checked_fields)
if(checked_fields.indexOf($(nRow).find("td:first").text()) >= 0 )
{
$(nRow).find("td input[type='checkbox']").attr("checked", "checked");
}
@ -67,7 +71,7 @@ $(document).ready(function() {
"fnServerParams": function ( aoData ) {
//aoData.push( {"name":"iIdOnTop","value":"[% value %]"} );
},
} );
} );
} );
</script>

@ -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 _ '<br/>';
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 #')});

Loading…
Cancel
Save