|
1 |
| -<legend><%= t 'title_section' %></legend> |
| 1 | +<div class="alert-status"></div> |
| 2 | + |
| 3 | +<em> |
| 4 | + <%= t 'helper_soratble' %> |
| 5 | +</em> |
| 6 | + |
| 7 | +<br /> |
| 8 | +<br /> |
2 | 9 |
|
| 10 | +<legend><%= t 'title_section' %></legend> |
3 | 11 | <ul id="sortable">
|
4 |
| - <% @abstract_model.all.each do |o| %> |
5 |
| - <li class="sortable-container"> |
| 12 | + <% @objects.each do |o| %> |
| 13 | + <li data-id="<%= o.id %>" data-position="" class="sortable-container"> |
6 | 14 | <span class="ref_number">
|
7 | 15 | <% unless @sortable_section.position_method.nil? %>
|
8 | 16 | <%= o.send(@sortable_section.position_method) %>
|
|
21 | 29 |
|
22 | 30 | <script type="text/javascript" charset="utf-8">
|
23 | 31 | $(function () {
|
| 32 | + handleBaseNumberJs(); |
| 33 | + |
24 | 34 | $("#sortable").sortable({
|
25 |
| - placeholder: "ui-state-highlight" |
| 35 | + axis: 'y', |
| 36 | + placeholder: "ui-state-highlight", |
| 37 | + update: function () { |
| 38 | + $.when(handleBaseNumberJs()).done(function () { |
| 39 | + $('.btn-validate').attr( "disabled", "disabled" ); |
| 40 | + |
| 41 | + var ordered = []; |
| 42 | + $('.sortable-container').each(function (i, elem) { |
| 43 | + ordered.push({id: $(this).attr('data-id'), position: $(this).attr('data-position')}); |
| 44 | + }); |
| 45 | + |
| 46 | + $.ajax({ |
| 47 | + type: "POST", |
| 48 | + url: '<%= sortable_path(:model_name => @abstract_model.to_param) %>', |
| 49 | + data: { 'data': ordered }, |
| 50 | + success: function (data) { |
| 51 | + $('.btn-validate').removeAttr("disabled"); |
| 52 | + $('.alert-status').html('<div class="alert alert-dismissible alert-success"> <button class="close" data-dismiss="alert" type="button">×</button>Modification éffectuée avec succès</div>').fadeIn().delay(3000).fadeOut(); |
| 53 | + }, |
| 54 | + error: function (data) { |
| 55 | + $('.alert-status').html('<div class="alert alert-dismissible alert-danger"> <button class="close" data-dismiss="alert" type="button">×</button>Erreur lors de la modification</div>').fadeIn().delay(3000).fadeOut(); |
| 56 | + } |
| 57 | + }); |
| 58 | + }); |
| 59 | + } |
26 | 60 | });
|
| 61 | + |
27 | 62 | $("#sortable").disableSelection();
|
28 |
| - $('.ref_number').each(function (i, elem) { |
29 |
| - $(this).html(i + 1); |
30 |
| - }) |
| 63 | + |
| 64 | + function handleBaseNumberJs() { |
| 65 | + $('.ref_number').each(function (i, elem) { |
| 66 | + $(elem).html(i + 1); |
| 67 | + }); |
| 68 | + $('.sortable-container').each(function (i, elem) { |
| 69 | + $(elem).attr('data-position', i + 1) |
| 70 | + }); |
| 71 | + } |
31 | 72 | });
|
32 | 73 | </script>
|
0 commit comments