Class: Decidim::Meetings::Admin::MeetingsPollController

Inherits:
ApplicationController show all
Includes:
TranslatableAttributes
Defined in:
decidim-meetings/app/controllers/decidim/meetings/admin/meetings_poll_controller.rb

Instance Method Summary collapse

Methods included from TranslatableAttributes

#default_locale?

Methods inherited from ApplicationController

#maps_enabled?, #meetings

Methods inherited from Admin::Components::BaseController

#current_component, #current_participatory_space, #parent_path, #permission_class_chain, #permission_scope, #permissions_context, #skip_manage_component_permission

Methods included from RegistersPermissions

register_permissions

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 NeedsOrganization

enhance_controller, extended, included

Instance Method Details

#answer_optionsObject


43
44
45
46
47
48
49
50
51
# File 'decidim-meetings/app/controllers/decidim/meetings/admin/meetings_poll_controller.rb', line 43

def answer_options
  respond_to do |format|
    format.json do
      question_id = params["id"]
      question = Decidim::Meetings::Question.find_by(id: question_id)
      render json: question.answer_options.map { |answer_option| AnswerOptionPresenter.new(answer_option).as_json } if question.present?
    end
  end
end

#answer_options_url(params) ⇒ Object

Returns the url to get the answer options json (for the display conditions form) for the question with id = params


59
60
61
# File 'decidim-meetings/app/controllers/decidim/meetings/admin/meetings_poll_controller.rb', line 59

def answer_options_url(params)
  url_for([questionnaire.questionnaire_for, { action: :answer_options, format: :json, **params }])
end

#editObject


15
16
17
18
19
20
21
# File 'decidim-meetings/app/controllers/decidim/meetings/admin/meetings_poll_controller.rb', line 15

def edit
  enforce_permission_to :update, :poll, meeting: meeting, poll: poll

  @form = form(Admin::QuestionnaireForm).from_model(questionnaire)

  render template: "decidim/meetings/admin/poll/edit"
end

#edit_questionnaire_titleObject

Implement this method in your controller to set the title of the edit form.


65
66
67
# File 'decidim-meetings/app/controllers/decidim/meetings/admin/meetings_poll_controller.rb', line 65

def edit_questionnaire_title
  t(:title, scope: "decidim.meetings.admin.meetings_poll.form", questionnaire_for: translated_attribute(meeting.try(:title)))
end

#questionnaire_forObject


53
54
55
# File 'decidim-meetings/app/controllers/decidim/meetings/admin/meetings_poll_controller.rb', line 53

def questionnaire_for
  poll
end

#updateObject


23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'decidim-meetings/app/controllers/decidim/meetings/admin/meetings_poll_controller.rb', line 23

def update
  enforce_permission_to :update, :poll, meeting: meeting, poll: poll

  @form = form(Admin::QuestionnaireForm).from_params(params)

  Admin::UpdateQuestionnaire.call(@form, questionnaire) do
    on(:ok) do
      # i18n-tasks-use t("decidim.forms.admin.questionnaires.update.success")
      flash[:notice] = I18n.t("update.success", scope: "decidim.meetings.admin.meetings_poll")
      redirect_to after_update_url
    end

    on(:invalid) do
      # i18n-tasks-use t("decidim.forms.admin.questionnaires.update.invalid")
      flash.now[:alert] = I18n.t("update.invalid", scope: "decidim.meetings.admin.meetings_poll")
      render template: "decidim/meetings/admin/poll/edit"
    end
  end
end