Class: Decidim::ScopesController

Inherits:
ApplicationController show all
Defined in:
app/controllers/decidim/scopes_controller.rb

Overview

Exposes the scopes text search so users can choose a scope writing its name.

Instance Method Summary collapse

Methods included from HttpCachingDisabler

#disable_http_caching

Methods included from RegistersPermissions

register_permissions

Methods included from NeedsOrganization

enhance_controller, extended, included

Instance Method Details

#pickerObject



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'app/controllers/decidim/scopes_controller.rb', line 8

def picker
  enforce_permission_to :pick, :scope

  context = root ? { root: root.id, title: title } : { title: title }
  required = params[:required] && params[:required] != "false"
  current = (root&.descendants || current_organization.scopes).find_by(id: params[:current]) if params[:current].present?

  if current
    scopes = current.children
    parent_scopes = current.part_of_scopes(root)
  else
    current = root
    scopes = root&.children || current_organization.scopes.top_level
    parent_scopes = [root].compact
  end

  render :picker, layout: nil, locals: { required: required, title: title, root: root, current: current, scopes: scopes.order(name: :asc),
                                         parent_scopes: parent_scopes, global_value: params[:global_value], context: context }
end