Class: Decidim::Proposals::Admin::ParticipatoryTextsController
- Inherits:
-
ApplicationController
- Object
- Admin::Components::BaseController
- ApplicationController
- Decidim::Proposals::Admin::ParticipatoryTextsController
- Defined in:
- app/controllers/decidim/proposals/admin/participatory_texts_controller.rb
Overview
This controller manages the participatory texts area.
Instance Method Summary collapse
-
#discard ⇒ Object
Removes all the unpublished proposals (drafts).
- #import ⇒ Object
- #index ⇒ Object
- #new_import ⇒ Object
-
#update ⇒ Object
When ‘save_draft` param exists, proposals are only saved.
Instance Method Details
#discard ⇒ Object
Removes all the unpublished proposals (drafts).
87 88 89 90 91 92 93 94 95 96 |
# File 'app/controllers/decidim/proposals/admin/participatory_texts_controller.rb', line 87 def discard :manage, :participatory_texts DiscardParticipatoryText.call(current_component) do on(:ok) do flash[:notice] = I18n.t("participatory_texts.discard.success", scope: "decidim.proposals.admin") redirect_to EngineRouter.admin_proxy(current_component).participatory_texts_path end end end |
#import ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'app/controllers/decidim/proposals/admin/participatory_texts_controller.rb', line 23 def import :manage, :participatory_texts @import = form(Admin::ImportParticipatoryTextForm).from_params(params) Admin::ImportParticipatoryText.call(@import) do on(:ok) do flash[:notice] = I18n.t("participatory_texts.import.success", scope: "decidim.proposals.admin") redirect_to EngineRouter.admin_proxy(current_component).participatory_texts_path end on(:invalid) do flash.now[:alert] = I18n.t("participatory_texts.import.invalid", scope: "decidim.proposals.admin") render action: "new_import" end on(:invalid_file) do flash.now[:alert] = I18n.t("participatory_texts.import.invalid_file", scope: "decidim.proposals.admin") render action: "new_import" end end end |
#index ⇒ Object
11 12 13 14 15 |
# File 'app/controllers/decidim/proposals/admin/participatory_texts_controller.rb', line 11 def index @drafts = Proposal.where(component: current_component).drafts.order(:position) @preview_form = form(Admin::PreviewParticipatoryTextForm).instance @preview_form.from_models(@drafts) end |
#new_import ⇒ Object
17 18 19 20 21 |
# File 'app/controllers/decidim/proposals/admin/participatory_texts_controller.rb', line 17 def new_import :manage, :participatory_texts participatory_text = Decidim::Proposals::ParticipatoryText.find_by(component: current_component) @import = form(Admin::ImportParticipatoryTextForm).from_model(participatory_text) end |
#update ⇒ Object
When ‘save_draft` param exists, proposals are only saved. When no `save_draft` param is set, proposals are saved and published.
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'app/controllers/decidim/proposals/admin/participatory_texts_controller.rb', line 47 def update :manage, :participatory_texts form_params = params.require(:preview_participatory_text) @preview_form = form(Admin::PreviewParticipatoryTextForm).from_params(proposals: form_params[:proposals_attributes]&.values) if params.has_key?("save_draft") UpdateParticipatoryText.call(@preview_form) do on(:ok) do flash[:notice] = I18n.t("participatory_texts.update.success", scope: "decidim.proposals.admin") redirect_to EngineRouter.admin_proxy(current_component).participatory_texts_path end on(:invalid) do |failures| alert_msg = [I18n.t("participatory_texts.publish.invalid", scope: "decidim.proposals.admin")] failures.each_pair { |id, msg| alert_msg << "ID:[#{id}] #{msg}" } flash.now[:alert] = alert_msg.join("<br/>").html_safe index render action: "index" end end else PublishParticipatoryText.call(@preview_form) do on(:ok) do flash[:notice] = I18n.t("participatory_texts.publish.success", scope: "decidim.proposals.admin") redirect_to proposals_path end on(:invalid) do |failures| alert_msg = [I18n.t("participatory_texts.publish.invalid", scope: "decidim.proposals.admin")] failures.each_pair { |id, msg| alert_msg << "ID:[#{id}] #{msg}" } flash.now[:alert] = alert_msg.join("<br/>").html_safe index render action: "index" end end end end |