Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 4d45be84

Von Tamino Steinert vor 6 Monaten hinzugefügt

  • ID 4d45be848f4418fa2518f62c111d1f0b164c5eb6
  • Vorgänger e4982f5b
  • Nachfolger 5f8fd730

Varianten: Sortieren der Variantentabelle ermöglicht

Unterschiede anzeigen:

SL/Controller/Part.pm
857 857
  $self->js->run('kivi.Part.redisplay_items', \@to_sort)->render;
858 858
}
859 859

  
860
sub action_reorder_variants {
861
  my ($self) = @_;
862

  
863
  my $part= $self->part;
864

  
865
  my %sort_keys = (
866
    partnumber       => sub { $_[0]->partnumber },
867
    description      => sub { $_[0]->description },
868
    sellprice        => sub { $_[0]->sellprice },
869
    lastcost         => sub { $_[0]->lastcost },
870
    variant_values   => sub { $_[0]->variant_values },
871
  );
872
  foreach my $variant_property (@{$part->variant_properties}) {
873
    my $key = 'variant_property_' . $variant_property->unique_name;
874
    $sort_keys{$key} = sub {
875
      $_[0]->get_variant_property_value_by_unique_name($variant_property->unique_name)->value;
876
    }
877
  }
878

  
879
  my $method = $sort_keys{$::form->{order_by}};
880

  
881
  my @items = $part->variants;
882

  
883
  my %variant_id_to_position =
884
    map {$_->{id} => $_->{position}}
885
    @{$::form->{variants}};
886

  
887
  my @to_sort = map { { old_pos => $variant_id_to_position{$_->id}, order_by => $method->($_) } } @items;
888
  if ($::form->{order_by} =~ /^(sellprice|lastcost)$/) {
889
    if ($::form->{sort_dir}) {
890
      @to_sort = sort { $a->{order_by} <=> $b->{order_by} } @to_sort;
891
    } else {
892
      @to_sort = sort { $b->{order_by} <=> $a->{order_by} } @to_sort;
893
    }
894
  } else {
895
    if ($::form->{sort_dir}) {
896
      @to_sort = sort { $a->{order_by} cmp $b->{order_by} } @to_sort;
897
    } else {
898
      @to_sort = sort { $b->{order_by} cmp $a->{order_by} } @to_sort;
899
    }
900
  };
901

  
902
  $self->js->run('kivi.Part.redisplay_variants', \@to_sort)->render;
903
}
904

  
860 905
sub action_warehouse_changed {
861 906
  my ($self) = @_;
862 907

  
SL/DB/Part.pm
339 339
  shift->buchungsgruppen(@_);
340 340
}
341 341

  
342
sub get_variant_property_value_by_unique_name {
343
  my ($self, $variant_property_unique_name) = @_;
344

  
345
  my %unique_name_to_variant_property_value =
346
    map { $_->variant_property->unique_name => $_ }
347
    $self->variant_property_values;
348

  
349
  my $variant_property_value = $unique_name_to_variant_property_value{$variant_property_unique_name}
350
    or confess "Part is not associated with a matching SL::DB::VariantPropertyValue";
351
  return $variant_property_value;
352
}
353

  
342 354
sub get_taxkey {
343 355
  my ($self, %params) = @_;
344 356

  
js/kivi.Part.js
83 83
    $.post("controller.pl", data, kivi.eval_json_result);
84 84
  };
85 85

  
86
  ns.redisplay_items = function(data) {
87
    var old_rows;
88
    var part_type = $("#part_part_type").val();
89
    if (part_type === 'assortment') {
90
      old_rows = $('.assortment_item_row').detach();
91
    } else if ( part_type === 'assembly') {
92
      old_rows = $('.assembly_item_row').detach();
93
    }
94
    var new_rows = [];
95
    $(data).each(function(_idx, elt) {
96
      new_rows.push(old_rows[elt.old_pos - 1]);
97
    });
98
    if (part_type === 'assortment') {
99
      $(new_rows).appendTo($('#assortment_items'));
100
    } else if ( part_type === 'assembly') {
101
      $(new_rows).appendTo($('#assembly_items'));
102
    }
103
    ns.renumber_positions();
104
  };
105

  
106
  ns.reorder_variants = function(order_by) {
107
    var dir = $('#variant_' + order_by + '_header_id a img').attr("data-sort-dir");
108
    $('#parent_variant_table thead a img').remove();
109

  
110
    var src;
111
    if (dir == "1") {
112
      dir = "0";
113
      src = "image/up.png";
114
    } else {
115
      dir = "1";
116
      src = "image/down.png";
117
    }
118

  
119
    $('#variant_' + order_by + '_header_id a').append('<img border=0 data-sort-dir=' + dir + ' src=' + src + ' alt="' + kivi.t8('sort items') + '">');
120

  
121
    var data = $('#ic').serializeArray();
122
    data.push({ name: 'action',   value: 'Part/reorder_variants' },
123
              { name: 'order_by', value: order_by              },
124
              { name: 'sort_dir', value: dir                   });
125

  
126
    $.post("controller.pl", data, kivi.eval_json_result);
127
  };
