<%doc> Custom Interface for Contact Lists % % <%attr> title => 'Contact List' section => 'Generic' % % <%args> $id $user => $ui->get_current_user($r) $view => undef $edit => undef $submit => undef $_action => undef $contact_id => undef $person_id => undef $role_id => undef $personstatus => undef $newname => undef % % <%init> my $DEBUG = 0; print '%ARGS is
', Dumper(%ARGS), '

' if $DEBUG; my $obj = ContactList->retrieve($id); # Check if user can view this object my $manager = $ui->get_permission_manager($r); unless ( $manager && $manager->can($user, "view", $obj) ){ $m->comp('/generic/error.mhtml', error=>"You don't have permission to view this object"); } my %linksfrom = ContactList->meta_data->get_links_from; if ( $_action ){ my %ret; if ( $_action eq 'edit_contact' ){ eval { %ret = $ui->form_to_db(%ARGS); print 'form_to_db returned:
', Dumper(%ret), '

' if $DEBUG; }; if ( my $e = $@ ){ $m->comp('/generic/error.mhtml', error=>$e); } }elsif ( $_action eq 'new_contact' ){ my (%pargs, %cargs); foreach my $arg ( keys %ARGS ){ if ( $personstatus eq 'new' && $arg =~ /^Person__/ ){ $pargs{$arg} = $ARGS{$arg}; } if ( $arg =~ /^Contact__/ ){ if ( $personstatus eq 'new' && $arg =~ /^Contact__NEW__person/ ){ next; }else{ $cargs{$arg} = $ARGS{$arg}; } } } # This should be atomic because inserting ContactList may fail, # and we want to roll back creating the person if it does eval { Netdot::Model->do_transaction(sub{ if ( $personstatus eq 'new' ){ %ret = $ui->form_to_db(%pargs); print 'form_to_db returned:
', Dumper(%ret), '

' if $DEBUG; } # Now we add the Contact record if ( $personstatus eq 'new' && %ret ){ my $personid = (keys %{$ret{'Person'}{id}})[0]; $cargs{'Contact__NEW__person'} = $personid; } $cargs{'Contact__NEW__contactlist'} = $id; %ret = $ui->form_to_db(%cargs); print 'form_to_db returned:
', Dumper(%ret), '

' if $DEBUG; }); }; if ( my $e = $@ ){ $m->comp('/generic/error.mhtml', error=>$e); } }elsif ( $_action eq 'delete_person' ){ $m->comp('.delete_person_confirmation', person_id=>$person_id, contactlist_id=>$id); $m->abort; }elsif ( $_action eq 'delete_person_confirm' ){ my $person = Person->retrieve($person_id); unless ( $person ){ $m->comp('/generic/error.mhtml', error=>"Cannot retrieve Person id $person_id"); } eval { $person->delete(); }; if ( my $e = $@ ){ $m->comp('/generic/error.mhtml', error=>$e); } }elsif ( $_action eq 'delete_role' ){ $m->comp('.delete_role_confirmation', role_id=>$role_id, contactlist_id=>$id); $m->abort; }elsif ( $_action eq 'delete_role_confirm' ){ my $role = Contact->retrieve($role_id); unless ( $role ){ $m->comp('/generic/error.mhtml', error=>"Cannot retrieve Role id $role_id"); } eval { $role->delete(); }; if ( my $e = $@ ){ $m->comp('/generic/error.mhtml', error=>$e); } }elsif ( $_action eq 'edit_name' ){ eval { my %pargs; my $tmp = sprintf("ContactList__%s__name", $id); $pargs{ $tmp } = $newname; # $m->comp('/generic/error.mhtml', error=>"$id+$newname"); %ret = $ui->form_to_db(%pargs); print 'form_to_db returned:
', Dumper(%ret), '

' if $DEBUG; }; if ( my $e = $@ ){ $m->comp('/generic/error.mhtml', error=>$e); } } }
<& /generic/contactlist.mhtml, id=>$id, edit=>$edit, contact_id => $contact_id &>
% if ( $manager && $manager->can($user, "access_section", 'contactlist.html:display_has_many') ){ % if ( keys %linksfrom ){
View
% if ( $view eq "all" ){ [all] % }elsif ( keys %linksfrom > 1 ){ [all] % } % foreach my $i ( sort keys %linksfrom ){ % next if ($i eq 'contacts'); % next if ($i =~ /history/); % if ( $view eq $i ){ [<% $i %>] % }else{ [<% $i %>] % } % }
% } <%perl> foreach my $i ( keys %linksfrom ){ if ( ($view eq 'all' || $view eq $i ) ){ next if ($i eq 'contacts'); # Table that points to us my $j = (keys %{ $linksfrom{$i} })[0]; # Column in the other table that points to this table my $ffield = $linksfrom{$i}{$j}; # Determine if the has_many method returns ordered data from the db my $ffattrs = $j->meta_data->get_column($ffield)->links_to_attrs(); my $ffield_order = $ffattrs->{order_by} if ( defined $ffattrs && exists $ffattrs->{order_by} ); my @robjs = $obj->$i; my $dtbl = $j; my $ctbl = $j; my $num = scalar(@robjs);
% my $title = $i; % $title .= " ($num)" if $num;
<% $title %>
% if ( $edit eq $i ){   % }else{ % if ( $num ){ [edit] % } [add] % }
% my %args = ( table=>$dtbl, object=>\@robjs ); % if ( $edit eq $i ){ % $args{withedit} = 1; % }else{ % # If data came ordered from the db, tell sortresults not to bother sorting % $args{sort} = 0 if ( $ffield_order ); % } % if ( $num ) { % $m->comp('sortresults.mhtml', %args); % }
% } % } % } <%def .delete_person_confirmation> <%args> $contactlist_id $person_id <%init> my $person = Person->retrieve($person_id); unless ( $person ){ $m->comp('/generic/error.mhtml', error=>"Cannot retrieve Person id $person_id"); }

<% $person->get_label %> % my @r = $person->roles; % my @roles; % map { push @roles, $_ if ($_->contactlist ne $contactlist_id) } @r; % if ( @roles ){

is also in the following Contact Lists:

    % foreach my $role ( @roles ){
  • <% $role->contactlist->get_label %> (<% $role->contacttype->name %>)
    % }
% }

Are you sure you want to delete this person?

<%def .delete_role_confirmation> <%args> $contactlist_id $role_id <%init> my $role = Contact->retrieve($role_id); unless ( $role ){ $m->comp('/generic/error.mhtml', error=>"Cannot retrieve Role id $role_id"); }

<% $role->get_label %>

Are you sure you want to delete this role?