%#-- Begin HTML --#
<& '/widgets/wrappers/sharky/header.mc',
   title => "$disp Profile",
   context => "Admin | Profile | $disp | $crumb"
 &>
<& '/javascripts/profile/formValidator.js', id => $id &>
<form method="post" action="<% $r->uri %>" name="action_profile" onSubmit="return confirmChanges(this)">
<%perl>;
$m->comp('/widgets/profile/hidden.mc', value => $id, name => 'action_id')
  if defined $id;
$m->comp('/widgets/profile/hidden.mc', name => 'dest_id', value => $dest_id);

# Output the key properties.
$m->comp("/widgets/wrappers/sharky/table_top.mc", caption => "Properties");
my $used = { active => 1, ord => 1 };
my $label = 'next_dkgreen';

if (defined $id || $next) {
    # This is an existing action. Disallow ability to change the type.
    $m->comp('/widgets/profile/displayFormElement.mc', objref => $act,
	     key => 'type', readOnly => 1);
    $used->{type} = 1;
    $label = 'save_red';
}
# Okay now, output the normal form fields.
$m->comp('/widgets/profile/dumpRemainingFields.mc', objref => $act,
         fieldsUsed => $used, readOnly => $no_edit );

# Output the Order from field.
# HACK. There should probably be a more elegant way for my_meths to determine
# the upper limits of the select list, but currently there isn't one. So I create
# one here by loading what my_meths() returns, and then setting the value and the
# vals list manually.
my $ord_vals = { %{ $act->my_meths->{ord} } };
$ord_vals->{props}{vals} = [1..($id ? $next_ord - 1 : $next_ord)];
$ord_vals->{value} = $act->get_ord;
$m->comp('/widgets/profile/displayFormElement.mc', vals => $ord_vals,
	 readOnly => $no_edit, key => 'ord');

# Close 'er up!
$m->comp("/widgets/wrappers/sharky/table_bottom.mc");
$m->comp('/widgets/profile/formButtons.mc', type => $type, no_del => $no_del,
	 section => $section, return => "/admin/profile/dest?id=$dest_id",
	 val => $label, no_save => $no_edit);
</%perl>
</form>
<& '/widgets/wrappers/sharky/footer.mc', param => \%ARGS &>

%#-- End HTML --#

%#-- Once Section --#
<%once>;
my $widget = 'profile';
my $section = 'admin';
my $type = 'action';
my $class = get_package_name($type);
my $disp = get_disp_name($type);
my $dest_key = 'dest';
my $dest_class = get_package_name($dest_key);
</%once>

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

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

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

# Get the server type (destination profile) ID and instantiate the destination
# object.
$dest_id ||= get_state_data($widget, $dest_key) || $act->get_server_type_id;
my $dest = $dest_class->lookup({ id => $dest_id });

# Check authorization.
chk_authz($dest, EDIT);
my $no_edit = !chk_authz($dest, EDIT, 1);
my $no_del = !$id || $no_edit;

# Set the ord to the next ord by default, if this is a new action.
my $next_ord = Bric::Dist::Action->next_ord($dest_id);
$act->set_ord($next_ord) unless defined $id;

# Set the type, if it has already been selected.
$act->set_type($type) if $next;

# Get the name for the breadcrumb trail.
my $crumb = $act->get_name;
$crumb = $crumb ? "&quot;$crumb&quot;" : 'New';
</%init>

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

=head1 NAME

/admin/profile/action/dhandler - Interface for managing actions.

=head1 VERSION

$Revision: 1.7 $

=head1 DATE

$Date: 2002/05/20 03:21:56 $

=head1 DESCRIPTION

This element handles the display for editing distribution actions.

</%doc>
