%# BEGIN BPS TAGGED BLOCK {{{
%# 
%# COPYRIGHT:
%#  
%# This software is Copyright (c) 1996-2004 Best Practical Solutions, LLC 
%#                                          <jesse@bestpractical.com>
%# 
%# (Except where explicitly superseded by other copyright notices)
%# 
%# 
%# LICENSE:
%# 
%# This work is made available to you under the terms of Version 2 of
%# the GNU General Public License. A copy of that license should have
%# been provided with this software, but in any event can be snarfed
%# from www.gnu.org.
%# 
%# This work is distributed in the hope that it will be useful, but
%# WITHOUT ANY WARRANTY; without even the implied warranty of
%# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
%# General Public License for more details.
%# 
%# You should have received a copy of the GNU General Public License
%# along with this program; if not, write to the Free Software
%# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
%# 
%# 
%# CONTRIBUTION SUBMISSION POLICY:
%# 
%# (The following paragraph is not intended to limit the rights granted
%# to you to modify and distribute this software under the terms of
%# the GNU General Public License and is only of importance to you if
%# you choose to contribute your changes and enhancements to the
%# community by submitting them to Best Practical Solutions, LLC.)
%# 
%# By intentionally submitting any modifications, corrections or
%# derivatives to this work, or any other work intended for use with
%# Request Tracker, to Best Practical Solutions, LLC, you confirm that
%# you are the copyright holder for those contributions and you grant
%# Best Practical Solutions,  LLC a nonexclusive, worldwide, irrevocable,
%# royalty-free, perpetual, license to use, copy, create derivative
%# works based on those contributions, and sublicense and distribute
%# those contributions and any derivatives thereof.
%# 
%# END BPS TAGGED BLOCK }}}
<%ARGS>
$Name => undef
$Attr => undef
</%ARGS>


<%ONCE>
my $COLUMN_MAP;

my $LinkCallback = sub {
    my $method = shift;

    my $mode            = $RTx::AssetTracker::Asset::LINKTYPEMAP{$method}{Mode};
    my $mode_uri        = $mode.'URI';
    my $mode_is_local   = $mode.'IsLocal';
    my $local_type      = 'Local'.$mode;

	{ export_value =>
        sub {
            map {
                $_->$mode_uri->Resolver->HREF;
            } @{ $_[0]->$method->ItemsArrayRef }
        },
	  value =>
        sub {
            map {
                \'<A HREF="',
                $_->$mode_uri->Resolver->HREF,
                \'">',
                ( $_->$mode_uri->IsLocal ?
                  $_->$mode_uri->Resolver->AsString
                 :
                  $_->$mode
                ),
                \'</A><BR>',
            } @{ $_[0]->$method->ItemsArrayRef }
        }
    }
};

$COLUMN_MAP = {
    IP => {
        attribute => 'IP',
        title     => 'IP Address',
        value     => sub { return map { ($_, \'<br>') } $_[0]->IPsAsList },
        export_value     => sub { $_[0]->_export_formatted_IPs() },
    },
    TypeName => {
        attribute => 'Type',
        title     => 'Type',
        value     => sub { return $_[0]->TypeObj->Name }
    },
    id => {
        attribute => 'id',
        align     => 'right',
        type      => 'Number',
        export_style     => 's23',
        value     => sub { return $_[0]->id }
    },
    Name => {
        attribute => 'Name',
        title     => 'Name',
        value     => sub { return $_[0]->Name }
    },
    Status => {
        attribute => 'Status',
        title     => 'Status',
        value     => sub { return loc($_[0]->Status) }
    },
    Description => {
        attribute => 'Description',
        title     => 'Description',
        value     => sub { return $_[0]->Description || "(" . loc('No description') . ")" }
    },
    ExtendedStatus => {
        title     => 'Status',
        attribute => 'Status',
        value     => sub {
            my $Asset = shift;

            if ( $Asset->HasUnresolvedDependencies ) {
                if (   $Asset->HasUnresolvedDependencies( Type => 'approval' )
                    or $Asset->HasUnresolvedDependencies( Type => 'code' ) )
                {
                    return \'<em>', loc('(pending approval)'), \'</em>';
                }
                else {
                    return \'<em>', loc('(pending other Collection)'), \'</em>';
                }
            }
            else {
                return loc( $Asset->Status );
            }

          }
    },
    Created => {
        attribute => 'Created',
        type      => 'DateTime',
        export_style   => 's21',
        value     => sub { return $_[0]->CreatedObj->AsString },
        export_value     => sub { my $date = $_[0]->Created . '.000'; $date =~ s/ /T/; $date }
    },
    LastUpdated => {
        attribute => 'LastUpdated',
        title     => 'Last Updated',
        type      => 'DateTime',
        export_style   => 's21',
        value     => sub { return $_[0]->LastUpdatedObj->AsString },
        export_value     => sub { my $date = $_[0]->Created . '.000'; $date =~ s/ /T/; $date }
    },
    LastTransaction => {
        attribute => 'LastTransaction',
        title     => 'Last Transaction',
        value     => sub { return $_[0]->Transactions->Last->BriefDescription }
    },

    # Everything from LINKTYPEMAP
    (map {
        $_ => $LinkCallback->( $_ )
    } keys %RTx::AssetTracker::Asset::LINKTYPEMAP),

    '_CLASS' => {
        value => sub { return $_[1] % 2 ? 'oddline' : 'evenline' }
    },
    '_CHECKBOX' => {
        attribute => 'checkbox',
        title => 'Update',
        align     => 'right',
        value     => sub { return \('<input type="checkbox" class="checkbox" name="UpdateAsset'.$_[0]->id.'" value="1" checked="checked" />') }
    },

};

for my $role ( ActiveRoleArray() ) {
    my $group_method = $role . 'RoleGroup';
    my $export_method = $role . 'RoleGroupExportString';
    $COLUMN_MAP->{$role} = {
        attribute => "$role.EmailAddress",
        value => sub { return $_[0]->$group_method->MemberEmailAddressesAsString },
        export_value => sub { return $_[0]->$export_method },
    };
}


# }}}
</%ONCE>
<%init>
$m->callback( COLUMN_MAP => $COLUMN_MAP, CallbackName => 'ColumnMap' );
return GetColumnMapEntry( Map => $COLUMN_MAP, Name => $Name, Attribute => $Attr );
</%init>
