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 NeedsSnippets

#snippets

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
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'app/controllers/decidim/scopes_controller.rb', line 8

def picker
  enforce_permission_to :pick, :scope

  context = root ? { root: root.id, title: title, max_depth: max_depth } : { title: title, max_depth: max_depth }
  required = params[:required] && params[:required] != "false"

  if current
    scopes = current.children unless scope_depth_limit?
    parent_scopes = current.part_of_scopes(root)
  else
    scopes = root&.children || current_organization.scopes.top_level unless scope_depth_limit?

    parent_scopes = [root].compact
  end

  render(
    :picker,
    layout: nil,
    locals: {
      required: required,
      title: title,
      root: root,
      current: (current || root),
      scopes: scopes&.order(name: :asc),
      parent_scopes: parent_scopes,
      picker_target_id: (params[:target_element_id] || "content"),
      global_value: params[:global_value],
      max_depth: max_depth,
      context: context
    }
  )
end