diff --git a/lib/NGCP/Panel/Controller/Contact.pm b/lib/NGCP/Panel/Controller/Contact.pm index bef731d9a8..d45eebe427 100644 --- a/lib/NGCP/Panel/Controller/Contact.pm +++ b/lib/NGCP/Panel/Controller/Contact.pm @@ -196,7 +196,16 @@ sub delete :Chained('base') :PathPart('delete') :Args(0) { sub ajax :Chained('list_contact') :PathPart('ajax') :Args(0) { my ($self, $c) = @_; - NGCP::Panel::Utils::Datatables::process($c, $c->stash->{contacts}, $c->stash->{contact_dt_columns}); + NGCP::Panel::Utils::Datatables::process( + $c, + $c->stash->{contacts}->search_rs(undef, {prefetch=>"contracts"}), + $c->stash->{contact_dt_columns}, + sub { + my ($result) = @_; + my %data = (deletable => ($result->contracts->all) ? 0 : 1); + return %data + }, + ); $c->detach( $c->view("JSON") ); } diff --git a/lib/NGCP/Panel/Utils/Datatables.pm b/lib/NGCP/Panel/Utils/Datatables.pm index eea4643ca3..d050a6280a 100644 --- a/lib/NGCP/Panel/Utils/Datatables.pm +++ b/lib/NGCP/Panel/Utils/Datatables.pm @@ -8,7 +8,7 @@ use Scalar::Util qw/blessed/; use DateTime::Format::Strptime; sub process { - my ($c, $rs, $cols) = @_; + my ($c, $rs, $cols, $row_func) = @_; my $aaData = []; my $totalRecords = $rs->count; @@ -92,6 +92,9 @@ sub process { if(defined $topId) { if(defined(my $row = $rs->find($topId))) { push @{ $aaData }, _prune_row($cols, $row->get_inflated_columns); + if (defined $row_func) { + $aaData->[-1]->put($row_func->($row)); + } $rs = $rs->search({ 'me.id' => { '!=', $topId} }); } } @@ -135,6 +138,9 @@ sub process { for my $row ($rs->all) { push @{ $aaData }, _prune_row($cols, $row->get_inflated_columns); + if (defined $row_func) { + $aaData->[-1]->put($row_func->($row)); + } } $c->stash( diff --git a/share/templates/contact/list.tt b/share/templates/contact/list.tt index df221b03eb..3b28b774f3 100644 --- a/share/templates/contact/list.tt +++ b/share/templates/contact/list.tt @@ -15,7 +15,7 @@ UNLESS c.user.read_only; helper.dt_buttons = [ { name = 'Edit', uri = "/contact/'+full.id+'/edit", class = 'btn-small btn-primary', icon = 'icon-edit' }, - { name = 'Delete', uri = "/contact/'+full.id+'/delete", class = 'btn-small btn-secondary', icon = 'icon-trash' }, + { name = 'Delete', uri = "/contact/'+full.id+'/delete", class = 'btn-small btn-secondary', icon = 'icon-trash' condition = 'full.deletable' }, ]; helper.top_buttons = [ { name = 'Create Contact', uri = c.uri_for('/contact/create'), icon = 'icon-star' },