X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;ds=sidebyside;f=SL%2FController%2FRequirementSpec.pm;h=3fa13c0f50e1544499544298dbb81dbaa564830a;hb=aaa2cd9291719d6a8f327606fc5aeeeb172b7ecb;hp=689ef19a8fe0852332df54519850cdff860a6c10;hpb=55e399ab36e9b688a4bfbb7b90422fe33e9e14e7;p=kivitendo-erp.git diff --git a/SL/Controller/RequirementSpec.pm b/SL/Controller/RequirementSpec.pm index 689ef19a8..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); } @@ -86,35 +93,41 @@ sub action_new { $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 { +sub action_ajax_show_basic_settings { my ($self) = @_; - $self->render('requirement_spec/_form', { layout => 0 }, submit_as => 'ajax'); + $self->render('requirement_spec/_show_basic_settings', { layout => 0 }); } -sub action_ajax_show_time_and_cost_estimate { +sub action_ajax_edit { my ($self) = @_; - $self->render('requirement_spec/_show_time_and_cost_estimate', { layout => 0 }); + my $html = $self->render('requirement_spec/_form', { output => 0 }, submit_as => 'ajax'); + + $self->js + ->hide('#basic_settings') + ->after('#basic_settings', $html) + ->render($self); } -sub action_ajax_cancel_time_and_cost_estimate { +sub action_ajax_show_time_and_cost_estimate { my ($self) = @_; - my $html = $self->render('requirement_spec/_show_time_and_cost_estimate', { output => 0 }); - - $self->js - ->replaceWith('#time_cost_estimate', $html) - ->render($self); + $self->render('requirement_spec/_show_time_and_cost_estimate', { layout => 0 }); } 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 - ->replaceWith('#time_cost_estimate', $html) + ->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); } @@ -134,9 +147,15 @@ sub action_ajax_save_time_and_cost_estimate { 1; }); - my $html = $self->render('requirement_spec/_show_time_and_cost_estimate', { output => 0 }); + $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 }, 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); $self->js->html('#column-content', $html); @@ -186,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); @@ -198,7 +216,11 @@ sub action_revert_to { sub action_create_pdf { my ($self, %params) = @_; - my %result = SL::Template::LaTeX->parse_and_create_pdf('requirement_spec.tex', SELF => $self, rspec => $self->requirement_spec); + 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}; @@ -245,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; @@ -332,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; @@ -343,9 +365,12 @@ sub create_or_update { 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 }); + my $header_html = $self->render('requirement_spec/_header', { output => 0 }); + my $basics_html = $self->render('requirement_spec/_show_basic_settings', { output => 0 }); return $self->invalidate_version - ->replaceWith('#requirement-spec-header', $html) + ->replaceWith('#requirement-spec-header', $header_html) + ->replaceWith('#basic_settings', $basics_html) + ->remove('#basic_settings_form') ->flash('info', $info) ->render($self); } @@ -354,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) = @_; @@ -400,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') } }, ); } @@ -476,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;