From 0a2fb69e21af67fdc5d162294c08b1847c9aa021 Mon Sep 17 00:00:00 2001 From: Moritz Bunkus Date: Wed, 28 Jan 2015 14:55:31 +0100 Subject: [PATCH] Pflichtenhefte: benutzerdefinierte Variablen anzeigen und bearbeiten --- SL/Controller/RequirementSpec.pm | 10 +++++++++- SL/DB/RequirementSpec.pm | 4 ++++ css/requirement_spec.css | 2 +- .../common/render_cvar_value_readonly.html | 18 ++++++++++++++++++ templates/webpages/requirement_spec/_form.html | 16 +++++++++++++++- .../requirement_spec/_show_basic_settings.html | 9 +++++++++ 6 files changed, 56 insertions(+), 3 deletions(-) create mode 100644 templates/webpages/common/render_cvar_value_readonly.html diff --git a/SL/Controller/RequirementSpec.pm b/SL/Controller/RequirementSpec.pm index 3158cd09a..bd37a02ab 100644 --- a/SL/Controller/RequirementSpec.pm +++ b/SL/Controller/RequirementSpec.pm @@ -373,9 +373,17 @@ sub create_or_update { my $self = shift; my $is_new = !$self->requirement_spec->id; my $params = delete($::form->{requirement_spec}) || { }; + my $cvars = delete($::form->{cvars}) || { }; $self->requirement_spec->assign_attributes(%{ $params }); + foreach my $var (@{ $self->requirement_spec->cvars_by_config }) { + my $value = $cvars->{ $var->config->name }; + $value = $::form->parse_amount(\%::myconfig, $value) if $var->config->type eq 'number'; + + $var->value($value); + } + my $title = $is_new && $self->requirement_spec->is_template ? t8('Create a new requirement spec template') : $is_new ? t8('Create a new requirement spec') : $self->requirement_spec->is_template ? t8('Edit requirement spec template') @@ -396,7 +404,7 @@ sub create_or_update { if ($self->copy_source) { $self->requirement_spec($self->copy_source->create_copy(%{ $params })); } else { - $self->requirement_spec->save; + $self->requirement_spec->save(cascade => 1); } })) { $::lxdebug->message(LXDebug::WARN(), "Error: " . $db->error); diff --git a/SL/DB/RequirementSpec.pm b/SL/DB/RequirementSpec.pm index bc68c17c4..bad980387 100644 --- a/SL/DB/RequirementSpec.pm +++ b/SL/DB/RequirementSpec.pm @@ -9,6 +9,10 @@ use Rose::DB::Object::Helpers; use SL::DB::MetaSetup::RequirementSpec; use SL::DB::Manager::RequirementSpec; use SL::DB::Helper::AttrDuration; +use SL::DB::Helper::CustomVariables ( + module => 'RequirementSpecs', + cvars_alias => 1, +); use SL::DB::Helper::LinkedRecords; use SL::Locale::String; use SL::Util qw(_hashify); diff --git a/css/requirement_spec.css b/css/requirement_spec.css index 9dbd0d693..36dfeb5a3 100644 --- a/css/requirement_spec.css +++ b/css/requirement_spec.css @@ -3,7 +3,7 @@ /* ------------------------------------------------------------ */ input.rs_input_field, select.rs_input_field, -table.rs_input_field input, table.rs_input_field select { +table.rs_input_field input[type=text], table.rs_input_field input[type=password], table.rs_input_field select { width: 300px; } diff --git a/templates/webpages/common/render_cvar_value_readonly.html b/templates/webpages/common/render_cvar_value_readonly.html new file mode 100644 index 000000000..76e3fa892 --- /dev/null +++ b/templates/webpages/common/render_cvar_value_readonly.html @@ -0,0 +1,18 @@ +[%- USE T8 %] +[%- USE HTML %] +[%- USE L %] +[%- USE LxERP %] + +[%- IF ( var.config .type == 'bool' ) %] + [% IF var.value %] + [% LxERP.t8("Yes") %] + [% ELSE %] + [% LxERP.t8("No") %] + [% END %] +[%- ELSIF ( var.config .type == 'textfield' ) %] +
[% HTML.escape(var.value) %]
+[%- ELSIF ( var.config.type == 'number' ) %] + [%- LxERP.format_amount(var.value, -2) %] +[%- ELSE %] + [% HTML.escape(var.value) %] +[%- END %] diff --git a/templates/webpages/requirement_spec/_form.html b/templates/webpages/requirement_spec/_form.html index 20bf7a116..a89a99b28 100644 --- a/templates/webpages/requirement_spec/_form.html +++ b/templates/webpages/requirement_spec/_form.html @@ -1,4 +1,4 @@ -[%- USE LxERP -%][%- USE L -%] +[%- USE LxERP -%][%- USE L -%][%- USE HTML -%] [%- DEFAULT id_prefix = 'basic_settings_form' submit_as = 'post' %] @@ -39,6 +39,20 @@ [%- END %] + [% cvars = SELF.requirement_spec.cvars_by_config %] + + [% FOREACH var = cvars %] + + [% HTML.escape(var.config.description) %] + + + [% INCLUDE 'common/render_cvar_input.html' + cvar_name_prefix = 'cvars.' + %] + + + [% END %] + [%- IF SELF.copy_source %] diff --git a/templates/webpages/requirement_spec/_show_basic_settings.html b/templates/webpages/requirement_spec/_show_basic_settings.html index 7f69f8c57..a89c36a1f 100644 --- a/templates/webpages/requirement_spec/_show_basic_settings.html +++ b/templates/webpages/requirement_spec/_show_basic_settings.html @@ -36,6 +36,15 @@ [% HTML.escape(SELF.requirement_spec.hourly_rate_as_number) %] + [% cvars = SELF.requirement_spec.cvars_by_config %] + + [% FOREACH var = cvars %] + + [% HTML.escape(var.config.description) %] + [% INCLUDE 'common/render_cvar_value_readonly.html' %] + + [% END %] + [%- END %] -- 2.20.1