Class: Decidim::Initiatives::CreateInitiativeController

Inherits:
ApplicationController show all
Includes:
FormFactory, InitiativeHelper, SingleInitiativeType, TypeSelectorOptions
Defined in:
decidim-initiatives/app/controllers/decidim/initiatives/create_initiative_controller.rb

Overview

Controller in charge of managing the create initiative wizard.

Instance Method Summary collapse

Methods included from TranslationsHelper

empty_translatable, ensure_translatable, multi_translation, translated_in_current_locale?

Methods included from TranslatableAttributes

#default_locale?

Methods included from InitiativeHelper

#authorized_create_modal_button, #authorized_vote_modal_button, #can_edit_area?, #can_edit_custom_signature_end_date?, #hero_background_path, #humanize_admin_state, #humanize_state, #metadata_badge_css_class, #popularity_class, #popularity_level1?, #popularity_level2?, #popularity_level3?, #popularity_level4?, #popularity_level5?, #popularity_tag, #render_committee_tooltip, #state_badge_css_class

Methods included from ResourceVersionsHelper

#link_to_other_resource_versions, #resource_version, #resource_version_number, #resource_version_of

Methods included from ResourceHelper

#linked_classes_filter_values_for, #linked_classes_for, #resource_locator, #resource_title

Methods included from SanitizeHelper

#decidim_html_escape, #decidim_sanitize, #decidim_sanitize_admin, #decidim_sanitize_editor, #decidim_sanitize_editor_admin, #decidim_sanitize_newsletter, #decidim_url_escape, included

Methods inherited from ApplicationController

#permission_class_chain, #permission_scope, #permissions_context

Methods included from RegistersPermissions

register_permissions

Methods included from UserBlockedChecker

#check_user_block_status, #check_user_not_blocked

Methods included from NeedsSnippets

#snippets

Methods included from Headers::HttpCachingDisabler

#disable_http_caching

Methods included from HasStoredPath

#skip_store_location?, #store_current_location

Methods included from NeedsOrganization

enhance_controller, extended, included

Instance Method Details

#fill_dataObject



48
49
50
51
52
53
54
55
# File 'decidim-initiatives/app/controllers/decidim/initiatives/create_initiative_controller.rb', line 48

def fill_data
  @form = if session[:initiative_id].present?
            form(Decidim::Initiatives::InitiativeForm).from_model(current_initiative, { initiative_type: })
          else
            extras = { type_id: initiative_type_id, signature_type: initiative_type.signature_type }
            form(Decidim::Initiatives::InitiativeForm).from_params(params.merge(extras), { initiative_type: })
          end
end

#finishObject



79
80
81
82
83
# File 'decidim-initiatives/app/controllers/decidim/initiatives/create_initiative_controller.rb', line 79

def finish
  current_initiative.presence
  session[:type_id] = nil
  session[:initiative_id] = nil
end

#promotal_committeeObject



75
76
77
# File 'decidim-initiatives/app/controllers/decidim/initiatives/create_initiative_controller.rb', line 75

def promotal_committee
  redirect_to finish_create_initiative_index_path unless promotal_committee_required?
end

#select_initiative_typeObject



31
32
33
34
35
# File 'decidim-initiatives/app/controllers/decidim/initiatives/create_initiative_controller.rb', line 31

def select_initiative_type
  @form = form(Decidim::Initiatives::SelectInitiativeTypeForm).from_params(params)

  redirect_to fill_data_create_initiative_index_path if single_initiative_type?
end

#store_dataObject



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'decidim-initiatives/app/controllers/decidim/initiatives/create_initiative_controller.rb', line 57

def store_data
  @form = form(Decidim::Initiatives::InitiativeForm).from_params(params, { initiative_type: })

  CreateInitiative.call(@form, current_user) do
    on(:ok) do |initiative|
      session[:initiative_id] = initiative.id

      path = promotal_committee_required? ? "promotal_committee" : "finish"

      redirect_to send("#{path}_create_initiative_index_path".to_sym)
    end

    on(:invalid) do
      render :fill_data
    end
  end
end

#store_initiative_typeObject



37
38
39
40
41
42
43
44
45
46
# File 'decidim-initiatives/app/controllers/decidim/initiatives/create_initiative_controller.rb', line 37

def store_initiative_type
  @form = form(Decidim::Initiatives::SelectInitiativeTypeForm).from_params(params)

  if @form.valid?
    session[:type_id] = @form.type_id
    redirect_to fill_data_create_initiative_index_path
  else
    render :select_initiative_type
  end
end