OrderController: reorder mit Sort::Naturally damit nach Preis ordentlich
[kivitendo-erp.git] / SL / Controller / Project.pm
index 06d4384..11cdd9c 100644 (file)
@@ -12,6 +12,7 @@ use SL::Controller::Helper::ReportGenerator;
 use SL::CVar;
 use SL::DB::Customer;
 use SL::DB::DeliveryOrder;
+use SL::DB::Employee;
 use SL::DB::Invoice;
 use SL::DB::Order;
 use SL::DB::Project;
@@ -29,11 +30,12 @@ use Rose::DB::Object::Helpers qw(as_tree);
 use Rose::Object::MakeMethods::Generic
 (
  scalar => [ qw(project) ],
- 'scalar --get_set_init' => [ qw(models customers project_types project_statuses projects linked_records) ],
+ 'scalar --get_set_init' => [ qw(models customers project_types project_statuses projects linked_records employees may_edit_invoice_permissions) ],
 );
 
 __PACKAGE__->run_before('check_auth',   except => [ qw(ajax_autocomplete) ]);
 __PACKAGE__->run_before('load_project', only   => [ qw(edit update destroy) ]);
+__PACKAGE__->run_before('use_multiselect_js', only => [ qw(new create edit update) ]);
 
 #
 # actions
@@ -51,12 +53,16 @@ sub action_search {
                                   include_prefix => 'l_',
                                   include_value  => 'Y');
 
+  $self->setup_search_action_bar;
+
   $self->render('project/search', %params);
 }
 
 sub action_list {
   my ($self) = @_;
 
+  $self->setup_search_action_bar;
+
   $self->make_filter_summary;
 
   $self->prepare_report;
@@ -69,14 +75,14 @@ sub action_new {
 
   $self->project(SL::DB::Project->new);
   $self->display_form(title    => $::locale->text('Create a new project'),
-                      callback => $::form->{callback} || $self->url_for(action => 'new'));
+                      callback => $::form->{callback} || $self->url_for(action => 'list'));
 }
 
 sub action_edit {
   my ($self) = @_;
 
   $self->display_form(title    => $::locale->text('Edit project #1', $self->project->projectnumber),
-                      callback => $::form->{callback} || $self->url_for(action => 'edit', id => $self->project->id));
+                      callback => $::form->{callback} || $self->url_for(action => 'list'));
 }
 
 sub action_create {
@@ -162,6 +168,8 @@ sub check_auth {
 
 sub init_project_statuses { SL::DB::Manager::ProjectStatus->get_all_sorted }
 sub init_project_types    { SL::DB::Manager::ProjectType->get_all_sorted   }
+sub init_employees        { SL::DB::Manager::Employee->get_all_sorted   }
+sub init_may_edit_invoice_permissions { $::auth->assert('project_edit_view_invoices_permission', 1) }
 
 sub init_linked_records {
   my ($self) = @_;
@@ -219,6 +227,10 @@ sub init_customers {
   return SL::DB::Manager::Customer->get_all_sorted(where => [ or => [ obsolete => 0, obsolete => undef, @customer_id ]]);
 }
 
+sub use_multiselect_js {
+  $::request->layout->use_javascript("${_}.js") for qw(jquery.selectboxes jquery.multiselect2side);
+}
+
 sub display_form {
   my ($self, %params) = @_;
 
@@ -232,6 +244,8 @@ sub display_form {
 
   CVar->render_inputs(variables => $params{CUSTOM_VARIABLES}) if @{ $params{CUSTOM_VARIABLES} };
 
+  $self->setup_edit_action_bar(callback => $params{callback});
+
   $self->render('project/form', %params);
 }
 
@@ -240,6 +254,12 @@ sub create_or_update {
   my $is_new = !$self->project->id;
   my $params = delete($::form->{project}) || { };
 
+  if (!$self->may_edit_invoice_permissions) {
+    delete $params->{employee_invoice_permissions};
+  } elsif (!$params->{employee_invoice_permissions}) {
+    $params->{employee_invoice_permissions} = [];
+  }
+
   delete $params->{id};
   $self->project->assign_attributes(%{ $params });
 
@@ -291,7 +311,7 @@ sub prepare_report {
     project_type  => { sub  => sub { $_[0]->project_type->description } },
     project_status => { sub  => sub { $_[0]->project_status->description }, text => t8('Status') },
     customer      => { sub       => sub { !$_[0]->customer_id ? '' : $_[0]->customer->name },
-                       raw_data  => sub { !$_[0]->customer_id ? '' : $self->presenter->customer($_[0]->customer, display => 'table-cell', callback => $callback) } },
+                       raw_data  => sub { !$_[0]->customer_id ? '' : $_[0]->customer->presenter->customer(display => 'table-cell', callback => $callback) } },
     active        => { sub  => sub { $_[0]->active   ? $::locale->text('Active') : $::locale->text('Inactive') },
                        text => $::locale->text('Active') },
     valid         => { sub  => sub { $_[0]->valid    ? $::locale->text('Valid')  : $::locale->text('Invalid')  },
@@ -372,4 +392,60 @@ sub make_filter_summary {
 
   $self->{filter_summary} = join ', ', @filter_strings;
 }
+
+sub setup_edit_action_bar {
+  my ($self, %params) = @_;
+
+  my $is_new = !$self->project->id;
+
+  for my $bar ($::request->layout->get('actionbar')) {
+    $bar->add(
+      combobox => [
+        action => [
+          t8('Save'),
+          submit    => [ '#form', { action => 'Project/' . ($is_new ? 'create' : 'update') } ],
+          accesskey => 'enter',
+        ],
+        action => [
+          t8('Save as new'),
+          submit   => [ '#form', { action => 'Project/create' }],
+          disabled => $is_new ? t8('The object has not been saved yet.') : undef,
+        ],
+      ], # end of combobox "Save"
+
+      action => [
+        t8('Delete'),
+        submit   => [ '#form', { action => 'Project/destroy' } ],
+        confirm  => $::locale->text('Do you really want to delete this object?'),
+        disabled => $is_new                 ? t8('This object has not been saved yet.')
+                  : $self->project->is_used ? t8('This object has already been used.')
+                  :                           undef,
+      ],
+
+      link => [
+        t8('Abort'),
+        link => $params{callback} || $self->url_for(action => 'list'),
+      ],
+    );
+  }
+}
+
+sub setup_search_action_bar {
+  my ($self, %params) = @_;
+
+  for my $bar ($::request->layout->get('actionbar')) {
+    $bar->add(
+      action => [
+        t8('Update'),
+        submit    => [ '#search_form', { action => 'Project/list' } ],
+        accesskey => 'enter',
+      ],
+      link => [
+        t8('Add'),
+        link => $self->url_for(action => 'new'),
+      ],
+    );
+  }
+}
+
 1;