Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 85c4af4a

Von Moritz Bunkus vor mehr als 10 Jahren hinzugefügt

  • ID 85c4af4a97e002a6ec7804c7fb28d3c4c0972398
  • Vorgänger b0ac4850
  • Nachfolger 9a71fdb6

Pflichtenheftitems: Masken für neue (Unter)Funktionsblöcke

Unterschiede anzeigen:

SL/Controller/RequirementSpecItem.pm
4 4

  
5 5
use parent qw(SL::Controller::Base);
6 6

  
7
use Carp;
7 8
use List::MoreUtils qw(apply);
8 9
use List::Util qw(first);
9 10
use Time::HiRes ();
......
23 24
);
24 25

  
25 26
__PACKAGE__->run_before('load_requirement_spec_item', only => [ qw(dragged_and_dropped ajax_update ajax_edit ajax_delete) ]);
26
__PACKAGE__->run_before('init_visible_section',       only => [ qw(dragged_and_dropped ajax_list   ajax_edit ajax_delete) ]);
27
__PACKAGE__->run_before('init_visible_section');
27 28

  
28 29
#
29 30
# actions
......
130 131
    ->render($self);
131 132
}
132 133

  
134
sub action_ajax_add_function_block {
135
  my ($self, %params) = @_;
136

  
137
  return $self->add_function_block('function-block');
138
}
139

  
140
sub action_ajax_add_sub_function_block {
141
  my ($self, %params) = @_;
142

  
143
  return $self->add_function_block('sub-function-block');
144
}
145

  
133 146
sub action_ajax_create {
134 147
  my ($self, %params) = @_;
135 148

  
......
187 200
  }
188 201

  
189 202
  # Edit a function block or a sub function block
190
  my $create_item = sub {
191
    [ $_[0]->id, $self->presenter->truncate(join(' ', grep { $_ } ($_[1], $_[0]->fb_number, $_[0]->description))) ]
192
  };
193
  my @dependencies =
194
    map { [ $_->fb_number . ' ' . $_->title,
195
            [ map { ( $create_item->($_),
196
                      map { $create_item->($_, '->') } @{ $_->sorted_children })
197
                  } @{ $_->sorted_children } ] ]
198
        } @{ $self->item->requirement_spec->sections };
199

  
203
  my @dependencies          = $self->create_dependencies;
200 204
  my @selected_dependencies = map { $_->id } @{ $self->item->dependencies };
201 205

  
202 206
  my $html                  = $self->render('requirement_spec_item/_function_block_form', { output => 0 }, DEPENDENCIES => \@dependencies, SELECTED_DEPENDENCIES => \@selected_dependencies);
......
378 382
     ->jstree->select_node('#tree', '#fb-' . $item->id);
