Commit 895f98e66f437913a9b99876b111e2cd2ffbcb54

Authored by Karpikau Andrei
1 parent 40c2023c

add sorting to repear element

@@ -506,8 +506,6 @@ jQuery(document).ready(function(){ @@ -506,8 +506,6 @@ jQuery(document).ready(function(){
506 506
507 return false; 507 return false;
508 }); 508 });
509 -  
510 -  
511 }); 509 });
512 510
513 511
@@ -515,4 +513,5 @@ jQuery(document).ready(function(){ @@ -515,4 +513,5 @@ jQuery(document).ready(function(){
515 513
516 514
517 515
  516 +
518 }); 517 });
@@ -154,6 +154,31 @@ jQuery(document).ready(function(){ @@ -154,6 +154,31 @@ jQuery(document).ready(function(){
154 clearAjaxFileUpload($('#work_area .editor-content')); 154 clearAjaxFileUpload($('#work_area .editor-content'));
155 ajaxFileUpload = initAjaxFileUpload($('#work_area .editor-content')); 155 ajaxFileUpload = initAjaxFileUpload($('#work_area .editor-content'));
156 156
  157 + if($('.sortable-list').length > 0){
  158 + $('.sortable-list').each(function(){
  159 + var $wrapper = $(this);
  160 + $wrapper.sortable({
  161 + stop: function( event, ui ) {
  162 + data = [];
  163 + position = 1;
  164 + $wrapper.find( " > .panel" ).each(function(){
  165 + data.push({position: position, index: $(this).data('id')});
  166 + position += 1;
  167 + });
  168 + jQuery.ajax({
  169 + type: 'POST',
  170 + url: $wrapper.data('update-url'),
  171 + data: {data: data},
  172 + success: function (data) {
  173 +
  174 + }
  175 + });
  176 + }
  177 + });
  178 + $wrapper.disableSelection();
  179 + });
  180 +
  181 + }
157 182
158 }; 183 };
159 184
@@ -194,6 +219,7 @@ jQuery(document).ready(function(){ @@ -194,6 +219,7 @@ jQuery(document).ready(function(){
194 content_type = $this.val(), 219 content_type = $this.val(),
195 show_content_url = $this.data('show_content_url') 220 show_content_url = $this.data('show_content_url')
196 221
  222 +
197 jQuery.ajax({ 223 jQuery.ajax({
198 type: 'POST', 224 type: 'POST',
199 url: show_content_url, 225 url: show_content_url,
@@ -27,7 +27,6 @@ module Kanjai @@ -27,7 +27,6 @@ module Kanjai
27 @current_row = @obj.page_content_markers.where('row_item != ?', @row_item).count 27 @current_row = @obj.page_content_markers.where('row_item != ?', @row_item).count
28 28
29 render layout: false 29 render layout: false
30 -  
31 end 30 end
32 31
33 def delete_item 32 def delete_item
@@ -38,7 +37,23 @@ module Kanjai @@ -38,7 +37,23 @@ module Kanjai
38 @obj.delete_markers_row(@row_item) 37 @obj.delete_markers_row(@row_item)
39 38
40 render :json => {status: 'ok'} 39 render :json => {status: 'ok'}
  40 + end
  41 +
  42 + def sorting
  43 + @obj = PageContent.find(params[:id])
41 44
  45 + h = {}
  46 + params[:data].each do |key, item|
  47 + h[item[:index].to_i] = item[:position].to_i
  48 + end
  49 +
  50 + @obj.page_content_markers.each do |item|
  51 + if h[item.row_item]
  52 + item.update_column(:row_item, h[item.row_item])
  53 + end
  54 + end
  55 +
  56 + render :json => {status: 'ok'}
42 end 57 end
43 58
44 end 59 end
@@ -64,9 +64,9 @@ @@ -64,9 +64,9 @@
64 </div> 64 </div>
65 <% end %> 65 <% end %>
66 66
67 - <div class="panel-group" id="accordion" role="tablist" aria-multiselectable="true"> 67 + <div class="panel-group sortable-list" id="accordion" role="tablist" aria-multiselectable="true" data-update-url="<%= url_for(:controller => 'admin/page_contents', :action => 'sorting', id: @obj.id) %>" >
68 <% row_items.sort.each do |index| %> 68 <% row_items.sort.each do |index| %>
69 - <div class="panel panel-default"> 69 + <div class="panel panel-default" data-id="<%= index %>" >
70 70
71 <div class="panel-heading" role="tab" id="heading_<%= index %>"> 71 <div class="panel-heading" role="tab" id="heading_<%= index %>">
72 <h4> 72 <h4>
@@ -19,6 +19,7 @@ Kanjai::Engine.routes.draw do @@ -19,6 +19,7 @@ Kanjai::Engine.routes.draw do
19 post 'page_contents/show_content_form' => "page_contents#show_content_form" 19 post 'page_contents/show_content_form' => "page_contents#show_content_form"
20 post 'page_contents/add_item' => "page_contents#add_item" 20 post 'page_contents/add_item' => "page_contents#add_item"
21 post 'page_contents/delete_item' => "page_contents#delete_item" 21 post 'page_contents/delete_item' => "page_contents#delete_item"
  22 + post 'page_contents/sorting' => "page_contents#sorting"
22 23
23 resources :admin_users 24 resources :admin_users
24 25
1 module Kanjai 1 module Kanjai
2 - VERSION = "0.0.109" 2 + VERSION = "0.0.110"
3 end 3 end