Commit e12530554faa74d175f93d40feafd0bd5f5ff9c8

Authored by Karpikau Andrei
1 parent 895f98e6

add sorting to repear element

... ... @@ -159,8 +159,9 @@ jQuery(document).ready(function(){
159 159 var $wrapper = $(this);
160 160 $wrapper.sortable({
161 161 stop: function( event, ui ) {
162   - data = [];
163   - position = 1;
  162 + var data = [],
  163 + position = 1;
  164 +
164 165 $wrapper.find( " > .panel" ).each(function(){
165 166 data.push({position: position, index: $(this).data('id')});
166 167 position += 1;
... ... @@ -320,6 +321,42 @@ jQuery(document).ready(function(){
320 321 return false;
321 322 });
322 323
  324 + $('.html-generator').on('click', '.sort-repeat-row', function(data, status, xhr){
  325 + var $this = $(this),
  326 + url = $this.attr('href'),
  327 + $wrapper = $this.closest('.panel-group'),
  328 + $currentItem = $this.closest('.panel'),
  329 + $prevItem = $currentItem.prev(),
  330 + $nextItem = $currentItem.next();
  331 +
  332 + if($this.hasClass('sort-up') && $prevItem){
  333 + $currentItem.insertBefore($prevItem);
  334 + }
  335 + if($this.hasClass('sort-down') && $nextItem){
  336 + $currentItem.insertAfter($nextItem);
  337 + }
  338 +
  339 +
  340 + var data = [],
  341 + position = 1;
  342 +
  343 + $wrapper.find( " > .panel" ).each(function(){
  344 + data.push({position: position, index: $(this).data('id')});
  345 + position += 1;
  346 + });
  347 + jQuery.ajax({
  348 + type: 'POST',
  349 + url: $wrapper.data('update-url'),
  350 + data: {data: data},
  351 + success: function (data) {
  352 +
  353 + }
  354 + });
  355 +
  356 +
  357 + return false;
  358 + });
  359 +
323 360
324 361
325 362
... ...
... ... @@ -77,7 +77,16 @@
77 77 </a>
78 78 </div>
79 79 <div class="col-md-2">
80   - <%= link_to 'x', url_for(:controller => 'admin/page_contents', :action => 'delete_item', id: @obj.id, row_item: index), class: 'delete-repeat-row' %>
  80 + <%= link_to '#', class: 'sort-repeat-row sort-up' do %>
  81 + <i class="fa fa-arrow-up"></i>
  82 + <% end %>
  83 + <%= link_to '#', class: 'sort-repeat-row sort-down' do %>
  84 + <i class="fa fa-arrow-down"></i>
  85 + <% end %>
  86 + <%= link_to url_for(:controller => 'admin/page_contents', :action => 'delete_item', id: @obj.id, row_item: index), class: 'delete-repeat-row' do %>
  87 + <i class="fa fa-close"></i>
  88 + <% end %>
  89 +
81 90 </div>
82 91 </div>
83 92 </h4>
... ...
1 1 module Kanjai
2   - VERSION = "0.0.110"
  2 + VERSION = "0.0.111"
3 3 end
... ...