hash-based aaData for datatables via serialisation hook

agranig/1_0_subfix
Lars Dieckow 13 years ago
parent ee642f0b93
commit 9df80c6caf

@ -41,7 +41,8 @@ my $builder = Local::Module::Build->new(
'Moose::Util::TypeConstraints' => 0,
'MooseX::Object::Pluggable' => 0,
'namespace::autoclean' => 0,
'NGCP::Schema' => '1.002',
'NGCP::Schema' => '1.003',
'Scalar::Util' => 0,
'strict' => 0,
'Template' => 0,
'warnings' => 0,

@ -5,6 +5,7 @@ use namespace::autoclean;
BEGIN { extends 'Catalyst::Controller' }
use NGCP::Panel::Widget;
use Scalar::Util qw(blessed);
#
# Sets the actions in this controller to be registered with no prefix
@ -114,15 +115,13 @@ sub ajax_process_resultset :Private {
my $totalDisplayRecords = $rs->count;
#potentially selected Id as first element
if (defined($iIdOnTop)) {
my $topRow = $rs->find($iIdOnTop);
if (defined($topRow)) {
my %tmpTopRow = $topRow->get_columns;
my @tmpTopRowArray = @tmpTopRow{@$columns};
push @$aaData, \@tmpTopRowArray;
$rs = $rs->search({ 'me.id' => { '!=', $iIdOnTop}});
}
if (defined $iIdOnTop) {
if (defined(my $row = $rs->find($iIdOnTop))) {
push @{ $aaData }, _prune_row($columns, $row->get_inflated_columns);
$rs = $rs->search({ 'me.id' => { '!=', $iIdOnTop} });
} else {
$c->log->error("iIdOnTop $iIdOnTop not found in resultset " . ref $rs);
};
}
#Sorting
@ -145,9 +144,7 @@ sub ajax_process_resultset :Private {
}
for my $row ($rs->all) {
my %tmpRow = $row->get_inflated_columns;
my @aaRow = @tmpRow{@$columns};
push @$aaData, \@aaRow;
push @{ $aaData }, _prune_row($columns, $row->get_inflated_columns);
}
$c->stash(
@ -159,6 +156,18 @@ sub ajax_process_resultset :Private {
}
sub _prune_row {
my ($columns, %row) = @_;
while (my ($k,$v) = each %row) {
unless ($k ~~ $columns) {
delete $row{$k};
next;
}
$row{$k} = $v->datetime if blessed($v) && $v->isa('DateTime');
}
return { %row };
}
sub error_page :Private {
my ($self,$c) = @_;

@ -11,7 +11,7 @@ has_field 'id' => (
template => 'share/templates/helpers/datatables_field.tt',
ajax_src => '/contract/peering/ajax',
table_titles => ['#', 'Contact #', 'Billing Profile #', 'Status'],
table_fields => ['id', 'contact.id', 'billing_profile.id', 'status'],
table_fields => ['id', 'contact_id', 'billing_profile', 'status'],
);
has_field 'create' => (

@ -11,7 +11,7 @@ has_field 'id' => (
template => 'share/templates/helpers/datatables_field.tt',
ajax_src => '/reseller/ajax_contract',
table_titles => ['#', 'Contact #', 'External #', 'Status'],
table_fields => ['id', 'contact.id', 'external_id', 'status'],
table_fields => ['id', 'contact_id', 'external_id', 'status'],
);
has_field 'create' => (

@ -22,7 +22,7 @@ $(document).ready(function() {
"sAjaxSource": "[% helper.ajax_uri %]",
"aoColumns": [
[% FOREACH f IN helper.column_fields -%]
{ "sName": "[% f %]" },
{ "mData": "[% f %]" },
[% END -%]
{ "mRender": function ( data, type, full ) {
return '' +

@ -27,10 +27,10 @@ $(document).ready(function() {
"aoColumns": [
[% FOREACH f IN table_fields -%]
{ "sName": "[% f %]" },
{ "mData": "[% f %]" },
[% END -%]
{ "mRender": function ( data, type, full ) {
return '<input type="checkbox" value="' + full[0] + '"></input>';
return '<input type="checkbox" value="' + full.id + '"></input>';
},
"mData": null,
"bSortable": false

Loading…
Cancel
Save