Class: Decidim::Votings::Admin::PollingStationsController

Inherits:
ApplicationController
  • Object
show all
Includes:
PollingStations::Admin::Filterable, VotingAdmin
Defined in:
app/controllers/decidim/votings/admin/polling_stations_controller.rb

Overview

This controller allows to create or update a polling station.

Instance Method Summary collapse

Instance Method Details

#createObject



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'app/controllers/decidim/votings/admin/polling_stations_controller.rb', line 23

def create
  enforce_permission_to :create, :polling_station, voting: current_voting
  @form = form(PollingStationForm).from_params(params, voting: current_voting)

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

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

#destroyObject



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'app/controllers/decidim/votings/admin/polling_stations_controller.rb', line 62

def destroy
  enforce_permission_to :delete, :polling_station, voting: current_voting, polling_station: polling_station

  DestroyPollingStation.call(polling_station, current_user) do
    on(:ok) do
      flash[:notice] = I18n.t("polling_stations.destroy.success", scope: "decidim.votings.admin")
    end

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

  redirect_to voting_polling_stations_path(current_voting)
end

#editObject



40
41
42
43
# File 'app/controllers/decidim/votings/admin/polling_stations_controller.rb', line 40

def edit
  enforce_permission_to :update, :polling_station, voting: current_voting, polling_station: polling_station
  @form = form(PollingStationForm).from_model(polling_station, voting: current_voting)
end

#indexObject



14
15
16
# File 'app/controllers/decidim/votings/admin/polling_stations_controller.rb', line 14

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

#newObject



18
19
20
21
# File 'app/controllers/decidim/votings/admin/polling_stations_controller.rb', line 18

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

#updateObject



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'app/controllers/decidim/votings/admin/polling_stations_controller.rb', line 45

def update
  enforce_permission_to :update, :polling_station, voting: current_voting, polling_station: polling_station
  @form = form(PollingStationForm).from_params(params, voting: current_voting)

  UpdatePollingStation.call(@form, polling_station) do
    on(:ok) do
      flash[:notice] = I18n.t("polling_stations.update.success", scope: "decidim.votings.admin")
      redirect_to voting_polling_stations_path(current_voting)
    end

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