Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 88ad13f9

Von Tamino Steinert vor 6 Tagen hinzugefügt

  • ID 88ad13f98aa6f7dcf45738925a5d7caac1c04fb9
  • Vorgänger daa95513
  • Nachfolger 58c39ac5

Varianten: Sortieren der Variantentabelle ermöglicht

Unterschiede anzeigen:

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

  
867
sub action_reorder_variants {
868
  my ($self) = @_;
869

  
870
  my $part= $self->part;
871

  
872
  my %sort_keys = (
873
    partnumber       => sub { $_[0]->partnumber },
874
    description      => sub { $_[0]->description },
875
    sellprice        => sub { $_[0]->sellprice },
876
    lastcost         => sub { $_[0]->lastcost },
877
    variant_values   => sub { $_[0]->variant_values },
878
  );
879
  foreach my $variant_property (@{$part->variant_properties}) {
880
    my $key = 'variant_property_' . $variant_property->unique_name;
881
    $sort_keys{$key} = sub {
882
      $_[0]->get_variant_property_value_by_unique_name($variant_property->unique_name)->value;
883
    }
884
  }
885

  
886
  my $method = $sort_keys{$::form->{order_by}};
887

  
888
  my @items = $part->variants;
889

  
890
  my %variant_id_to_position =
891
    map {$_->{id} => $_->{position}}
892
    @{$::form->{variants}};
893

  
894
  my @to_sort = map { { old_pos => $variant_id_to_position{$_->id}, order_by => $method->($_) } } @items;
895
  if ($::form->{order_by} =~ /^(sellprice|lastcost)$/) {
896
    if ($::form->{sort_dir}) {
897
      @to_sort = sort { $a->{order_by} <=> $b->{order_by} } @to_sort;
898
    } else {
899
      @to_sort = sort { $b->{order_by} <=> $a->{order_by} } @to_sort;
900
    }
901
  } else {
902
    if ($::form->{sort_dir}) {
903
      @to_sort = sort { $a->{order_by} cmp $b->{order_by} } @to_sort;
904
    } else {
905
      @to_sort = sort { $b->{order_by} cmp $a->{order_by} } @to_sort;
906
    }
907
  };
908

  
909
  $self->js->run('kivi.Part.redisplay_variants', \@to_sort)->render;
910
}
911

  
867 912
sub action_warehouse_changed {
868 913
  my ($self) = @_;
869 914

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

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

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

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

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

  
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