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   my %data_params = map { $_ => delete $params{$_}  } grep { defined $params{$_} } qw(customer_id active valid description_style);
 
  45     input_tag($name, (ref $value && $value->can('id') ? $value->id : ''), class => "@classes", type => 'hidden', id => $id,
 
  46               'data-project-picker-data' => JSON::to_json(\%data_params),
 
  48     input_tag("", ref $value ? $value->displayable_name : '', id => "${id}_name", %params);
 
  50   $::request->layout->add_javascripts('autocomplete_project.js');
 
  51   $::request->presenter->need_reinit_widgets($id);
 
  53   html_tag('span', $ret, class => 'project_picker');
 
  56 sub picker { goto &project_picker };
 
  68 SL::Presenter::Project - Presenter module for project Rose::DB objects
 
  72   my $project = SL::DB::Manager::Project->get_first;
 
  73   my $html    = SL::Presenter::Project->project($project, display => 'inline');
 
  79 =item C<project $object, %params>
 
  81 Returns a rendered version (actually an instance of
 
  82 L<SL::Presenter::EscapedText>) of the project object C<$customer>.
 
  84 C<%params> can include:
 
  90 Either C<inline> (the default) or C<table-cell>. At the moment both
 
  91 representations are identical and produce the project's description
 
  92 (controlled by the C<style> parameter) linked to the corresponding
 
  97 Determines what exactly will be output. Can be one of the values with
 
  98 C<both> being the default if it is missing:
 
 102 =item C<projectnumber> (or simply C<number>)
 
 104 Outputs only the project's number.
 
 106 =item C<projectdescription> (or simply C<description>)
 
 108 Outputs only the project's description.
 
 112 Outputs the project's number followed by its description in
 
 113 parenthesis (e.g. "12345 (Secret Combinations)"). If the project's
 
 114 description is already part of the project's number then it will not
 
 121 If falsish (the default) then the project's description will be linked to
 
 122 the "edit project" dialog from the master data menu.
 
 134 Moritz Bunkus E<lt>m.bunkus@linet-services.deE<gt>