]> wagnertech.de Git - mfinanz.git/blobdiff - SL/Controller/RequirementSpecItem.pm
Pflichtenheftitems: Reihenfolge bei Anzeigen Unterfunktionsblockmaske für Focus gefixt
[mfinanz.git] / SL / Controller / RequirementSpecItem.pm
index 98e160ab88d149f9df787efb1334a64fc703e193..6b833f7bf7ea65c904a3584fe39f422b33b52482 100644 (file)
@@ -84,16 +84,17 @@ sub action_dragged_and_dropped {
   my $old_visible_section = $self->visible_section ? $self->visible_section : undef;
   my $old_parent_id       = $self->item->parent_id;
   my $old_type            = $self->item->item_type;
   my $old_visible_section = $self->visible_section ? $self->visible_section : undef;
   my $old_parent_id       = $self->item->parent_id;
   my $old_type            = $self->item->item_type;
+  my $new_type            = $position =~ m/before|after/ ? $dropped_item->item_type : $dropped_item->child_type;
 
   $self->item->db->do_transaction(sub {
     $self->item->remove_from_list;
     $self->item->parent_id($position =~ m/before|after/ ? $dropped_item->parent_id : $dropped_item->id);
 
   $self->item->db->do_transaction(sub {
     $self->item->remove_from_list;
     $self->item->parent_id($position =~ m/before|after/ ? $dropped_item->parent_id : $dropped_item->id);
+    $self->item->item_type($new_type);
     $self->item->add_to_list(position => $position, reference => $::form->{dropped_id} || undef);
   });
 
   $self->item(SL::DB::RequirementSpecItem->new(id => $self->item->id)->load);
   my $new_section         = $self->item->section;
     $self->item->add_to_list(position => $position, reference => $::form->{dropped_id} || undef);
   });
 
   $self->item(SL::DB::RequirementSpecItem->new(id => $self->item->id)->load);
   my $new_section         = $self->item->section;
-  my $new_type            = $self->item->item_type;
   my $new_visible_section = SL::DB::RequirementSpecItem->new(id => $self->visible_item->id)->load->section;
 
   return $self->invalidate_version->render($self) if !$old_visible_section || ($new_type eq 'section');
   my $new_visible_section = SL::DB::RequirementSpecItem->new(id => $self->visible_item->id)->load->section;
 
   return $self->invalidate_version->render($self) if !$old_visible_section || ($new_type eq 'section');
@@ -103,9 +104,13 @@ sub action_dragged_and_dropped {
   my $old_parent  = SL::DB::RequirementSpecItem->new(id => $old_parent_id)->load;
   my $old_section = $old_parent->section;
 
   my $old_parent  = SL::DB::RequirementSpecItem->new(id => $old_parent_id)->load;
   my $old_section = $old_parent->section;
 
+  # Section debug info:
   # $::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
   #                       . " PARENT: old " . $old_parent->id . " new " . $self->item->parent_id . '/' . $self->item->parent->id);
 
   # $::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
   #                       . " PARENT: old " . $old_parent->id . " new " . $self->item->parent_id . '/' . $self->item->parent->id);
 
+  # Item debug info:
+  # $::lxdebug->message(0, 'item id: ' . $self->item->id . " new type: $new_type old type: $old_type #old children: " . scalar(@{ $old_parent->children }));
+
   if ($old_visible_section->id != $new_visible_section->id) {
     # The currently visible item has been dragged to a different section.
     $self->invalidate_version;
   if ($old_visible_section->id != $new_visible_section->id) {
     # The currently visible item has been dragged to a different section.
     $self->invalidate_version;
@@ -172,6 +177,10 @@ sub action_ajax_create {
   my $attributes      = $::form->{$prefix}     || die "Missing parameter group '${prefix}'";
   my $insert_after    = delete $attributes->{insert_after};
 
   my $attributes      = $::form->{$prefix}     || die "Missing parameter group '${prefix}'";
   my $insert_after    = delete $attributes->{insert_after};
 
+  if (!$attributes->{parent_id}) {
+    $attributes->{order_part_id} ||= $::instance_conf->get_requirement_spec_section_order_part_id;
+  }
+
   my @errors = $self->item(SL::DB::RequirementSpecItem->new(%{ $attributes }))->validate;
   return $self->js->error(@errors)->render($self) if @errors;
 
   my @errors = $self->item(SL::DB::RequirementSpecItem->new(%{ $attributes }))->validate;
   return $self->js->error(@errors)->render($self) if @errors;
 
@@ -183,9 +192,11 @@ sub action_ajax_create {
   if ($type eq 'section') {
     my $node = $self->presenter->requirement_spec_item_jstree_data($self->item);
     $self->invalidate_version;
   if ($type eq 'section') {
     my $node = $self->presenter->requirement_spec_item_jstree_data($self->item);
     $self->invalidate_version;
-    return $self->render_list($self->item)
+    $self->render_list($self->item)
+      ->hide('#section-list-empty')
       ->jstree->create_node('#tree', $insert_after ? ('#fb-' . $insert_after, 'after') : ('#sections', 'last'), $node)
       ->jstree->create_node('#tree', $insert_after ? ('#fb-' . $insert_after, 'after') : ('#sections', 'last'), $node)
-      ->jstree->select_node('#tree', '#fb-' . $self->item->id)
+      ->jstree->select_node('#tree', '#fb-' . $self->item->id);
+    return $self->add_new_item_form_after_create
       ->render($self);
   }
 
       ->render($self);
   }
 
@@ -201,6 +212,8 @@ sub action_ajax_create {
 
   $self->replace_bottom($self->item->parent) if $type eq 'sub-function-block';
 
 
   $self->replace_bottom($self->item->parent) if $type eq 'sub-function-block';
 
+  $self->add_new_item_form_after_create;
+
   $self->invalidate_version->render($self);
 }
 
   $self->invalidate_version->render($self);
 }
 
@@ -403,7 +416,7 @@ sub determine_paste_position {
 sub assign_requirement_spec_id_rec {
   my ($self, $item) = @_;
 
 sub assign_requirement_spec_id_rec {
   my ($self, $item) = @_;
 
-  $item->requirement_spec_id($::form->{requirement_spec_id});
+  $item->assign_attributes(requirement_spec_id => $::form->{requirement_spec_id}, fb_number => undef);
   $self->assign_requirement_spec_id_rec($_) for @{ $item->children || [] };
 
   return $item;
   $self->assign_requirement_spec_id_rec($_) for @{ $item->children || [] };
 
   return $item;
@@ -444,7 +457,7 @@ sub action_ajax_paste {
   my ($new_parent_id, $insert_after) = $self->determine_paste_position;
 
   # Store result in database.
   my ($new_parent_id, $insert_after) = $self->determine_paste_position;
 
   # Store result in database.
-  $self->item->update_attributes(requirement_spec_id => $::form->{requirement_spec_id}, parent_id => $new_parent_id);
+  $self->item->update_attributes(parent_id => $new_parent_id);
   $self->item->add_to_list(position => 'after', reference => $insert_after) if $insert_after;
 
   # Update the tree: create the node for all pasted objects.
   $self->item->add_to_list(position => 'after', reference => $insert_after) if $insert_after;
 
   # Update the tree: create the node for all pasted objects.
@@ -547,6 +560,65 @@ sub create_dependencies {
              } @{ $self->item->requirement_spec->sections };
 }
 
              } @{ $self->item->requirement_spec->sections };
 }
 
+sub ensure_section_is_shown {
+  my ($self, %params) = @_;
+
+  return $self->js if $self->is_item_visible;
+
+  # Show section/item to edit if it is not visible.
+  my $new_section = $self->item->section;
+  my $html        = $self->render('requirement_spec_item/_section', { output => 0 }, requirement_spec_item => $new_section);
+
+  return $self->js
+    ->html('#column-content', $html)
+    ->val('#current_content_type', 'section')
+    ->val('#current_content_id',   $new_section->id)
+    ->jstree->select_node('#tree', '#fb-' . $new_section->id);
+}
+
+sub add_new_item_form {
+  my ($self, %params) = @_;
+
+  for (qw(insert_position display_reference)) {
+    croak "Missing parameter $_" if !$params{$_};
+  }
+  croak "Missing parameter insert_reference" if ($params{insert_position} eq 'insertAfter') && !$params{insert_reference};
+
+  my $id_base = join('_', 'new_function_block', Time::HiRes::gettimeofday(), int rand 1000000000000);
+  my $html    = $self->render(
+    'requirement_spec_item/_function_block_form',
+    { output => 0 },
+    DEPENDENCIES          => [ $self->create_dependencies ],
+    SELECTED_DEPENDENCIES => [],
+    requirement_spec_item => $self->item,
+    id_base               => $id_base,
+    insert_after          => $params{insert_position} eq 'insertAfter' ? $params{insert_reference} : undef,
+  );
+
+  return $self->js
+    ->action($params{insert_position}, $html, $params{display_reference})
+    ->focus("#${id_base}_description");
+}
+
+sub add_new_item_form_after_create {
+  my ($self, %params) = @_;
+
+  my $created_item    = $self->item;
+  my $is_section      = $created_item->item_type eq 'section';
+
+  $self->item(SL::DB::RequirementSpecItem->new(
+    requirement_spec_id => $created_item->requirement_spec_id,
+    parent_id           => $is_section ? $created_item->id : $created_item->parent_id,
+    item_type           => $is_section ? 'function-block'  : $created_item->item_type,
+  ));
+
+  $self->add_new_item_form(
+    insert_reference  => $created_item->id,
+    insert_position   => $is_section ? 'appendTo'      : 'insertAfter',
+    display_reference => $is_section ? '#section-list' : '#' . $created_item->item_type . '-' . $created_item->id,
+  );
+}
+
 sub add_function_block {
   my ($self, $new_type) = @_;
 
 sub add_function_block {
   my ($self, $new_type) = @_;
 
@@ -571,38 +643,13 @@ sub add_function_block {
     : $case eq 'sub-function-block:sub-function-block' ? ( 'insertAfter', $clicked_item->id,        $clicked_item->parent_id,         '#sub-function-block-'           )
     :                                                    die "Invalid combination of 'clicked_type (section)/new_type ($new_type)'";
 
     : $case eq 'sub-function-block:sub-function-block' ? ( 'insertAfter', $clicked_item->id,        $clicked_item->parent_id,         '#sub-function-block-'           )
     :                                                    die "Invalid combination of 'clicked_type (section)/new_type ($new_type)'";
 
-  $self->item(SL::DB::RequirementSpecItem->new(requirement_spec_id => $::form->{requirement_spec_id}, parent_id => $parent_id, item_type => $new_type));
-
   $display_reference .= $insert_reference if $display_reference =~ m/-$/;
   $display_reference .= $insert_reference if $display_reference =~ m/-$/;
-  my $id_base         = join('_', 'new_function_block', Time::HiRes::gettimeofday(), int rand 1000000000000);
-  my $html            = $self->render(
-    'requirement_spec_item/_function_block_form',
-    { output => 0 },
-    DEPENDENCIES          => [ $self->create_dependencies ],
-    SELECTED_DEPENDENCIES => [],
-    requirement_spec_item => $self->item,
-    id_base               => $id_base,
-    insert_after          => $insert_position eq 'insertAfter' ? $insert_reference : undef,
-  );
-
-  my $new_section = $self->item->section;
-  if (!$self->is_item_visible) {
-    # Show section/item to edit if it is not visible.
 
 
-    $html = $self->render('requirement_spec_item/_section', { output => 0 }, requirement_spec_item => $new_section);
-    $self->js
-      ->html('#column-content', $html)
-      ->val('#current_content_type', 'section')
-      ->val('#current_content_id',   $new_section->id)
-      ->jstree->select_node('#tree', '#fb-' . $new_section->id);
-  }
-
-  # $::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");
-
-  $self->js->action($insert_position, $html, $display_reference)
-           ->focus("#${id_base}_description");
+  $self->item(SL::DB::RequirementSpecItem->new(requirement_spec_id => $::form->{requirement_spec_id}, parent_id => $parent_id, item_type => $new_type));
 
 
+  $self->ensure_section_is_shown;
   $self->js->show('#sub-function-block-container-' . $parent_id) if $new_type eq 'sub-function-block';
   $self->js->show('#sub-function-block-container-' . $parent_id) if $new_type eq 'sub-function-block';
+  $self->add_new_item_form(insert_position => $insert_position, insert_reference => $insert_reference, display_reference => $display_reference);
 
   $self->js->render($self);
 }
 
   $self->js->render($self);
 }