X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=SL%2FController%2FRequirementSpecItem.pm;h=3129b43f013458458f3ea5b5a5bf7f4d9d07ff5d;hb=e8ac38a63f43c43b30cdf45bd877e39bf0fd41b1;hp=570a8cb378bcbecf9b99b4494b1261a25680405a;hpb=85c4af4a97e002a6ec7804c7fb28d3c4c0972398;p=kivitendo-erp.git diff --git a/SL/Controller/RequirementSpecItem.pm b/SL/Controller/RequirementSpecItem.pm index 570a8cb37..3129b43f0 100644 --- a/SL/Controller/RequirementSpecItem.pm +++ b/SL/Controller/RequirementSpecItem.pm @@ -23,7 +23,7 @@ use Rose::Object::MakeMethods::Generic 'scalar --get_set_init' => [ qw(complexities risks) ], ); -__PACKAGE__->run_before('load_requirement_spec_item', only => [ qw(dragged_and_dropped ajax_update ajax_edit ajax_delete) ]); +__PACKAGE__->run_before('load_requirement_spec_item', only => [ qw(dragged_and_dropped ajax_update ajax_edit ajax_delete ajax_flag) ]); __PACKAGE__->run_before('init_visible_section'); # @@ -40,22 +40,27 @@ sub action_ajax_list { return $self->render($js); } - $self->item(SL::DB::RequirementSpecItem->new(id => $::form->{clicked_id})->load->get_section); + my $clicked_item = SL::DB::RequirementSpecItem->new(id => $::form->{clicked_id})->load; + $self->item($clicked_item->get_section); - $self->render_list($js, $self->item) if !$self->visible_section || ($self->visible_section->id != $self->item->id); + if (!$self->visible_section || ($self->visible_section->id != $self->item->id)) { + $self->render_list($js, $self->item, $clicked_item); + } else { + $self->select_node($js, $clicked_item); + } $self->render($js); } sub action_dragged_and_dropped { - my ($self) = @_; + my ($self) = @_; - my $position = $::form->{position} =~ m/^ (?: before | after | last ) $/x ? $::form->{position} : die "Unknown 'position' parameter"; - my $dropped_item = $::form->{dropped_id} ? SL::DB::RequirementSpecItem->new(id => $::form->{dropped_id})->load : undef; + my $position = $::form->{position} =~ m/^ (?: before | after | last ) $/x ? $::form->{position} : die "Unknown 'position' parameter"; + my $dropped_item = $::form->{dropped_id} ? SL::DB::RequirementSpecItem->new(id => $::form->{dropped_id})->load : undef; - my $visible_section_id = $self->visible_section ? $self->visible_section->id : undef; - my $old_parent_id = $self->item->parent_id; - my $old_type = $self->item->get_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->get_type; $self->item->db->do_transaction(sub { $self->item->remove_from_list; @@ -66,17 +71,27 @@ sub action_dragged_and_dropped { my $js = SL::ClientJS->new; $self->item(SL::DB::RequirementSpecItem->new(id => $self->item->id)->load); - my $new_section = $self->item->get_section; - my $new_type = $self->item->get_type; + my $new_section = $self->item->get_section; + my $new_type = $self->item->get_type; + my $new_visible_section = SL::DB::RequirementSpecItem->new(id => $self->visible_item->id)->load->get_section; - return $self->render($js) if !$visible_section_id || ($new_type eq 'section'); + return $self->render($js) if !$old_visible_section || ($new_type eq 'section'); + + # From here on $old_visible_section is definitely set. my $old_parent = SL::DB::RequirementSpecItem->new(id => $old_parent_id)->load; my $old_section = $old_parent->get_section; - # $::lxdebug->message(0, "old sec ID " . $old_section->id . " new " . $new_section->id . " visible $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); + + if ($old_visible_section->id != $new_visible_section->id) { + # The currently visible item has been dragged to a different section. + return $self->render_list($js, $new_section, $self->item) + ->render($self); + } - if ($visible_section_id == $old_section->id) { + if ($old_visible_section->id == $old_section->id) { my $id_prefix = $old_type eq 'sub-function-block' ? 'sub-' : ''; $js->remove('#' . $id_prefix . 'function-block-' . $self->item->id); @@ -89,7 +104,7 @@ sub action_dragged_and_dropped { } } - if ($visible_section_id == $new_section->id) { + if ($old_visible_section->id == $new_section->id) { $js->hide('#section-list-empty'); my $id_prefix = $new_type eq 'sub-function-block' ? 'sub-' : ''; @@ -167,7 +182,18 @@ sub action_ajax_create { ->render($self); } - die 'TODO: create item'; + my $template = 'requirement_spec_item/_' . (apply { s/-/_/g; $_ } $type); + my $html = $self->render($template, { output => 0 }, requirement_spec_item => $self->item, id_prefix => $type eq 'function-block' ? '' : 'sub-'); + my $node = $self->presenter->requirement_spec_item_jstree_data($self->item); + + $js->replaceWith('#' . $prefix . '_form', $html) + ->hide('#section-list-empty') + ->jstree->create_node('#tree', $insert_after ? ('#fb-' . $insert_after, 'after') : ('#fb-' . $self->item->parent_id, 'last'), $node) + ->jstree->select_node('#tree', '#fb-' . $self->item->id); + + $self->replace_bottom($js, $self->item->parent) if $type eq 'sub-function-block'; + + $js->render($self); } sub action_ajax_edit { @@ -270,7 +296,8 @@ sub action_ajax_update { sub action_ajax_delete { my ($self) = @_; - my $js = SL::ClientJS->new; + my $js = SL::ClientJS->new; + my $full_list = $self->item->get_full_list; $self->item->delete; @@ -297,7 +324,7 @@ sub action_ajax_delete { $self->replace_bottom($js, $self->item->parent_id) if $type eq 'sub-function-block'; - if (1 == scalar @{ $self->item->get_full_list }) { + if (1 == scalar @{ $full_list }) { if ($type eq 'function-block') { $js->show('#section-list-empty'); } elsif ($type eq 'sub-function-block') { @@ -310,6 +337,19 @@ sub action_ajax_delete { ->render($self); } +sub action_ajax_flag { + my ($self) = @_; + + $self->item->update_attributes(is_flagged => !$self->item->is_flagged); + + my $is_visible = $self->visible_section && ($self->visible_section->id == $self->item->get_section->id); + + SL::ClientJS->new + ->action_if($is_visible, 'toggleClass', '#' . $self->item->get_type . '-' . $self->item->id, 'flagged') + ->toggleClass('#fb-' . $self->item->id, 'flagged') + ->render($self); +} + # # filters # @@ -373,11 +413,16 @@ sub replace_bottom { } sub render_list { - my ($self, $js, $item) = @_; + my ($self, $js, $item, $item_to_select) = @_; my $html = $self->render('requirement_spec_item/_section', { output => 0 }, requirement_spec_item => $item); - $js->html('#column-content', $html) - ->val( '#current_content_type', $item->get_type) + $self->select_node($js->html('#column-content', $html), $item_to_select || $item); +} + +sub select_node { + my ($self, $js, $item) = @_; + + $js->val( '#current_content_type', $item->get_type) ->val( '#current_content_id', $item->id) ->jstree->select_node('#tree', '#fb-' . $item->id); } @@ -400,11 +445,13 @@ sub create_dependencies { sub add_function_block { my ($self, $new_type) = @_; - die "Invalid new_type '$new_type'" if $new_type !~ m/^(?:sub-)?function-block$/; - die "Missing parameter 'id'" if !$::form->{id}; - die "Missing parameter 'requirement_spec_id'" if !$::form->{requirement_spec_id}; + my $clicked_id = $::form->{id} || ($self->visible_item ? $self->visible_item->id : undef); + + die "Invalid new_type '$new_type'" if $new_type !~ m/^(?:sub-)?function-block$/; + die "Missing parameter 'id' and no visible item" if !$clicked_id; + die "Missing parameter 'requirement_spec_id'" if !$::form->{requirement_spec_id}; - my $clicked_item = SL::DB::RequirementSpecItem->new(id => $::form->{id})->load; + my $clicked_item = SL::DB::RequirementSpecItem->new(id => $clicked_id)->load; my $clicked_type = $clicked_item->get_type; die "Invalid clicked_type '$clicked_type'" if $clicked_type !~ m/^(?: section | (?:sub-)? function-block )$/x; @@ -430,7 +477,7 @@ sub add_function_block { SELECTED_DEPENDENCIES => [], requirement_spec_item => $self->item, id_base => $id_base, - insert_after => $insert_reference, + insert_after => $insert_position eq 'insertAfter' ? $insert_reference : undef, ); my $js = SL::ClientJS->new; @@ -449,8 +496,11 @@ sub add_function_block { # $::lxdebug->message(0, "alright! clicked ID " . $::form->{id} . " type $clicked_type new_type $new_type insert_pos $insert_position ref " . ($insert_reference // '') . " parent $parent_id display_ref $display_reference"); $js->action($insert_position, $html, $display_reference) - ->focus("#${id_base}_description") - ->render($self); + ->focus("#${id_base}_description"); + + $js->show('#sub-function-block-container-' . $parent_id) if $new_type eq 'sub-function-block'; + + $js->render($self); } 1;