Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 48d73a85

Von Moritz Bunkus vor mehr als 10 Jahren hinzugefügt

  • ID 48d73a85a323578cf2fafde0f6716dd164213856
  • Vorgänger a202449b
  • Nachfolger dfa92a5e

Pflichtenheftitems: Typen direkt in Tabelle speichern

Unterschiede anzeigen:

SL/Controller/RequirementSpecItem.pm
41 41
  }
42 42

  
43 43
  my $clicked_item = SL::DB::RequirementSpecItem->new(id => $::form->{clicked_id})->load;
44
  $self->item($clicked_item->get_section);
44
  $self->item($clicked_item->section);
45 45

  
46 46
  if (!$self->visible_section || ($self->visible_section->id != $self->item->id)) {
47 47
    $self->render_list($js, $self->item, $clicked_item);
......
60 60

  
61 61
  my $old_visible_section = $self->visible_section ? $self->visible_section : undef;
62 62
  my $old_parent_id       = $self->item->parent_id;
63
  my $old_type            = $self->item->get_type;
63
  my $old_type            = $self->item->item_type;
64 64

  
65 65
  $self->item->db->do_transaction(sub {
66 66
    $self->item->remove_from_list;
......
71 71
  my $js = SL::ClientJS->new;
72 72

  
73 73
  $self->item(SL::DB::RequirementSpecItem->new(id => $self->item->id)->load);
74
  my $new_section         = $self->item->get_section;
75
  my $new_type            = $self->item->get_type;
76
  my $new_visible_section = SL::DB::RequirementSpecItem->new(id => $self->visible_item->id)->load->get_section;
74
  my $new_section         = $self->item->section;
75
  my $new_type            = $self->item->item_type;
76
  my $new_visible_section = SL::DB::RequirementSpecItem->new(id => $self->visible_item->id)->load->section;
77 77

  
78 78
  return $self->render($js) if !$old_visible_section || ($new_type eq 'section');
79 79

  
80 80
  # From here on $old_visible_section is definitely set.
81 81

  
82 82
  my $old_parent  = SL::DB::RequirementSpecItem->new(id => $old_parent_id)->load;
83
  my $old_section = $old_parent->get_section;
83
  my $old_section = $old_parent->section;
84 84

  
85 85
  # $::lxdebug->message(0, "old sec ID " . $old_section->id . " new " . $new_section->id . " old visible " . $old_visible_section->id . " new visible " . $new_visible_section->id
86 86
  #                       . " PARENT: old " . $old_parent->id . " new " . $self->item->parent_id . '/' . $self->item->parent->id);
......
115 115
    if ($next_item) {
116 116
      $js->insertBefore($html, '#' . $id_prefix . 'function-block-' . $next_item->id);
117 117
    } else {
118
      my $parent_is_section = $self->item->parent->get_type eq 'section';
118
      my $parent_is_section = $self->item->parent->item_type eq 'section';
119 119
      $js->appendTo($html, $parent_is_section ? '#section-list' : '#sub-function-block-container-' . $self->item->parent_id);
120 120
      $js->show('#sub-function-block-container-' . $self->item->parent_id) if !$parent_is_section;
121 121
    }
......
133 133

  
134 134
  die "Missing parameter 'requirement_spec_id'" if !$::form->{requirement_spec_id};
135 135

  
136
  $self->item(SL::DB::RequirementSpecItem->new(requirement_spec_id => $::form->{requirement_spec_id}));
136
  $self->item(SL::DB::RequirementSpecItem->new(requirement_spec_id => $::form->{requirement_spec_id}, item_type => 'section'));
137 137

  
138
  my $insert_after = $::form->{id} ? SL::DB::RequirementSpecItem->new(id => $::form->{id})->load->get_section->id : undef;
138
  my $insert_after = $::form->{id} ? SL::DB::RequirementSpecItem->new(id => $::form->{id})->load->section->id : undef;
139 139
  my $html         = $self->render('requirement_spec_item/_section_form', { output => 0 }, id_base => 'new_section', insert_after => $insert_after);
140 140

  
141 141
  SL::ClientJS->new
......
172 172
  $self->item->save;
173 173
  $self->item->add_to_list(position => 'after', reference => $insert_after) if $insert_after;
174 174

  
175
  my $type = $self->item->get_type;
175
  my $type = $self->item->item_type;
176 176

  
177 177
  if ($type eq 'section') {
178 178
    my $node = $self->presenter->requirement_spec_item_jstree_data($self->item);
......
203 203

  
204 204
  my $js = SL::ClientJS->new;
205 205

  
206
  if (!$self->visible_section || ($self->visible_section->id != $self->item->get_section->id)) {
206
  if (!$self->visible_section || ($self->visible_section->id != $self->item->section->id)) {
207 207
    # Show section/item to edit if it is not visible.
208 208

  
209 209
    my $html = $self->render('requirement_spec_item/_section', { output => 0 }, requirement_spec_item => $self->item);
210 210
    $js->html('#column-content', $html);
211 211
  }
212 212

  
213
  if ($self->item->get_type =~ m/section/) {
213
  if ($self->item->item_type =~ m/section/) {
214 214
    # Edit the section header, not an item.
215 215
    my $html = $self->render('requirement_spec_item/_section_form', { output => 0 });
216 216

  
......
231 231

  
232 232
  my $html                  = $self->render('requirement_spec_item/_function_block_form', { output => 0 }, DEPENDENCIES => \@dependencies, SELECTED_DEPENDENCIES => \@selected_dependencies);
233 233
  my $id_base               = 'edit_function_block_' . $self->item->id;
234
  my $content_top_id        = '#' . $self->item->get_type . '-content-top-' . $self->item->id;
234
  my $content_top_id        = '#' . $self->item->item_type . '-content-top-' . $self->item->id;
235 235

  
236 236
  $js->hide($content_top_id)
237 237
     ->remove("#${id_base}_form")
238 238
     ->insertAfter($html, $content_top_id)
239 239
     ->jstree->select_node('#tree', '#fb-' . $self->item->id)
240 240
     ->focus("#${id_base}_description")
241
     ->val('#current_content_type', $self->item->get_type)
241
     ->val('#current_content_type', $self->item->item_type)
242 242
     ->val('#current_content_id', $self->item->id)
243 243
     ->render($self);
244 244
}
......
259 259

  
260 260
  $self->item->save;
261 261

  
262
  my $type = $self->item->get_type;
262
  my $type = $self->item->item_type;
263 263

  
264 264
  if ($type eq 'section') {
265 265
    # Updated section, now update section header.
......
315 315
         ->val('#current_content_id', '')
316 316
    }
317 317

  
318
  } elsif ($self->visible_section && ($self->visible_section->id == $self->item->get_section->id)) {
318
  } elsif ($self->visible_section && ($self->visible_section->id == $self->item->section->id)) {
319 319
    # Item in currently visible section is deleted.
320 320

  
321
    my $type = $self->item->get_type;
321
    my $type = $self->item->item_type;
322 322
    $js->remove('#edit_function_block_' . $self->item->id . '_form')
323 323
       ->remove('#' . $type . '-' . $self->item->id);
324 324

  
......
342 342

  
343 343
  $self->item->update_attributes(is_flagged => !$self->item->is_flagged);
344 344

  
345
  my $is_visible = $self->visible_section && ($self->visible_section->id == $self->item->get_section->id);
345
  my $is_visible = $self->visible_section && ($self->visible_section->id == $self->item->section->id);
346 346

  
347 347
  SL::ClientJS->new
348
   ->action_if($is_visible, 'toggleClass', '#' . $self->item->get_type . '-' . $self->item->id, 'flagged')
348
   ->action_if($is_visible, 'toggleClass', '#' . $self->item->item_type . '-' . $self->item->id, 'flagged')
349 349
   ->toggleClass('#fb-' . $self->item->id, 'flagged')
350 350
   ->render($self);
351 351
}
......
388 388
  $self->visible_item(SL::DB::Manager::RequirementSpecItem->find_by(id => $content_id));
389 389
  return undef unless $self->visible_item;
390 390

  
391
  return $self->visible_section($self->visible_item->get_section);
391
  return $self->visible_section($self->visible_item->section);
392 392
}
393 393

  
394 394
sub init_complexities {
......
407 407
  my ($self, $js, $item_or_id) = @_;
408 408

  
409 409
  my $item      = (ref($item_or_id) ? $item_or_id : SL::DB::RequirementSpecItem->new(id => $item_or_id))->load;
410
  my $id_prefix = $item->get_type eq 'function-block' ? '' : 'sub-';
410
  my $id_prefix = $item->item_type eq 'function-block' ? '' : 'sub-';
411 411
  my $html      = $self->render('requirement_spec_item/_function_block_content_bottom', { output => 0 }, requirement_spec_item => $item, id_prefix => $id_prefix);
412 412
  return $js->replaceWith('#' . $id_prefix . 'function-block-content-bottom-' . $item->id, $html);
413 413
}
......
422 422
sub select_node {
423 423
  my ($self, $js, $item) = @_;
424 424

  
425
  $js->val( '#current_content_type', $item->get_type)
425
  $js->val( '#current_content_type', $item->item_type)
426 426
     ->val( '#current_content_id',   $item->id)
427 427
     ->jstree->select_node('#tree', '#fb-' . $item->id);
428 428
}
......
452 452
  die "Missing parameter 'requirement_spec_id'"    if !$::form->{requirement_spec_id};
453 453

  
454 454
  my $clicked_item = SL::DB::RequirementSpecItem->new(id => $clicked_id)->load;
455
  my $clicked_type = $clicked_item->get_type;
455
  my $clicked_type = $clicked_item->item_type;
456 456

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

  
......
466 466
    : $case eq 'sub-function-block:sub-function-block' ? ( 'insertAfter', $clicked_item->id,        $clicked_item->parent_id,         '#sub-function-block-'           )
467 467
    :                                                    die "Invalid combination of 'clicked_type (section)/new_type ($new_type)'";
468 468

  
469
  $self->item(SL::DB::RequirementSpecItem->new(requirement_spec_id => $::form->{requirement_spec_id}, parent_id => $parent_id));
469
  $self->item(SL::DB::RequirementSpecItem->new(requirement_spec_id => $::form->{requirement_spec_id}, parent_id => $parent_id, item_type => $new_type));
470 470

  
471 471
  $display_reference .= $insert_reference if $display_reference =~ m/-$/;
472 472
  my $id_base         = join('_', 'new_function_block', Time::HiRes::gettimeofday(), int rand 1000000000000);
......
482 482

  
483 483
  my $js = SL::ClientJS->new;
484 484

  
485
  my $new_section = $self->item->get_section;
485
  my $new_section = $self->item->section;
486 486
  if (!$self->visible_section || ($self->visible_section->id != $new_section->id)) {
487 487
    # Show section/item to edit if it is not visible.
488 488

  
SL/DB/MetaSetup/RequirementSpecItem.pm
12 12
  columns => [
13 13
    id                   => { type => 'serial', not_null => 1 },
14 14
    requirement_spec_id  => { type => 'integer', not_null => 1 },
15
    item_type            => { type => 'text', not_null => 1 },
15 16
    parent_id            => { type => 'integer' },
16 17
    position             => { type => 'integer', not_null => 1 },
17 18
    fb_number            => { type => 'text', not_null => 1 },
SL/DB/RequirementSpecItem.pm
2 2

  
3 3
use strict;
4 4

  
5
use Carp;
6

  
5 7
use SL::DB::MetaSetup::RequirementSpecItem;
6 8
use SL::DB::Manager::RequirementSpecItem;
7 9
use SL::DB::Helper::ActsAsList;
......
78 80
}
79 81

  
80 82
sub sorted_children {
81
  my ($self) = @_;
83
  my ($self, @args) = @_;
84

  
85
  croak "Not a writer" if @args;
82 86

  
83 87
  return [ sort { $a->position <=> $b->position } @{ $self->children } ];
84 88
}
85 89

  
86
sub get_section {
87
  my ($self) = @_;
90
sub section {
91
  my ($self, @args) = @_;
88 92

  
93
  croak "Not a writer" if @args;
89 94
  $self = $self->parent while $self->parent_id;
90 95

  
91 96
  return $self;
92 97
}
93 98

  
94
sub get_type {
95
  my ($self) = @_;
99
sub child_type {
100
  my ($self, @args) = @_;
101

  
102
  croak "Not a writer" if @args;
96 103

  
97
  return 'section' if !$self->parent_id;
98
  return $self->parent->parent_id ? 'sub-function-block' : 'function-block';
104
  return $self->item_type eq 'section' ? 'function-block' : 'sub-function-block';
99 105
}
100 106

  
101 107
1;
templates/webpages/requirement_spec_item/_function_block_form.html
2 2
[% DEFAULT id_base = 'edit_function_block_' _ SELF.item.id %]
3 3
[%- SET a_options = '' %]
4 4
[%- IF SELF.item.id %]
5
 [%- SET a_options = "to_show: '#" _ SELF.item.get_type _ "-content-top-" _ SELF.item.id _ "'" %]
5
 [%- SET a_options = "to_show: '#" _ SELF.item.item_type _ "-content-top-" _ SELF.item.id _ "'" %]
6 6
[%- END %]
7
[%- IF SELF.item.get_type == 'sub-function-block' %]
7
[%- IF SELF.item.item_type == 'sub-function-block' %]
8 8
 [%- SET a_options = a_options ? a_options _ ', ' : a_options %]
9 9
 [%- SET a_options = a_options _ "to_hide_if_empty: '#sub-function-block-container-" _ SELF.item.parent_id _ "'" %]
10 10
[%- END %]
......
13 13
 [% L.hidden_tag('id',                             SELF.item.id, id=id_base _ '_id') %]
14 14
 [% L.hidden_tag(id_base _ '.requirement_spec_id', SELF.item.requirement_spec_id) %]
15 15
 [% L.hidden_tag(id_base _ '.parent_id',           SELF.item.parent_id) %]
16
 [% L.hidden_tag(id_base _ '.item_type',           SELF.item.item_type) %]
16 17
 [% IF insert_after %]
17 18
  [% L.hidden_tag(id_base _ '.insert_after',       insert_after) %]
18 19
 [% END %]
......
39 40
  <div style="width: 59%">
40 41
[%- IF SELF.item.id -%]
41 42
   [% LxERP.t8("Description of #1", SELF.item.fb_number) %]
42
[%- ELSIF SELF.item.get_type == 'function-block' -%]
43
[%- ELSIF SELF.item.item_type == 'function-block' -%]
43 44
   [%- LxERP.t8("Add function block") %]
44 45
[%- ELSE -%]
45 46
   [%- LxERP.t8("Add sub function block") %]
templates/webpages/requirement_spec_item/_section_form.html
15 15
 [% L.hidden_tag('form_prefix',                    id_base       id=id_base _ '_form_prefix') %]
16 16
 [% L.hidden_tag('id',                             SELF.item.id, id=id_base _ '_id') %]
17 17
 [% L.hidden_tag(id_base _ '.requirement_spec_id', SELF.item.requirement_spec_id) %]
18
 [% L.hidden_tag(id_base _ '.item_type',           'section') %]
18 19
 [% IF insert_after %]
19 20
  [% L.hidden_tag(id_base _ '.insert_after',       insert_after) %]
20 21
 [% END %]

Auch abrufbar als: Unified diff