Class: Decidim::Meetings::Admin::MeetingsPollController
- Inherits:
-
Admin::ApplicationController
- Object
- Admin::ApplicationController
- Decidim::Meetings::Admin::MeetingsPollController
- Includes:
- TranslatableAttributes
- Defined in:
- app/controllers/decidim/meetings/admin/meetings_poll_controller.rb
Instance Method Summary collapse
- #edit ⇒ Object
-
#edit_questionnaire_title ⇒ Object
Implement this method in your controller to set the title of the edit form.
- #questionnaire_for ⇒ Object
- #response_options ⇒ Object
-
#response_options_url(params) ⇒ Object
Returns the url to get the response options json (for the display conditions form) for the question with id = params.
- #update ⇒ Object
Instance Method Details
#edit ⇒ Object
15 16 17 18 19 20 21 |
# File 'app/controllers/decidim/meetings/admin/meetings_poll_controller.rb', line 15 def edit (:update, :poll, meeting:, poll:) @form = form(Admin::QuestionnaireForm).from_model(questionnaire) render template: "decidim/meetings/admin/poll/edit" end |
#edit_questionnaire_title ⇒ Object
Implement this method in your controller to set the title of the edit form.
77 78 79 |
# File 'app/controllers/decidim/meetings/admin/meetings_poll_controller.rb', line 77 def edit_questionnaire_title t(:title, scope: "decidim.meetings.admin.meetings_poll.form", questionnaire_for: translated_attribute(meeting.try(:title))) end |
#questionnaire_for ⇒ Object
65 66 67 |
# File 'app/controllers/decidim/meetings/admin/meetings_poll_controller.rb', line 65 def questionnaire_for poll end |
#response_options ⇒ Object
55 56 57 58 59 60 61 62 63 |
# File 'app/controllers/decidim/meetings/admin/meetings_poll_controller.rb', line 55 def respond_to do |format| format.json do question_id = params["id"] question = Decidim::Meetings::Question.find_by(id: question_id) render json: question..map { |response_option| ResponseOptionPresenter.new(response_option).as_json } if question.present? end end end |
#response_options_url(params) ⇒ Object
Returns the url to get the response options json (for the display conditions form) for the question with id = params
71 72 73 |
# File 'app/controllers/decidim/meetings/admin/meetings_poll_controller.rb', line 71 def (params) url_for([questionnaire.questionnaire_for, { action: :response_options, format: :json, **params }]) end |
#update ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'app/controllers/decidim/meetings/admin/meetings_poll_controller.rb', line 23 def update (:update, :poll, meeting:, poll:) current_questions_forms = form(Admin::QuestionnaireForm).from_model(questionnaire).questions @form = form(Admin::QuestionnaireForm).from_params(params) # Although the question values (except the position) will be ignored if they are not editable, # its information is completed so that if any update failure occurs, the form is rendered again # with the full data for the disabled questions. @form.questions = @form.questions.map do |question_form| next question_form if question_form.editable? full_question_form = current_questions_forms.find { |form| form.id.to_s == question_form.id.to_s } full_question_form.position = question_form.position full_question_form end 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", status: :unprocessable_content end end end |