X-Git-Url: http://wagnertech.de/gitweb/gitweb.cgi/mfinanz.git/blobdiff_plain/51fec3106e49e1ffc7d6a0a2c577bea8641efbff..2eb2bc5583f28aa5f9bb18c2cd314995d0570f8c:/SL/Controller/RequirementSpec.pm?ds=inline diff --git a/SL/Controller/RequirementSpec.pm b/SL/Controller/RequirementSpec.pm index 68e060c1c..b72a8c4b4 100644 --- a/SL/Controller/RequirementSpec.pm +++ b/SL/Controller/RequirementSpec.pm @@ -1,6 +1,7 @@ package SL::Controller::RequirementSpec; use strict; +use utf8; use parent qw(SL::Controller::Base); @@ -20,11 +21,12 @@ use SL::DB::RequirementSpecType; use SL::DB::RequirementSpec; use SL::Helper::Flash; use SL::Locale::String; +use SL::Template::LaTeX; use Rose::Object::MakeMethods::Generic ( scalar => [ qw(requirement_spec_item customers types statuses db_args flat_filter is_template visible_item visible_section) ], - 'scalar --get_set_init' => [ qw(requirement_spec complexities risks projects copy_source) ], + 'scalar --get_set_init' => [ qw(requirement_spec complexities risks projects copy_source js) ], ); __PACKAGE__->run_before('setup'); @@ -101,9 +103,9 @@ sub action_ajax_cancel_time_and_cost_estimate { my $html = $self->render('requirement_spec/_show_time_and_cost_estimate', { output => 0 }); - SL::ClientJS->new - ->replaceWith('#time_cost_estimate', $html) - ->render($self); + $self->js + ->replaceWith('#time_cost_estimate', $html) + ->render($self); } sub action_ajax_edit_time_and_cost_estimate { @@ -111,9 +113,9 @@ sub action_ajax_edit_time_and_cost_estimate { my $html = $self->render('requirement_spec/_edit_time_and_cost_estimate', { output => 0 }); - SL::ClientJS->new - ->replaceWith('#time_cost_estimate', $html) - ->render($self); + $self->js + ->replaceWith('#time_cost_estimate', $html) + ->render($self); } sub action_ajax_save_time_and_cost_estimate { @@ -133,14 +135,14 @@ sub action_ajax_save_time_and_cost_estimate { }); my $html = $self->render('requirement_spec/_show_time_and_cost_estimate', { output => 0 }); - my $js = SL::ClientJS->new->replaceWith('#time_cost_estimate', $html); + $self->js->replaceWith('#time_cost_estimate', $html); if ($self->visible_section) { $html = $self->render('requirement_spec_item/_section', { output => 0 }, requirement_spec_item => $self->visible_section); - $js->html('#column-content', $html); + $self->js->html('#column-content', $html); } - $js->render($self); + $self->js->render($self); } sub action_show { @@ -176,12 +178,36 @@ sub action_destroy { $self->redirect_to(action => 'list'); } -sub action_reorder { - my ($self) = @_; +sub action_revert_to { + my ($self, %params) = @_; + + return $self->js->error(t8('Cannot revert a versioned copy.'))->render($self) if $self->requirement_spec->working_copy_id; + + 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, + ); + + 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); +} + +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); + + $::form->error(t8('Conversion to PDF failed: #1', $result{error})) if $result{error}; - SL::DB::RequirementSpec->reorder_list(@{ $::form->{requirement_spec_id} || [] }); + my $attachment_name = $self->requirement_spec->type->description . ' ' . ($self->requirement_spec->working_copy_id || $self->requirement_spec->id); + $attachment_name .= ' (v' . $self->requirement_spec->version->version_number . ')' if $self->requirement_spec->version; + $attachment_name .= '.pdf'; + $attachment_name =~ s/[^\wäöüÄÖÜß \-\+\(\)\[\]\{\}\.,]+/_/g; - $self->render('1;', { type => 'js', inline => 1 }); + $self->send_file($result{file_name}, type => 'application/pdf', name => $attachment_name); + unlink $result{file_name}; } # @@ -225,6 +251,11 @@ sub init_copy_source { $self->copy_source(SL::DB::RequirementSpec->new(id => $::form->{copy_source_id})->load) if $::form->{copy_source_id}; } +sub init_js { + my ($self) = @_; + $self->js(SL::ClientJS->new); +} + sub load_select_options { my ($self) = @_; @@ -251,7 +282,7 @@ sub create_or_update { my @errors = $self->requirement_spec->validate; if (@errors) { - return SL::ClientJS->new->error(@errors)->render($self) if $::request->is_ajax; + return $self->js->error(@errors)->render($self) if $::request->is_ajax; flash('error', @errors); $self->render('requirement_spec/new', title => $title); @@ -268,7 +299,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); - return SL::ClientJS->new->error(@errors)->render($self) if $::request->is_ajax; + return $self->js->error(@errors)->render($self) if $::request->is_ajax; $self->requirement_spec->id(undef) if $is_new; flash('error', @errors); @@ -277,7 +308,7 @@ sub create_or_update { if ($::request->is_ajax) { my $html = $self->render('requirement_spec/_header', { output => 0 }); - return SL::ClientJS->new + return $self->invalidate_version ->replaceWith('#requirement-spec-header', $html) ->flash('info', t8('The requirement spec has been saved.')) ->render($self); @@ -351,4 +382,15 @@ sub prepare_report { $self->disable_pagination if $report->{options}{output_format} =~ /^(pdf|csv)$/i; } +sub invalidate_version { + my ($self) = @_; + + my $rspec = SL::DB::RequirementSpec->new(id => $self->requirement_spec->id)->load; + $rspec->invalidate_version; + + my $html = $self->render('requirement_spec/_version', { output => 0 }, requirement_spec => $rspec); + return $self->js->html('#requirement_spec_version', $html); +} + + 1;