Only expose delete button to contacts with no contracts

else the delete fails anyway with foreign key constraint
agranig/peering-route
Gerhard Jungwirth 13 years ago
parent 52e353d594
commit 4cfa5b7870

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

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

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

Loading…
Cancel
Save