Projekt

Allgemein

Profil

Herunterladen (3,29 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);
use SL::Presenter::Tag qw(input_tag html_tag name_to_id select_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)$/;

b2e1809f Moritz Bunkus
my $description = $project->full_description(style => $params{style});
my $callback = $params{callback} ? '&callback=' . $::form->escape($params{callback}) : '';
5b5dbec0 Moritz Bunkus
my $text = join '', (
0e5e3501 Sven Schöling
$params{no_link} ? '' : '<a href="controller.pl?action=Project/edit&amp;id=' . escape($project->id) . $callback . '">',
escape($description),
5b5dbec0 Moritz Bunkus
$params{no_link} ? '' : '</a>',
);
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>.

C<%params> can include:

=over 2

=item * display

Either C<inline> (the default) or C<table-cell>. At the moment both
representations are identical and produce the project's description
(controlled by the C<style> parameter) linked to the corresponding
'edit' action.

=item * style

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

=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