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

$m->comp("/widgets/wrappers/sharky/table_top.mc", caption => "Properties", number => 1);
# Dump the basic fields.
$m->comp('/widgets/profile/dumpRemainingFields.mc', objref => $ct,
	 readOnly => $no_edit, fieldsUsed => $exclude);
if (defined $id && $ct->get_media) {
    $type_vals->{value} = $ct->get_biz_class_id;
    $m->comp('/widgets/profile/displayFormElement.mc', key => 'biz_class_id',
	     vals => $type_vals, readOnly => $no_edit);
} elsif (!defined $id ) {
    # Output the Element Type Select list.
    $m->comp('/widgets/profile/select.mc', disp => 'Type', name => 'elem_type',
	     options => [qw(Element Story Media)], value => $type,
	     readOnly => $no_edit);
} else {
    $m->comp('/widgets/profile/text.mc', disp => 'Type', value => $type, readOnly => 1);
}
$m->comp("/widgets/wrappers/sharky/table_bottom.mc");

# Output group membership.
$m->comp("/widgets/grp_membership/grp_membership.mc",
         grp_class => 'Bric::Util::Grp::ElementType',
         obj => $ct,
         formName => 'ct_profile',
         widget => $widget,
         no_edit => $no_edit,
         num => 2
);

$m->comp('/widgets/profile/formButtons.mc',
	 type => $type,
         widget => $widget,
	 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 Section --#
<%once>;
my $class = 'Bric::Biz::ATType';
my $section = 'admin';
my $widget = 'element_type';
my $disp = get_disp_name($widget);
my $type_vals = { %{ $class->my_meths->{biz_class_id} } };
{
    # HACK. There must be a better way to get rid of the Story option!
    my $story_pkg_id = get_class_info('story')->get_id;
    my $tmp = [];
    foreach (@{ $type_vals->{props}{vals}}) {
	push @$tmp, $_ unless $_->[0] == $story_pkg_id;
    }
    $type_vals->{props}{vals} = $tmp;
    $type_vals->{disp} = 'Media Type';
}

</%once>

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

%#-- Init Section --#
<%init>;
# Instantiate an object.
my $ct = $ARGS{obj} ? $ARGS{obj} : defined $id ? $class->lookup({ id => $id})
  : $class->new;
$id ||= $ct->get_id;

# Check authorization.
chk_authz($ct, $id ? READ : CREATE);
my $no_edit = !chk_authz($ct, ($id ? EDIT : CREATE), 1);
my $no_del = !$id || $no_edit;

# Figure out its type.
my $type = 'Subelement';
my $exclude = { active => 1, media => 1, top_level => 1, biz_class_id => 1};
if (defined $id) {
    if ($ct->get_top_level) {
	$ct->get_media ? ($type, $exclude->{paginated}) = ('Media', 1)
	  : $type = 'Story';
    } else {
	# Set the proper flags.
	$exclude->{biz_class_id} = 1;
    }
} else {
    @{$exclude}{qw(paginated fixed_url related_story related_media)}
      = (1, 1, 1, 1);
}

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

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

=head1 NAME

/admin/profile/source/dhandler - Interface for managing element types.

=head1 VERSION

$LastChangedRevision$

=head1 DATE

$LastChangedDate$

=head1 DESCRIPTION

This element handles the display for editing element types.

</%doc>
