Class: ClassificationTermsController

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

Constant Summary

Constants included from Searchable

Searchable::ABSTRACT

Instance Method Summary collapse

Methods inherited from ApplicationController

#archivesspace, can_access?, permission_mappings, set_access_control

Methods included from JsonHelper

#merge_notes, #process_json_notes

Methods included from Searchable

#default_search_opts, #get_filter_years, #handle_results, #html_notes, #process_results, #process_search_results, #repo_context, #search_terms, #set_up_advanced_search, #set_up_and_run_search, #set_up_search, #strip_facet_fields

Methods included from HandleFaceting

#fetch_only_facets, #get_pretty_facet_value, #strip_facets

Methods included from ManipulateNode

#inheritance, #process_mixed_content, #strip_mixed_content

Instance Method Details

#accept_childrenObject



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

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
62
# 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 ?
                                    I18n.t("classification_term._frontend.messages.created_with_parent", JSONModelI18nWrapper.new(:classification_term => @classification_term, :classification => @classification_term['classification']['_resolved'], :parent => @classification_term['parent']['_resolved'])) :
                                    I18n.t("classification_term._frontend.messages.created", JSONModelI18nWrapper.new(:classification_term => @classification_term, :classification => @classification_term['classification']['_resolved']))

                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] = I18n.t("slug.autogen_disabled")
                  else
                    flash.now[:warning] = I18n.t("slug.autogen_disabled")
                  end
                end

                render_aspace_partial :partial => "classification_terms/edit_inline"

              })
end

#current_recordObject



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

def current_record
  @classification_term
end

#defaultsObject



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

def defaults
  defaults = DefaultValues.get 'classification_term'

  values = defaults ? defaults.form_values : {}

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

  render "defaults"
end

#deleteObject



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

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

  flash[:success] = I18n.t("classification_term._frontend.messages.deleted", JSONModelI18nWrapper.new(:classification_term => classification_term))

  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 = I18n.t("classification_term._singular")
  end

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

#showObject



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

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



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
91
# File 'frontend/app/controllers/classification_terms_controller.rb', line 65

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 ?
                  I18n.t("classification_term._frontend.messages.updated_with_parent", JSONModelI18nWrapper.new(:classification_term => @classification_term, :classification => @classification_term['classification']['_resolved'], :parent => parent)) :
                  I18n.t("classification_term._frontend.messages.updated", JSONModelI18nWrapper.new(:classification_term => @classification_term, :classification => @classification_term['classification']['_resolved']))

                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] = I18n.t("slug.autogen_disabled")
                end

                render_aspace_partial :partial => "edit_inline"
              })
end

#update_defaultsObject



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

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] = I18n.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