Class: Decidim::Initiatives::CreateInitiativeController

Inherits:
ApplicationController show all
Includes:
FormFactory, InitiativeHelper, SingleInitiativeType, TypeSelectorOptions
Defined in:
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 InitiativeHelper

#authorized_create_modal_button, #authorized_vote_modal_button, #can_edit_custom_signature_end_date?, #hero_background_path, #humanize_admin_state, #metadata_badge_css_class, #render_committee_tooltip

Methods inherited from ApplicationController

#permission_class_chain, #permission_scope, #permissions_context

Instance Method Details

#fill_dataObject



48
49
50
51
52
53
54
55
# File '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 '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 '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 '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 '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) 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 '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