faafd2685398050ab1b9d3e5373ce2ef135f4575
[kivitendo-erp.git] / SL / Presenter / RequirementSpecItem.pm
1 package SL::Presenter::RequirementSpecItem;
2
3 use strict;
4
5 use parent qw(Exporter);
6
7 use Exporter qw(import);
8 our @EXPORT = qw(requirement_spec_item_tree_node_title requirement_spec_item_jstree_data requirement_spec_item_dependency_list);
9
10 use Carp;
11
12 sub requirement_spec_item_tree_node_title {
13   my ($self, $item) = @_;
14
15   return join(' ', map { $_ || '' } ($item->fb_number, $self->truncate($item->parent_id ? $item->description_as_stripped_html : $item->title, at => 30)));
16 }
17
18 sub requirement_spec_item_jstree_data {
19   my ($self, $item, %params) = @_;
20
21   my @children = map { $self->requirement_spec_item_jstree_data($_, %params) } @{ $item->children_sorted };
22   my $type     = !$item->parent_id ? 'section' : 'function-block';
23   my $class    = $type . '-context-menu tooltip';
24   $class      .= ' flagged' if $item->is_flagged;
25
26   return {
27     data     => $self->requirement_spec_item_tree_node_title($item),
28     metadata => { id =>         $item->id, type => $type },
29     attr     => { id => "fb-" . $item->id, href => $params{href} || '#', class => $class, title => $item->content_excerpt },
30     children => \@children,
31   };
32 }
33
34 sub requirement_spec_item_dependency_list {
35   my ($self, $item) = @_;
36
37   $::locale->language_join([ map { $_->fb_number } @{ $item->dependencies } ]);
38 }
39
40 1;