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


### 1. PROPERTIES
$m->comp("/widgets/wrappers/sharky/table_top.mc", caption => "Properties",
	 number => 1);

# Output fields from 'media_type'.
$m->comp('/widgets/profile/dumpRemainingFields.mc', objref => $mt,
	 readOnly => $no_edit, fieldsUsed => { active => 1 });

$m->comp("/widgets/wrappers/sharky/table_bottom.mc");


### 2. EXTENSIONS
# Output the extensions.

$m->comp("/widgets/wrappers/sharky/table_top.mc",
	 caption => "Extensions",
	 number => 2);

my $meths = {
	     extension => {
			   disp => 'Extension',
			   props => {
				     type => 'text',
				     length => 10,
				     maxlength => 10,
				    },
			  }
	    };

my $objs = [];
if (defined $id) {
    my @exts = sort($mt->get_exts);
    for my $ext (@exts) {
	push @$objs, {
		      id => $ext,
		      extension => $ext,
		     };
    }
}
$m->comp('/widgets/add_more/add_more.mc', type => 'media_type_ext',
	 fields => [qw(extension)], name => 'media_type_ext', read_only => $no_edit,
	 use_vals => 1, reset_key => $id, objs => $objs, meths => $meths,
	 formName => 'mt_profile', param => \%ARGS,
);

$m->comp("/widgets/wrappers/sharky/table_bottom.mc");



$m->out("<br />\n");

# Get the group's membership listed
$m->comp("/widgets/grp_membership/grp_membership.mc",
         grp_class => 'Bric::Util::Grp::MediaType',
         obj => $mt,
         formName => 'mt_profile',
         widget   => $type,
         no_edit => $no_edit,
);


$m->comp('/widgets/profile/formButtons.mc',
	 type    => $type,
         widget  => $type,
	 section => $section,
	 no_del  => $no_del,
	 no_save => $no_edit,
	 formName => 'mt_profile'
	);
($no_edit, $no_del) = ();
</%perl>
</form>
<& '/widgets/wrappers/sharky/footer.mc', param => \%ARGS &>

%#-- End HTML --#


%#-- Once Section --#
<%once>;
my $class = 'Bric::Util::MediaType';
my $section = 'admin';
my $type = 'media_type';
my $disp = get_disp_name($type);
my ($no_edit, $no_del);
</%once>

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

%#-- Init Section --#
<%init>;
$id = $ARGS{"${type}_id"} unless defined $id;

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

# Disallow editing of the "none" media type group.
$m->comp('/errors/403.mc', obj => $mt) if defined $id && !$id;

$id ||= $mt->get_id;

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

# Get the name for the breadcrumb trail.
# XXX: there's something wrong I think, as $mt is undef whenever
# you delete a profile from the 'Media Type Profile' page.
# It's the same as user/dhandler, though... (I think)
# Anyway, it seems to work.
my $crumb = '';
if (defined $mt && $mt->get_name) {
    $crumb = '&quot;' . $mt->get_name . '&quot;';
} else {
    $crumb = 'New';
}
</%init>

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

=head1 NAME

/admin/profile/media_type/dhandler - Interface for managing media types.

=head1 VERSION

$LastChangedRevision$

=head1 DATE

$LastChangedDate$

=head1 DESCRIPTION

This element handles the display for editing media (MIME) types.

</%doc>
