From 925d83320dc168529afc4370b460000a67a1bcf0 Mon Sep 17 00:00:00 2001 From: f Date: Fri, 27 Apr 2018 17:24:28 -0300 Subject: [PATCH] reordenar los articulos al soltar --- app/assets/javascripts/drag.js | 3 ++ app/views/posts/index.haml | 63 ++++++++++++++++++---------------- config/routes.rb | 1 + 3 files changed, 37 insertions(+), 30 deletions(-) diff --git a/app/assets/javascripts/drag.js b/app/assets/javascripts/drag.js index b99b9c6..e65ede5 100644 --- a/app/assets/javascripts/drag.js +++ b/app/assets/javascripts/drag.js @@ -3,5 +3,8 @@ $(document).on('turbolinks:load', function() { mode: 'row', onlyBody: true, dragHandler: '.handle' + }).on('drop', function(from, to, el, mode) { + // Al soltar, reordenamos toda la tabla + $('.post_order').val(function(i,v) { return i; }); }); }); diff --git a/app/views/posts/index.haml b/app/views/posts/index.haml index 3034fae..28d1aea 100644 --- a/app/views/posts/index.haml +++ b/app/views/posts/index.haml @@ -19,36 +19,39 @@ .row .col - if @posts.present? - %table.table.table-condensed.table-striped.table-draggable - %tbody - - @posts.each do |post| - - if @category - -# saltearse el post a menos que esté en la categoría - -# por la que estamos filtrando - - next unless post.categories.include?(@category) - -# establecer la direccion del texto - - direction = post.get_front_matter(:dir) - %tr - %td - = fa_icon 'arrows-v', class: 'handle' - %td{class: direction} - = link_to post.title, site_post_path(@site, post, lang: @lang) - %br - %small - - post.categories.each do |c| - = link_to c, site_posts_path(@site, category: c, lang: @lang), - data: { toggle: 'tooltip' }, title: t('help.category') - %td - - if post.translations - %small - - post.translations.each do |pt| - = link_to pt.title, site_post_path(@site, pt, lang: pt.lang), - data: { toggle: 'tooltip' }, title: t("i18n.#{pt.lang}") - %br + = form_tag site_reorder_posts_path, method: :post do + %table.table.table-condensed.table-striped.table-draggable + %tbody + - @posts.each_with_index do |post, i| + - if @category + -# saltearse el post a menos que esté en la categoría + -# por la que estamos filtrando + - next unless post.categories.include?(@category) + -# establecer la direccion del texto + - direction = post.get_front_matter(:dir) + %tr + %td + = fa_icon 'arrows-v', class: 'handle' + = text_field 'posts[order]', i, value: post.order || i, class: 'post_order' - %td= post.date.strftime('%F') - %td= link_to t('posts.edit'), - edit_site_post_path(@site, post, lang: @lang), - class: 'btn btn-info' + %td{class: direction} + = link_to post.title, site_post_path(@site, post, lang: @lang) + %br + %small + - post.categories.each do |c| + = link_to c, site_posts_path(@site, category: c, lang: @lang), + data: { toggle: 'tooltip' }, title: t('help.category') + %td + - if post.translations + %small + - post.translations.each do |pt| + = link_to pt.title, site_post_path(@site, pt, lang: pt.lang), + data: { toggle: 'tooltip' }, title: t("i18n.#{pt.lang}") + %br + + %td= post.date.strftime('%F') + %td= link_to t('posts.edit'), + edit_site_post_path(@site, post, lang: @lang), + class: 'btn btn-info' - else %h2= t('posts.none') diff --git a/config/routes.rb b/config/routes.rb index ec7561c..0d74a19 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -16,5 +16,6 @@ Rails.application.routes.draw do post 'enqueue', to: 'sites#enqueue' get 'build_log', to: 'sites#build_log' + post 'reorder_posts', to: 'sites#reorder_posts' end end