From: Moritz Bunkus Date: Mon, 25 Mar 2019 15:42:56 +0000 (+0100) Subject: Projekte: benutzerdefinierte Variablen in Suchmaske X-Git-Tag: release-3.5.4~80^2~1 X-Git-Url: http://wagnertech.de/git?a=commitdiff_plain;h=55a74ec99d06cf44900f4b9dfba86a8525ed48b9;p=kivitendo-erp.git Projekte: benutzerdefinierte Variablen in Suchmaske --- diff --git a/SL/Controller/Project.pm b/SL/Controller/Project.pm index 66f228725..14f27dc68 100644 --- a/SL/Controller/Project.pm +++ b/SL/Controller/Project.pm @@ -30,7 +30,8 @@ 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 employees may_edit_invoice_permissions) ], + 'scalar --get_set_init' => [ qw(models customers project_types project_statuses projects linked_records employees may_edit_invoice_permissions + cvar_configs includeable_cvar_configs include_cvars) ], ); __PACKAGE__->run_before('check_auth', except => [ qw(ajax_autocomplete) ]); @@ -153,6 +154,14 @@ 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_cvar_configs { SL::DB::Manager::CustomVariableConfig->get_all_sorted(where => [ module => 'Projects' ]) } +sub init_includeable_cvar_configs { [ grep { $_->includeable } @{ $_[0]->cvar_configs } ] }; + +sub init_include_cvars { + my ($self) = @_; + return { map { ($_->name => $::form->{"include_cvars_" . $_->name}) } @{ $self->cvar_configs } } if $::form->{_include_cvars_from_form}; + return { map { ($_->name => ($_->includeable && $_->included_by_default)) } @{ $self->cvar_configs } }; +} sub init_linked_records { my ($self) = @_; @@ -303,6 +312,21 @@ sub prepare_report { map { $column_defs{$_}->{text} ||= $::locale->text( $self->models->get_sort_spec->{$_}->{title} ) } keys %column_defs; + # Custom variables + my %cvar_column_defs = map { + my $cfg = $_; + (('cvar_' . $cfg->name) => { + sub => sub { my $var = $_[0]->cvar_by_name($cfg->name); $var ? $var->value_as_text : '' }, + text => $cfg->description, + visible => $self->include_cvars->{ $cfg->name } ? 1 : 0, + }) + } @{ $self->includeable_cvar_configs }; + + push @columns, map { 'cvar_' . $_->name } @{ $self->includeable_cvar_configs }; + %column_defs = (%column_defs, %cvar_column_defs); + + my @cvar_column_form_names = ('_include_cvars_from_form', map { "include_cvars_" . $_->name } @{ $self->includeable_cvar_configs }); + $report->set_options( std_column_visibility => 1, controller_class => 'Project', @@ -313,7 +337,7 @@ sub prepare_report { ); $report->set_columns(%column_defs); $report->set_column_order(@columns); - $report->set_export_options(qw(list filter)); + $report->set_export_options(qw(list filter), @cvar_column_form_names); $report->set_options_from_form; $self->models->disable_plugin('paginated') if $report->{options}{output_format} =~ /^(pdf|csv)$/i; $self->models->set_report_generator_sort_options(report => $report, sortable_columns => \@sortable); diff --git a/templates/webpages/project/_filter.html b/templates/webpages/project/_filter.html index 5a522264a..924ca95ea 100644 --- a/templates/webpages/project/_filter.html +++ b/templates/webpages/project/_filter.html @@ -3,6 +3,8 @@ [%- USE L %] [%- USE LxERP %] +[% L.hidden_tag("_include_cvars_from_form", 1) %] + @@ -29,7 +31,14 @@ - [% CUSTOM_VARIABLES_FILTER_CODE %] + [% FOREACH cvar_cfg = SELF.cvar_configs %] + [%- IF cvar_cfg.searchable %] + + + + + [% END %] + [% END %] @@ -47,7 +56,14 @@ - [% CUSTOM_VARIABLES_INCLUSION_CODE %] + [% FOREACH cvar_cfg = SELF.includeable_cvar_configs %] + + + + [% END %]
[% 'Number' | $T8 %][% L.select_tag('filter.project_status_id', SELF.project_statuses, default=filter.project_status_id, title_key='description', with_empty=1, style="width: 200px") %]
[% HTML.escape(cvar_cfg.description) %][% INCLUDE 'common/render_cvar_filter_input.html' cvar_cfg=cvar_cfg cvar_class="rs_input_field" %]
[% 'Include in Report' | $T8 %][% L.select_tag('filter.status', [ [ 'all', LxERP.t8('All') ], [ 'orphaned', LxERP.t8('Orphaned') ] ], default=filter.status, style="width: 200px") %]
+ [% name__ = cvar_cfg.name; + L.checkbox_tag("include_cvars_" _ name__, value="1", checked=(SELF.include_cvars.$name__ ? 1 : ''), label=cvar_cfg.description) %] +