%#-- Begin HTML --#
<& '/widgets/wrappers/sharky/header.mc', title => "$disp Profile",
   context => "Admin | Profile | $disp | $crumb"
&>
% if (ENABLE_WYSIWYG) {
% # WYSIWYG code here, only used if textarea is in the page with wysiwyg on.
<& /widgets/wysiwyg/load.mc &>
% }
<form method="post" action="<% $r->uri %>" name="ct_profile" id="ct_profile">
<%perl>;
$m->comp('/widgets/profile/hidden.mc', value => $id, name => 'contrib_type_id')
  if defined $id;

# Output the primary fields.
$m->comp("/widgets/wrappers/sharky/table_top.mc",
  	 caption => "Properties", number  => 1);
$m->comp('/widgets/profile/dumpRemainingFields.mc', objref => $grp,
	 readOnly => $no_edit, fieldsUsed => { active => 1, parent_id => 1 });
$m->comp("/widgets/wrappers/sharky/table_bottom.mc");


my $all = $grp->all_for_member_subsys;
# sort the attrs and build an array
my $attr = [];
my @sortedAttrs = sort { $all->{$a}{meta}{pos}{value}
			 <=> $all->{$b}{meta}{pos}{value} } keys %$all;

foreach my $key (@sortedAttrs ) {
    $all->{$key}{name} = $key;
    push @$attr, $all->{$key};
}

my $num_fields = @$attr;
my $sel_opts = [(1..$num_fields)];

# Get the group's membership listed
$m->comp("/widgets/grp_membership/grp_membership.mc",
         grp_class => 'Bric::Util::Grp::ContribType',
         obj => $grp,
         formName => 'ct_profile',
         no_edit => $no_edit,
         no_cb   => 1,
         widget => $type,
         num => 2
);



# display attrs
$m->comp("/widgets/wrappers/sharky/table_top.mc",
	 caption => "Custom Fields",
	 number  => 3);

if ($num_fields) {
    $m->comp("/widgets/profile/displayAttrs.mc",
	     attr        => $attr,
	     readOnly    => $no_edit,
	     usePosition => 1,
	     useDelete   => 1
	    );
} else {
    # Output a message if no attributes defined, yet.
    $m->out(qq{<span class="label">} . $lang->maketext("No custom fields defined."). "</span>\n")
      unless $num_fields;
}

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

if (!$no_edit) {
# Output the formBuilder.
$m->comp('/widgets/formBuilder/formBuilder.mc',
	 numFields => 0,
	 widget => 1,
	 formName => 'ct_profile',
	 numFields => $num_fields,
	 num => 4,
	 stay => 1,
	 caption => 'Add New Field'
	);

} else {


    # Add the buttons.
    $m->comp('/widgets/profile/formButtons.mc',
	     type => $type,
	     section => $section,
         widget => $type,    # XXX: there isn't a Profile/ContribType...
	     no_del => 1,
	     no_save => 1
	    );
}


</%perl>
<& '/widgets/wrappers/sharky/footer.mc', param => \%ARGS &>

%#-- End HTML --#


%#-- Once Section --#
<%once>;
my $class = 'Bric::Util::Grp::Person';
my $type = 'contrib_type';
my $section = 'admin';
my $disp = get_disp_name($type);
my %meta_props = ( type => 'type',
		   length => 'length',
		   maxlength => 'maxlength',
		   rows => 'rows',
		   cols => 'cols',
		   multiple => 'multiple'
		 );
</%once>

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

%#-- Init Section --#
<%init>;
$id ||= $ARGS{contrib_type_id};

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

$id ||= $grp->get_id;

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

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

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

=head1 NAME

/admin/profile/contrib_type/dhandler - Contributor Type profile interface

=head1 VERSION

$LastChangedRevision$

=head1 DATE

$LastChangedDate$

=head1 DESCRIPTION

Diplays the profile for contributor types (groups of people).

</%doc>
