Sha256: 43b1e0d62ad87eced751917adabb63d8f462b727eb77a3cb891c413f1eccb9c6

Contents?: true

Size: 1.73 KB

Versions: 6

Compression:

Stored size: 1.73 KB

Contents

import $ from 'jquery'

import visit from '../core/visit'

// Allow clicking on any part of a table row to follow either the table's data-url
// or the first link within the row (that is not in the actions column).
$(document).on('click', 'tr[data-url]:not([data-behavior="dialog"])', function (e) {
  const row = $(e.currentTarget)

  let url

  if (row.data('url') === 'auto') {
    url = row.find('td:not(.actions) a:first').attr('href')
  } else {
    url = row.data('url')
  }

  if (url) {
    if (e.metaKey || e.ctrlKey) {
      window.open(url, '_blank')
    } else {
      visit(url)
    }
  }
})

// Ignore the above event handler when clicking directly on a link or input element
$(document).on('click', 'tr[data-url] a, tr[data-url] input, .select-row', function (e) {
  e.stopPropagation()
})

// Handle clicking on select all checkbox in table header
$(document).on('click', 'th.select-row input', function (e) {
  const table = $(this).closest('table')
  const checked = $(this).is(':checked')

  table.find('td.select-row input').prop('checked', checked)
})

// Handle single row selection to update header row status
$(document).on('click', 'td.select-row input', function (e) {
  const table = $(this).closest('table')

  const checkboxes = table.find('td.select-row input')
  const selectedCheckboxes = checkboxes.filter(':checked')

  const header = table.find('th.select-row input')

  if (checkboxes.length === selectedCheckboxes.length) {
    // All checked
    header.prop('indeterminate', false)
    header.prop('checked', true)
  } else if (selectedCheckboxes.length === 0) {
    // None checked
    header.prop('indeterminate', false)
    header.prop('checked', false)
  } else {
    // Some checked
    header.prop('indeterminate', true)
  }
})

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
trestle-0.9.8 frontend/js/components/table.js
trestle-0.9.7 frontend/js/components/table.js
trestle-0.9.6 frontend/js/components/table.js
trestle-0.9.5 frontend/js/components/table.js
trestle-0.9.4 frontend/js/components/table.js
trestle-0.9.3 frontend/js/components/table.js