X-Git-Url: http://wagnertech.de/gitweb/gitweb.cgi/mfinanz.git/blobdiff_plain/9dffe94b2b63322be723ad557ba1e1222185bf1c..1cc65ebc086c1821dfcd08bcc97f8b6255dcec65:/SL/Controller/RequirementSpec.pm?ds=inline diff --git a/SL/Controller/RequirementSpec.pm b/SL/Controller/RequirementSpec.pm index abcfbff1e..689ef19a8 100644 --- a/SL/Controller/RequirementSpec.pm +++ b/SL/Controller/RequirementSpec.pm @@ -26,7 +26,7 @@ use SL::Template::LaTeX; use Rose::Object::MakeMethods::Generic ( scalar => [ qw(requirement_spec_item customers types statuses db_args flat_filter visible_item visible_section) ], - 'scalar --get_set_init' => [ qw(requirement_spec complexities risks projects copy_source js) ], + 'scalar --get_set_init' => [ qw(requirement_spec complexities risks projects copy_source js current_text_block_output_position) ], ); __PACKAGE__->run_before('setup'); @@ -83,7 +83,7 @@ sub action_new { $self->requirement_spec->$_($self->copy_source->$_) for qw(type_id status_id customer_id title hourly_rate) } - $self->render('requirement_spec/new', title => $self->requirement_spec->is_template ? t8('Create a new requirement spec section template') : t8('Create a new requirement spec')); + $self->render('requirement_spec/new', title => $self->requirement_spec->is_template ? t8('Create a new requirement spec template') : t8('Create a new requirement spec')); } sub action_ajax_edit { @@ -148,10 +148,11 @@ sub action_ajax_save_time_and_cost_estimate { sub action_show { my ($self) = @_; - my $item = $::form->{requirement_spec_item_id} ? SL::DB::RequirementSpecItem->new(id => $::form->{requirement_spec_item_id})->load : @{ $self->requirement_spec->sections }[0]; + my $title = $self->requirement_spec->is_template ? t8('Show requirement spec template') : t8('Show requirement spec'); + my $item = $::form->{requirement_spec_item_id} ? SL::DB::RequirementSpecItem->new(id => $::form->{requirement_spec_item_id})->load : @{ $self->requirement_spec->sections }[0]; $self->requirement_spec_item($item); - $self->render('requirement_spec/show', title => t8('Show requirement spec')); + $self->render('requirement_spec/show', title => $title); } sub action_create { @@ -210,6 +211,31 @@ sub action_create_pdf { unlink $result{file_name}; } +sub action_select_template_to_paste { + my ($self) = @_; + + my @templates = grep { @{ $_->sections } || @{ $_->text_blocks } } @{ SL::DB::Manager::RequirementSpec->get_all(where => [ is_template => 1 ], sort_by => 'lower(title)') }; + $self->render('requirement_spec/select_template_to_paste', { layout => 0 }, TEMPLATES => \@templates); +} + +sub action_paste_template { + my ($self, %params) = @_; + + my $template = SL::DB::RequirementSpec->new(id => $::form->{template_id})->load; + my %result = $self->requirement_spec->paste_template($template); + + return $self->js->error($self->requirement_spec->error)->render($self) if !%result; + + $self->render_pasted_text_block($_) for sort { $a->position <=> $b->position } @{ $result{text_blocks} }; + $self->render_pasted_section($_) for sort { $a->position <=> $b->position } @{ $result{sections} }; + + if (@{ $result{sections} } && (($::form->{current_content_type} || 'sections') eq 'sections') && !$::form->{current_content_id}) { + $self->render_first_pasted_section_as_list($result{sections}->[0]); + } + + $self->invalidate_version->render($self); +} + # # filters # @@ -255,6 +281,11 @@ sub init_js { $self->js(SL::ClientJS->new); } +sub init_current_text_block_output_position { + my ($self) = @_; + $self->current_text_block_output_position($::form->{current_content_type} !~ m/^(?:text-blocks|tb)-(front|back)/ ? -1 : $1 eq 'front' ? 0 : 1); +} + sub load_select_options { my ($self) = @_; @@ -277,9 +308,9 @@ sub create_or_update { $self->requirement_spec->assign_attributes(%{ $params }); - my $title = $is_new && $self->requirement_spec->is_template ? t8('Create a new requirement spec section template') + my $title = $is_new && $self->requirement_spec->is_template ? t8('Create a new requirement spec template') : $is_new ? t8('Create a new requirement spec') - : $self->requirement_spec->is_template ? t8('Edit section template') + : $self->requirement_spec->is_template ? t8('Edit requirement spec template') : t8('Edit requirement spec'); my @errors = $self->requirement_spec->validate; @@ -309,7 +340,7 @@ sub create_or_update { return $self->render('requirement_spec/new', title => $title); } - my $info = $self->requirement_spec->is_template ? t8('The section template has been saved.') : t8('The requirement spec has been saved.'); + my $info = $self->requirement_spec->is_template ? t8('The requirement spec template has been saved.') : t8('The requirement spec has been saved.'); if ($::request->is_ajax) { my $html = $self->render('requirement_spec/_header', { output => 0 }); @@ -381,7 +412,7 @@ sub prepare_report { output_format => 'HTML', raw_top_info_text => $self->render('requirement_spec/report_top', { output => 0 }, is_template => $is_template), raw_bottom_info_text => $self->render('requirement_spec/report_bottom', { output => 0 }), - title => $is_template ? t8('Requirement Spec Section Templates') : t8('Requirement Specs'), + title => $is_template ? t8('Requirement Spec Templates') : t8('Requirement Specs'), allow_pdf_export => 1, allow_csv_export => 1, ); @@ -406,4 +437,43 @@ sub invalidate_version { return $self->js->html('#requirement_spec_version', $html); } +sub render_pasted_text_block { + my ($self, $text_block, %params) = @_; + + if ($self->current_text_block_output_position == $text_block->output_position) { + my $html = $self->render('requirement_spec_text_block/_text_block', { output => 0 }, text_block => $text_block); + $self->js + ->appendTo($html, '#text-block-list') + ->hide('#text-block-list-empty'); + } + + my $node = $self->presenter->requirement_spec_text_block_jstree_data($text_block); + my $front_back = $text_block->output_position == 0 ? 'front' : 'back'; + $self->js + ->jstree->create_node('#tree', "#tb-${front_back}", 'last', $node) + ->jstree->open_node( '#tree', "#tb-${front_back}"); +} + +sub render_pasted_section { + my ($self, $item, $parent_id) = @_; + + my $node = $self->presenter->requirement_spec_item_jstree_data($item); + $self->js + ->jstree->create_node('#tree', $parent_id ? "#fb-${parent_id}" : '#sections', 'last', $node) + ->jstree->open_node( '#tree', $parent_id ? "#fb-${parent_id}" : '#sections'); + + $self->render_pasted_section($_, $item->id) for @{ $item->children_sorted }; +} + +sub render_first_pasted_section_as_list { + my ($self, $section, %params) = @_; + + my $html = $self->render('requirement_spec_item/_section', { output => 0 }, requirement_spec_item => $section); + $self->js + ->html('#column-content', $html) + ->val( '#current_content_type', $section->item_type) + ->val( '#current_content_id', $section->id) + ->jstree->select_node('#tree', '#fb-' . $section->id); +} + 1;