Browse Source

Table list now have clickable rows

remotes/origin/master
echarp 2 years ago
parent
commit
164e0781f4
  1. 25
      app/assets/javascripts/list.js.coffee
  2. 15
      app/assets/javascripts/pagination.coffee
  3. 5
      app/assets/stylesheets/list.sass
  4. 2
      app/views/orgas/_orga.html.haml
  5. 4
      app/views/versions/index.haml

25
app/assets/javascripts/list.js.coffee

@ -1 +1,26 @@
$(document).on 'turbolinks:load', ->
$('table.list td.view a').each -> visit $(this)
# Automatic ajax pagination
$('.pagination .next a').attr('data-remote', true).each ->
# Go to the next page when page is scrolled
$(document).scroll =>
if $(this).visible true, true
# "Next" link is also hidden while pagination is done
$(this).click().parents('.pagination').hide()
$(document).on 'ajax:success', '.pagination .next a', (event, data) ->
$(this).parents('tfoot')
.prev()
.append($('tbody tr', data))
.find('td.view a').each ->
visit $(this)
next = $('.pagination .next a', data).attr 'href'
if next?
$(this).attr('href', next).parents('.pagination').show()
# Clicking on a table.list row
visit = (elt) =>
elt.closest('tr').click -> Turbolinks.visit elt.attr 'href'

15
app/assets/javascripts/pagination.coffee

@ -1,15 +0,0 @@
# Automatic ajax pagination
$(document).on 'turbolinks:load', ->
$('.pagination .next a').attr('data-remote', true).each ->
# Go to the next page when page is scrolled
$(document).scroll =>
if $(this).visible true, true
# "Next" link is also hidden while pagination is done
$(this).click().parents('.pagination').hide()
$(document).on 'ajax:success', '.pagination .next a', (event, data) ->
$(this).parents('tfoot').prev().append $('tbody tr', data)
next = $('.pagination .next a', data).attr 'href'
if next?
$(this).attr('href', next).parents('.pagination').show()

5
app/assets/stylesheets/list.sass

@ -23,6 +23,11 @@ table
&.kind, &.updated_at
text-align: center
html.js table.list tbody tr
cursor: pointer
&:hover
background-color: lightgrey
dl
dt
clear: left

2
app/views/orgas/_orga.html.haml

@ -17,7 +17,7 @@
%em.fa.fa-tags
- elsif orga.tags.count.positive?
%em.fa.fa-tag
%td.view{ title: t('.view') }
%td.view
= link_to orga_path orga, q: params[:q].permit, page: params[:page] do
%em.fa.fa-arrow-circle-right

4
app/views/versions/index.haml

@ -47,11 +47,11 @@
%td= object
%td.changes= changes
%td= l version.created_at, format: :short
%td
%td.view
- unless version.event == 'destroy'
%a{ href: polymorphic_path(version.item_type.tableize.singularize,
id: version.item_id) }
%em.fa.fa-eye
%em.fa.fa-arrow-circle-right
%tfoot
%tr

Loading…
Cancel
Save