%#-- Begin HTML --#
<& '/widgets/wrappers/sharky/header.mc',
   title => "$disp Profile",
   context => "Admin | Profile | $wf_disp | &quot;" . $wf->get_name . "&quot;"
              . "| $disp | $crumb"
&>

% # Prevent the workflow profile redirect here when our cancel button is pushed
% # and then the workflow profile's cancel button is pushed.
% pop_page;
<form method="post" action="<% $r->uri %>" name="desk_profile" onsubmit="return confirmChanges(this)">
<%perl>;
$m->comp('/widgets/profile/hidden.mc', value => $wid, name => 'workflow_id')
  if defined $wid;

if (! defined $id && ! defined $new_desk) {
    my $excl = [ map { $_->get_id } $wf->allowed_desks ];
    # Adding a new desk. Give 'em a choice.
    $m->comp("/widgets/wrappers/sharky/table_top.mc", caption => "Select Desk");
    $m->comp('/widgets/select_object/select_object.mc',
         object => 'desk',
         no_persist => 1,
         exclude => $excl,
         name => 'desk_id',
         field => 'name',
         disp => 'Select Desk',
         useTable => 1);
    $m->out(qq {<table width=578 cellpadding=2 cellspacing=0 border=0><tr><td width=140>&nbsp;</td><td width=438>});

    $m->comp('/widgets/profile/imageSubmit.mc',
         formName => "desk_profile",
         callback => "new_desk",
         alt      => 'New Desk',
	     image    => "new_desk_red",
	     js       => qq{onClick="requiredFields='';return customSubmit('desk_profile', 'new_desk', 1)"}
	   );

    $m->out(qq{</td></tr></table>\n});
} else {
    # Let 'em create a new desk.
    $m->comp('/widgets/profile/hidden.mc', value => $id, name => 'desk_id')
      if defined $id;
    $m->comp("/widgets/wrappers/sharky/table_top.mc", caption => "Properties");

    # Dump the basic fields.
    $m->comp('/widgets/profile/dumpRemainingFields.mc', objref => $desk,
	     readOnly => $no_edit, fieldsUsed => { active => 1 });
}
$m->comp("/widgets/wrappers/sharky/table_bottom.mc");

$m->comp('/widgets/profile/formButtons.mc',
	 type => $type,
	 section => $section,
	 no_del => $no_del,
	 chk_label => "Delete this $disp from all Workflows",
	 return => defined $wid ? "/admin/profile/workflow/$wid" : undef,
	 no_save => $no_edit,
         widget => $type);
</%perl>
</form>
<& '/widgets/wrappers/sharky/footer.mc', param => \%ARGS &>
%#-- End HTML --#

%#-- Once Section --#
<%once>;
my $section = 'admin';
my $type = 'desk';
my $disp = get_disp_name($type);
my $class = get_package_name($type);
my $wf_key = 'workflow';
my $widget = 'profile';
my $wf_class = get_package_name($wf_key);
my $wf_disp = get_disp_name($wf_key);
</%once>

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

%#-- Init Section --#
<%init>;
# Make sure we have a workflow ID.
my $wid = get_state_data($widget, $wf_key);

# Check authorization.
my $wf = $wf_class->lookup({ id => $wid });

chk_authz($wf, EDIT);
my $no_edit = !chk_authz($wf, EDIT, 1);
my $no_del = !$id || $no_edit
  || @{Bric::Biz::Workflow->list_ids({ head_desk_id => $id })};

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

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

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

=head1 NAME

/admin/profile/desk/dhandler - Interface for managing desks.

=head1 VERSION

$LastChangedRevision$

=head1 DATE

$LastChangedDate$

=head1 DESCRIPTION

This element handles the display for editing desks.

</%doc>
