<%perl>;
# Output the header and other necessities.
$m->comp('/widgets/wrappers/sharky/header.mc',
         title => "$disp Profile",
	 context => "Admin | Profile | $disp | &quot;" . $job->get_name . "&quot;"
);
$m->out(qq{<form method="post" name="job_profile" action="} . $r->uri
        . qq{" onSubmit="return confirmChanges(this)">\n});
# Output a hidden field with the ID, if we have one.
$m->comp('/widgets/profile/hidden.mc', value => $id, name => 'job_id')
  if defined $id;

if ($job->has_failed) { 
    $m->out('<span class="redLabel"><b>' 
      . $lang->maketext('This job has failed')
      . '</b></span><p>'
      .  $lang->maketext(q{ The error message is available below.  No further execution attempts will be made on this job.  Please leave it in the queue until your administrator has seen the error message.})
      . '</p>'
      . '<pre>'
      .  $job->get_error_message
      . '</pre>');
}

# Display the Basics.
$m->comp("/widgets/wrappers/sharky/table_top.mc",
  	 caption => "Properties",
	 number  => 1);

# Dump out the fields for display.
$m->comp('/widgets/profile/dumpRemainingFields.mc',
	 readOnly => $no_edit,
	 objref => $job,
	 fieldsUsed => { comp_time => 1,
		         sched_time => 1,
                         type => 1,
		       }
	);

# Type should really be read-only
$m->comp("/widgets/profile/displayFormElement.mc",
         key      => 'type',
         objref   => $job,
         readOnly => 1 
        );

$m->comp("/widgets/select_time/select_time.mc",
	 base_name => 'sched_time' ,
	 def_date  => $job->get_sched_time(ISO_8601_FORMAT),
	 useTable  => 1,
	 disp      => "Scheduled Time"
	);

$m->comp("/widgets/wrappers/sharky/table_bottom.mc");

if (ref $job eq 'Bric::Util::Job::Dist') {
    # Show a list of the Distribution Profiles.
    $m->comp("/widgets/wrappers/sharky/table_top.mc",
             caption => "Destinations",
             number => 2);
    $m->out("<table border=0 cellpadding=0 cellspacing=0 width=575>");
    foreach my $st ($job->get_server_types) {
        $m->out(qq{<tr><td width="20" height="25"></td><td width="555">&nbsp;} . $st->get_name . "</td></tr>\n");
    }
    $m->out("</table>\n");
    $m->comp("/widgets/wrappers/sharky/table_bottom.mc");

    # Show a list of the Resources.
    $m->comp("/widgets/wrappers/sharky/table_top.mc",
             caption => "Resources",
             number => 3
            );
    $m->out("<table border=0 cellpadding=0 cellspacing=0 width=575>");
    foreach my $st ($job->get_resources) {
        $m->out(qq{<tr><td width="20" height="25"></td><td width="555">&nbsp;} . $st->get_uri . "</td></tr>\n");
    }
    $m->out("</table>\n");
    $m->comp("/widgets/wrappers/sharky/table_bottom.mc");
}


# Add the form buttons and other necessities.
$m->comp("/widgets/profile/formButtons.mc", type => $type, section => $widget,
	 no_del => $no_del, no_save => $no_edit, chk_label => 'Cancel this Job',
	 ret_val => 'return_dgreen', widget => $type);
$m->out("</form>\n");
$m->comp('/widgets/wrappers/sharky/footer.mc', param => \%ARGS );
</%perl>

%#-- Once Section --#
<%once>;
my $class = "Bric::Util::Job";
my $widget = 'profile';
my $type = 'job';
my $disp = get_disp_name($type);
</%once>

%#-- Args Section --#
<%args>
$id => undef
</%args>

<%init>;
# Do any redirects first.
do_queued_redirect();

# Instantiate an object.
my $job = $ARGS{obj} ? $ARGS{obj} : defined $id ? $class->lookup({ id => $id})
  : $class->new;
$id ||= $job->get_id;

# Check authorization.
chk_authz($job, $id ? READ : CREATE);
my $no_edit = !chk_authz($job, ($id ? EDIT : CREATE), 1);
my $no_del = !$id || $no_edit;
</%init>

<%doc>
###############################################################################

=head1 NAME

=head1 VERSION

$LastChangedRevision$

=head1 DATE

$LastChangedDate$

=head1 SYNOPSIS

/admin/profile/job/dhandler - Distribution Job Profile.

=head1 DESCRIPTION

This element displays Distribution Job profiles for editing.

</%doc>
