Class: ClassificationTermsController

Inherits:
ApplicationController show all
Defined in:
frontend/app/controllers/classification_terms_controller.rb

Instance Method Summary collapse

Methods inherited from ApplicationController

#archivesspace, can_access?, permission_mappings, set_access_control

Instance Method Details

#accept_childrenObject



107
108
109
# File 'frontend/app/controllers/classification_terms_controller.rb', line 107

def accept_children
  handle_accept_children(JSONModel(:classification_term))
end

#createObject



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'frontend/app/controllers/classification_terms_controller.rb', line 31

def create
  handle_crud(:instance => :classification_term,
              :find_opts => find_opts,
              :on_invalid => ->() { render_aspace_partial :partial => "new_inline" },
              :on_valid => ->(id) {

                success_message = @classification_term.parent ?
                                    t("classification_term._frontend.messages.created_with_parent", classification_term_title: @classification_term.title) :
                                    t("classification_term._frontend.messages.created", classification_term_title: @classification_term.title)
                if params.has_key?(:plus_one)
                  flash[:success] = success_message
                else
                  flash.now[:success] = success_message
                end

                if @classification_term["is_slug_auto"] == false &&
                    @classification_term["slug"] == nil &&
                    params["classification_term"] &&
                    params["classification_term"]["is_slug_auto"] == "1"

                  if params.has_key?(:plus_one)
                    flash[:warning] = t("slug.autogen_disabled")
                  else
                    flash.now[:warning] = t("slug.autogen_disabled")
                  end
                end

                render_aspace_partial :partial => "classification_terms/edit_inline"

              })
end

#current_recordObject



93
94
95
# File 'frontend/app/controllers/classification_terms_controller.rb', line 93

def current_record
  @classification_term
end

#defaultsObject



123
124
125
126
127
128
129
130
131
132
# File 'frontend/app/controllers/classification_terms_controller.rb', line 123

def defaults
  defaults = DefaultValues.get 'classification_term'

  values = defaults ? defaults.form_values : {}

  @classification_term = JSONModel(:classification_term).new(values)._always_valid!
  @form_title = t("default_values.form_title.classification_term")

  render "defaults"
end

#deleteObject



112
113
114
115
116
117
118
119
120
# File 'frontend/app/controllers/classification_terms_controller.rb', line 112

def delete
  classification_term = JSONModel(:classification_term).find(params[:id])
  classification_term.delete

  flash[:success] = t("classification_term._frontend.messages.deleted", classification_term_title: classification_term.title)

  resolver = Resolver.new(classification_term['classification']['ref'])
  redirect_to resolver.view_uri
end

#editObject



25
26
27
28
# File 'frontend/app/controllers/classification_terms_controller.rb', line 25

def edit
  @classification_term = JSONModel(:classification_term).find(params[:id], find_opts)
  render_aspace_partial :partial => "classification_terms/edit_inline" if inline?
end

#newObject



9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'frontend/app/controllers/classification_terms_controller.rb', line 9

def new
  @classification_term = JSONModel(:classification_term).new._always_valid!
  @classification_term.parent = {'ref' => JSONModel(:classification_term).uri_for(params[:classification_term_id])} if params.has_key?(:classification_term_id)
  @classification_term.classification = {'ref' => JSONModel(:classification).uri_for(params[:classification_id])} if params.has_key?(:classification_id)
  @classification_term.position = params[:position]

  if user_prefs['default_values']
    defaults = DefaultValues.get 'classification_term'
    @classification_term.update(defaults.values) if defaults
    @form_title = t("classification_term._singular")
  end

  return render_aspace_partial :partial => "classification_terms/new_inline" if inline?
end

#showObject



98
99
100
101
102
103
104
# File 'frontend/app/controllers/classification_terms_controller.rb', line 98

def show
  if params[:inline]
    @classification_term = JSONModel(:classification_term).find(params[:id], find_opts)
    return render_aspace_partial :partial => "classification_terms/show_inline"
  end
  @classification_id = params['classification_id']
end

#updateObject



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'frontend/app/controllers/classification_terms_controller.rb', line 64

def update
  params['classification_term']['position'] = params['classification_term']['position'].to_i if params['classification_term']['position']

  @classification_term = JSONModel(:classification_term).find(params[:id], find_opts)
  parent = @classification_term['parent'] ? @classification_term['parent']['_resolved'] : false

  handle_crud(:instance => :classification_term,
              :obj => @classification_term,
              :on_invalid => ->() { return render_aspace_partial :partial => "edit_inline" },
              :on_valid => ->(id) {

                success_message = parent ?
                  t("classification_term._frontend.messages.updated_with_parent", classification_term_title: @classification_term.title) :
                  t("classification_term._frontend.messages.updated", classification_term_title: @classification_term.title)
                flash.now[:success] = success_message

                if @classification_term["is_slug_auto"] == false &&
                   @classification_term["slug"] == nil &&
                   params["classification_term"] &&
                   params["classification_term"]["is_slug_auto"] == "1"

                  flash.now[:warning] = t("slug.autogen_disabled")
                end

                render_aspace_partial :partial => "edit_inline"
              })
end

#update_defaultsObject



134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
# File 'frontend/app/controllers/classification_terms_controller.rb', line 134

def update_defaults
  begin
    DefaultValues.from_hash({
                              "record_type" => "classification_term",
                              "lock_version" => params[:classification_term].delete('lock_version'),
                              "defaults" => cleanup_params_for_schema(
                                                                      params[:classification_term],
                                                                      JSONModel(:classification_term).schema)
                            }).save

    flash[:success] = t("default_values.messages.defaults_updated")
    redirect_to :controller => :classification_terms, :action => :defaults
  rescue Exception => e
    flash[:error] = e.message
    redirect_to :controller => :classification_terms, :action => :defaults
  end
end