]> wagnertech.de Git - mfinanz.git/blobdiff - SL/Controller/Order.pm
Auftrags-Controller: zweite Zeile laden mit Icons und alle zweiten Zeilen laden.
[mfinanz.git] / SL / Controller / Order.pm
index 78e9e5436041a78664c7ae4040c84820b9a3f54f..b11e364b9313e48fb6fc3b1f35f3bd1865bdd2ac 100644 (file)
@@ -594,6 +594,43 @@ sub action_get_item_longdescription {
   $_[0]->render(\ $longdescription, { type => 'text' });
 }
 
+# load the second row for one or more items (cvars only for now)
+#
+# This action gets the html code for all items second rows by rendering a template for
+# the second row and sets the html code via client js.
+sub action_load_second_rows {
+  my ($self) = @_;
+
+  foreach my $item_id (@{ $::form->{item_ids} }) {
+    my $idx  = first_index { $_ eq $item_id } @{ $::form->{orderitem_ids} };
+    my $item = $self->order->items_sorted->[$idx];
+
+    $self->_js_load_second_row($item, $item_id, 0);
+  }
+
+  $self->js->render();
+}
+
+sub _js_load_second_row {
+  my ($self, $item, $item_id, $do_parse) = @_;
+
+  if ($do_parse) {
+    # 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_' . $item_id . ') [name = "second_row"]', $row_as_html)
+    ->data('.row_entry:has(#item_' . $item_id . ') [name = "second_row"]', 'loaded', 1);
+}
+
 sub _js_redisplay_linetotals {
   my ($self) = @_;
 
@@ -1289,15 +1326,6 @@ should be implemented.
 C<show_multi_items_dialog> 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<INCLUDE> on the cvar input template.
-
-Suggestion: fetch second rows when asked for.
-
 =back
 
 =head1 AUTHOR