Class: Decidim::Templates::Admin::BlockUserTemplatesController

Inherits:
ApplicationController
  • Object
show all
Includes:
Paginable, Decidim::TranslatableAttributes
Defined in:
app/controllers/decidim/templates/admin/block_user_templates_controller.rb

Instance Method Summary collapse

Methods inherited from ApplicationController

#permission_class_chain

Instance Method Details

#copyObject



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
  enforce_permission_to :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

#createObject



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
  enforce_permission_to :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

#destroyObject



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
  enforce_permission_to(: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

#editObject



70
71
72
73
# File 'app/controllers/decidim/templates/admin/block_user_templates_controller.rb', line 70

def edit
  enforce_permission_to(:update, :template, template:)
  @form = form(TemplateForm).from_model(template)
end

#fetchObject



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
  enforce_permission_to(: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

#indexObject



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
  enforce_permission_to :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

#newObject



93
94
95
96
# File 'app/controllers/decidim/templates/admin/block_user_templates_controller.rb', line 93

def new
  enforce_permission_to :create, :template
  @form = form(TemplateForm).instance
end

#updateObject



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
  enforce_permission_to(: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