Class: Decidim::Votings::Admin::VotingsController
Overview
This controller allows to create or update a voting.
Instance Method Summary
collapse
#permission_class_chain, #permission_scope, #user_has_no_permission_path, #user_not_authorized_path
#disable_http_caching
#snippets
register_permissions
enhance_controller, extended, included
Instance Method Details
#available_polling_officers ⇒ Object
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
|
# File 'decidim-elections/app/controllers/decidim/votings/admin/votings_controller.rb', line 63
def available_polling_officers
respond_to do |format|
format.json do
if (term = params[:term].to_s).present?
query = current_voting.available_polling_officers.joins(:user)
query = if term.start_with?("@")
query.where("nickname ILIKE ?", "#{term.delete("@")}%")
else
query.where("name ILIKE ?", "%#{term}%").or(
query.where("email ILIKE ?", "%#{term}%")
)
end
render json: query.all.collect { |u| { value: u.id, label: "#{u.name} (@#{u.nickname}) #{u.email}" } }
else
render json: []
end
end
end
end
|
#create ⇒ Object
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
# File 'decidim-elections/app/controllers/decidim/votings/admin/votings_controller.rb', line 23
def create
enforce_permission_to :create, :voting
@form = form(VotingForm).from_params(params)
CreateVoting.call(@form) do
on(:ok) do
flash[:notice] = I18n.t("votings.create.success", scope: "decidim.votings.admin")
redirect_to votings_path
end
on(:invalid) do
flash.now[:alert] = I18n.t("votings.create.invalid", scope: "decidim.votings.admin")
render action: "new"
end
end
end
|
#edit ⇒ Object
40
41
42
43
44
|
# File 'decidim-elections/app/controllers/decidim/votings/admin/votings_controller.rb', line 40
def edit
enforce_permission_to :edit, :voting, voting: current_voting
@form = form(VotingForm).from_model(current_voting)
render layout: "decidim/admin/voting"
end
|
#index ⇒ Object
12
13
14
15
16
|
# File 'decidim-elections/app/controllers/decidim/votings/admin/votings_controller.rb', line 12
def index
enforce_permission_to :read, :votings
@votings = filtered_collection
render layout: "decidim/admin/votings"
end
|
#new ⇒ Object
18
19
20
21
|
# File 'decidim-elections/app/controllers/decidim/votings/admin/votings_controller.rb', line 18
def new
enforce_permission_to :create, :voting
@form = form(VotingForm).instance
end
|
#update ⇒ Object
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
# File 'decidim-elections/app/controllers/decidim/votings/admin/votings_controller.rb', line 46
def update
enforce_permission_to :update, :voting, voting: current_voting
@form = form(VotingForm).from_params(params, voting_id: current_voting.id)
UpdateVoting.call(current_voting, @form) do
on(:ok) do |voting|
flash[:notice] = I18n.t("votings.update.success", scope: "decidim.votings.admin")
redirect_to edit_voting_path(voting)
end
on(:invalid) do
flash.now[:alert] = I18n.t("votings.update.invalid", scope: "decidim.votings.admin")
render action: "edit"
end
end
end
|