kivitendo/SL/Presenter/Project.pm @ cbdc5c37
5b5dbec0 | Moritz Bunkus | package SL::Presenter::Project;
|
||
use strict;
|
||||
use parent qw(Exporter);
|
||||
use Exporter qw(import);
|
||||
fac8417d | Moritz Bunkus | our @EXPORT = qw(project project_picker);
|
||
5b5dbec0 | Moritz Bunkus | |||
use Carp;
|
||||
sub project {
|
||||
my ($self, $project, %params) = @_;
|
||||
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 '', (
|
||||
b2e1809f | Moritz Bunkus | $params{no_link} ? '' : '<a href="controller.pl?action=Project/edit&id=' . $self->escape($project->id) . $callback . '">',
|
||
5b5dbec0 | Moritz Bunkus | $self->escape($description),
|
||
$params{no_link} ? '' : '</a>',
|
||||
);
|
||||
return $self->escaped_text($text);
|
||||
}
|
||||
fac8417d | Moritz Bunkus | sub project_picker {
|
||
my ($self, $name, $value, %params) = @_;
|
||||
$value = SL::DB::Manager::Project->find_by(id => $value) if $value && !ref $value;
|
||||
my $id = delete($params{id}) || $self->name_to_id($name);
|
||||
my @classes = $params{class} ? ($params{class}) : ();
|
||||
push @classes, 'project_autocomplete';
|
||||
my $ret =
|
||||
$self->input_tag($name, (ref $value && $value->can('id') ? $value->id : ''), class => "@classes", type => 'hidden', id => $id) .
|
||||
join('', map { $params{$_} ? $self->input_tag("", delete $params{$_}, id => "${id}_${_}", type => 'hidden') : '' } qw(customer_id)) .
|
||||
$self->input_tag("", ref $value ? $value->displayable_name : '', id => "${id}_name", %params);
|
||||
$::request->layout->add_javascripts('autocomplete_project.js');
|
||||
$::request->presenter->need_reinit_widgets($id);
|
||||
$self->html_tag('span', $ret, class => '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;
|
||||
my $html = SL::Presenter->get->project($project, display => 'inline');
|
||||
=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
|