X-Git-Url: http://wagnertech.de/gitweb/gitweb.cgi/mfinanz.git/blobdiff_plain/cced2d9f2e54131bd8eb8001adb9d1bdd9415810..8388c9bf9ba2e2a1fe5b49b4797ed74d1a42a1dc:/SL/Controller/RequirementSpecTextBlock.pm diff --git a/SL/Controller/RequirementSpecTextBlock.pm b/SL/Controller/RequirementSpecTextBlock.pm index 964ddbabc..1901ce87c 100644 --- a/SL/Controller/RequirementSpecTextBlock.pm +++ b/SL/Controller/RequirementSpecTextBlock.pm @@ -5,10 +5,12 @@ use strict; use parent qw(SL::Controller::Base); use Carp; +use Params::Validate (); use Time::HiRes (); use SL::ClientJS; use SL::Clipboard; +use SL::Controller::Helper::RequirementSpec; use SL::DB::RequirementSpec; use SL::DB::RequirementSpecPredefinedText; use SL::DB::RequirementSpecTextBlock; @@ -43,15 +45,7 @@ sub action_ajax_list { # $::lxdebug->message(0, "cur $current_where new $new_where"); - if (!defined($current_where) || ($new_where != $current_where)) { - my $text_blocks = SL::DB::Manager::RequirementSpecTextBlock->get_all_sorted(where => [ output_position => $new_where, requirement_spec_id => $::form->{requirement_spec_id} ]); - my $html = $self->render('requirement_spec_text_block/ajax_list', { output => 0 }, TEXT_BLOCKS => $text_blocks, output_position => $new_where); - - $self->js - ->html('#column-content', $html) - ->val('#current_content_type', 'text-blocks-' . (0 == $new_where ? 'front' : 'back')) - ->val('#current_content_id', $::form->{clicked_id}); - } + $self->show_list(output_position => $new_where, id => $::form->{clicked_id}, set_type => 1) if ($new_where != ($current_where // -1)); $self->render($self->js); } @@ -62,14 +56,9 @@ sub action_ajax_add { my $current_where = $self->output_position_from_id($::form->{current_content_id}, $::form->{current_content_type}) // -1; my $new_where = $self->output_position_from_id($::form->{id}) // $::form->{output_position}; - if ($new_where != $current_where) { - my $text_blocks = SL::DB::Manager::RequirementSpecTextBlock->get_all_sorted(where => [ output_position => $new_where, requirement_spec_id => $::form->{requirement_spec_id} ]); - my $html = $self->render('requirement_spec_text_block/ajax_list', { output => 0 }, TEXT_BLOCKS => $text_blocks, output_position => $new_where); - - $self->js->html('#column-content', $html); - } + $self->show_list(output_position => $new_where) if $new_where != $current_where; - $self->add_new_text_block_form(output_position => $new_where, insert_after_id => $::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->render($self); } @@ -78,14 +67,9 @@ sub action_ajax_edit { my ($self) = @_; my $current_where = $self->output_position_from_id($::form->{current_content_id}, $::form->{current_content_type}) // -1; - if ($self->text_block->output_position != $current_where) { - my $text_blocks = $self->text_block->get_full_list; - my $html = $self->render('requirement_spec_text_block/ajax_list', { output => 0 }, TEXT_BLOCKS => $text_blocks, output_position => $self->text_block->output_position); - $self->js - ->html('#column-content', $html) - ->val('#current_content_type', 'text-block') - ->val('#current_content_id', $self->text_block->id); + if ($self->text_block->output_position != $current_where) { + $self->show_list(output_position => $self->text_block->output_position, id => $self->text_block->id, requirement_spec_id => $self->text_block->requirement_spec_id); } my $html = $self->render('requirement_spec_text_block/_form', { output => 0 }); @@ -115,9 +99,11 @@ sub action_ajax_create { my $node = $self->presenter->requirement_spec_text_block_jstree_data($self->text_block); $self->invalidate_version + ->hide('#text-block-list-empty') ->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); } @@ -208,12 +194,7 @@ sub action_dragged_and_dropped { if (($old_where != $new_where) && ($::form->{current_content_id} == $self->text_block->id)) { # The currently selected text block is dragged to the opposite # text block location. Re-render the whole content column. - my $text_blocks = SL::DB::Manager::RequirementSpecTextBlock->get_all_sorted(where => [ output_position => $new_where ]); - my $html = $self->render('requirement_spec_text_block/ajax_list', { output => 0 }, TEXT_BLOCKS => $text_blocks, output_position => $new_where); - - $self->js - ->val('#current_content_type', 'text-blocks-' . ($new_where == 0 ? 'front' : 'back')) - ->html('#column-content', $html); + $self->show_list(output_position => $new_where, id => $id); } else { if ($old_where == $current_where) { @@ -324,10 +305,11 @@ sub invalidate_version { 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 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 => $::form->{requirement_spec_id}, + requirement_spec_id => $params{requirement_spec_id}, output_position => $params{output_position}, )); @@ -339,4 +321,22 @@ sub add_new_text_block_form { ->focus('#' . $id_base . '_title'); } +sub show_list { + my $self = shift; + my %params = Params::Validate::validate(@_, { output_position => 1, id => 0, requirement_spec_id => 0, set_type => 0, }); + + $params{requirement_spec_id} ||= $::form->{requirement_spec_id}; + croak "Unknown requirement_spec_id" if !$params{requirement_spec_id}; + + my $text_blocks = SL::DB::Manager::RequirementSpecTextBlock->get_all_sorted(where => [ output_position => $params{output_position}, requirement_spec_id => $params{requirement_spec_id} ]); + my $html = $self->render('requirement_spec_text_block/ajax_list', { output => 0 }, TEXT_BLOCKS => $text_blocks, output_position => $params{output_position}); + + $self->js->html('#column-content', $html); + + $self->js->val('#current_content_type', 'text-blocks-' . (0 == $params{output_position} ? 'front' : 'back')) if $params{id} || $params{set_type}; + $self->js->val('#current_content_id', $params{id}) if $params{id}; + + return $self->set_function_blocks_tab_menu_class(class => 'text-block-context-menu'); +} + 1;