%#-- Begin HTML --#
<& '/widgets/wrappers/sharky/header.mc',
   title => "$disp Profile",
   context => "Admin | Profile | $disp | $crumb",
   jsInit => (defined $id) ? "showForm('$which')" : ""
&>
<form method="post" action="<% $r->uri %>" name="element_data_profile"
      onSubmit="return confirmChanges(this)">
<%perl>;
my $num = 0;

$m->comp('/widgets/profile/hidden.mc',
         'name' => 'element_data_id',
         'value' => $id)
  if defined $id;

# PROPERTIES
$m->comp('/widgets/wrappers/sharky/table_top.mc',
         'caption' => 'Properties',
         'number' => ++$num);
$m->comp('/widgets/profile/text.mc', 'disp' => 'Key Name',
         'value' => $field->get_key_name(), 'readOnly' => 1);
$m->comp('/widgets/profile/dumpRemainingFields.mc', 'objref' => $field,
         'readOnly' => $no_edit, 'fieldsUsed' => $exclude);
$m->comp('/widgets/wrappers/sharky/table_bottom.mc');

# META DATA
$m->comp('/widgets/profile/hidden.mc', 'name' => 'type', 'value' => $which);
$m->comp('/widgets/wrappers/sharky/table_top.mc',
         'caption' => 'Display Attributes',
         'number' => ++$num);
$m->comp("/widgets/$type/$type.mc", 'field' => $field);
$m->comp('/widgets/wrappers/sharky/table_bottom.mc');

$m->comp('/widgets/profile/formButtons.mc',
	 type => $type,
         widget => $type,
	 section => $section,
	 no_del => $no_del,
	 val => defined $id ? undef : 'next_dkgreen',
	 no_save => $no_edit);
</%perl>
</form>
<& '/widgets/wrappers/sharky/footer.mc', 'param' => \%ARGS &>
%#-- End HTML --#

<%once>;
my $class = 'Bric::Biz::AssetType::Parts::Data';
my $section = 'admin';
my $type = 'element_data';
my $disp = get_disp_name($type);
</%once>

<%args>
$id => undef
</%args>

<%init>;
# Instantiate an object.
my $field = $ARGS{obj}
  ? $ARGS{obj}
  : defined($id)
      ? $class->lookup({'id' => $id})
      # This part isn't really necessary, since no new fields are ever created
      # here.
      : $class->new();
$id ||= $field->get_id();

my $meta = $field->get_meta('html_info');
my $which = $meta->{'type'};  # text, radio, etc..

# Get the element object to which the field belongs.
my $elem = Bric::Biz::AssetType->lookup({ id => $field->get_element__id });

# Check authorization. We check the element, rather than the field, since
# field permissions are not (currently) supported.
#chk_authz($field, $id ? READ : CREATE);
#my $no_edit = !chk_authz($field, ($id ? EDIT : CREATE), 1);
chk_authz($elem, READ);
my $no_edit = !chk_authz($elem, EDIT, 1);
my $no_del = !$id || $no_edit;

my $exclude = {
    'name'   => 1,
    'active' => 1,
};

# Get the name for the breadcrumb trail
my $crumb = $field->get_key_name();
$crumb = $crumb ? "&quot;$crumb&quot;" : 'New';
</%init>

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

=head1 NAME

/admin/profile/element_data/dhandler - Interface for managing fields.

=head1 VERSION

$LastChangedRevision$

=head1 DATE

$LastChangedDate$

=head1 DESCRIPTION

This element handles the display for editing fields.

</%doc>
