5
0
Fork 0
mirror of https://0xacab.org/sutty/sutty synced 2024-11-15 06:01:42 +00:00

reordenar los articulos al soltar

This commit is contained in:
f 2018-04-27 17:24:28 -03:00
parent 801602c062
commit 925d83320d
No known key found for this signature in database
GPG key ID: F3FDAB97B5F9F7E7
3 changed files with 37 additions and 30 deletions

View file

@ -3,5 +3,8 @@ $(document).on('turbolinks:load', function() {
mode: 'row', mode: 'row',
onlyBody: true, onlyBody: true,
dragHandler: '.handle' dragHandler: '.handle'
}).on('drop', function(from, to, el, mode) {
// Al soltar, reordenamos toda la tabla
$('.post_order').val(function(i,v) { return i; });
}); });
}); });

View file

@ -19,9 +19,10 @@
.row .row
.col .col
- if @posts.present? - if @posts.present?
= form_tag site_reorder_posts_path, method: :post do
%table.table.table-condensed.table-striped.table-draggable %table.table.table-condensed.table-striped.table-draggable
%tbody %tbody
- @posts.each do |post| - @posts.each_with_index do |post, i|
- if @category - if @category
-# saltearse el post a menos que esté en la categoría -# saltearse el post a menos que esté en la categoría
-# por la que estamos filtrando -# por la que estamos filtrando
@ -31,6 +32,8 @@
%tr %tr
%td %td
= fa_icon 'arrows-v', class: 'handle' = fa_icon 'arrows-v', class: 'handle'
= text_field 'posts[order]', i, value: post.order || i, class: 'post_order'
%td{class: direction} %td{class: direction}
= link_to post.title, site_post_path(@site, post, lang: @lang) = link_to post.title, site_post_path(@site, post, lang: @lang)
%br %br

View file

@ -16,5 +16,6 @@ Rails.application.routes.draw do
post 'enqueue', to: 'sites#enqueue' post 'enqueue', to: 'sites#enqueue'
get 'build_log', to: 'sites#build_log' get 'build_log', to: 'sites#build_log'
post 'reorder_posts', to: 'sites#reorder_posts'
end end
end end