X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=SL%2FController%2FRequirementSpecItem.pm;h=3129b43f013458458f3ea5b5a5bf7f4d9d07ff5d;hb=e8ac38a63f43c43b30cdf45bd877e39bf0fd41b1;hp=c2f470aba2b25f0e15ecefb45e2985ffc8dfc681;hpb=9a71fdb60ef0a0dcc50b858d34b552f937880778;p=kivitendo-erp.git diff --git a/SL/Controller/RequirementSpecItem.pm b/SL/Controller/RequirementSpecItem.pm index c2f470aba..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 !$old_visible_section || ($new_type eq 'section'); - return $self->render($js) if !$visible_section_id || ($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 ($visible_section_id == $old_section->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 ($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-' : ''; @@ -322,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 # @@ -385,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); }