Pflichtenhefte: Zuweisung Artikel zu Abschnitten implementiert
authorMoritz Bunkus <m.bunkus@linet-services.de>
Tue, 9 Jul 2013 14:17:16 +0000 (16:17 +0200)
committerMoritz Bunkus <m.bunkus@linet-services.de>
Tue, 1 Apr 2014 11:05:56 +0000 (13:05 +0200)
SL/Controller/RequirementSpecOrder.pm
SL/DB/RequirementSpecItem.pm
js/requirement_spec.js
templates/webpages/requirement_spec_order/_assignment_form.html [new file with mode: 0644]
templates/webpages/requirement_spec_order/edit_assignment.html [new file with mode: 0644]
templates/webpages/requirement_spec_order/list.html

index 67b780f..1822e2b 100644 (file)
@@ -6,6 +6,7 @@ use utf8;
 use parent qw(SL::Controller::Base);
 
 use SL::ClientJS;
+use SL::DB::Part;
 use SL::DB::RequirementSpec;
 use SL::DB::RequirementSpecOrder;
 use SL::Helper::Flash;
@@ -13,7 +14,7 @@ use SL::Locale::String;
 
 use Rose::Object::MakeMethods::Generic
 (
-  'scalar --get_set_init' => [ qw(requirement_spec js) ],
+  'scalar --get_set_init' => [ qw(requirement_spec js all_parts) ],
 );
 
 __PACKAGE__->run_before('setup');
@@ -26,10 +27,35 @@ __PACKAGE__->run_before('setup');
 sub action_list {
   my ($self) = @_;
 
-  $::lxdebug->dump(0, "hmm", $self->requirement_spec->sections_sorted);
   $self->render('requirement_spec_order/list', { layout => 0 });
 }
 
+sub action_edit_assignment {
+  my ($self) = @_;
+
+  my $html   = $self->render('requirement_spec_order/edit_assignment', { output => 0 }, make_part_title => sub { $_[0]->partnumber . ' ' . $_[0]->description });
+  $self->js->html('#ui-tabs-4', $html)
+           ->render($self);
+}
+
+sub action_save_assignment {
+  my ($self)   = @_;
+  my $sections = $::form->{sections} || [];
+  SL::DB::RequirementSpecItem->new(id => $_->{id})->load->update_attributes(order_part_id => ($_->{order_part_id} || undef)) for @{ $sections };
+
+  my $html = $self->render('requirement_spec_order/list', { output => 0 });
+  $self->js->html('#ui-tabs-4', $html)
+           ->render($self);
+}
+
+sub action_cancel {
+  my ($self) = @_;
+
+  my $html = $self->render('requirement_spec_order/list', { output => 0 });
+  $self->js->html('#ui-tabs-4', $html)
+           ->render($self);
+}
+
 #
 # filters
 #
