Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 28a7a539

Von Bernd Bleßmann vor fast 8 Jahren hinzugefügt

  • ID 28a7a5397bb2363fe72f9f43759d429535e29391
  • Vorgänger 76592c8a
  • Nachfolger 9eb765a5

Auftrags-Controller: zweite Zeile (im Moment Cvars) nur bei Bedarf laden.

Unterschiede anzeigen:

SL/Controller/Order.pm
594 594
  $_[0]->render(\ $longdescription, { type => 'text' });
595 595
}
596 596

  
597
# load the second row for an item (cvars only for now)
598
#
599
# This action gets the html code for the items second row by rendering a template for
600
# the second row and calls a javascript function with this html code via client js.
601
sub action_load_second_row {
602
  my ($self) = @_;
603

  
604
  my $idx  = first_index { $_ eq $::form->{item_id} } @{ $::form->{orderitem_ids} };
605
  my $item = $self->order->items_sorted->[$idx];
606

  
607
  # Parse values from form (they are formated while rendering (template)).
608
  # Workaround to pre-parse number-cvars (parse_custom_variable_values does not parse number values).
609
  # This parsing is not necessary at all, if we assure that the second row/cvars are only loaded once.
610
  #foreach my $var (@{ $item->cvars_by_config }) {
611
  #  $var->unparsed_value($::form->parse_amount(\%::myconfig, $var->{__unparsed_value})) if ($var->config->type eq 'number' && exists($var->{__unparsed_value}));
612
  #}
613
  #$item->parse_custom_variable_values;
614

  
615
  my $row_as_html = $self->p->render('order/tabs/_second_row', ITEM => $item);
616

  
617
  $self->js
618
    ->html('.row_entry:has(#item_' . $::form->{item_id} . ') [name = "second_row"]', $row_as_html)
619
    ->data('.row_entry:has(#item_' . $::form->{item_id} . ') [name = "second_row"]', 'loaded', 1)
620
    ->render();
621
}
622

  
597 623
sub _js_redisplay_linetotals {
598 624
  my ($self) = @_;
599 625

  
......
1289 1315
C<show_multi_items_dialog> does not use the currently inserted string for
1290 1316
filtering.
1291 1317

  
1292
=item * Performance
1293

  
1294
Rendering a 50 items order takes twice as long as the old code.
1295

  
1296
90% of that is rendering the (hidden) second rows, and 50% of those again are
1297
checks for is_valid and C<INCLUDE> on the cvar input template.
1298

  
1299
Suggestion: fetch second rows when asked for.
1300

  
1301 1318
=back
1302 1319

  
1303 1320
=head1 AUTHOR
js/kivi.Order.js
182 182
    html_elt.html(price_str);
183 183
  };
184 184

  
185
  ns.load_second_row = function(row) {
186
    var item_id_dom = $(row).find('[name="orderitem_ids[+]"]');
187
    var div_elt = $(row).find('[name="second_row"]');
188

  
189
    if ($(div_elt).data('loaded') == 1) {
190
      return;
191
    }
192
    var data = $('#order_form').serializeArray();
193
    data.push({ name: 'action', value: 'Order/load_second_row' });
194
    data.push({ name: 'item_id', value: item_id_dom.val() });
195

  
196
    $.post("controller.pl", data, kivi.eval_json_result);
197
  };
198

  
199

  
185 200
  ns.init_row_handlers = function() {
186 201
    kivi.run_once_for('.recalc', 'on_change_recalc', function(elt) {
187 202
      $(elt).change(ns.recalc_amounts_and_taxes);
......
198 213

  
199 214
    kivi.run_once_for('.row_entry', 'on_kbd_click_show_hide', function(elt) {
200 215
      $(elt).keydown(function(event) {
201
        var row;
202 216
        if(event.keyCode == 40 && event.shiftKey === true) {
203 217
          // shift arrow down
204 218
          event.preventDefault();
205
          row = $(event.target).parents(".row_entry").first();
219
          var row = $(event.target).parents(".row_entry").first();
220
          ns.load_second_row(row);
206 221
          $(row).children().not(':first').show();
207 222
          return false;
208 223
        }
209 224
        if(event.keyCode == 38 && event.shiftKey === true) {
210 225
          // shift arrow up
211 226
          event.preventDefault();
212
          row = $(event.target).parents(".row_entry").first();
227
          var row = $(event.target).parents(".row_entry").first();
213 228
          $(row).children().not(':first').hide();
214 229
          return false;
215 230
        }
......
217 232
      $(elt).dblclick(function(event) {
218 233
        event.preventDefault();
219 234
        var row = $(event.target).parents(".row_entry").first();
235
        ns.load_second_row(row);
220 236
        $(row).children().not(':first').toggle();
221 237
        return false;
222 238
      });
templates/webpages/order/tabs/_row.html
102 102

  
103 103
  <tr class="listrow1" style="display:none">
104 104
    <td colspan="100%">
105
      <table>
106
        <tr class="listrow1">
107
          [%- SET n = 0 %]
108
          [%- FOREACH var = ITEM.cvars_by_config %]
109
            [%- NEXT UNLESS (var.config.processed_flags.editable && ITEM.part.cvar_by_name(var.config.name).is_valid) %]
110
            [%- SET n = n + 1 %]
111
            <th>
112
              [% var.config.description %]
113
            </th>
114
            <td>
115
              [% L.hidden_tag('order.orderitems[].custom_variables[+].config_id', var.config.id) %]
116
              [% L.hidden_tag('order.orderitems[].custom_variables[].id', var.id) %]
117
              [% L.hidden_tag('order.orderitems[].custom_variables[].sub_module', var.sub_module) %]
118
              [% INCLUDE 'common/render_cvar_input.html' var_name='order.orderitems[].custom_variables[].unparsed_value' %]
119
            </td>
120
            [%- IF (n % (MYCONFIG.form_cvars_nr_cols || 3)) == 0 %]
121
              </tr><tr class="listrow1">
122
            [%- END %]
123
          [%- END %]
124
        </tr>
125
      </table>
105
      <div name="second_row">
106
        [%- LxERP.t8("Loading...") %]
107
      </div>
126 108
    </td>
127 109
  </tr>
128 110

  
templates/webpages/order/tabs/_second_row.html
1
[%- USE T8 %]
2
[%- USE HTML %]
3
[%- USE LxERP %]
4
[%- USE L %]
5

  
6
<table>
7
  <tr class="listrow1">
8
    [%- SET n = 0 %]
9
    [%- FOREACH var = ITEM.cvars_by_config %]
10
    [%- NEXT UNLESS (var.config.processed_flags.editable && ITEM.part.cvar_by_name(var.config.name).is_valid) %]
11
    [%- SET n = n + 1 %]
12
    <th>
13
      [% var.config.description %]
14
    </th>
15
    <td>
16
      [% L.hidden_tag('order.orderitems[].custom_variables[+].config_id', var.config.id) %]
17
      [% L.hidden_tag('order.orderitems[].custom_variables[].id', var.id) %]
18
      [% L.hidden_tag('order.orderitems[].custom_variables[].sub_module', var.sub_module) %]
19
      [% INCLUDE 'common/render_cvar_input.html' var_name='order.orderitems[].custom_variables[].unparsed_value' %]
20
    </td>
21
    [%- IF (n % (MYCONFIG.form_cvars_nr_cols || 3)) == 0 %]
22
  </tr><tr class="listrow1">
23
    [%- END %]
24
    [%- END %]
25
  </tr>
26
</table>

Auch abrufbar als: Unified diff