From b48939fe80e819f27898d0782e802440170ac0bb Mon Sep 17 00:00:00 2001 From: Moritz Bunkus Date: Wed, 13 Mar 2013 15:40:59 +0100 Subject: [PATCH] Pflichtenhefte: show & Bearbeiten in eigenen Tab --- SL/Controller/RequirementSpec.pm | 46 +++++++++----- js/requirement_spec.js | 14 ++++- locale/de/all | 1 + .../webpages/requirement_spec/_form.html | 50 +++++++++++++++ .../webpages/requirement_spec/_header.html | 8 +++ templates/webpages/requirement_spec/form.html | 62 ------------------- templates/webpages/requirement_spec/new.html | 5 ++ templates/webpages/requirement_spec/show.html | 48 +++++++------- 8 files changed, 133 insertions(+), 101 deletions(-) create mode 100644 templates/webpages/requirement_spec/_form.html create mode 100644 templates/webpages/requirement_spec/_header.html delete mode 100644 templates/webpages/requirement_spec/form.html create mode 100644 templates/webpages/requirement_spec/new.html diff --git a/SL/Controller/RequirementSpec.pm b/SL/Controller/RequirementSpec.pm index 2c1139e13..5d581f4fb 100644 --- a/SL/Controller/RequirementSpec.pm +++ b/SL/Controller/RequirementSpec.pm @@ -4,6 +4,7 @@ use strict; use parent qw(SL::Controller::Base); +use SL::ClientJS; use SL::Controller::Helper::GetModels; use SL::Controller::Helper::Paginated; use SL::Controller::Helper::Sorted; @@ -23,9 +24,9 @@ use Rose::Object::MakeMethods::Generic ); __PACKAGE__->run_before('setup'); -__PACKAGE__->run_before('load_requirement_spec', only => [ qw( edit update show destroy) ]); -__PACKAGE__->run_before('load_select_options', only => [ qw(new edit create update list) ]); -__PACKAGE__->run_before('load_search_select_options', only => [ qw( list) ]); +__PACKAGE__->run_before('load_requirement_spec', only => [ qw( ajax_edit update show destroy) ]); +__PACKAGE__->run_before('load_select_options', only => [ qw(new ajax_edit create update list) ]); +__PACKAGE__->run_before('load_search_select_options', only => [ qw( list) ]); __PACKAGE__->get_models_url_params('flat_filter'); __PACKAGE__->make_paginated( @@ -68,13 +69,14 @@ sub action_list { sub action_new { my ($self) = @_; - $self->{requirement_spec} = SL::DB::RequirementSpec->new; - $self->render('requirement_spec/form', title => t8('Create a new requirement spec')); + $self->requirement_spec(SL::DB::RequirementSpec->new); + $self->render('requirement_spec/new', title => t8('Create a new requirement spec')); } -sub action_edit { +sub action_ajax_edit { my ($self) = @_; - $self->render('requirement_spec/form', title => t8('Edit requirement spec')); + + $self->render('requirement_spec/_form', { layout => 0 }, submit_as => 'ajax'); } sub action_show { @@ -89,7 +91,7 @@ sub action_show { sub action_create { my ($self) = @_; - $self->{requirement_spec} = SL::DB::RequirementSpec->new; + $self->requirement_spec(SL::DB::RequirementSpec->new); $self->create_or_update; } @@ -101,7 +103,7 @@ sub action_update { sub action_destroy { my ($self) = @_; - if (eval { $self->{requirement_spec}->delete; 1; }) { + if (eval { $self->requirement_spec->delete; 1; }) { flash_later('info', t8('The requirement spec has been deleted.')); } else { flash_later('error', t8('The requirement spec is in use and cannot be deleted.')); @@ -135,7 +137,7 @@ sub setup { sub load_requirement_spec { my ($self) = @_; - $self->{requirement_spec} = SL::DB::RequirementSpec->new(id => $::form->{id})->load || die "No such requirement spec"; + $self->requirement_spec(SL::DB::RequirementSpec->new(id => $::form->{id})->load || die "No such requirement spec"); } sub load_select_options { @@ -163,24 +165,34 @@ sub load_search_select_options { sub create_or_update { my $self = shift; - my $is_new = !$self->{requirement_spec}->id; + my $is_new = !$self->requirement_spec->id; my $params = delete($::form->{requirement_spec}) || { }; my $title = $is_new ? t8('Create a new requirement spec') : t8('Edit requirement spec'); - $self->{requirement_spec}->assign_attributes(%{ $params }); + $self->requirement_spec->assign_attributes(%{ $params }); - my @errors = $self->{requirement_spec}->validate; + my @errors = $self->requirement_spec->validate; if (@errors) { + return SL::ClientJS->new->error(@errors)->render($self) if $::request->is_ajax; + flash('error', @errors); - $self->render('requirement_spec/form', title => $title); + $self->render('requirement_spec/new', title => $title); return; } - $self->{requirement_spec}->save; + $self->requirement_spec->save; + + if ($::request->is_ajax) { + my $html = $self->render('requirement_spec/_header', { output => 0 }); + return SL::ClientJS->new + ->replaceWith('#requirement-spec-header', $html) + ->flash('info', t8('The requirement spec has been saved.')) + ->render($self); + } flash_later('info', $is_new ? t8('The requirement spec has been created.') : t8('The requirement spec has been saved.')); - $self->redirect_to(action => 'list'); + $self->redirect_to(action => 'show', id => $self->requirement_spec->id); } sub setup_db_args_from_filter { @@ -214,7 +226,7 @@ sub prepare_report { my @sortable = qw(title customer status type projectnumber); my %column_defs = ( - title => { obj_link => sub { $self->url_for(action => 'edit', id => $_[0]->id, callback => $callback) } }, + title => { obj_link => sub { $self->url_for(action => 'show', id => $_[0]->id, callback => $callback) } }, customer => { raw_data => sub { $self->presenter->customer($_[0]->customer, display => 'table-cell', callback => $callback) }, sub => sub { $_[0]->customer->name } }, projectnumber => { raw_data => sub { $self->presenter->project($_[0]->project, display => 'table-cell', callback => $callback) }, diff --git a/js/requirement_spec.js b/js/requirement_spec.js index 896b93ba1..c84dc79f3 100644 --- a/js/requirement_spec.js +++ b/js/requirement_spec.js @@ -1,4 +1,16 @@ -/* Functions used for the requirement specs tree view */ +/* Functions used for the requirement specs */ + +// ----------------------------------------------------------------------------- +// ------------------------------ basic settings ------------------------------- +// ----------------------------------------------------------------------------- + +function basic_settings_customer_changed(customer_ctrl, value_ctrl) { + $.get( + 'controller.pl?action=Customer/get_hourly_rate', + { id: $(customer_ctrl).val() }, + function(data) { if (data.hourly_rate_formatted) $(value_ctrl).val(data.hourly_rate_formatted); } + ); +} // ----------------------------------------------------------------------------- // ------------------------------ the tree itself ------------------------------ diff --git a/locale/de/all b/locale/de/all index e3be4f307..f732911eb 100755 --- a/locale/de/all +++ b/locale/de/all @@ -304,6 +304,7 @@ $self->{texts} = { 'Bank transfers via SEPA' => 'Überweisungen via SEPA', 'Base unit' => 'Basiseinheit', 'Basic Data' => 'Basisdaten', + 'Basic settings' => 'Grundeinstellungen', 'Batch Printing' => 'Druck', 'Bcc' => 'Bcc', 'Bcc E-mail' => 'BCC (E-Mail)', diff --git a/templates/webpages/requirement_spec/_form.html b/templates/webpages/requirement_spec/_form.html new file mode 100644 index 000000000..68d9153db --- /dev/null +++ b/templates/webpages/requirement_spec/_form.html @@ -0,0 +1,50 @@ +[%- USE LxERP -%][%- USE L -%] +[%- DEFAULT id_prefix = 'basic_settings_form' + submit_as = 'post' +%] +
+ [% L.hidden_tag("id", SELF.requirement_spec.id, id=id_prefix _ '_id') %] + + + + + + + + + + + + + + + + + + + + + + + + + + + +
[% LxERP.t8("Title") %][% L.input_tag("requirement_spec.title", SELF.requirement_spec.title, id=id_prefix _ '_title') %]
[% LxERP.t8("Requirement Spec Type") %][% L.select_tag("requirement_spec.type_id", SELF.types, default=SELF.requirement_spec.type_id, title_key="description", id=id_prefix _ '_type_id') %]
[% LxERP.t8("Requirement Spec Status") %][% L.select_tag("requirement_spec.status_id", SELF.statuses, default=SELF.requirement_spec.status_id, title_key="description", id=id_prefix _ '_status_id') %]
[% LxERP.t8("Customer") %][% L.select_tag("requirement_spec.customer_id", SELF.customers, default=SELF.requirement_spec.customer_id, title_key="name", id=id_prefix _ '_customer_id', + onchange="basic_settings_customer_changed('#" _ id_prefix _ "_customer_id', '#" _ id_prefix _ "_hourly_rate_as_number')") %]
[% LxERP.t8("Hourly Rate") %][% L.input_tag(form_prefix _ "hourly_rate_as_number", SELF.requirement_spec.hourly_rate_as_number, id=id_prefix _ '_hourly_rate_as_number') %]
+ +

+[% IF submit_as == 'post' %] + [% L.hidden_tag("action", "RequirementSpec/dispatch", id=id_prefix _ '_action') %] + [% L.submit_tag("action_" _ (SELF.requirement_spec.id ? "update" : "create"), LxERP.t8('Save'), id=id_prefix _ '_action_update') %] + [%- IF SELF.requirement_spec.id %] + [% L.submit_tag("action_destroy", LxERP.t8('Delete'), confirm=LxERP.t8('Do you really want to delete this object?'), id=id_prefix _ '_action_destroy') %] + [%- END %] + [% LxERP.t8('Abort') %] +[% ELSE %] + [% L.button_tag("submit_ajax_form('controller.pl?action=RequirementSpec/update', '#" _ id_prefix _ "')", LxERP.t8("Save")) %] + [% L.button_tag("submit_ajax_form('controller.pl?action=RequirementSpec/destroy', '#" _ id_prefix _ "')", LxERP.t8("Delete"), confirm=LxERP.t8("Do you really want to delete this object?")) %] +[% END %] +

+
diff --git a/templates/webpages/requirement_spec/_header.html b/templates/webpages/requirement_spec/_header.html new file mode 100644 index 000000000..0171e5ce8 --- /dev/null +++ b/templates/webpages/requirement_spec/_header.html @@ -0,0 +1,8 @@ +[%- USE HTML -%][%- USE LxERP -%] +
+

+ [%- HTML.escape(SELF.requirement_spec.displayable_name('format', 'with_customer')) %] + [% LxERP.t8("for") %] + [% HTML.escape(SELF.requirement_spec.customer.displayable_name) -%] +

+
diff --git a/templates/webpages/requirement_spec/form.html b/templates/webpages/requirement_spec/form.html deleted file mode 100644 index e038c3f31..000000000 --- a/templates/webpages/requirement_spec/form.html +++ /dev/null @@ -1,62 +0,0 @@ -[% USE HTML %][% USE L %][% USE LxERP %] - -
-
[% FORM.title %]
- -[%- INCLUDE 'common/flash.html' %] - - - - - - - - - - - - - - - - - - - - - - - - - - - -
[% LxERP.t8("Title") %][% L.input_tag("requirement_spec.title", SELF.requirement_spec.description) %]
[% LxERP.t8("Requirement Spec Type") %][% L.select_tag("requirement_spec.type_id", SELF.types, default=SELF.requirement_spec.type_id, title_key="description") %]
[% LxERP.t8("Requirement Spec Status") %][% L.select_tag("requirement_spec.status_id", SELF.statuses, default=SELF.requirement_spec.status_id, title_key="description") %]
[% LxERP.t8("Customer") %][% L.select_tag("requirement_spec.customer_id", SELF.customers, default=SELF.requirement_spec.customer_id, title_key="name", id="customer_id") %]
[% LxERP.t8("Hourly Rate") %][% L.input_tag("requirement_spec.hourly_rate_as_number", SELF.requirement_spec.hourly_rate_as_number, id="hourly_rate") %]
- -

- [% L.hidden_tag("id", SELF.requirement_spec.id) %] - [% L.hidden_tag("action", "RequirementSpec/dispatch") %] - [% L.submit_tag("action_" _ (SELF.requirement_spec.id ? "update" : "create"), LxERP.t8('Save')) %] - [%- IF SELF.requirement_spec.id %] - [% L.submit_tag("action_destroy", LxERP.t8('Delete'), confirm=LxERP.t8('Do you really want to delete this object?')) %] - [%- END %] - [% LxERP.t8('Abort') %] -

-
- - diff --git a/templates/webpages/requirement_spec/new.html b/templates/webpages/requirement_spec/new.html new file mode 100644 index 000000000..3a2534d96 --- /dev/null +++ b/templates/webpages/requirement_spec/new.html @@ -0,0 +1,5 @@ +

[% FORM.title %]

+ +[%- INCLUDE 'common/flash.html' %] + +[%- INCLUDE 'requirement_spec/_form.html' %] diff --git a/templates/webpages/requirement_spec/show.html b/templates/webpages/requirement_spec/show.html index e4846f51b..5a92d0fbe 100644 --- a/templates/webpages/requirement_spec/show.html +++ b/templates/webpages/requirement_spec/show.html @@ -2,32 +2,38 @@ [%- INCLUDE 'common/flash.html' %] -

[%- HTML.escape(SELF.requirement_spec.displayable_name('format', 'with_customer')) %] - [% LxERP.t8("for") %] - [% HTML.escape(SELF.requirement_spec.customer.displayable_name) -%] -

+[%- INCLUDE 'requirement_spec/_header.html' %] [%- L.hidden_tag('requirement_spec_id', SELF.requirement_spec.id) -%] -
- [%- INCLUDE 'requirement_spec/_version.html' requirement_spec=SELF.requirement_spec -%] -
- -
-
-
-
+
+ -
- [% L.hidden_tag('current_content_type', SELF.requirement_spec_item.id ? 'section' : '') %] - [% L.hidden_tag('current_content_id', SELF.requirement_spec_item.id) %] +
+
+ [%- INCLUDE 'requirement_spec/_version.html' requirement_spec=SELF.requirement_spec -%] +
-
- [%- IF SELF.requirement_spec_item -%] - [%- INCLUDE 'requirement_spec_item/_section.html' requirement_spec_item=SELF.requirement_spec_item -%] - [%- ELSE -%] - [%- INCLUDE 'requirement_spec_item/_no_section.html' -%] - [%- END -%] +
+
+
+
+ +
+ [% L.hidden_tag('current_content_type', SELF.requirement_spec_item.id ? 'section' : '') %] + [% L.hidden_tag('current_content_id', SELF.requirement_spec_item.id) %] + +
+ [%- IF SELF.requirement_spec_item -%] + [%- INCLUDE 'requirement_spec_item/_section.html' requirement_spec_item=SELF.requirement_spec_item -%] + [%- ELSE -%] + [%- INCLUDE 'requirement_spec_item/_no_section.html' -%] + [%- END -%] +
+
-- 2.20.1