Class: Decidim::TermCustomizer::Admin::TranslationSetsController

Inherits:
ApplicationController
  • Object
show all
Includes:
TranslatableAttributes
Defined in:
app/controllers/decidim/term_customizer/admin/translation_sets_controller.rb

Instance Method Summary collapse

Methods inherited from ApplicationController

#permission_class_chain

Instance Method Details

#createObject



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'app/controllers/decidim/term_customizer/admin/translation_sets_controller.rb', line 24

def create
  enforce_permission_to :create, :translation_set
  @form = form(TranslationSetForm).from_params(
    params,
    current_organization: current_organization
  )

  CreateTranslationSet.call(@form) do
    on(:ok) do |set|
      flash[:notice] = I18n.t("translation_sets.create.success", scope: "decidim.term_customizer.admin")
      redirect_to translation_set_translations_path(set)
    end

    on(:invalid) do
      flash.now[:alert] = I18n.t("translation_sets.create.error", scope: "decidim.term_customizer.admin")
      render action: "new"
    end
  end
end

#destroyObject



69
70
71
72
73
74
75
76
# File 'app/controllers/decidim/term_customizer/admin/translation_sets_controller.rb', line 69

def destroy
  enforce_permission_to :destroy, :translation_set, translation_set: set
  set.destroy!

  flash[:notice] = I18n.t("translation_sets.destroy.success", scope: "decidim.term_customizer.admin")

  redirect_to translation_sets_path
end

#editObject



44
45
46
47
# File 'app/controllers/decidim/term_customizer/admin/translation_sets_controller.rb', line 44

def edit
  enforce_permission_to :update, :translation_set, translation_set: set
  @form = form(TranslationSetForm).from_model(set)
end

#indexObject



11
12
13
14
# File 'app/controllers/decidim/term_customizer/admin/translation_sets_controller.rb', line 11

def index
  enforce_permission_to :read, :translation_set
  @sets = collection
end

#newObject



16
17
18
19
20
21
22
# File 'app/controllers/decidim/term_customizer/admin/translation_sets_controller.rb', line 16

def new
  enforce_permission_to :create, :translation_set

  @form = form(TranslationSetForm).from_model(
    TranslationSet.new(constraints: [Constraint.new])
  )
end

#updateObject



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'app/controllers/decidim/term_customizer/admin/translation_sets_controller.rb', line 49

def update
  enforce_permission_to :update, :translation_set, translation_set: set
  @form = form(TranslationSetForm).from_params(
    params,
    current_organization: current_organization
  )

  UpdateTranslationSet.call(@form, set) do
    on(:ok) do
      flash[:notice] = I18n.t("translation_sets.update.success", scope: "decidim.term_customizer.admin")
      redirect_to translation_sets_path
    end

    on(:invalid) do
      flash.now[:alert] = I18n.t("translation_sets.update.error", scope: "decidim.term_customizer.admin")
      render action: "edit"
    end
  end
end