128

  
129
  ns.redisplay_variants = function(data) {
130
    var old_rows = $('.variant_row_entry').detach();
131
    var new_rows = [];
132
    $(data).each(function(idx, elt) {
133
      let new_row = old_rows[elt.old_pos - 1];
134
      $(new_row).find('[name="variants[].position"]').val( idx+1);
135
      new_rows.push(new_row);
136
    });
137
    $(new_rows).appendTo($('#parent_variant_table'));
138
  };
139

  
86 140
  ns.assortment_recalc = function() {
87 141
    var data = $('#assortment :input').serializeArray();
88 142
    data.push(
......
215 269
    });
216 270
  };
217 271

  
218
  ns.redisplay_items = function(data) {
219
    var old_rows;
220
    var part_type = $("#part_part_type").val();
221
    if (part_type === 'assortment') {
222
      old_rows = $('.assortment_item_row').detach();
223
    } else if ( part_type === 'assembly') {
224
      old_rows = $('.assembly_item_row').detach();
225
    }
226
    var new_rows = [];
227
    $(data).each(function(idx, elt) {
228
      new_rows.push(old_rows[elt.old_pos - 1]);
229
    });
230
    if (part_type === 'assortment') {
231
      $(new_rows).appendTo($('#assortment_items'));
232
    } else if ( part_type === 'assembly') {
233
      $(new_rows).appendTo($('#assembly_items'));
234
    }
235
    ns.renumber_positions();
236
  };
237

  
238 272
  ns.focus_last_assortment_input = function () {
239 273
    $("#assortment_items tr:last").find('input[type=text]').filter(':visible:first').focus();
240 274
  };
templates/design40_webpages/part/_parent_variant.html
4 4
[% USE L %]
5 5
[% USE P %]
6 6

  
7
<div class="wrapper">
7
<div id="parent_variant" class="wrapper">
8 8
  <div class="wrapper input-panel">
9 9
    <h3> [% LxERP.t8("Variant Properties") %] </h3>
10
    <table class="tbl-list">
10
    <table id="parent_variant_table" class="tbl-list">
11 11
      <caption>
12 12
        [% LxERP.t8("Variants") %]
13 13
      </caption>
14 14
      <thead>
15
        <th>[% "Partnumber" | $T8 %]</th>
16
        <th>[% "Description" | $T8 %]</th>
17
        <th>[% "Property Values (Abbreviation)" | $T8 %]</th>
15
        <th></th>
16
        <th id="variant_partnumber_header_id">
17
          <a href='#' onClick='javascript:kivi.Part.reorder_variants("partnumber")'>
18
            [% 'Partnumber' | $T8 %]
19
          </a>
20
        </th>
21
        <th id="variant_description_header_id">
22
          <a href='#' onClick='javascript:kivi.Part.reorder_variants("description")'>
23
            [% "Description" | $T8 %]
24
          </a>
25
        </th>
26
        <th id="variant_variant_values_header_id">
27
          <a href='#' onClick='javascript:kivi.Part.reorder_variants("variant_values")'>
28
            [% "Property Values (Abbreviation)" | $T8 %]
29
          </a>
30
        </th>
18 31
        [% FOREACH variant_property = SELF.part.variant_properties %]
19
        <th> [% variant_property.displayable_name %] </th>
32
        <th id="variant_variant_property_[% variant_property.unique_name %]_header_id">
33
          <a href='#' onClick='javascript:kivi.Part.reorder_variants("variant_property_[% variant_property.unique_name %]")'>
34
            [% variant_property.displayable_name %]
35
          </a>
36
        </th>
20 37
        [% END %]
21 38
        <th>
22 39
          [% L.select_tag("add_variant_property", AVAILABLE_VARIANT_PROPERIES
......
27 44
          [% L.button_tag('kivi.Part.add_variant_property();', LxERP.t8("Insert new")) %]
28 45
        </th>
29 46
      </thead>
30
      <tbody class="row_entry listrow">
47
      <tbody class="listrow">
31 48
        [% FOREACH variant = SELF.part.variants %]
32
          <tr>
49
          <tr class="variant_row_entry">
50
            <td>
51
              [% L.hidden_tag("variants[+].id", variant.id) %]
52
              [% L.hidden_tag("variants[].position", loop.count) %]
53
            </td>
33 54
            <td>[% variant.presenter.part %]</td>
34 55
            <td>[% variant.description | html %]</td>
35 56
            <td>[% variant.variant_values | html %]</td>

Auch abrufbar als: Unified diff