Pflichtenhefte: show & Bearbeiten in eigenen Tab
authorMoritz Bunkus <m.bunkus@linet-services.de>
Wed, 13 Mar 2013 14:40:59 +0000 (15:40 +0100)
committerMoritz Bunkus <m.bunkus@linet-services.de>
Tue, 1 Apr 2014 11:02:28 +0000 (13:02 +0200)
SL/Controller/RequirementSpec.pm
js/requirement_spec.js
locale/de/all
templates/webpages/requirement_spec/_form.html [new file with mode: 0644]
templates/webpages/requirement_spec/_header.html [new file with mode: 0644]
templates/webpages/requirement_spec/form.html [deleted file]
templates/webpages/requirement_spec/new.html [new file with mode: 0644]
templates/webpages/requirement_spec/show.html

index 2c1139e..5d581f4 100644 (file)
@@ -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) },
index 896b93b..c84dc79 100644 (file)
@@ -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 ------------------------------
index e3be4f3..f732911 100755 (executable)
@@ -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 (file)
index 0000000..68d9153
--- /dev/null
@@ -0,0 +1,50 @@
+[%- USE LxERP -%][%- USE L -%]
+[%- DEFAULT id_prefix = 'basic_settings_form'
+            submit_as = 'post'
+%]
+<form method="post" action="controller.pl" id="[% id_prefix %]">
+ [% L.hidden_tag("id", SELF.requirement_spec.id, id=id_prefix _ '_id') %]
+
+ <table class="rs_input_field">
+  <tr>
+   <td>[% LxERP.t8("Title") %]</td>
+   <td>[% L.input_tag("requirement_spec.title", SELF.requirement_spec.title, id=id_prefix _ '_title') %]</td>
+  </tr>
+
+  <tr>
+   <td>[% LxERP.t8("Requirement Spec Type") %]</td>
+   <td>[% L.select_tag("requirement_spec.type_id",  SELF.types, default=SELF.requirement_spec.type_id, title_key="description", id=id_prefix _ '_type_id') %]</td>
+  </tr>
+
+  <tr>
+   <td>[% LxERP.t8("Requirement Spec Status") %]</td>
+   <td>[% L.select_tag("requirement_spec.status_id",  SELF.statuses, default=SELF.requirement_spec.status_id, title_key="description", id=id_prefix _ '_status_id') %]</td>
+  </tr>
+
+  <tr>
+   <td>[% LxERP.t8("Customer") %]</td>
+   <td>[% 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')") %]</td>
+  </tr>
+
+  <tr>
+   <td>[% LxERP.t8("Hourly Rate") %]</td>
+   <td>[% L.input_tag(form_prefix _ "hourly_rate_as_number", SELF.requirement_spec.hourly_rate_as_number, id=id_prefix _ '_hourly_rate_as_number') %]</td>
+  </tr>
+
+ </table>
+
+ <p>
+[% 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 %]
+  <a href="[% SELF.url_for(action="list") %]">[% LxERP.t8('Abort') %]</a>
+[% 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 %]
+ </p>
+</form>
diff --git a/templates/webpages/requirement_spec/_header.html b/templates/webpages/requirement_spec/_header.html
new file mode 100644 (file)
index 0000000..0171e5c
--- /dev/null
@@ -0,0 +1,8 @@
+[%- USE HTML -%][%- USE LxERP -%]
+<div id="requirement-spec-header">
+ <h1>
+  [%- HTML.escape(SELF.requirement_spec.displayable_name('format', 'with_customer')) %]
+  [% LxERP.t8("for") %]
+  [% HTML.escape(SELF.requirement_spec.customer.displayable_name) -%]
+ </h1>
+</div>
diff --git a/templates/webpages/requirement_spec/form.html b/templates/webpages/requirement_spec/form.html
deleted file mode 100644 (file)
index e038c3f..0000000
+++ /dev/null
@@ -1,62 +0,0 @@
-[% USE HTML %][% USE L %][% USE LxERP %]
-
- <form method="post" action="controller.pl">
-  <div class="listtop">[% FORM.title %]</div>
-
-[%- INCLUDE 'common/flash.html' %]
-
-  <table class="rs_input_field">
-   <tr>
-    <td>[% LxERP.t8("Title") %]</td>
-    <td>[% L.input_tag("requirement_spec.title", SELF.requirement_spec.description) %]</td>
-   </tr>
-
-   <tr>
-    <td>[% LxERP.t8("Requirement Spec Type") %]</td>
-    <td>[% L.select_tag("requirement_spec.type_id",  SELF.types, default=SELF.requirement_spec.type_id, title_key="description") %]</td>
-   </tr>
-
-   <tr>
-    <td>[% LxERP.t8("Requirement Spec Status") %]</td>
-    <td>[% L.select_tag("requirement_spec.status_id",  SELF.statuses, default=SELF.requirement_spec.status_id, title_key="description") %]</td>
-   </tr>
-
-   <tr>
-    <td>[% LxERP.t8("Customer") %]</td>
-    <td>[% L.select_tag("requirement_spec.customer_id",  SELF.customers, default=SELF.requirement_spec.customer_id, title_key="name", id="customer_id") %]</td>
-   </tr>
-
-   <tr>
-    <td>[% LxERP.t8("Hourly Rate") %]</td>
-    <td>[% L.input_tag("requirement_spec.hourly_rate_as_number", SELF.requirement_spec.hourly_rate_as_number, id="hourly_rate") %]</td>
-   </tr>
-
-  </table>
-
-  <p>
-   [% 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 %]
-   <a href="[% SELF.url_for(action="list") %]">[% LxERP.t8('Abort') %]</a>
-  </p>
- </form>
-
- <script type="text/javascript">
-  <!--
-    function on_customer_changed() {
-      $.ajax({
-        url: 'controller.pl?action=Customer/get_hourly_rate',
-        dataType: "json",
-        data: { id: $("#customer_id").attr('value') },
-        success: function(data) { if (data["hourly_rate"] > 0) $("#hourly_rate").attr("value", data["hourly_rate_formatted"]); }
-      });
-    }
-
-    $(document).ready(function() {
-      $("#customer_id").change(on_customer_changed);
-    });
-  -->
- </script>
diff --git a/templates/webpages/requirement_spec/new.html b/templates/webpages/requirement_spec/new.html
new file mode 100644 (file)
index 0000000..3a2534d
--- /dev/null
@@ -0,0 +1,5 @@
+<h1>[% FORM.title %]</h1>
+
+[%- INCLUDE 'common/flash.html' %]
+
+[%- INCLUDE 'requirement_spec/_form.html' %]
index e4846f5..5a92d0f 100644 (file)
@@ -2,32 +2,38 @@
 
 [%- INCLUDE 'common/flash.html' %]
 
-<h1>[%- HTML.escape(SELF.requirement_spec.displayable_name('format', 'with_customer')) %]
-  [% LxERP.t8("for") %]
-  [% HTML.escape(SELF.requirement_spec.customer.displayable_name) -%]
-</h1>
+[%- INCLUDE 'requirement_spec/_header.html' %]
 
 [%- L.hidden_tag('requirement_spec_id', SELF.requirement_spec.id) -%]
 
-<div id="requirement_spec_version">
-  [%- INCLUDE 'requirement_spec/_version.html' requirement_spec=SELF.requirement_spec -%]
-</div>
-
-<div id="column-container">
- <div id="tree-column">
-  <div id="tree"></div>
- </div>
+<div class="tabwidget">
+ <ul>
+  <li><a href="#function-blocks-tab">[%- LxERP.t8("Content") %]</a></li>
+  <li><a href="controller.pl?action=RequirementSpec/ajax_edit&id=[% HTML.url(SELF.requirement_spec.id) %]">[%- LxERP.t8("Basic settings") %]</a></li>
+ </ul>
 
- <div id="content-column" class="clearfix">
-  [% L.hidden_tag('current_content_type', SELF.requirement_spec_item.id ? 'section' : '') %]
-  [% L.hidden_tag('current_content_id',   SELF.requirement_spec_item.id) %]
+ <div id="function-blocks-tab">
+  <div id="requirement_spec_version">
+    [%- INCLUDE 'requirement_spec/_version.html' requirement_spec=SELF.requirement_spec -%]
+  </div>
 
-  <div id="column-content">
-   [%- 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 -%]
+  <div id="column-container" class="clearfix">
+   <div id="tree-column">
+    <div id="tree"></div>
+   </div>
+
+   <div id="content-column" class="clearfix">
+    [% L.hidden_tag('current_content_type', SELF.requirement_spec_item.id ? 'section' : '') %]
+    [% L.hidden_tag('current_content_id',   SELF.requirement_spec_item.id) %]
+
+    <div id="column-content">
+     [%- 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 -%]
+    </div>
+   </div>
   </div>
  </div>
 </div>