+ $self->models->set_report_generator_sort_options(report => $report, sortable_columns => \@sortable);
+}
+
+sub invalidate_version {
+ my ($self) = @_;
+
+ my $rspec = SL::DB::RequirementSpec->new(id => $self->requirement_spec->id)->load;
+ return $self->js if $rspec->is_template;
+
+ $rspec->invalidate_version;
+
+ my $html = $self->render('requirement_spec/_version', { output => 0 }, requirement_spec => $rspec);
+ 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 = $text_block->presenter->jstree_data;
+ 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 set_default_filter_args {
+ my ($self) = @_;
+
+ if (!$::form->{filter} && !$::form->{is_template}) {
+ $::form->{filter} = {
+ status_id => [ map { $_->{id} } grep { $_->name ne 'done' } @{ $self->statuses } ],
+ };
+ }
+
+ return 1;
+}
+
+sub render_pasted_section {
+ my ($self, $item, $parent_id) = @_;
+
+ my $node = $item->presenter->jstree_data;
+ $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);
+}
+
+sub prepare_pictures_for_printing {
+ my ($self, $userspath) = @_;
+
+ my @files;
+ $userspath ||= SL::System::Process::exe_dir() . "/" . $::lx_office_conf{paths}->{userspath};
+ my $target = "${userspath}/kivitendo-print-requirement-spec-picture-" . Common::unique_id() . '-';
+
+ foreach my $picture (map { @{ $_->pictures } } @{ $self->requirement_spec->text_blocks }) {
+ my $output_file_name = $target . $picture->id . '.' . $picture->get_default_file_name_extension;
+ $picture->{print_file_name} = File::Spec->abs2rel($output_file_name, $userspath);
+ my $out = IO::File->new($output_file_name, 'w') || die("Could not create file " . $output_file_name);
+ $out->binmode;
+ $out->print($picture->picture_content);
+ $out->close;
+
+ push @files, $output_file_name;
+ }
+
+ return @files;
+}
+
+sub update_project_link_none_keep_existing {
+ my ($self, $action) = @_;
+
+ $self->requirement_spec->update_attributes(project_id => undef) if $action eq 'none';
+ $self->requirement_spec->update_attributes(project_id => $::form->{new_project_id}) if $action eq 'existing';
+
+ return $self->invalidate_version
+ ->replaceWith('#basic_settings', $self->render('requirement_spec/_show_basic_settings', { output => 0 }))
+ ->remove('#project_link_form')
+ ->flash('info', t8('The project link has been updated.'))
+ ->render;
+}
+
+sub update_project_link_new {
+ my ($self) = @_;
+
+ return $self->js
+ ->replaceWith('#project_link_form', $self->render('requirement_spec/_new_project_form', { output => 0 }))
+ ->render;
+}