<%doc> Delete one or more objects <%args> $table => undef $id => undef $user => $ui->get_current_user($r) $submit => "Delete" $sid => undef $selectall => undef $selectall_ids => undef $return_url => undef $warning => undef <%init> my $DEBUG = 0; my $session; my @objs; print '%ARGS is
', Dumper(%ARGS), '

' if $DEBUG; my $manager = $ui->get_permission_manager($r);
%if ( $submit eq "Delete" ){ Are you sure you want to delete the following objects?

    <%perl> eval { $session = $ui->mk_session(); }; if ( my $e = $@ ){ $m->comp('error.mhtml', error=>$e); } if ( $selectall && $selectall_ids && $table ){ # This means that we were passed a list of ids for a given table foreach my $id ( split /,/, $selectall_ids ){ my $key = $table . "__" . $id; $ARGS{$key} = ""; } }elsif ( $table && $id ){ # We were passed a single id for a given table my $key = $table . "__" . $id; $ARGS{$key} = ""; } foreach my $arg ( sort keys %ARGS ){ next unless $arg =~ /__/; my ($table, $id) = split /__/, $arg; my $obj; unless ( $obj = $table->retrieve($id) ){ $m->comp('error.mhtml', error => "Error retrieving $table id $id"); } my $lbl = $obj->get_label; print "
  • $table $lbl
  • "; push @objs, [$table, $obj->id]; } $session->{objects} = \@objs;
% if ( !($warning eq "") ){

WARNINGS: <% $warning %>


%}
<%perl> }elsif ( $submit eq "Confirm" ){ eval{ $session = $ui->get_session($sid); }; if ( my $e = $@ ){ $m->comp('error.mhtml', error=>$e); } my @records = @{$session->{objects}}; my @objs; foreach my $l ( @records ){ my ($table, $id) = @$l; push @objs, $table->retrieve($id); } my @lbls = map { "$table " . $_->get_label } @objs; eval { Netdot::Model->do_transaction(sub{ foreach my $obj ( @objs ){ unless ( $manager && $manager->can($user, "delete", $obj) ){ $ui->throw_user("You don't have permission to delete this object"); } $obj->delete(); } }); }; if ( my $e = $@ ){ $m->comp('error.mhtml', error=>$e); } print "
    \n"; foreach my $lbl ( @lbls ){ print "
  • $lbl has been deleted
  • "; } print "
\n"; if ( $return_url ){ print '


'; print "  [return]"; } }elsif ( $submit eq "Cancel" ){ print "


"; print "Delete cancelled"; if ( $session ){ $ui->rm_session($session); } }