From: Bernd Bleßmann Date: Thu, 1 Sep 2016 13:53:46 +0000 (+0200) Subject: Auftrags-Controller: zweite Zeile (im Moment Cvars) nur bei Bedarf laden. X-Git-Tag: release-3.5.4~1830 X-Git-Url: http://wagnertech.de/git?a=commitdiff_plain;h=28a7a5397bb2363fe72f9f43759d429535e29391;p=kivitendo-erp.git Auftrags-Controller: zweite Zeile (im Moment Cvars) nur bei Bedarf laden. --- diff --git a/SL/Controller/Order.pm b/SL/Controller/Order.pm index 78e9e5436..144a195d2 100644 --- a/SL/Controller/Order.pm +++ b/SL/Controller/Order.pm @@ -594,6 +594,32 @@ sub action_get_item_longdescription { $_[0]->render(\ $longdescription, { type => 'text' }); } +# load the second row for an item (cvars only for now) +# +# This action gets the html code for the items second row by rendering a template for +# the second row and calls a javascript function with this html code via client js. +sub action_load_second_row { + my ($self) = @_; + + my $idx = first_index { $_ eq $::form->{item_id} } @{ $::form->{orderitem_ids} }; + my $item = $self->order->items_sorted->[$idx]; + + # Parse values from form (they are formated while rendering (template)). + # Workaround to pre-parse number-cvars (parse_custom_variable_values does not parse number values). + # This parsing is not necessary at all, if we assure that the second row/cvars are only loaded once. + #foreach my $var (@{ $item->cvars_by_config }) { + # $var->unparsed_value($::form->parse_amount(\%::myconfig, $var->{__unparsed_value})) if ($var->config->type eq 'number' && exists($var->{__unparsed_value})); + #} + #$item->parse_custom_variable_values; + + my $row_as_html = $self->p->render('order/tabs/_second_row', ITEM => $item); + + $self->js + ->html('.row_entry:has(#item_' . $::form->{item_id} . ') [name = "second_row"]', $row_as_html) + ->data('.row_entry:has(#item_' . $::form->{item_id} . ') [name = "second_row"]', 'loaded', 1) + ->render(); +} + sub _js_redisplay_linetotals { my ($self) = @_; @@ -1289,15 +1315,6 @@ should be implemented. C does not use the currently inserted string for filtering. -=item * Performance - -Rendering a 50 items order takes twice as long as the old code. - -90% of that is rendering the (hidden) second rows, and 50% of those again are -checks for is_valid and C on the cvar input template. - -Suggestion: fetch second rows when asked for. - =back =head1 AUTHOR diff --git a/js/kivi.Order.js b/js/kivi.Order.js index c4aabf763..741526f86 100644 --- a/js/kivi.Order.js +++ b/js/kivi.Order.js @@ -182,6 +182,21 @@ namespace('kivi.Order', function(ns) { html_elt.html(price_str); }; + ns.load_second_row = function(row) { + var item_id_dom = $(row).find('[name="orderitem_ids[+]"]'); + var div_elt = $(row).find('[name="second_row"]'); + + if ($(div_elt).data('loaded') == 1) { + return; + } + var data = $('#order_form').serializeArray(); + data.push({ name: 'action', value: 'Order/load_second_row' }); + data.push({ name: 'item_id', value: item_id_dom.val() }); + + $.post("controller.pl", data, kivi.eval_json_result); + }; + + ns.init_row_handlers = function() { kivi.run_once_for('.recalc', 'on_change_recalc', function(elt) { $(elt).change(ns.recalc_amounts_and_taxes); @@ -198,18 +213,18 @@ namespace('kivi.Order', function(ns) { kivi.run_once_for('.row_entry', 'on_kbd_click_show_hide', function(elt) { $(elt).keydown(function(event) { - var row; if(event.keyCode == 40 && event.shiftKey === true) { // shift arrow down event.preventDefault(); - row = $(event.target).parents(".row_entry").first(); + var row = $(event.target).parents(".row_entry").first(); + ns.load_second_row(row); $(row).children().not(':first').show(); return false; } if(event.keyCode == 38 && event.shiftKey === true) { // shift arrow up event.preventDefault(); - row = $(event.target).parents(".row_entry").first(); + var row = $(event.target).parents(".row_entry").first(); $(row).children().not(':first').hide(); return false; } @@ -217,6 +232,7 @@ namespace('kivi.Order', function(ns) { $(elt).dblclick(function(event) { event.preventDefault(); var row = $(event.target).parents(".row_entry").first(); + ns.load_second_row(row); $(row).children().not(':first').toggle(); return false; }); diff --git a/templates/webpages/order/tabs/_row.html b/templates/webpages/order/tabs/_row.html index 63243c605..88888e9db 100644 --- a/templates/webpages/order/tabs/_row.html +++ b/templates/webpages/order/tabs/_row.html @@ -102,27 +102,9 @@ - - - [%- SET n = 0 %] - [%- FOREACH var = ITEM.cvars_by_config %] - [%- NEXT UNLESS (var.config.processed_flags.editable && ITEM.part.cvar_by_name(var.config.name).is_valid) %] - [%- SET n = n + 1 %] - - - [%- IF (n % (MYCONFIG.form_cvars_nr_cols || 3)) == 0 %] - - [%- END %] - [%- END %] - -
- [% var.config.description %] - - [% L.hidden_tag('order.orderitems[].custom_variables[+].config_id', var.config.id) %] - [% L.hidden_tag('order.orderitems[].custom_variables[].id', var.id) %] - [% L.hidden_tag('order.orderitems[].custom_variables[].sub_module', var.sub_module) %] - [% INCLUDE 'common/render_cvar_input.html' var_name='order.orderitems[].custom_variables[].unparsed_value' %] -
+
+ [%- LxERP.t8("Loading...") %] +
diff --git a/templates/webpages/order/tabs/_second_row.html b/templates/webpages/order/tabs/_second_row.html new file mode 100644 index 000000000..7f9a17bf2 --- /dev/null +++ b/templates/webpages/order/tabs/_second_row.html @@ -0,0 +1,26 @@ +[%- USE T8 %] +[%- USE HTML %] +[%- USE LxERP %] +[%- USE L %] + + + + [%- SET n = 0 %] + [%- FOREACH var = ITEM.cvars_by_config %] + [%- NEXT UNLESS (var.config.processed_flags.editable && ITEM.part.cvar_by_name(var.config.name).is_valid) %] + [%- SET n = n + 1 %] + + + [%- IF (n % (MYCONFIG.form_cvars_nr_cols || 3)) == 0 %] + + [%- END %] + [%- END %] + +
+ [% var.config.description %] + + [% L.hidden_tag('order.orderitems[].custom_variables[+].config_id', var.config.id) %] + [% L.hidden_tag('order.orderitems[].custom_variables[].id', var.id) %] + [% L.hidden_tag('order.orderitems[].custom_variables[].sub_module', var.sub_module) %] + [% INCLUDE 'common/render_cvar_input.html' var_name='order.orderitems[].custom_variables[].unparsed_value' %] +