Class: Decidim::Votings::Admin::VotingsController
- Inherits:
-
ApplicationController
- Object
- Admin::ApplicationController
- ApplicationController
- Decidim::Votings::Admin::VotingsController
- Includes:
- Admin::ParticipatorySpaceAdminBreadcrumb, 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
- #update ⇒ Object
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 '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 'app/controllers/decidim/votings/admin/votings_controller.rb', line 23 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
40 41 42 43 44 |
# File 'app/controllers/decidim/votings/admin/votings_controller.rb', line 40 def edit :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 'app/controllers/decidim/votings/admin/votings_controller.rb', line 12 def index :read, :votings @votings = filtered_collection render layout: "decidim/admin/votings" end |
#new ⇒ Object
18 19 20 21 |
# File 'app/controllers/decidim/votings/admin/votings_controller.rb', line 18 def new :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 'app/controllers/decidim/votings/admin/votings_controller.rb', line 46 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 |