Sha256: a2d590c949f01aede94149a3677ade6c653efee585771f32794027f0346c71d7

Contents?: true

Size: 1.52 KB

Versions: 70

Compression:

Stored size: 1.52 KB

Contents

module Admin
  class Select2AjaxController < ApplicationController
    before_action(:authenticate_user!) if defined?(Devise)
    before_action { EffectiveResources.authorize!(self, :admin, :effective_resources) }

    include Effective::Select2AjaxController

    def users
      collection = current_user.class.all

      if collection.respond_to?(:to_select2)
        collection = collection.to_select2
      elsif collection.respond_to?(:sorted)
        collection = collection.sorted
      end

      respond_with_select2_ajax(collection) do |user|
        { id: user.to_param, text: user.try(:to_select2) || to_select2(user) }
      end
    end

    def organizations
      raise('the effective memberships gem is required') unless defined?(EffectiveMemberships)

      klass = EffectiveMemberships.Organization
      raise('an EffectiveMemberships.Organization is required') unless klass.try(:effective_memberships_organization?)

      collection = klass.all

      if collection.respond_to?(:to_select2)
        collection = collection.to_select2
      elsif collection.respond_to?(:sorted)
        collection = collection.sorted
      end

      respond_with_select2_ajax(collection) do |organization|
        { id: organization.to_param, text: organization.try(:to_select2) || to_select2(organization) }
      end
    end

    private

    def to_select2(resource)
      if resource.try(:email).present?
        "<span>#{resource}</span> <small>#{resource.email}</small>"
      else
        "<span>#{resource}</span>"
      end
    end

  end

end

Version data entries

70 entries across 70 versions & 1 rubygems

Version Path
effective_resources-2.20.5 app/controllers/admin/select2_ajax_controller.rb
effective_resources-2.20.4 app/controllers/admin/select2_ajax_controller.rb
effective_resources-2.20.3 app/controllers/admin/select2_ajax_controller.rb
effective_resources-2.20.2 app/controllers/admin/select2_ajax_controller.rb
effective_resources-2.20.1 app/controllers/admin/select2_ajax_controller.rb
effective_resources-2.20.0 app/controllers/admin/select2_ajax_controller.rb
effective_resources-2.19.13 app/controllers/admin/select2_ajax_controller.rb
effective_resources-2.19.12 app/controllers/admin/select2_ajax_controller.rb
effective_resources-2.19.11 app/controllers/admin/select2_ajax_controller.rb
effective_resources-2.19.10 app/controllers/admin/select2_ajax_controller.rb
effective_resources-2.19.9 app/controllers/admin/select2_ajax_controller.rb
effective_resources-2.19.8 app/controllers/admin/select2_ajax_controller.rb
effective_resources-2.19.7 app/controllers/admin/select2_ajax_controller.rb
effective_resources-2.19.6 app/controllers/admin/select2_ajax_controller.rb
effective_resources-2.19.5 app/controllers/admin/select2_ajax_controller.rb
effective_resources-2.19.4 app/controllers/admin/select2_ajax_controller.rb
effective_resources-2.19.3 app/controllers/admin/select2_ajax_controller.rb
effective_resources-2.19.2 app/controllers/admin/select2_ajax_controller.rb
effective_resources-2.19.1 app/controllers/admin/select2_ajax_controller.rb
effective_resources-2.19.0 app/controllers/admin/select2_ajax_controller.rb