Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 69d4e8e8

Von Sven Schöling vor fast 7 Jahren hinzugefügt

  • ID 69d4e8e828afe0b06baf896eb9bac7feb27a018a
  • Vorgänger 4d90276b
  • Nachfolger 5f67a255

Presenter::RecordItem: cvar_inputs_as_block

Unterschiede anzeigen:

SL/Presenter/ALL.pm
14 14
use SL::Presenter::Part;
15 15
use SL::Presenter::Project;
16 16
use SL::Presenter::Record;
17
use SL::Presenter::RecordItem;
17 18
use SL::Presenter::RequirementSpec;
18 19
use SL::Presenter::RequirementSpecItem;
19 20
use SL::Presenter::RequirementSpecTextBlock;
......
26 27
our %presenters = (
27 28
  chart                       => 'SL::Presenter::Chart',
28 29
  customer_vendor             => 'SL::Presenter::CustomerVendor',
30
  custom_variable             => 'SL::Presenter::CustomVariable',
29 31
  delivery_order              => 'SL::Presenter::DeliveryOrder',
30 32
  escaped_text                => 'SL::Presenter::EscapedText',
31 33
  invoice                     => 'SL::Presenter::Invoice',
......
35 37
  part                        => 'SL::Presenter::Part',
36 38
  project                     => 'SL::Presenter::Project',
37 39
  record                      => 'SL::Presenter::Record',
40
  record_item                 => 'SL::Presenter::RecordItem',
38 41
  requirement_spec            => 'SL::Presenter::RequirementSpec',
39 42
  requirement_spec_item       => 'SL::Presenter::RequirementSpecItem',
40 43
  requirement_spec_text_block => 'SL::Presenter::RequirementSpecTextBlock',
SL/Presenter/RecordItem.pm
1
package SL::Presenter::RecordItem;
2

  
3
use strict;
4

  
5
use List::UtilsBy qw(partition_by);
6
use SL::Presenter::CustomVariable qw(custom_variable_input_field custom_variable_label);
7
use SL::Presenter::Tag qw(html_tag);
8
use SL::Presenter::EscapedText qw(escape is_escaped);
9

  
10
use Exporter qw(import);
11
our @EXPORT_OK = qw();
12

  
13
sub cvar_inputs_as_block {
14
  my ($obj, %params) = @_;
15

  
16
  return '' unless $obj;
17

  
18
  $params{columns} //= $::myconfig{form_cvars_nr_cols} || 3;
19

  
20
  # all _valid_ of these have to be rendered, either hidden or openly.
21
  # if non-editable should be hidden, filter those out
22
  # partsgroup filtered are done by validity
23

  
24
  my $cvars        = $obj->cvars_by_config;
25
  my $hidden_cvars = [];
26

  
27
  if ($params{hide_non_editable}) {
28
    my %cvars_by_editable = partition_by { $_->config->has_flag('editable') * 1 } @$cvars;
29
    $cvars        = $cvars_by_editable{1};
30
    $hidden_cvars = $cvars_by_editable{0};
31
  }
32

  
33
  my $row_html = '';
34
  my $hidden = join '', map custom_variable_input_field($_, hidden => 1), @$hidden_cvars;
35

  
36
  for my $row (_tuples_of($params{columns} => @$cvars)) {
37
    $row_html .= html_tag('tr', join '', map {
38
      html_tag('th', custom_variable_label($_)),
39
      html_tag('td', custom_variable_input_field($_))
40
    } @$row)
41
  }
42

  
43
  $row_html .= html_tag('tr', html_tag('td', $hidden), style => 'display:hidden');
44

  
45
  $params{table} ? html_tag('table', $row_html, class => 'row2-cvars-table') : $row_html;
46
}
47

  
48
sub _tuples_of {
49
  my ($size, @array) = @_;
50

  
51
  die 'tuple size must be positive' unless defined $size && $size > 0;
52

  
53
  my $number_of_tuples = int(@array / $size) + !!(@array % $size);
54

  
55
  @array ? map [ splice @array, 0, $size ], 1 .. $number_of_tuples : ()
56
}
57

  
58
1;

Auch abrufbar als: Unified diff