Sha256: 4f4e509db9f5f0b7677ebfdb34efa8939249a75fb3db57d8b7388075f54af350

Contents?: true

Size: 1.29 KB

Versions: 49

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

49 entries across 49 versions & 1 rubygems

Version Path
effective_datatables-4.30.1 app/models/effective/effective_datatable/dsl/bulk_actions.rb
effective_datatables-4.30.0 app/models/effective/effective_datatable/dsl/bulk_actions.rb
effective_datatables-4.29.0 app/models/effective/effective_datatable/dsl/bulk_actions.rb
effective_datatables-4.26.0 app/models/effective/effective_datatable/dsl/bulk_actions.rb
effective_datatables-4.25.3 app/models/effective/effective_datatable/dsl/bulk_actions.rb
effective_datatables-4.25.2 app/models/effective/effective_datatable/dsl/bulk_actions.rb
effective_datatables-4.25.1 app/models/effective/effective_datatable/dsl/bulk_actions.rb
effective_datatables-4.25.0 app/models/effective/effective_datatable/dsl/bulk_actions.rb
effective_datatables-4.24.2 app/models/effective/effective_datatable/dsl/bulk_actions.rb
effective_datatables-4.24.1 app/models/effective/effective_datatable/dsl/bulk_actions.rb
effective_datatables-4.24.0 app/models/effective/effective_datatable/dsl/bulk_actions.rb
effective_datatables-4.23.0 app/models/effective/effective_datatable/dsl/bulk_actions.rb
effective_datatables-4.22.3 app/models/effective/effective_datatable/dsl/bulk_actions.rb
effective_datatables-4.22.2 app/models/effective/effective_datatable/dsl/bulk_actions.rb
effective_datatables-4.22.1 app/models/effective/effective_datatable/dsl/bulk_actions.rb
effective_datatables-4.22.0 app/models/effective/effective_datatable/dsl/bulk_actions.rb
effective_datatables-4.21.1 app/models/effective/effective_datatable/dsl/bulk_actions.rb
effective_datatables-4.21.0 app/models/effective/effective_datatable/dsl/bulk_actions.rb
effective_datatables-4.20.6 app/models/effective/effective_datatable/dsl/bulk_actions.rb
effective_datatables-4.20.5 app/models/effective/effective_datatable/dsl/bulk_actions.rb