Sha256: e999ab446bb91572720b8725e01da394119ddfa8dda8ecbc59ef039cc8dcd74b

Contents?: true

Size: 1.58 KB

Versions: 10

Compression:

Stored size: 1.58 KB

Contents

module Effective
  module EffectiveDatatable
    module Dsl
      module BulkActions

        def bulk_action(*args)
          datatable._bulk_actions.push(link_to_bulk_action(*args))
        end

        def bulk_download(*args)
          datatable._bulk_actions.push(link_to_bulk_action(*args.merge('data-authenticity-token' => form_authenticity_token)))
        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(*args)
          args.map! do |arg|
            if arg.kind_of?(Hash)
              data_method = (
                arg.delete(:'data-method') ||
                arg.delete('data-method') ||
                (arg[:data] || {}).delete('method') ||
                (arg[:data] || {}).delete(:method)
              )

              # But if the data-method was :get, we add bulk-actions-get-link = true
              if data_method.to_s == 'get'
                arg[:data].present? ? arg[:data]['bulk-actions-get'] = true : arg['data-bulk-actions-get'] = true
              end

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

            arg
          end

          args << { class: 'dropdown-item' } if args.none? { |arg| arg.kind_of?(Hash) }

          link_to(*args)
        end

      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
effective_datatables-4.2.0 app/models/effective/effective_datatable/dsl/bulk_actions.rb
effective_datatables-4.1.1 app/models/effective/effective_datatable/dsl/bulk_actions.rb
effective_datatables-4.1.0 app/models/effective/effective_datatable/dsl/bulk_actions.rb
effective_datatables-4.0.6 app/models/effective/effective_datatable/dsl/bulk_actions.rb
effective_datatables-4.0.5 app/models/effective/effective_datatable/dsl/bulk_actions.rb
effective_datatables-4.0.4 app/models/effective/effective_datatable/dsl/bulk_actions.rb
effective_datatables-4.0.3 app/models/effective/effective_datatable/dsl/bulk_actions.rb
effective_datatables-4.0.2 app/models/effective/effective_datatable/dsl/bulk_actions.rb
effective_datatables-4.0.1 app/models/effective/effective_datatable/dsl/bulk_actions.rb
effective_datatables-4.0.0 app/models/effective/effective_datatable/dsl/bulk_actions.rb