From 1bacd5c15dbf06c84167d823544015d59fdc23be Mon Sep 17 00:00:00 2001 From: Moritz Bunkus Date: Tue, 9 Jul 2013 16:17:16 +0200 Subject: [PATCH] Pflichtenhefte: Zuweisung Artikel zu Abschnitten implementiert --- SL/Controller/RequirementSpecOrder.pm | 32 ++++++++++++- SL/DB/RequirementSpecItem.pm | 2 +- js/requirement_spec.js | 45 ++++++++++++++----- .../_assignment_form.html | 31 +++++++++++++ .../edit_assignment.html | 6 +++ .../webpages/requirement_spec_order/list.html | 1 + 6 files changed, 102 insertions(+), 15 deletions(-) create mode 100644 templates/webpages/requirement_spec_order/_assignment_form.html create mode 100644 templates/webpages/requirement_spec_order/edit_assignment.html diff --git a/SL/Controller/RequirementSpecOrder.pm b/SL/Controller/RequirementSpecOrder.pm index 67b780f42..1822e2be3 100644 --- a/SL/Controller/RequirementSpecOrder.pm +++ b/SL/Controller/RequirementSpecOrder.pm @@ -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; diff --git a/SL/DB/RequirementSpecItem.pm b/SL/DB/RequirementSpecItem.pm index d07ed04c8..35acefcb6 100644 --- a/SL/DB/RequirementSpecItem.pm +++ b/SL/DB/RequirementSpecItem.pm @@ -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 { diff --git a/js/requirement_spec.js b/js/requirement_spec.js index 9b68bc7b6..649171826 100644 --- a/js/requirement_spec.js +++ b/js/requirement_spec.js @@ -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 index 000000000..cee29d0f0 --- /dev/null +++ b/templates/webpages/requirement_spec_order/_assignment_form.html @@ -0,0 +1,31 @@ +[%- USE HTML -%][%- USE LxERP -%][%- USE L -%][%- USE P -%] +
+ [% 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')) %] +
+ +
+ + + + + + + + + + + + [% FOREACH section = SELF.requirement_spec.sections_sorted %] + + [% L.hidden_tag("sections[+].id", section.id, no_id=1) %] + + + + + + [% END %] + +
[% LxERP.t8("Number") %][% LxERP.t8("Title") %][% LxERP.t8("Description") %][% LxERP.t8("Article") %]
[% HTML.escape(section.fb_number) %][% HTML.escape(section.title) %][% HTML.escape(P.truncate(section.description)) %][% 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) %]
+
diff --git a/templates/webpages/requirement_spec_order/edit_assignment.html b/templates/webpages/requirement_spec_order/edit_assignment.html new file mode 100644 index 000000000..d33624e7f --- /dev/null +++ b/templates/webpages/requirement_spec_order/edit_assignment.html @@ -0,0 +1,6 @@ +[%- USE LxERP -%][%- USE L -%] +
+

[% LxERP.t8("Edit assignment of articles to sections") %]

+ + [% INCLUDE 'requirement_spec_order/_assignment_form.html' %] +
diff --git a/templates/webpages/requirement_spec_order/list.html b/templates/webpages/requirement_spec_order/list.html index fb86baf5c..b48f2e2f6 100644 --- a/templates/webpages/requirement_spec_order/list.html +++ b/templates/webpages/requirement_spec_order/list.html @@ -1,6 +1,7 @@ [%- USE HTML -%][%- USE LxERP -%][%- USE L -%][%- USE P -%]

[% LxERP.t8("Assignment of articles to sections") %]

+ [% SET sections = SELF.requirement_spec.sections_sorted %] [% IF !sections.size %]
-- 2.20.1