X-Git-Url: http://wagnertech.de/gitweb/gitweb.cgi/mfinanz.git/blobdiff_plain/603481b2eab49e4e70b43cc9cec269c426fffb9d..5723fbf943e494ce9ffd6f9fc44251eb04d3362c:/SL/Controller/RequirementSpecTextBlock.pm?ds=inline diff --git a/SL/Controller/RequirementSpecTextBlock.pm b/SL/Controller/RequirementSpecTextBlock.pm index 34d4aec52..589e52fd2 100644 --- a/SL/Controller/RequirementSpecTextBlock.pm +++ b/SL/Controller/RequirementSpecTextBlock.pm @@ -4,6 +4,7 @@ use strict; use parent qw(SL::Controller::Base); +use Carp; use Time::HiRes (); use SL::ClientJS; @@ -68,18 +69,9 @@ sub action_ajax_add { $self->js->html('#column-content', $html); } - $self->text_block(SL::DB::RequirementSpecTextBlock->new( - requirement_spec_id => $::form->{requirement_spec_id}, - output_position => $::form->{output_position}, - )); - - my $id_base = join('_', 'new_text_block', Time::HiRes::gettimeofday(), int rand 1000000000000); - my $html = $self->render('requirement_spec_text_block/_form', { output => 0 }, id_base => $id_base, insert_after => $::form->{id}); + $self->add_new_text_block_form(output_position => $new_where, insert_after_id => $::form->{id}, requirement_spec_id => $::form->{requirement_spec_id}); - $self->invalidate_version - ->action($::form->{id} ? 'insertAfter' : 'appendTo', $html, '#text-block-' . ($::form->{id} || 'list')) - ->focus('#' . $id_base . '_title') - ->render($self); + $self->invalidate_version->render($self); } sub action_ajax_edit { @@ -125,7 +117,8 @@ sub action_ajax_create { $self->invalidate_version ->replaceWith('#' . $::form->{form_prefix} . '_form', $html) ->jstree->create_node('#tree', $insert_after ? ('#tb-' . $insert_after, 'after') : ('#tb-' . ($attributes->{output_position} == 0 ? 'front' : 'back'), 'last'), $node) - ->jstree->select_node('#tree', '#tb-' . $self->text_block->id) + ->jstree->select_node('#tree', '#tb-' . $self->text_block->id); + $self->add_new_text_block_form(output_position => $self->text_block->output_position, insert_after_id => $self->text_block->id, requirement_spec_id => $self->text_block->requirement_spec_id) ->render($self); } @@ -203,7 +196,10 @@ sub action_dragged_and_dropped { # $::lxdebug->dump(0, "form", $::form); - return $self->invalidate_version->render($self) if $::form->{current_content_type} !~ m/^text-block/; + $self->invalidate_version + ->jstree->open_node('#tree', '#tb-' . (!$self->text_block->output_position ? 'front' : 'back')); + + return $self->js->render($self) if $::form->{current_content_type} !~ m/^text-block/; my $current_where = $self->output_position_from_id($::form->{current_content_id}, $::form->{current_content_type}) // -1; my $new_where = $self->text_block->output_position; @@ -244,8 +240,7 @@ sub action_dragged_and_dropped { } } - $self->invalidate_version - ->render($self); + $self->js->render($self); } sub action_ajax_copy { @@ -327,4 +322,23 @@ sub invalidate_version { return $self->js->html('#requirement_spec_version', $html); } +sub add_new_text_block_form { + my ($self, %params) = @_; + + croak "Missing parameter output_position" unless defined($params{output_position}) && ($params{output_position} ne ''); + croak "Missing parameter requirement_spec_id" unless $params{requirement_spec_id}; + + $self->text_block(SL::DB::RequirementSpecTextBlock->new( + requirement_spec_id => $params{requirement_spec_id}, + output_position => $params{output_position}, + )); + + my $id_base = join('_', 'new_text_block', Time::HiRes::gettimeofday(), int rand 1000000000000); + my $html = $self->render('requirement_spec_text_block/_form', { output => 0 }, id_base => $id_base, insert_after => $params{insert_after_id}); + + $self->js + ->action($params{insert_after_id} ? 'insertAfter' : 'appendTo', $html, '#text-block-' . ($params{insert_after_id} || 'list')) + ->focus('#' . $id_base . '_title'); +} + 1;