]> 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 54518b7c51e78ef194f4c07b6912374618cfc7d2..b72a8c4b4e6110a6483b268e48cd2ad87846a8f7 100644 (file)
@@ -1,11 +1,10 @@
 package SL::Controller::RequirementSpec;
 
 use strict;
+use utf8;
 
 use parent qw(SL::Controller::Base);
 
-use Rose::DB::Object::Helpers;
-
 use SL::ClientJS;
 use SL::Controller::Helper::GetModels;
 use SL::Controller::Helper::Paginated;
@@ -22,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');
@@ -52,6 +52,8 @@ __PACKAGE__->make_sorted(
   type          => t8('Requirement Spec Type'),
   status        => t8('Requirement Spec Status'),
   projectnumber => t8('Project Number'),
+  version       => t8('Version'),
+  mtime         => t8('Last modification'),
 );
 
 #
@@ -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);
 
-  SL::DB::RequirementSpec->reorder_list(@{ $::form->{requirement_spec_id} || [] });
+  $::form->error(t8('Conversion to PDF failed: #1', $result{error})) if $result{error};
 
-  $self->render('1;', { type => 'js', inline => 1 });
+  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};
 }
 
 #
@@ -191,7 +217,7 @@ sub action_reorder {
 sub setup {
   my ($self) = @_;
 
-  $::auth->assert('config');
+  $::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);
   $self->is_template($::form->{is_template} ? 1 : 0);
@@ -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);
@@ -267,8 +298,8 @@ sub create_or_update {
     }
   })) {
     $::lxdebug->message(LXDebug::WARN(), "Error: " . $db->error);
-    @errors = ($::locale->text('Saving failed. Erro message from the database: #1'), $db->error);
-    return SL::ClientJS->new->error(@errors)->render($self) if $::request->is_ajax;
+    @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;
     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);
@@ -300,7 +331,8 @@ sub setup_db_args_from_filter {
   $args{where} = [
     and => [
       @{ $args{where} || [] },
-      is_template => $self->is_template
+      working_copy_id => undef,
+      is_template     => $self->is_template
     ]];
 
   $self->db_args(\%args);
@@ -314,8 +346,8 @@ sub prepare_report {
   my $report      = SL::ReportGenerator->new(\%::myconfig, $::form);
   $self->{report} = $report;
 
-  my @columns     = qw(title customer status type projectnumber);
-  my @sortable    = qw(title customer status type projectnumber);
+  my @columns     = qw(title customer status type projectnumber mtime version);
+  my @sortable    = qw(title customer status type projectnumber mtime);
 
   my %column_defs = (
     title         => { obj_link => sub { $self->url_for(action => 'show', id => $_[0]->id, callback => $callback) } },
@@ -325,6 +357,8 @@ 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') } },
+    mtime         => { sub      => sub { $_[0]->mtime->to_kivitendo(precision => 'minute') } },
   );
 
   map { $column_defs{$_}->{text} ||= $::locale->text( $self->get_sort_spec->{$_}->{title} ) } keys %column_defs;
@@ -348,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;