Sha256: 9e13d13738964f10611d85367b1777c4d7264d8172ec07273f817e5e1cc8e665

Contents?: true

Size: 1.12 KB

Versions: 10

Compression:

Stored size: 1.12 KB

Contents

# frozen_string_literal: true

module Decidim
  # Exposes the scopes text search so users can choose a scope writing its name.
  class ScopesController < Decidim::ApplicationController
    def search
      authorize! :search, Scope
      root = Scope.where(id: params[:root], organization: current_organization).first
      scopes = if params[:term].present?
                 FreetextScopes.for(current_organization, I18n.locale, params[:term], root)
               elsif root
                 root.children
               else
                 current_organization.top_scopes
               end
      root_option = if params[:include_root] == "true" && params[:term].blank?
                      if root
                        [{ id: root.id.to_s, text: root.name[I18n.locale.to_s] }]
                      else
                        [{ id: "global", text: I18n.t("decidim.scopes.global") }]
                      end
                    else
                      []
                    end

      render json: { results: root_option + scopes.map { |scope| { id: scope.id.to_s, text: scope.name[I18n.locale.to_s] } } }
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
decidim-core-0.8.4 app/controllers/decidim/scopes_controller.rb
decidim-core-0.8.3 app/controllers/decidim/scopes_controller.rb
decidim-core-0.8.2 app/controllers/decidim/scopes_controller.rb
decidim-core-0.8.1 app/controllers/decidim/scopes_controller.rb
decidim-core-0.8.0 app/controllers/decidim/scopes_controller.rb
decidim-core-0.7.4 app/controllers/decidim/scopes_controller.rb
decidim-core-0.7.3 app/controllers/decidim/scopes_controller.rb
decidim-core-0.7.2 app/controllers/decidim/scopes_controller.rb
decidim-core-0.7.1 app/controllers/decidim/scopes_controller.rb
decidim-core-0.7.0 app/controllers/decidim/scopes_controller.rb