Class: Decidim::Surveys::Admin::SurveysController
- Inherits:
-
ApplicationController
- Object
- Admin::Components::BaseController
- ApplicationController
- Decidim::Surveys::Admin::SurveysController
- Includes:
- Forms::Admin::Concerns::HasQuestionnaire, Forms::Admin::Concerns::HasQuestionnaireAnswersUrlHelper, Filterable
- Defined in:
- app/controllers/decidim/surveys/admin/surveys_controller.rb
Overview
This controller allows the user create and edit questionnaires for Surveys.
Instance Method Summary collapse
- #after_update_url ⇒ Object
- #create ⇒ Object
- #destroy ⇒ Object
- #edit ⇒ Object
- #edit_questionnaire_title ⇒ Object
- #edit_questions_template ⇒ Object
- #index ⇒ Object
-
#public_url ⇒ Object
Specify the public url from which the survey can be viewed and answered.
- #publish ⇒ Object
- #questionnaire_for ⇒ Object
- #questionnaire_participants_url ⇒ Object
- #unpublish ⇒ Object
- #update ⇒ Object
Instance Method Details
#after_update_url ⇒ Object
102 103 104 |
# File 'app/controllers/decidim/surveys/admin/surveys_controller.rb', line 102 def after_update_url surveys_path end |
#create ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'app/controllers/decidim/surveys/admin/surveys_controller.rb', line 16 def create (:create, :questionnaire) Decidim::Surveys::Admin::CreateSurvey.call(current_component) do on(:ok) do |survey| flash[:notice] = I18n.t("create.success", scope: "decidim.surveys.admin.surveys") redirect_to edit_survey_path(survey) end on(:invalid) do flash.now[:alert] = I18n.t("create.invalid", scope: "decidim.surveys.admin.surveys") render action: "index" end end end |
#destroy ⇒ Object
83 84 85 86 87 88 89 90 91 92 |
# File 'app/controllers/decidim/surveys/admin/surveys_controller.rb', line 83 def destroy (:destroy, :questionnaire, questionnaire:) Decidim::Commands::DestroyResource.call(survey, current_user) do on(:ok) do flash[:notice] = I18n.t("destroy.success", scope: "decidim.surveys.admin.surveys") redirect_to surveys_path end end end |
#edit ⇒ Object
31 32 33 34 |
# File 'app/controllers/decidim/surveys/admin/surveys_controller.rb', line 31 def edit (:update, :questionnaire, questionnaire:) @form = form(Admin::SurveyForm).from_model(survey) end |
#edit_questionnaire_title ⇒ Object
115 116 117 |
# File 'app/controllers/decidim/surveys/admin/surveys_controller.rb', line 115 def edit_questionnaire_title t(:title, scope: "decidim.forms.admin.questionnaires.form", questionnaire_for: translated_attribute(current_component.name)) end |
#edit_questions_template ⇒ Object
94 95 96 |
# File 'app/controllers/decidim/surveys/admin/surveys_controller.rb', line 94 def edit_questions_template "decidim/surveys/admin/surveys/edit_questions" end |
#index ⇒ Object
14 |
# File 'app/controllers/decidim/surveys/admin/surveys_controller.rb', line 14 def index; end |
#public_url ⇒ Object
Specify the public url from which the survey can be viewed and answered
111 112 113 |
# File 'app/controllers/decidim/surveys/admin/surveys_controller.rb', line 111 def public_url Decidim::EngineRouter.main_proxy(current_component).survey_path(survey) end |
#publish ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'app/controllers/decidim/surveys/admin/surveys_controller.rb', line 53 def publish (:update, :questionnaire, questionnaire:) Decidim::Surveys::Admin::PublishSurvey.call(survey, current_user) do on(:ok) do flash[:notice] = I18n.t("publish.success", scope: "decidim.surveys.admin.surveys") redirect_to surveys_path end on(:invalid) do flash.now[:alert] = I18n.t("publish.invalid", scope: "decidim.surveys.admin.surveys") render action: "index" end end end |
#questionnaire_for ⇒ Object
98 99 100 |
# File 'app/controllers/decidim/surveys/admin/surveys_controller.rb', line 98 def questionnaire_for survey end |
#questionnaire_participants_url ⇒ Object
106 107 108 |
# File 'app/controllers/decidim/surveys/admin/surveys_controller.rb', line 106 def questionnaire_participants_url Decidim::EngineRouter.admin_proxy(survey.component).survey_answers_path(survey) end |
#unpublish ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'app/controllers/decidim/surveys/admin/surveys_controller.rb', line 68 def unpublish (:update, :questionnaire, questionnaire:) Decidim::Surveys::Admin::UnpublishSurvey.call(survey, current_user) do on(:ok) do flash[:notice] = I18n.t("unpublish.success", scope: "decidim.surveys.admin.surveys") redirect_to surveys_path end on(:invalid) do flash.now[:alert] = I18n.t("unpublish.invalid", scope: "decidim.surveys.admin.surveys") render action: "index" end end end |
#update ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'app/controllers/decidim/surveys/admin/surveys_controller.rb', line 36 def update (:update, :questionnaire, questionnaire:) @form = form(Admin::SurveyForm).from_params(params) Admin::UpdateSurvey.call(@form, survey, current_user) do on(:ok) do flash[:notice] = I18n.t("update.success", scope: "decidim.surveys.admin.surveys") redirect_to(surveys_path) && return end on(:invalid) do flash.now[:alert] = I18n.t("update.invalid", scope: "decidim.surveys.admin.surveys") render action: "edit" end end end |