Class: Decidim::Proposals::Admin::ParticipatoryTextsController
- Inherits:
-
ApplicationController
- Object
- DecidimController
- Admin::ApplicationController
- Admin::Components::BaseController
- ApplicationController
- Decidim::Proposals::Admin::ParticipatoryTextsController
- Defined in:
- decidim-proposals/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.
Methods inherited from Admin::Components::BaseController
#current_component, #current_participatory_space, #parent_path, #permission_class_chain, #permission_scope, #permissions_context, #set_component_breadcrumb_item, #skip_manage_component_permission
Methods included from RegistersPermissions
Methods inherited from Admin::ApplicationController
#permission_class_chain, #permission_scope, #user_has_no_permission_path, #user_not_authorized_path
Methods included from Headers::HttpCachingDisabler
Methods included from NeedsSnippets
Methods included from NeedsOrganization
enhance_controller, extended, included
Instance Method Details
#discard ⇒ Object
Removes all the unpublished proposals (drafts).
87 88 89 90 91 92 93 94 95 96 |
# File 'decidim-proposals/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 'decidim-proposals/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 'decidim-proposals/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 'decidim-proposals/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 'decidim-proposals/app/controllers/decidim/proposals/admin/participatory_texts_controller.rb', line 47 def update :manage, :participatory_texts form_params = params.require(:preview_participatory_text).permit! @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 |