Class: Decidim::Votings::Admin::VotingsController
- Inherits:
-
ApplicationController
- Object
- Admin::ApplicationController
- ApplicationController
- Decidim::Votings::Admin::VotingsController
- Includes:
- Filterable
- Defined in:
- app/controllers/decidim/votings/admin/votings_controller.rb
Overview
This controller allows to create or update a voting.
Instance Method Summary collapse
- #available_polling_officers ⇒ Object
- #create ⇒ Object
- #edit ⇒ Object
- #index ⇒ Object
- #new ⇒ Object
- #polling_officers_picker ⇒ Object
- #publish ⇒ Object
- #unpublish ⇒ Object
- #update ⇒ Object
Instance Method Details
#available_polling_officers ⇒ Object
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'app/controllers/decidim/votings/admin/votings_controller.rb', line 83 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
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'app/controllers/decidim/votings/admin/votings_controller.rb', line 21 def create :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
38 39 40 41 42 |
# File 'app/controllers/decidim/votings/admin/votings_controller.rb', line 38 def edit :edit, :voting, voting: current_voting @form = form(VotingForm).from_model(current_voting) render layout: "decidim/admin/voting" end |
#index ⇒ Object
11 12 13 14 |
# File 'app/controllers/decidim/votings/admin/votings_controller.rb', line 11 def index :read, :votings @votings = filtered_collection end |
#new ⇒ Object
16 17 18 19 |
# File 'app/controllers/decidim/votings/admin/votings_controller.rb', line 16 def new :create, :voting @form = form(VotingForm).instance end |
#polling_officers_picker ⇒ Object
103 104 105 |
# File 'app/controllers/decidim/votings/admin/votings_controller.rb', line 103 def polling_officers_picker render :polling_officers_picker, layout: false end |
#publish ⇒ Object
61 62 63 64 65 66 67 68 69 70 |
# File 'app/controllers/decidim/votings/admin/votings_controller.rb', line 61 def publish :publish, :voting, voting: current_voting PublishVoting.call(current_voting, current_user) do on(:ok) do flash[:notice] = I18n.t("votings.publish.success", scope: "decidim.votings.admin") redirect_to edit_voting_path(voting) end end end |
#unpublish ⇒ Object
72 73 74 75 76 77 78 79 80 81 |
# File 'app/controllers/decidim/votings/admin/votings_controller.rb', line 72 def unpublish :unpublish, :voting, voting: current_voting UnpublishVoting.call(current_voting, current_user) do on(:ok) do flash[:notice] = I18n.t("votings.unpublish.success", scope: "decidim.votings.admin") redirect_to edit_voting_path(voting) end end end |
#update ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'app/controllers/decidim/votings/admin/votings_controller.rb', line 44 def update :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 |