Showing
6 changed files
with
47 additions
and
6 deletions
| ... | ... | @@ -154,6 +154,31 @@ jQuery(document).ready(function(){ |
| 154 | 154 | clearAjaxFileUpload($('#work_area .editor-content')); |
| 155 | 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 | 219 | content_type = $this.val(), |
| 195 | 220 | show_content_url = $this.data('show_content_url') |
| 196 | 221 | |
| 222 | + | |
| 197 | 223 | jQuery.ajax({ |
| 198 | 224 | type: 'POST', |
| 199 | 225 | url: show_content_url, | ... | ... |
| ... | ... | @@ -27,7 +27,6 @@ module Kanjai |
| 27 | 27 | @current_row = @obj.page_content_markers.where('row_item != ?', @row_item).count |
| 28 | 28 | |
| 29 | 29 | render layout: false |
| 30 | - | |
| 31 | 30 | end |
| 32 | 31 | |
| 33 | 32 | def delete_item |
| ... | ... | @@ -38,7 +37,23 @@ module Kanjai |
| 38 | 37 | @obj.delete_markers_row(@row_item) |
| 39 | 38 | |
| 40 | 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 | 57 | end |
| 43 | 58 | |
| 44 | 59 | end | ... | ... |
| ... | ... | @@ -64,9 +64,9 @@ |
| 64 | 64 | </div> |
| 65 | 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 | 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 | 71 | <div class="panel-heading" role="tab" id="heading_<%= index %>"> |
| 72 | 72 | <h4> | ... | ... |
| ... | ... | @@ -19,6 +19,7 @@ Kanjai::Engine.routes.draw do |
| 19 | 19 | post 'page_contents/show_content_form' => "page_contents#show_content_form" |
| 20 | 20 | post 'page_contents/add_item' => "page_contents#add_item" |
| 21 | 21 | post 'page_contents/delete_item' => "page_contents#delete_item" |
| 22 | + post 'page_contents/sorting' => "page_contents#sorting" | |
| 22 | 23 | |
| 23 | 24 | resources :admin_users |
| 24 | 25 | ... | ... |