Sha256: ea3ba32ffe94e3c3aad1a4a74579cc582b07c64a32210fbe3be30e94723eb633

Contents?: true

Size: 1.64 KB

Versions: 14

Compression:

Stored size: 1.64 KB

Contents

# frozen_string_literal: true

module Decidim
  module Surveys
    module Admin
      # This controller allows the user to update a Page.
      class SurveysController < Admin::ApplicationController
        helper_method :survey, :blank_question, :blank_answer_option, :question_types

        def edit
          enforce_permission_to :update, :survey, survey: survey

          @form = form(Admin::SurveyForm).from_model(survey)
        end

        def update
          enforce_permission_to :update, :survey, survey: survey

          params["published_at"] = Time.current if params.has_key? "save_and_publish"
          @form = form(Admin::SurveyForm).from_params(params)

          Admin::UpdateSurvey.call(@form, survey) do
            on(:ok) do
              flash[:notice] = I18n.t("surveys.update.success", scope: "decidim.surveys.admin")
              redirect_to parent_path
            end

            on(:invalid) do
              flash.now[:alert] = I18n.t("surveys.update.invalid", scope: "decidim.surveys.admin")
              render action: "edit"
            end
          end
        end

        private

        def survey
          @survey ||= Survey.find_by(component: current_component)
        end

        def blank_question
          @blank_question ||= Admin::SurveyQuestionForm.new
        end

        def blank_answer_option
          @blank_answer_option ||= Admin::SurveyAnswerOptionForm.new
        end

        def question_types
          @question_types ||= SurveyQuestion::TYPES.map do |question_type|
            [question_type, I18n.t("decidim.surveys.question_types.#{question_type}")]
          end
        end
      end
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
decidim-surveys-0.15.2 app/controllers/decidim/surveys/admin/surveys_controller.rb
decidim-surveys-0.15.1 app/controllers/decidim/surveys/admin/surveys_controller.rb
decidim-surveys-0.15.0 app/controllers/decidim/surveys/admin/surveys_controller.rb
decidim-surveys-0.14.4 app/controllers/decidim/surveys/admin/surveys_controller.rb
decidim-surveys-0.14.3 app/controllers/decidim/surveys/admin/surveys_controller.rb
decidim-surveys-0.14.2 app/controllers/decidim/surveys/admin/surveys_controller.rb
decidim-surveys-0.14.1 app/controllers/decidim/surveys/admin/surveys_controller.rb
decidim-surveys-0.13.1 app/controllers/decidim/surveys/admin/surveys_controller.rb
decidim-surveys-0.12.2 app/controllers/decidim/surveys/admin/surveys_controller.rb
decidim-surveys-0.13.0 app/controllers/decidim/surveys/admin/surveys_controller.rb
decidim-surveys-0.12.1 app/controllers/decidim/surveys/admin/surveys_controller.rb
decidim-surveys-0.13.0.pre1 app/controllers/decidim/surveys/admin/surveys_controller.rb
decidim-surveys-0.12.0 app/controllers/decidim/surveys/admin/surveys_controller.rb
decidim-surveys-0.12.0.pre app/controllers/decidim/surveys/admin/surveys_controller.rb