1 package SL::Presenter::Project;
 
   5 use SL::Presenter::EscapedText qw(escape is_escaped);
 
   6 use SL::Presenter::Tag qw(input_tag html_tag name_to_id select_tag);
 
   8 use Exporter qw(import);
 
   9 our @EXPORT_OK = qw(project project_picker);
 
  14   my ($project, %params) = @_;
 
  16   return '' unless $project;
 
  18   $params{display} ||= 'inline';
 
  20   croak "Unknown display type '$params{display}'" unless $params{display} =~ m/^(?:inline|table-cell)$/;
 
  22   my $description = $project->full_description(style => $params{style});
 
  23   my $callback    = $params{callback} ? '&callback=' . $::form->escape($params{callback}) : '';
 
  26     $params{no_link} ? '' : '<a href="controller.pl?action=Project/edit&id=' . escape($project->id) . $callback . '">',
 
  28     $params{no_link} ? '' : '</a>',
 
  34   my ($name, $value, %params) = @_;
 
  36   $value      = SL::DB::Manager::Project->find_by(id => $value) if $value && !ref $value;
 
  37   my $id      = delete($params{id}) || name_to_id($name);
 
  38   my @classes = $params{class} ? ($params{class}) : ();
 
  39   push @classes, 'project_autocomplete';
 
  42     input_tag($name, (ref $value && $value->can('id') ? $value->id : ''), class => "@classes", type => 'hidden', id => $id) .
 
  43     join('', map { $params{$_} ? input_tag("", delete $params{$_}, id => "${id}_${_}", type => 'hidden') : '' } qw(customer_id)) .
 
  44     input_tag("", ref $value ? $value->displayable_name : '', id => "${id}_name", %params);
 
  46   $::request->layout->add_javascripts('autocomplete_project.js');
 
  47   $::request->presenter->need_reinit_widgets($id);
 
  49   html_tag('span', $ret, class => 'project_picker');
 
  52 sub picker { goto &project_picker };
 
  64 SL::Presenter::Project - Presenter module for project Rose::DB objects
 
  68   my $project = SL::DB::Manager::Project->get_first;
 
  69   my $html    = SL::Presenter::Project->project($project, display => 'inline');
 
  75 =item C<project $object, %params>
 
  77 Returns a rendered version (actually an instance of
 
  78 L<SL::Presenter::EscapedText>) of the project object C<$customer>.
 
  80 C<%params> can include:
 
  86 Either C<inline> (the default) or C<table-cell>. At the moment both
 
  87 representations are identical and produce the project's description
 
  88 (controlled by the C<style> parameter) linked to the corresponding
 
  93 Determines what exactly will be output. Can be one of the values with
 
  94 C<both> being the default if it is missing:
 
  98 =item C<projectnumber> (or simply C<number>)
 
 100 Outputs only the project's number.
 
 102 =item C<projectdescription> (or simply C<description>)
 
 104 Outputs only the project's description.
 
 108 Outputs the project's number followed by its description in
 
 109 parenthesis (e.g. "12345 (Secret Combinations)"). If the project's
 
 110 description is already part of the project's number then it will not
 
 117 If falsish (the default) then the project's description will be linked to
 
 118 the "edit project" dialog from the master data menu.
 
 130 Moritz Bunkus E<lt>m.bunkus@linet-services.deE<gt>