Class: Decidim::Elections::Admin::StepsController

Inherits:
ApplicationController
  • Object
show all
Defined in:
app/controllers/decidim/elections/admin/steps_controller.rb

Overview

This controller allows to manage the steps of an election.

Instance Method Summary collapse

Instance Method Details

#indexObject



11
12
13
14
15
16
17
18
# File 'app/controllers/decidim/elections/admin/steps_controller.rb', line 11

def index
  enforce_permission_to :read, :steps, election: election

  if current_step_form_class
    @form = form(current_step_form_class).instance(election: election)
    @form.valid?
  end
end

#statsObject



42
43
44
# File 'app/controllers/decidim/elections/admin/steps_controller.rb', line 42

def stats
  render "decidim/elections/admin/steps/_vote_stats", layout: false
end

#updateObject



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'app/controllers/decidim/elections/admin/steps_controller.rb', line 20

def update
  enforce_permission_to :update, :steps, election: election
  redirect_to election_steps_path(election) && return unless params[:id] == current_step

  @form = form(current_step_form_class).from_params(params, election: election)
  if @form.pending_action
    Decidim::Elections::Admin::UpdateActionStatus.call(@form.pending_action)
    return redirect_to election_steps_path(election)
  end

  current_step_command_class.call(@form) do
    on(:ok) do
      flash[:notice] = I18n.t("steps.#{current_step}.success", scope: "decidim.elections.admin")
      return redirect_to election_steps_path(election)
    end
    on(:invalid) do |message|
      flash.now[:alert] = message || I18n.t("steps.#{current_step}.invalid", scope: "decidim.elections.admin")
    end
  end
  render :index
end