From cced2d9f2e54131bd8eb8001adb9d1bdd9415810 Mon Sep 17 00:00:00 2001 From: Moritz Bunkus Date: Wed, 17 Jul 2013 15:43:20 +0200 Subject: [PATCH] Refactoring --- SL/Controller/RequirementSpecTextBlock.pm | 32 +++++++++++++++-------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/SL/Controller/RequirementSpecTextBlock.pm b/SL/Controller/RequirementSpecTextBlock.pm index 9fe3b9b83..964ddbabc 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}); - $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 { @@ -329,4 +321,22 @@ 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 ''); + + $self->text_block(SL::DB::RequirementSpecTextBlock->new( + requirement_spec_id => $::form->{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; -- 2.20.1