Class: Decidim::Templates::Admin::QuestionnaireTemplatesController
- Inherits:
-
ApplicationController
- Object
- Admin::ApplicationController
- ApplicationController
- Decidim::Templates::Admin::QuestionnaireTemplatesController
- Includes:
- Decidim::TranslatableAttributes
- Defined in:
- app/controllers/decidim/templates/admin/questionnaire_templates_controller.rb
Overview
Controller that allows managing templates.
Instance Method Summary collapse
- #apply ⇒ Object
- #copy ⇒ Object
- #create ⇒ Object
- #destroy ⇒ Object
- #edit ⇒ Object
- #index ⇒ Object
- #new ⇒ Object
- #preview ⇒ Object
- #skip ⇒ Object
- #update ⇒ Object
Methods inherited from ApplicationController
Instance Method Details
#apply ⇒ Object
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
# File 'app/controllers/decidim/templates/admin/questionnaire_templates_controller.rb', line 104 def apply questionnaire = Decidim::Forms::Questionnaire.find_by(id: params[:questionnaire_id]) template = Decidim::Templates::Template.find_by(id: params.dig(:questionnaire, :questionnaire_template_id)) ApplyQuestionnaireTemplate.call(questionnaire, template) do on(:ok) do flash[:notice] = I18n.t("templates.apply.success", scope: "decidim.admin") redirect_to URI.parse(params[:url]).path end on(:invalid) do flash[:error] = I18n.t("templates.apply.error", scope: "decidim.admin") redirect_to EngineRouter.admin_proxy(questionnaire.questionnaire_for.component).survey_path end end end |
#copy ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'app/controllers/decidim/templates/admin/questionnaire_templates_controller.rb', line 54 def copy :copy, :template CopyQuestionnaireTemplate.call(template, current_user) do on(:ok) do flash[:notice] = I18n.t("templates.copy.success", scope: "decidim.admin") redirect_to action: :index end on(:invalid) do flash[:alert] = I18n.t("templates.copy.error", scope: "decidim.admin") redirect_to action: :index end end end |
#create ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'app/controllers/decidim/templates/admin/questionnaire_templates_controller.rb', line 36 def create :create, :template @form = form(TemplateForm).from_params(params) CreateQuestionnaireTemplate.call(@form) do on(:ok) do |questionnaire_template| flash[:notice] = I18n.t("templates.create.success", scope: "decidim.admin") redirect_to edit_questionnaire_template_path(questionnaire_template) end on(:invalid) do flash.now[:alert] = I18n.t("templates.create.error", scope: "decidim.admin") render :new end end end |
#destroy ⇒ Object
93 94 95 96 97 98 99 100 101 102 |
# File 'app/controllers/decidim/templates/admin/questionnaire_templates_controller.rb', line 93 def destroy (:destroy, :template, template:) DestroyQuestionnaireTemplate.call(template, current_user) do on(:ok) do flash[:notice] = I18n.t("templates.destroy.success", scope: "decidim.admin") redirect_to action: :index end end end |
#edit ⇒ Object
70 71 72 73 74 |
# File 'app/controllers/decidim/templates/admin/questionnaire_templates_controller.rb', line 70 def edit (:update, :template, template:) @form = form(TemplateForm).from_model(template) @preview_form = form(Decidim::Forms::QuestionnaireForm).from_model(template.templatable) end |
#index ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'app/controllers/decidim/templates/admin/questionnaire_templates_controller.rb', line 15 def index :index, :templates @templates = collection respond_to do |format| format.html { render :index } format.json do term = params[:term] @templates = search(term) render json: @templates.map { |t| { value: t.id, label: translated_attribute(t.name) } } end end end |
#new ⇒ Object
31 32 33 34 |
# File 'app/controllers/decidim/templates/admin/questionnaire_templates_controller.rb', line 31 def new :create, :template @form = form(TemplateForm).instance end |
#preview ⇒ Object
120 121 122 123 124 125 126 127 128 |
# File 'app/controllers/decidim/templates/admin/questionnaire_templates_controller.rb', line 120 def preview respond_to do |format| format.js do @template = template @questionnaire = @template.templatable @preview_form = form(Decidim::Forms::QuestionnaireForm).from_model(@questionnaire) end end end |
#skip ⇒ Object
130 131 132 133 134 135 136 |
# File 'app/controllers/decidim/templates/admin/questionnaire_templates_controller.rb', line 130 def skip questionnaire = Decidim::Forms::Questionnaire.find_by(id: params[:questionnaire_id]) # rubocop:disable Rails/SkipsModelValidations questionnaire.touch # rubocop:enable Rails/SkipsModelValidations redirect_to URI.parse(params[:url]).path end |
#update ⇒ Object
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'app/controllers/decidim/templates/admin/questionnaire_templates_controller.rb', line 76 def update (:update, :template, template:) @form = form(TemplateForm).from_params(params) UpdateTemplate.call(template, @form, current_user) do on(:ok) do |questionnaire_template| flash[:notice] = I18n.t("templates.update.success", scope: "decidim.admin") redirect_to edit_questionnaire_template_path(questionnaire_template) end on(:invalid) do |template| @template = template flash.now[:error] = I18n.t("templates.update.error", scope: "decidim.admin") render action: :edit end end end |