Projektverwaltung: Fixes nach Rebase; Refactoring
authorMoritz Bunkus <m.bunkus@linet-services.de>
Thu, 23 Jan 2014 13:57:04 +0000 (14:57 +0100)
committerMoritz Bunkus <m.bunkus@linet-services.de>
Tue, 1 Apr 2014 11:12:28 +0000 (13:12 +0200)
SL/Controller/Project.pm
templates/webpages/project/_basic_data.html
templates/webpages/project/_filter.html
templates/webpages/project/search.html

index f028b9e..ba7bf1d 100644 (file)
@@ -25,13 +25,11 @@ use SL::Locale::String;
 use Rose::Object::MakeMethods::Generic
 (
  scalar => [ qw(project linked_records) ],
- 'scalar --get_set_init' => [ qw(models) ],
+ 'scalar --get_set_init' => [ qw(models customers project_types project_statuses) ],
 );
 
 __PACKAGE__->run_before('check_auth');
 __PACKAGE__->run_before('load_project',        only => [ qw(edit update destroy) ]);
-__PACKAGE__->run_before('load_project_types',  only => [ qw(search edit new list) ]);
-__PACKAGE__->run_before('load_project_status', only => [ qw(search edit new list) ]);
 
 #
 # actions
@@ -115,10 +113,19 @@ sub check_auth {
 # helpers
 #
 
+sub init_project_statuses { SL::DB::Manager::ProjectStatus->get_all_sorted }
+sub init_project_types    { SL::DB::Manager::ProjectType->get_all_sorted   }
+
+sub init_customers {
+  my ($self)      = @_;
+  my @customer_id = $self->project && $self->project->customer_id ? (id => $self->project->customer_id) : ();
+
+  return SL::DB::Manager::Customer->get_all_sorted(where => [ or => [ obsolete => 0, obsolete => undef, @customer_id ]]);
+}
+
 sub display_form {
   my ($self, %params) = @_;
 
-  $params{ALL_CUSTOMERS}     = SL::DB::Manager::Customer->get_all_sorted(where => [ or => [ obsolete => 0, obsolete => undef, id => $self->project->customer_id ]]);
   $params{CUSTOM_VARIABLES}  = CVar->get_custom_variables(module => 'Projects', trans_id => $self->project->id);
 
   if ($params{keep_cvars}) {
@@ -199,7 +206,7 @@ sub prepare_report {
     description   => { obj_link => sub { $self->url_for(action => 'edit', id => $_[0]->id, callback => $callback) } },
     project_type  => { sub  => sub { $_[0]->project_type->description } },
     project_status => { sub  => sub { $_[0]->project_status->description }, text => t8('Status') },
-    customer      => { raw_data  => sub { $self->presenter->customer($_[0]->customer, display => 'table-cell', callback => $callback) } },
+    customer      => { raw_data  => sub { $_[0]->customer_id ? $self->presenter->customer($_[0]->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')  },
@@ -281,13 +288,4 @@ sub make_filter_summary {
 
   $self->{filter_summary} = join ', ', @filter_strings;
 }
-
-sub load_project_types {
-  $_[0]{ALL_PROJECT_TYPES} = SL::DB::Manager::ProjectType->get_all_sorted;
-}
-
-sub load_project_status {
-  $_[0]{ALL_PROJECT_STATUS} = SL::DB::Manager::ProjectStatus->get_all_sorted;
-}
-
 1;
index c9dcd1d..31bf79d 100644 (file)
 
  <tr>
   <th align="right">[% 'Project Type' | $T8 %]</th>
-  <td>[% L.select_tag('project.project_type_id', SELF.ALL_PROJECT_TYPES, default=SELF.project.project_type_id, title_key='description', style='width: 300px') %]</td>
+  <td>[% L.select_tag('project.project_type_id', SELF.project_types, default=SELF.project.project_type_id, title_key='description', style='width: 300px') %]</td>
  </tr>
 
  <tr>
   <th align="right">[% 'Project Status' | $T8 %]</th>
-  <td>[% L.select_tag('project.project_status_id', SELF.ALL_PROJECT_STATUS, default=SELF.project.project_status_id, title_key='description', style='width: 300px') %]</td>
+  <td>[% L.select_tag('project.project_status_id', SELF.project_statuses, default=SELF.project.project_status_id, title_key='description', style='width: 300px') %]</td>
  </tr>
 
  <tr>
   <th align="right">[% 'Customer' | $T8 %]</th>
-  <td>[% L.select_tag('project.customer_id', ALL_CUSTOMERS, default=SELF.project.customer_id, title_key='name', with_empty=1, style='width: 300px') %]</td>
+  <td>[% L.select_tag('project.customer_id', SELF.customers, default=SELF.project.customer_id, title_key='name', with_empty=1, style='width: 300px') %]</td>
  </tr>
 
  <tr>
index 27fb84b..3bd1980 100644 (file)
@@ -11,7 +11,7 @@
 
  <tr>
   <th align="right">[% 'Description' | $T8 %]</th>
-  <td>[% L.input_tag('filter.description:substr::ilike', filter.description_substr__ilike, size=60) %]</td>
+  <td>[% L.input_tag('filter.description:substr::ilike', filter.description_substr__ilike, size=60, class='initial_focus') %]</td>
  </tr>
 
  <tr>
 
  <tr>
   <th align="right">[% 'Project Type' | $T8 %]</th>
-  <td>[% L.select_tag('filter.project_type_id', SELF.ALL_PROJECT_TYPES, default=filter.project_type_id, title_key='description', with_empty=1) %]</td>
+  <td>[% L.select_tag('filter.project_type_id', SELF.project_types, default=filter.project_type_id, title_key='description', with_empty=1, style="width: 200px") %]</td>
  </tr>
 
  <tr>
   <th align="right">[% 'Project Status' | $T8 %]</th>
-  <td>[% L.select_tag('filter.project_status_id', SELF.ALL_PROJECT_STATUS, default=filter.project_status_id, title_key='description', with_empty=1) %]</td>
+  <td>[% L.select_tag('filter.project_status_id', SELF.project_statuses, default=filter.project_status_id, title_key='description', with_empty=1, style="width: 200px") %]</td>
  </tr>
 
  [% CUSTOM_VARIABLES_FILTER_CODE %]
index 23c9fe8..a4a2d82 100644 (file)
   <div class="listtop">[% 'Search projects' | $T8 %]</div>
 
   <p>
-   <table>
-    <tr>
-     <th align="right">[% 'Number' | $T8 %]</th>
-     <td>[% L.input_tag('filter.projectnumber:substr::ilike', filter.projectnumber_substr__ilike, size=60) %]</td>
-    </tr>
-
-    <tr>
-     <th align="right">[% 'Description' | $T8 %]</th>
-     <td>[% L.input_tag('filter.description:substr::ilike', filter.description_substr__ilike, size=60, class='initial_focus') %]</td>
-    </tr>
-
-    <tr>
-     <th align="right">[% 'Customer' | $T8 %]</th>
-     <td>[% L.input_tag('filter.customer.name:substr::ilike', filter.customer.name_substr__ilike, size=60) %]</td>
-    </tr>
-
-    <tr>
-     <th align="right">[% 'Project Type' | $T8 %]</th>
-     <td>[% L.select_tag('filter.project_type_id', SELF.ALL_PROJECT_TYPES, default=filter.project_type_id, title_key='description', with_empty=1) %]</td>
-    </tr>
-
-    <tr>
-     <th align="right">[% 'Project Status' | $T8 %]</th>
-     <td>[% L.select_tag('filter.project_status_id', SELF.ALL_PROJECT_STATUS, default=filter.project_status_id, title_key='description', with_empty=1) %]</td>
-    </tr>
-
-    [% CUSTOM_VARIABLES_FILTER_CODE %]
-
-    <tr>
-     <th>[% 'Include in Report' | $T8 %]</th>
-     <td>
-      <table>
-       <tr>
-        <td>[% L.select_tag('filter.active', [ [ 'active', LxERP.t8('Active') ], [ 'inactive', LxERP.t8('Inactive') ], [ 'both', LxERP.t8('Both') ] ], default=filter.active, style="width: 200px") %]</td>
-       </tr>
-
-       <tr>
-        <td>[% L.select_tag('filter.valid', [ [ 'valid', LxERP.t8('Valid') ], [ 'invalid', LxERP.t8('Invalid') ], [ 'both', LxERP.t8('Both') ] ], default=filter.valid, style="width: 200px") %]</td>
-       </tr>
-
-       <tr>
-        <td>[% L.select_tag('filter.status', [ [ 'all', LxERP.t8('All') ], [ 'orphaned', LxERP.t8('Orphaned') ] ], default=filter.status, style="width: 200px") %]</td>
-       </tr>
-
-       [% CUSTOM_VARIABLES_INCLUSION_CODE %]
-
-      </table>
-     </td>
-    </tr>
-   </table>
+[%- INCLUDE 'project/_filter.html' %]
   </p>
 
   <hr size="3" noshade>