379 383
}
380 384

  
385
sub create_dependency_item {
386
  my $self = shift;
387
  [ $_[0]->id, $self->presenter->truncate(join(' ', grep { $_ } ($_[1], $_[0]->fb_number, $_[0]->description))) ];
388
}
389

  
390
sub create_dependencies {
391
  my ($self) = @_;
392

  
393
  return map { [ $_->fb_number . ' ' . $_->title,
394
                 [ map { ( $self->create_dependency_item($_),
395
                           map { $self->create_dependency_item($_, '->') } @{ $_->sorted_children })
396
                       } @{ $_->sorted_children } ] ]
397
             } @{ $self->item->requirement_spec->sections };
398
}
399

  
400
sub add_function_block {
401
  my ($self, $new_type) = @_;
402

  
403
  die "Invalid new_type '$new_type'"            if $new_type !~ m/^(?:sub-)?function-block$/;
404
  die "Missing parameter 'id'"                  if !$::form->{id};
405
  die "Missing parameter 'requirement_spec_id'" if !$::form->{requirement_spec_id};
406

  
407
  my $clicked_item = SL::DB::RequirementSpecItem->new(id => $::form->{id})->load;
408
  my $clicked_type = $clicked_item->get_type;
409

  
410
  die "Invalid clicked_type '$clicked_type'" if $clicked_type !~ m/^(?: section | (?:sub-)? function-block )$/x;
411

  
412
  my $case = "${clicked_type}:${new_type}";
413

  
414
  my ($insert_position, $insert_reference, $parent_id, $display_reference)
415
    = $case eq 'section:function-block'                ? ( 'appendTo',    $clicked_item->id,        $clicked_item->id,                '#section-list'                  )
416
    : $case eq 'function-block:function-block'         ? ( 'insertAfter', $clicked_item->id,        $clicked_item->parent_id,         '#function-block-'               )
417
    : $case eq 'function-block:sub-function-block'     ? ( 'appendTo'  ,  $clicked_item->id,        $clicked_item->id,                '#sub-function-block-container-' )
418
    : $case eq 'sub-function-block:function-block'     ? ( 'insertAfter', $clicked_item->parent_id, $clicked_item->parent->parent_id, '#function-block-'               )
419
    : $case eq 'sub-function-block:sub-function-block' ? ( 'insertAfter', $clicked_item->id,        $clicked_item->parent_id,         '#sub-function-block-'           )
420
    :                                                    die "Invalid combination of 'clicked_type (section)/new_type ($new_type)'";
421

  
422
  $self->item(SL::DB::RequirementSpecItem->new(requirement_spec_id => $::form->{requirement_spec_id}, parent_id => $parent_id));
423

  
424
  $display_reference .= $insert_reference if $display_reference =~ m/-$/;
425
  my $id_base         = join('_', 'new_function_block', Time::HiRes::gettimeofday(), int rand 1000000000000);
426
  my $html            = $self->render(
427
    'requirement_spec_item/_function_block_form',
428
    { output => 0 },
429
    DEPENDENCIES          => [ $self->create_dependencies ],
430
    SELECTED_DEPENDENCIES => [],
431
    requirement_spec_item => $self->item,
432
    id_base               => $id_base,
433
    insert_after          => $insert_reference,
434
  );
435

  
436
  my $js = SL::ClientJS->new;
437

  
438
  my $new_section = $self->item->get_section;
439
  if (!$self->visible_section || ($self->visible_section->id != $new_section->id)) {
440
    # Show section/item to edit if it is not visible.
441

  
442
    $html = $self->render('requirement_spec_item/_section', { output => 0 }, requirement_spec_item => $new_section);
443
    $js->html('#column-content', $html)
444
       ->val('#current_content_type', 'section')
445
       ->val('#current_content_id',   $new_section->id)
446
       ->jstree->select_node('#tree', '#fb-' . $new_section->id);
447
  }
448

  
449
  # $::lxdebug->message(0, "alright! clicked ID " . $::form->{id} . " type $clicked_type new_type $new_type insert_pos $insert_position ref " . ($insert_reference // '<undef>') . " parent $parent_id display_ref $display_reference");
450

  
451
  $js->action($insert_position, $html, $display_reference)
452
     ->focus("#${id_base}_description")
453
     ->render($self);
454
}
455

  
381 456
1;
templates/webpages/requirement_spec_item/_function_block_form.html
28 28
  </div>
29 29

  
30 30
  <div style="width: 59%">
31
   [% LxERP.t8("Description of #1", SELF.item.fb_number) %]:<br>
31
[%- IF SELF.item.id -%]
32
   [% LxERP.t8("Description of #1", SELF.item.fb_number) %]
33
[%- ELSIF SELF.item.get_type == 'function-block' -%]
34
   [%- LxERP.t8("Add function block") %]
35
[%- ELSE -%]
36
   [%- LxERP.t8("Add sub function block") %]
37
[%- END -%]:<br>
32 38
   [% L.textarea_tag(id_base _ '.description', SELF.item.description, rows=8, style="width: 100%") %]
33 39
  </div>
34 40
 </div>

Auch abrufbar als: Unified diff