]> wagnertech.de Git - mfinanz.git/blobdiff - SL/Controller/RequirementSpec.pm
Projektliste: Sortierung an bob angepasst und Spalten verlinkt
[mfinanz.git] / SL / Controller / RequirementSpec.pm
index d99aa9bbabf0a1295da2b95686fc5dcdfee7c6e2..b72a8c4b4e6110a6483b268e48cd2ad87846a8f7 100644 (file)
@@ -1,6 +1,7 @@
 package SL::Controller::RequirementSpec;
 
 use strict;
+use utf8;
 
 use parent qw(SL::Controller::Base);
 
@@ -20,6 +21,7 @@ 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
 (
@@ -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) = @_;
 
-  SL::DB::RequirementSpec->reorder_list(@{ $::form->{requirement_spec_id} || [] });
+  my %result = SL::Template::LaTeX->parse_and_create_pdf('requirement_spec.tex', SELF => $self, rspec => $self->requirement_spec);
 
-  $self->render('1;', { type => 'js', inline => 1 });
+  $::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);
+  $attachment_name    .=  ' (v' . $self->requirement_spec->version->version_number . ')' if $self->requirement_spec->version;
+  $attachment_name    .=  '.pdf';
+  $attachment_name     =~ s/[^\wäöüÄÖÜß \-\+\(\)\[\]\{\}\.,]+/_/g;
+
+  $self->send_file($result{file_name}, type => 'application/pdf', name => $attachment_name);
+  unlink $result{file_name};
 }
 
 #
@@ -282,7 +308,7 @@ sub create_or_update {
 
   if ($::request->is_ajax) {
     my $html = $self->render('requirement_spec/_header', { output => 0 });
-    return $self->js
+    return $self->invalidate_version
       ->replaceWith('#requirement-spec-header', $html)
       ->flash('info', t8('The requirement spec has been saved.'))
       ->render($self);
@@ -356,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;