<%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->comp(
        '/widgets/wrappers/sharky/table_top.mc',
        caption => 'Job Failure',
        number  => ++$i,
    );
    $m->print(qq{<div class="padding">\n});
    $m->out('<span class="errorMsg"><b>'
      . $lang->maketext('This job has failed')
      . '</b></span><p>'
      . $lang->maketext(
          'The error message is available below. No further execution '
          . 'attempts will be made on this job unless you check the "Reset '
          . 'this Job" checkbox below.'
      )
      . '</p>'
      . '<pre>'
      .  $job->get_error_message
      . '</pre>');
    $m->comp(
        '/widgets/profile/checkbox.mc',
        name  => 'reset',
        id    => 'reset',
        value => '1',
    );
    $m->print(' <label for="reset" class="burgandyLabel">Reset this Job</label>');
    $m->print("</div>\n");
    $m->comp('/widgets/wrappers/sharky/table_bottom.mc');
}

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

# 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(qq{<ol style="margin: 0; padding: 10px 10px 10px 30px;">});
    foreach my $st ($job->get_server_types) {
        $m->out(qq{<li>} . $st->get_name . "</li>\n");
    }
    $m->out("</ol>\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(qq{<ol style="margin: 0; padding: 10px 10px 10px 30px;">});
    foreach my $st ($job->get_resources) {
        $m->out(qq{<li>} . $st->get_uri . "</li>\n");
    }
    $m->out("</ol>\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>;
my $class = "Bric::Util::Job";
my $widget = 'profile';
my $type = 'job';
my $disp = get_disp_name($type);
</%once>
<%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;
my $i = 0;
</%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>
