Class: Decidim::Votings::Admin::BallotStylesController

Inherits:
ApplicationController show all
Includes:
VotingAdmin
Defined in:
decidim-elections/app/controllers/decidim/votings/admin/ballot_styles_controller.rb

Overview

This controller allows to create or update the ballot styles.

Instance Method Summary collapse

Methods inherited from Admin::ApplicationController

#permission_class_chain, #permission_scope, #user_has_no_permission_path, #user_not_authorized_path

Methods included from HttpCachingDisabler

#disable_http_caching

Methods included from NeedsSnippets

#snippets

Methods included from RegistersPermissions

register_permissions

Methods included from NeedsOrganization

enhance_controller, extended, included

Instance Method Details

#createObject


20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'decidim-elections/app/controllers/decidim/votings/admin/ballot_styles_controller.rb', line 20

def create
  enforce_permission_to :create, :ballot_style, voting: current_voting

  @form = form(BallotStyleForm).from_params(params, voting: current_voting)

  CreateBallotStyle.call(@form) do
    on(:ok) do
      flash[:notice] = I18n.t("create.success", scope: "decidim.votings.admin.ballot_styles")
      redirect_to voting_ballot_styles_path(current_voting)
    end

    on(:invalid) do
      flash[:alert] = t("create.error", scope: "decidim.votings.admin.ballot_styles")
      render action: "new"
    end
  end
end

#destroyObject


60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'decidim-elections/app/controllers/decidim/votings/admin/ballot_styles_controller.rb', line 60

def destroy
  enforce_permission_to :delete, :ballot_style, ballot_style: current_ballot_style, voting: current_voting

  DestroyBallotStyle.call(current_ballot_style) do
    on(:ok) do
      flash[:notice] = t("destroy.success", scope: "decidim.votings.admin.ballot_styles")
    end

    on(:invalid) do
      flash[:alert] = t("destroy.invalid", scope: "decidim.votings.admin.ballot_styles")
    end
  end

  redirect_to voting_ballot_styles_path(current_voting)
end

#editObject


38
39
40
41
# File 'decidim-elections/app/controllers/decidim/votings/admin/ballot_styles_controller.rb', line 38

def edit
  enforce_permission_to :update, :ballot_style, ballot_style: current_ballot_style, voting: current_voting
  @form = form(BallotStyleForm).from_model(current_ballot_style, voting: current_voting)
end

#indexObject


11
12
13
# File 'decidim-elections/app/controllers/decidim/votings/admin/ballot_styles_controller.rb', line 11

def index
  enforce_permission_to :read, :ballot_styles, voting: current_voting
end

#newObject


15
16
17
18
# File 'decidim-elections/app/controllers/decidim/votings/admin/ballot_styles_controller.rb', line 15

def new
  enforce_permission_to :create, :ballot_style, voting: current_voting
  @form = form(BallotStyleForm).instance
end

#updateObject


43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'decidim-elections/app/controllers/decidim/votings/admin/ballot_styles_controller.rb', line 43

def update
  enforce_permission_to :update, :ballot_style, ballot_style: current_ballot_style, voting: current_voting
  @form = form(BallotStyleForm).from_params(params, voting: current_voting, ballot_style_id: current_ballot_style.id)

  UpdateBallotStyle.call(@form, current_ballot_style) do
    on(:ok) do
      flash[:notice] = I18n.t("update.success", scope: "decidim.votings.admin.ballot_styles")
      redirect_to voting_ballot_styles_path(current_voting)
    end

    on(:invalid) do
      flash.now[:alert] = I18n.t("update.invalid", scope: "decidim.votings.admin.ballot_styles")
      render action: "edit"
    end
  end
end