Projekt

Allgemein

Profil

Herunterladen (3,45 KB) Statistiken
| Zweig: | Markierung: | Revision:
5b5dbec0 Moritz Bunkus
package SL::Presenter::Project;

use strict;

0e5e3501 Sven Schöling
use SL::Presenter::EscapedText qw(escape is_escaped);
ee51b82f Tamino Steinert
use SL::Presenter::Tag qw(input_tag html_tag name_to_id select_tag link_tag);
5b5dbec0 Moritz Bunkus
use Exporter qw(import);
0e5e3501 Sven Schöling
our @EXPORT_OK = qw(project project_picker);
5b5dbec0 Moritz Bunkus
use Carp;

sub project {
0e5e3501 Sven Schöling
my ($project, %params) = @_;
5b5dbec0 Moritz Bunkus
return '' unless $project;

$params{display} ||= 'inline';

croak "Unknown display type '$params{display}'" unless $params{display} =~ m/^(?:inline|table-cell)$/;

ee51b82f Tamino Steinert
my $description = $project->full_description(style => delete $params{style});
my $callback = $params{callback} ?
'&callback=' . $::form->escape(delete $params{callback})
: '';

my $text = escape($description);
if (! delete $params{no_link}) {
my $href = 'controller.pl?action=Project/edit'
. '&id=' . escape($project->id)
. $callback;
$text = link_tag($href, $text, %params);
}
5b5dbec0 Moritz Bunkus
0e5e3501 Sven Schöling
is_escaped($text);
5b5dbec0 Moritz Bunkus
}

fac8417d Moritz Bunkus
sub project_picker {
0e5e3501 Sven Schöling
my ($name, $value, %params) = @_;
fac8417d Moritz Bunkus
$value = SL::DB::Manager::Project->find_by(id => $value) if $value && !ref $value;
0e5e3501 Sven Schöling
my $id = delete($params{id}) || name_to_id($name);
fac8417d Moritz Bunkus
my @classes = $params{class} ? ($params{class}) : ();
push @classes, 'project_autocomplete';

8f7bb9d5 Bernd Bleßmann
40df0193 Bernd Bleßmann
my %data_params = map { $_ => delete $params{$_} } grep { defined $params{$_} } qw(customer_id active valid description_style);
8f7bb9d5 Bernd Bleßmann
fac8417d Moritz Bunkus
my $ret =
8f7bb9d5 Bernd Bleßmann
input_tag($name, (ref $value && $value->can('id') ? $value->id : ''), class => "@classes", type => 'hidden', id => $id,
'data-project-picker-data' => JSON::to_json(\%data_params),
) .
0e5e3501 Sven Schöling
input_tag("", ref $value ? $value->displayable_name : '', id => "${id}_name", %params);
fac8417d Moritz Bunkus
$::request->layout->add_javascripts('autocomplete_project.js');
$::request->presenter->need_reinit_widgets($id);

0e5e3501 Sven Schöling
html_tag('span', $ret, class => 'project_picker');
fac8417d Moritz Bunkus
}

0e5e3501 Sven Schöling
sub picker { goto &project_picker };

5b5dbec0 Moritz Bunkus
1;

__END__

=pod

=encoding utf8

=head1 NAME

SL::Presenter::Project - Presenter module for project Rose::DB objects

=head1 SYNOPSIS

my $project = SL::DB::Manager::Project->get_first;
0e5e3501 Sven Schöling
my $html = SL::Presenter::Project->project($project, display => 'inline');
5b5dbec0 Moritz Bunkus
=head1 FUNCTIONS

=over 4

=item C<project $object, %params>

Returns a rendered version (actually an instance of
L<SL::Presenter::EscapedText>) of the project object C<$customer>.

ee51b82f Tamino Steinert
Remaining C<%params> are passed to the function
C<SL::Presenter::Tag::link_tag>. It can include:
5b5dbec0 Moritz Bunkus
=over 2

=item * display

ee51b82f Tamino Steinert
Either C<inline> (the default) or C<table-cell>. Is passed to the function
C<SL::Presenter::Tag::link_tag>.
5b5dbec0 Moritz Bunkus
=item * style

Determines what exactly will be output. Can be one of the values with
C<both> being the default if it is missing:

ee51b82f Tamino Steinert
=item * no_link

If falsish (the default) then the description will be linked to the "edit"
dialog.

5b5dbec0 Moritz Bunkus
=over 2

=item C<projectnumber> (or simply C<number>)

Outputs only the project's number.

=item C<projectdescription> (or simply C<description>)

Outputs only the project's description.

=item C<both>

Outputs the project's number followed by its description in
parenthesis (e.g. "12345 (Secret Combinations)"). If the project's
description is already part of the project's number then it will not
be appended.

=back

=item * no_link

If falsish (the default) then the project's description will be linked to
the "edit project" dialog from the master data menu.

=back

=back

=head1 BUGS

Nothing here yet.

=head1 AUTHOR

Moritz Bunkus E<lt>m.bunkus@linet-services.deE<gt>

=cut