Class: Decidim::Templates::Admin::ProposalAnswerTemplatesController
- Inherits:
-
ApplicationController
- Object
- Admin::ApplicationController
- ApplicationController
- Decidim::Templates::Admin::ProposalAnswerTemplatesController
- Includes:
- Paginable, Decidim::TranslatableAttributes
- Defined in:
- app/controllers/decidim/templates/admin/proposal_answer_templates_controller.rb
Instance Method Summary collapse
- #copy ⇒ Object
- #create ⇒ Object
- #destroy ⇒ Object
- #edit ⇒ Object
- #fetch ⇒ Object
- #index ⇒ Object
- #new ⇒ Object
- #update ⇒ Object
Methods inherited from ApplicationController
Instance Method Details
#copy ⇒ Object
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'app/controllers/decidim/templates/admin/proposal_answer_templates_controller.rb', line 93 def copy :copy, :template CopyProposalAnswerTemplate.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
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'app/controllers/decidim/templates/admin/proposal_answer_templates_controller.rb', line 24 def create :create, :template @form = form(ProposalAnswerTemplateForm).from_params(params) CreateProposalAnswerTemplate.call(@form) do on(:ok) do |_template| flash[:notice] = I18n.t("templates.create.success", scope: "decidim.admin") redirect_to proposal_answer_templates_path end on(:component_selected) do render :new end on(:invalid) do flash.now[:alert] = I18n.t("templates.create.error", scope: "decidim.admin") render :new end end end |
#destroy ⇒ Object
46 47 48 49 50 51 52 53 54 55 |
# File 'app/controllers/decidim/templates/admin/proposal_answer_templates_controller.rb', line 46 def destroy (:destroy, :template, template:) DestroyTemplate.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
19 20 21 22 |
# File 'app/controllers/decidim/templates/admin/proposal_answer_templates_controller.rb', line 19 def edit (:update, :template, template:) @form = form(ProposalAnswerTemplateForm).from_model(template) end |
#fetch ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'app/controllers/decidim/templates/admin/proposal_answer_templates_controller.rb', line 57 def fetch (:read, :template, template:, proposal:) return render json: { msg: I18n.t("templates.fetch.error", scope: "decidim.admin") }, status: :unprocessable_entity if template.blank? state = fetch_proposal_state(template) response_object = { state: state&.token, template: populate_template_interpolations(proposal) } respond_to do |format| format.json do render json: response_object.to_json end end end |
#index ⇒ Object
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'app/controllers/decidim/templates/admin/proposal_answer_templates_controller.rb', line 109 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
14 15 16 17 |
# File 'app/controllers/decidim/templates/admin/proposal_answer_templates_controller.rb', line 14 def new :create, :template @form = form(ProposalAnswerTemplateForm).instance 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/proposal_answer_templates_controller.rb', line 76 def update (:update, :template, template:) @form = form(ProposalAnswerTemplateForm).from_params(params) UpdateProposalAnswerTemplate.call(template, @form, current_user) do on(:ok) do |_questionnaire_template| flash[:notice] = I18n.t("templates.update.success", scope: "decidim.admin") redirect_to proposal_answer_templates_path end on(:invalid) do |template| @template = template flash.now[:error] = I18n.t("templates.update.error", scope: "decidim.admin") render action: :edit end end end |