$_[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) = @_;
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
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);
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;
}
$(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;
});
<tr class="listrow1" style="display:none">
<td colspan="100%">
- <table>
- <tr class="listrow1">
- [%- 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 %]
- <th>
- [% var.config.description %]
- </th>
- <td>
- [% 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' %]
- </td>
- [%- IF (n % (MYCONFIG.form_cvars_nr_cols || 3)) == 0 %]
- </tr><tr class="listrow1">
- [%- END %]
- [%- END %]
- </tr>
- </table>
+ <div name="second_row">
+ [%- LxERP.t8("Loading...") %]
+ </div>
</td>
</tr>
--- /dev/null
+[%- USE T8 %]
+[%- USE HTML %]
+[%- USE LxERP %]
+[%- USE L %]
+
+<table>
+ <tr class="listrow1">
+ [%- 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 %]
+ <th>
+ [% var.config.description %]
+ </th>
+ <td>
+ [% 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' %]
+ </td>
+ [%- IF (n % (MYCONFIG.form_cvars_nr_cols || 3)) == 0 %]
+ </tr><tr class="listrow1">
+ [%- END %]
+ [%- END %]
+ </tr>
+</table>