X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;ds=sidebyside;f=SL%2FController%2FRequirementSpec.pm;h=3fa13c0f50e1544499544298dbb81dbaa564830a;hb=aaa2cd9291719d6a8f327606fc5aeeeb172b7ecb;hp=6afe9973086b910d3669a526c6e2bcd6771c8d48;hpb=4ee26bcc22fa980555706ca24323ee9c552c1303;p=kivitendo-erp.git diff --git a/SL/Controller/RequirementSpec.pm b/SL/Controller/RequirementSpec.pm index 6afe99730..3fa13c0f5 100644 --- a/SL/Controller/RequirementSpec.pm +++ b/SL/Controller/RequirementSpec.pm @@ -5,8 +5,12 @@ use utf8; use parent qw(SL::Controller::Base); +use File::Spec (); + use SL::ClientJS; +use SL::Common (); use SL::Controller::Helper::GetModels; +use SL::Controller::Helper::Filtered; use SL::Controller::Helper::Paginated; use SL::Controller::Helper::Sorted; use SL::Controller::Helper::ParseFilter; @@ -25,21 +29,21 @@ 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 => [ qw(requirement_spec_item customers types statuses visible_item visible_section) ], 'scalar --get_set_init' => [ qw(requirement_spec complexities risks projects copy_source js current_text_block_output_position) ], ); __PACKAGE__->run_before('setup'); __PACKAGE__->run_before('load_select_options', only => [ qw(new ajax_edit create update list) ]); - -__PACKAGE__->get_models_url_params('flat_filter'); +__PACKAGE__->make_filtered( + MODEL => 'RequirementSpec', + LAUNDER_TO => 'filter' +); __PACKAGE__->make_paginated( - MODEL => 'RequirementSpec', - PAGINATE_ARGS => 'db_args', - ONLY => [ qw(list) ], + MODEL => 'RequirementSpec', + ONLY => [ qw(list) ], ); - __PACKAGE__->make_sorted( MODEL => 'RequirementSpec', ONLY => [ qw(list) ], @@ -64,13 +68,16 @@ __PACKAGE__->make_sorted( sub action_list { my ($self) = @_; - $self->setup_db_args_from_filter; - $self->flat_filter({ map { $_->{key} => $_->{value} } $::form->flatten_variables('filter') }); + my $requirement_specs = $self->get_models( + query => [ + and => [ + working_copy_id => undef, + is_template => $::form->{is_template} ? 1 : 0, + ]], + with_objects => [ 'customer', 'type', 'status', 'project' ], + ); $self->prepare_report; - - my $requirement_specs = $self->get_models(%{ $self->db_args }); - $self->report_generator_list_objects(report => $self->{report}, objects => $requirement_specs); } @@ -113,11 +120,14 @@ sub action_ajax_edit_time_and_cost_estimate { my ($self) = @_; my $html = $self->render('requirement_spec/_edit_time_and_cost_estimate', { output => 0 }); + my $first = ($self->requirement_spec->sections_sorted || [])->[0]; + $first = ($first->children_sorted || [])->[0] if $first; $self->js ->hide('#time_cost_estimate') ->after('#time_cost_estimate', $html) ->on('#time_cost_estimate INPUT[type=text]', 'keydown', 'kivi.requirement_spec.time_cost_estimate_input_key_down') + ->action_if($first && $first->id, 'focus', '#time_and_cost_estimate_form_complexity_id_' . $first->id) ->render($self); } @@ -139,9 +149,12 @@ sub action_ajax_save_time_and_cost_estimate { $self->requirement_spec(SL::DB::RequirementSpec->new(id => $self->requirement_spec->id)->load); - my $html = $self->render('requirement_spec/_show_time_and_cost_estimate', { output => 0 }); - $self->js->replaceWith('#time_cost_estimate', $html) - ->remove('#time_cost_estimate_form_container'); + my $html = $self->render('requirement_spec/_show_time_and_cost_estimate', { output => 0 }, initially_hidden => !!$::form->{keep_open}); + $self->js->replaceWith('#time_cost_estimate', $html); + + return $self->js->render($self) if $::form->{keep_open}; + + $self->js->remove('#time_cost_estimate_form_container'); if ($self->visible_section) { $html = $self->render('requirement_spec_item/_section', { output => 0 }, requirement_spec_item => $self->visible_section); @@ -192,10 +205,9 @@ sub action_revert_to { my $versioned_copy = SL::DB::RequirementSpec->new(id => $::form->{versioned_copy_id})->load; - $self->requirement_spec->copy_from( - $versioned_copy, - version_id => $versioned_copy->version_id, - ); + $self->requirement_spec->copy_from($versioned_copy); + my $version = $versioned_copy->versions->[0]; + $version->update_attributes(working_copy_id => $self->requirement_spec->id); flash_later('info', t8('The requirement spec has been reverted to version #1.', $self->requirement_spec->version->version_number)); $self->js->redirect_to($self->url_for(action => 'show', id => $self->requirement_spec->id))->render($self); @@ -205,8 +217,11 @@ sub action_create_pdf { my ($self, %params) = @_; my $base_name = $self->requirement_spec->type->template_file_name || 'requirement_spec'; + my @pictures = $self->prepare_pictures_for_printing; my %result = SL::Template::LaTeX->parse_and_create_pdf("${base_name}.tex", SELF => $self, rspec => $self->requirement_spec); + unlink @pictures unless ($::lx_office_conf{debug} || {})->{keep_temp_files}; + $::form->error(t8('Conversion to PDF failed: #1', $result{error})) if $result{error}; my $attachment_name = $self->requirement_spec->type->description . ' ' . ($self->requirement_spec->working_copy_id || $self->requirement_spec->id); @@ -252,7 +267,7 @@ sub setup { $::auth->assert('sales_quotation_edit'); $::request->{layout}->use_stylesheet("${_}.css") for qw(jquery.contextMenu requirement_spec); - $::request->{layout}->use_javascript("${_}.js") for qw(jquery.jstree jquery/jquery.contextMenu client_js requirement_spec); + $::request->{layout}->use_javascript("${_}.js") for qw(jquery.jstree jquery/jquery.contextMenu jquery/jquery.hotkeys requirement_spec); $self->init_visible_section; return 1; @@ -339,7 +354,7 @@ sub create_or_update { } })) { $::lxdebug->message(LXDebug::WARN(), "Error: " . $db->error); - @errors = ($::locale->text('Saving failed. Error message from the database: #1'), $db->error); + @errors = ($::locale->text('Saving failed. Error message from the database: #1', $db->error)); return $self->js->error(@errors)->render($self) if $::request->is_ajax; $self->requirement_spec->id(undef) if $is_new; @@ -364,26 +379,6 @@ sub create_or_update { $self->redirect_to(action => 'show', id => $self->requirement_spec->id); } -sub setup_db_args_from_filter { - my ($self) = @_; - - $self->{filter} = {}; - my %args = parse_filter( - $::form->{filter}, - with_objects => [ 'customer', 'type', 'status', 'project' ], - launder_to => $self->{filter}, - ); - - $args{where} = [ - and => [ - @{ $args{where} || [] }, - working_copy_id => undef, - is_template => $::form->{is_template} ? 1 : 0, - ]]; - - $self->db_args(\%args); -} - sub prepare_report { my ($self) = @_; @@ -410,7 +405,7 @@ sub prepare_report { sub => sub { $_[0]->project_id ? $_[0]->project->projectnumber : '' } }, status => { sub => sub { $_[0]->status->description } }, type => { sub => sub { $_[0]->type->description } }, - version => { sub => sub { $_[0]->version_id ? $_[0]->version->version_number : t8('Working copy without version') } }, + version => { sub => sub { $_[0]->version ? $_[0]->version->version_number : t8('Working copy without version') } }, ); } @@ -486,4 +481,25 @@ sub render_first_pasted_section_as_list { ->jstree->select_node('#tree', '#fb-' . $section->id); } +sub prepare_pictures_for_printing { + my ($self) = @_; + + my @files; + my $userspath = File::Spec->rel2abs($::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; +} + 1;