Sha256: 9f77412291a5fdbec5ae5cabdf2b28d8730a725d87431a405eb530b50754895f

Contents?: true

Size: 1.29 KB

Versions: 10

Compression:

Stored size: 1.29 KB

Contents

# frozen_string_literal: true

module Effective
  module EffectiveDatatable
    module Dsl
      module BulkActions

        def bulk_action(title, url, opts = {})
          datatable._bulk_actions.push(link_to_bulk_action(title, url, opts))
        end

        def bulk_download(title, url, opts = {})
          datatable._bulk_actions.push(link_to_bulk_action(title, url, opts.merge('data-bulk-download': true)))
        end

        def bulk_action_divider
          datatable._bulk_actions.push(content_tag(:div, '', class: 'dropdown-divider'))
        end

        def bulk_action_content(&block)
          datatable._bulk_actions.push(block.call)
        end

        private

        # We can't let any data-method be applied to the link, or jquery_ujs does the wrong thing with it
        def link_to_bulk_action(title, url, opts = {})

          # Transform data: { ... } hash into 'data-' keys
          if (data = opts.delete(:data))
            data.each { |k, v| opts["data-#{k}"] ||= v }
          end

          verbs = {'DELETE' => 'DELETE', 'GET' => 'GET'}
          opts['data-ajax-method'] = verbs[opts.delete('data-method').to_s.upcase] || 'POST'

          opts[:class] = [opts[:class], 'dropdown-item'].compact.join(' ')

          link_to(title, url, opts)
        end

      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
effective_datatables-4.11.2 app/models/effective/effective_datatable/dsl/bulk_actions.rb
effective_datatables-4.11.1 app/models/effective/effective_datatable/dsl/bulk_actions.rb
effective_datatables-4.11.0 app/models/effective/effective_datatable/dsl/bulk_actions.rb
effective_datatables-4.10.7 app/models/effective/effective_datatable/dsl/bulk_actions.rb
effective_datatables-4.10.6 app/models/effective/effective_datatable/dsl/bulk_actions.rb
effective_datatables-4.10.5 app/models/effective/effective_datatable/dsl/bulk_actions.rb
effective_datatables-4.10.4 app/models/effective/effective_datatable/dsl/bulk_actions.rb
effective_datatables-4.10.3 app/models/effective/effective_datatable/dsl/bulk_actions.rb
effective_datatables-4.10.2 app/models/effective/effective_datatable/dsl/bulk_actions.rb
effective_datatables-4.10.1 app/models/effective/effective_datatable/dsl/bulk_actions.rb