@@ -58,4 +84,6 @@ sub init_js {
 # helpers
 #
 
+sub init_all_parts { SL::DB::Manager::Part->get_all_sorted }
+
 1;
index d07ed04..35acefc 100644 (file)
@@ -41,7 +41,7 @@ __PACKAGE__->configure_acts_as_list(group_by => [qw(requirement_spec_id parent_i
 __PACKAGE__->attr_duration(qw(time_estimation));
 
 __PACKAGE__->before_save(\&_before_save_create_fb_number);
-__PACKAGE__->before_save(\  &_before_save_invalidate_requirement_spec_version);
+__PACKAGE__->before_save(\&_before_save_invalidate_requirement_spec_version);
 __PACKAGE__->before_delete(\&_before_delete_invalidate_requirement_spec_version);
 
 sub _before_save_create_fb_number {
index 9b68bc7..6491718 100644 (file)
@@ -325,16 +325,21 @@ ns.find_quotation_order_id = function(clicked_elt) {
   return $(clicked_elt).find('>[name=order_id]').val();
 };
 
-ns.standard_quotation_order_ajax_call = function(key, opt, other_data) {
-  var data = {
-    action:              "RequirementSpecOrder/" + key,
-    requirement_spec_id: $('#requirement_spec_id').val(),
-    id:                  ns.find_quotation_order_id(opt.$trigger)
-  };
+ns.standard_quotation_order_ajax_call = function(key, opt) {
+  if ((key == 'cancel') && !confirm(kivi.t8('Do you really want to cancel?')))
+    return true;
+
+  var data = 'action=RequirementSpecOrder/' + key
+           + '&' + $('#requirement_spec_id').serialize();
+
+  if (key == 'save_assignment')
+    data += '&' + $('#quotations_and_orders_article_assignment_form').serialize();
+  else
+    data += '&id=' + encodeURIComponent(ns.find_quotation_order_id(opt.$trigger));
 
   // console.log("I would normally POST the following now:");
   // console.log(data);
-  $.post("controller.pl", $.extend(data, other_data || {}), kivi.eval_json_result);
+  $.post("controller.pl", data, kivi.eval_json_result);
 
   return true;
 };
@@ -347,6 +352,13 @@ ns.disable_create_quotation_order_commands = function(key, opt) {
   return !$('#quotations_and_orders_sections');
 };
 
+ns.assign_order_part_id_to_all = function() {
+  var order_part_id = $('#quoations_and_orders_order_id').val();
+  $('#quotations_and_orders_article_assignment_form SELECT[name="sections[].order_part_id"]').each(function(idx, elt) {
+    $(elt).val(order_part_id);
+  });
+};
+
 // -------------------------------------------------------------------------
 // ---------------------------- general actions ----------------------------
 // -------------------------------------------------------------------------
@@ -507,13 +519,22 @@ ns.create_context_menus = function(is_template) {
   $.contextMenu({
     selector: '.quotations-and-orders-context-menu,.quotations-and-orders-order-context-menu',
     items:    $.extend({
-        heading:            { name: kivi.t8('Orders/Quotations actions'), className: 'context-menu-heading' }
-      , edit:               { name: kivi.t8('Edit article/section assignments'), icon: "edit",   callback: ns.standard_quotation_order_ajax_call }
+        heading:            { name: kivi.t8('Orders/Quotations actions'), className: 'context-menu-heading'                                                                                            }
+      , edit_assignment:    { name: kivi.t8('Edit article/section assignments'), icon: "edit",   callback: ns.standard_quotation_order_ajax_call                                                       }
       , sep1:               "---------"
-      , new:                { name: kivi.t8('Create new qutoation/order'),       icon: "add",    callback: ns.standard_quotation_order_ajax_call, disabled: ns.disable_create_quotation_order_commands}
-      , update:             { name: kivi.t8('Update quotation/order'),           icon: "update", callback: ns.standard_quotation_order_ajax_call, disabled: ns.disable_edit_quotation_order_commands }
+      , new:                { name: kivi.t8('Create new qutoation/order'),       icon: "add",    callback: ns.standard_quotation_order_ajax_call, disabled: ns.disable_create_quotation_order_commands }
+      , update:             { name: kivi.t8('Update quotation/order'),           icon: "update", callback: ns.standard_quotation_order_ajax_call, disabled: ns.disable_edit_quotation_order_commands   }
       , sep2:               "---------"
-      , delete:             { name: kivi.t8('Delete quotation/order'),           icon: "delete", callback: ns.ask_delete_quotation_order,         disabled: ns.disable_edit_quotation_order_commands }
+      , delete:             { name: kivi.t8('Delete quotation/order'),           icon: "delete", callback: ns.ask_delete_quotation_order,         disabled: ns.disable_edit_quotation_order_commands   }
+    }, general_actions)
+  });
+
+  $.contextMenu({
+    selector: '.quotations-and-orders-edit-assignment-context-menu',
+    items:    $.extend({
+        heading:         { name: kivi.t8('Edit article/section assignments'), className: 'context-menu-heading'    }
+      , save_assignment: { name: kivi.t8('Save'),   icon: "edit",  callback: ns.standard_quotation_order_ajax_call }
+      , cancel:          { name: kivi.t8('Cancel'), icon: "close", callback: ns.standard_quotation_order_ajax_call }
     }, general_actions)
   });
 
diff --git a/templates/webpages/requirement_spec_order/_assignment_form.html b/templates/webpages/requirement_spec_order/_assignment_form.html
new file mode 100644 (file)
index 0000000..cee29d0
--- /dev/null
@@ -0,0 +1,31 @@
+[%- USE HTML -%][%- USE LxERP -%][%- USE L -%][%- USE P -%]
+<div>
+ [% LxERP.t8("Assign the following article to all sections") %]:
+ [% L.select_tag('quotations_and_orders_dummy', SELF.all_parts, default=INSTANCE_CONF.get_requirement_spec_section_order_part_id, title_sub=\make_part_title, id='quoations_and_orders_order_id') %]
+ [% L.button_tag('kivi.requirement_spec.assign_order_part_id_to_all()', LxERP.t8('Assign article')) %]
+</div>
+
+<form id="quotations_and_orders_article_assignment_form">
+ <table style="width: 100%">
+  <thead>
+   <tr class="listheading">
+    <th>[% LxERP.t8("Number") %]</th>
+    <th>[% LxERP.t8("Title") %]</th>
+    <th>[% LxERP.t8("Description") %]</th>
+    <th>[% LxERP.t8("Article") %]</th>
+   </tr>
+  </thead>
+
+  <tbody>
+   [% FOREACH section = SELF.requirement_spec.sections_sorted %]
+   <tr class="listrow">
+    [% L.hidden_tag("sections[+].id", section.id, no_id=1) %]
+    <td>[% HTML.escape(section.fb_number) %]</td>
+    <td>[% HTML.escape(section.title) %]</td>
+    <td>[% HTML.escape(P.truncate(section.description)) %]</td>
+    <td>[% L.select_tag('sections[].order_part_id', SELF.all_parts, default=section.order_part_id, with_empty=1, title_sub=\make_part_title, no_id=1) %]</td>
+   </tr>
+   [% END %]
+  </tbody>
+ </table>
+</form>
diff --git a/templates/webpages/requirement_spec_order/edit_assignment.html b/templates/webpages/requirement_spec_order/edit_assignment.html
new file mode 100644 (file)
index 0000000..d33624e
--- /dev/null
@@ -0,0 +1,6 @@
+[%- USE LxERP -%][%- USE L -%]
+<div id="quotations_and_orders_article_assignment" class="quotations-and-orders-edit-assignment-context-menu">
+ <h2>[% LxERP.t8("Edit assignment of articles to sections") %]</h2>
+
+ [% INCLUDE 'requirement_spec_order/_assignment_form.html' %]
+</div>
index fb86baf..b48f2e2 100644 (file)
@@ -1,6 +1,7 @@
 [%- USE HTML -%][%- USE LxERP -%][%- USE L -%][%- USE P -%]
 <div id="quotations_and_orders" class="quotations-and-orders-context-menu">
  <h2>[% LxERP.t8("Assignment of articles to sections") %]</h2>
+
  [% SET sections = SELF.requirement_spec.sections_sorted %]
  [% IF !sections.size %]
  <div>