Class: Decidim::Templates::Admin::BlockUserTemplatesController
- Inherits:
-
ApplicationController
- Object
- Admin::ApplicationController
- ApplicationController
- Decidim::Templates::Admin::BlockUserTemplatesController
- Includes:
- Paginable, Decidim::TranslatableAttributes
- Defined in:
- app/controllers/decidim/templates/admin/block_user_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
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'app/controllers/decidim/templates/admin/block_user_templates_controller.rb', line 26 def copy :copy, :template CopyTemplate.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
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'app/controllers/decidim/templates/admin/block_user_templates_controller.rb', line 75 def create :create, :template @form = form(TemplateForm).from_params(params) CreateBlockUserTemplate.call(@form) do on(:ok) do flash[:notice] = I18n.t("templates.create.success", scope: "decidim.admin") redirect_to action: :index end on(:invalid) do flash.now[:alert] = I18n.t("templates.create.error", scope: "decidim.admin") render :new end end end |
#destroy ⇒ Object
42 43 44 45 46 47 48 49 50 51 |
# File 'app/controllers/decidim/templates/admin/block_user_templates_controller.rb', line 42 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
70 71 72 73 |
# File 'app/controllers/decidim/templates/admin/block_user_templates_controller.rb', line 70 def edit (:update, :template, template:) @form = form(TemplateForm).from_model(template) end |
#fetch ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'app/controllers/decidim/templates/admin/block_user_templates_controller.rb', line 12 def fetch (:read, :template, template:) response_object = { template: translated_attribute(template.description) } respond_to do |format| format.json do render json: response_object.to_json end end end |
#index ⇒ Object
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'app/controllers/decidim/templates/admin/block_user_templates_controller.rb', line 98 def index :index, :templates @templates = paginate(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
93 94 95 96 |
# File 'app/controllers/decidim/templates/admin/block_user_templates_controller.rb', line 93 def new :create, :template @form = form(TemplateForm).instance end |
#update ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'app/controllers/decidim/templates/admin/block_user_templates_controller.rb', line 53 def update (:update, :template, template:) @form = form(TemplateForm).from_params(params) UpdateTemplate.call(template, @form, current_user) do on(:ok) do flash[:notice] = I18n.t("templates.update.success", scope: "decidim.admin") redirect_to action: :index end on(:invalid) do |template| @template = template flash.now[:error] = I18n.t("templates.update.error", scope: "decidim.admin") render action: :edit end end end |