Class: ClassificationTermsController

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

Instance Method Summary (collapse)

Methods inherited from ApplicationController

can_access?, permission_mappings, set_access_control

Instance Method Details

- (Object) accept_children



83
84
85
# File 'frontend/app/controllers/classification_terms_controller.rb', line 83

def accept_children
  handle_accept_children(JSONModel(:classification_term))
end

- (Object) create



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'frontend/app/controllers/classification_terms_controller.rb', line 30

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']))

                @refresh_tree_node = true

                if params.has_key?(:plus_one)
                  flash[:success] = success_message
                else
                  flash.now[:success] = success_message
                end

                render_aspace_partial :partial => "classification_terms/edit_inline"

              })
end

- (Object) defaults



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

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

- (Object) delete



88
89
90
91
92
93
94
95
96
# File 'frontend/app/controllers/classification_terms_controller.rb', line 88

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

- (Object) edit



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

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

- (Object) new



9
10
11
12
13
14
15
16
17
18
19
20
21
# 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)

  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

- (Object) show



76
77
78
79
80
# File 'frontend/app/controllers/classification_terms_controller.rb', line 76

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

- (Object) update



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'frontend/app/controllers/classification_terms_controller.rb', line 54

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

                @refresh_tree_node = true

                render_aspace_partial :partial => "edit_inline"
              })
end

- (Object) update_defaults



110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
# File 'frontend/app/controllers/classification_terms_controller.rb', line 110

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