Class: DigitalObjectComponentsController
  
  
  
  
    - Inherits:
 
    - 
      ApplicationController
      
        
        show all
      
      
 
    
  
  
    
  
    
  
  
  
    - Defined in:
 
    - frontend/app/controllers/digital_object_components_controller.rb
 
  
  
    
      Instance Method Summary
      (collapse)
    
    
  
  
  
  
  
  
  
  
  
  
  can_access?, permission_mappings, set_access_control
  
  
    Instance Method Details
    
      
  
  
    - (Object) accept_children 
  
  
  
  
    
      
112
113
114 
     | 
    
      # File 'frontend/app/controllers/digital_object_components_controller.rb', line 112
def accept_children
  handle_accept_children(JSONModel(:digital_object_component))
end
 
     | 
  
 
    
      
  
  
    - (Object) add_children 
  
  
  
  
    
      
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212 
     | 
    
      # File 'frontend/app/controllers/digital_object_components_controller.rb', line 173
def add_children
  @parent = JSONModel(:digital_object_component).find(params[:id])
  if params[:digital_record_children].blank? or params[:digital_record_children]["children"].blank?
    @children = DigitalObjectComponentChildren.new
    flash.now[:error] = I18n.t("rde.messages.no_rows")
  else
    children_data = cleanup_params_for_schema(params[:digital_record_children], JSONModel(:digital_record_children).schema)
    begin
      @children = DigitalObjectComponentChildren.from_hash(children_data, false)
      if params["validate_only"] == "true"
        @exceptions = @children.children.collect{|c| JSONModel(:digital_object_component).from_hash(c, false)._exceptions}
        error_count = @exceptions.select{|e| !e.empty?}.length
        if error_count > 0
          flash.now[:error] = I18n.t("rde.messages.rows_with_errors", :count => error_count)
        else
          flash.now[:success] = I18n.t("rde.messages.rows_no_errors")
        end
        return render_aspace_partial :partial => "shared/rde"
      else
        @children.save(:digital_object_component_id => @parent.id)
      end
      return render :text => I18n.t("rde.messages.success")
    rescue JSONModel::ValidationException => e
      @exceptions = @children.children.collect{|c| JSONModel(:digital_object_component).from_hash(c, false)._exceptions}
      flash.now[:error] = I18n.t("rde.messages.rows_with_errors", :count => @exceptions.select{|e| !e.empty?}.length)
    end
  end
  render_aspace_partial :partial => "shared/rde"
end
     | 
  
 
    
      
  
  
    - (Object) create 
  
  
  
  
    
      
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65 
     | 
    
      # File 'frontend/app/controllers/digital_object_components_controller.rb', line 41
def create
  handle_crud(:instance => :digital_object_component,
              :find_opts => find_opts,
              :on_invalid => ->(){ render_aspace_partial :partial => "new_inline" },
              :on_valid => ->(id){
                
                
                
                @digital_object_component = JSONModel(:digital_object_component).find(id, find_opts)
                success_message = @digital_object_component.parent ?
                  I18n.t("digital_object_component._frontend.messages.created_with_parent", JSONModelI18nWrapper.new(:digital_object_component => @digital_object_component, :digital_object => @digital_object_component['digital_object']['_resolved'], :parent => @digital_object_component['parent']['_resolved'])) :
                  I18n.t("digital_object_component._frontend.messages.created", JSONModelI18nWrapper.new(:digital_object_component => @digital_object_component, :digital_object => @digital_object_component['digital_object']['_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 => "digital_object_components/edit_inline"
              })
end
     | 
  
 
    
      
  
  
    - (Object) defaults 
  
  
  
  
    
      
116
117
118
119
120
121
122
123
124
125
126 
     | 
    
      # File 'frontend/app/controllers/digital_object_components_controller.rb', line 116
def defaults
  defaults = DefaultValues.get 'digital_object_component'
  values = defaults ? defaults.form_values : {}
  @digital_object_component = JSONModel(:digital_object_component).new(values)._always_valid!
  @digital_object_component.display_string = I18n.t("default_values.form_title.digital_object_component")
  render "defaults"
end
     | 
  
 
    
      
  
  
    - (Object) delete 
  
  
  
  
    
      
101
102
103
104
105
106
107
108
109 
     | 
    
      # File 'frontend/app/controllers/digital_object_components_controller.rb', line 101
def delete
  digital_object_component = JSONModel(:digital_object_component).find(params[:id])
  digital_object_component.delete
  flash[:success] = I18n.t("digital_object_component._frontend.messages.deleted", JSONModelI18nWrapper.new(:digital_object_component => digital_object_component))
  resolver = Resolver.new(digital_object_component['digital_object']['ref'])
  redirect_to resolver.view_uri
end
     | 
  
 
    
      
  
  
    - (Object) edit 
  
  
  
  
    
      
30
31
32
33
34
35
36
37
38 
     | 
    
      # File 'frontend/app/controllers/digital_object_components_controller.rb', line 30
def edit
  @digital_object_component = JSONModel(:digital_object_component).find(params[:id], find_opts)
  if @digital_object_component.suppressed
    return redirect_to(:action => :show, :id => params[:id], :inline => params[:inline])
  end
  render_aspace_partial :partial => "digital_object_components/edit_inline" if inline?
end
     | 
  
 
    
      
  
  
    - (Object) new 
  
  
  
  
    
      
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28 
     | 
    
      # File 'frontend/app/controllers/digital_object_components_controller.rb', line 10
def new
  @digital_object_component = JSONModel(:digital_object_component).new._always_valid!
  @digital_object_component.title = I18n.t("digital_object_component.title_default", :default => "")
  @digital_object_component.parent = {'ref' => JSONModel(:digital_object_component).uri_for(params[:digital_object_component_id])} if params.has_key?(:digital_object_component_id)
  @digital_object_component.digital_object = {'ref' => JSONModel(:digital_object).uri_for(params[:digital_object_id])} if params.has_key?(:digital_object_id)
  if user_prefs['default_values']
    defaults = DefaultValues.get 'digital_object_component'
    @digital_object_component.update(defaults.values) if defaults
    @form_title = I18n.t("digital_object_component.title_default")
  end
  return render_aspace_partial :partial => "digital_object_components/new_inline" if inline?
  
end
     | 
  
 
    
      
  
  
    - (Object) rde 
  
  
  
  
    
      
152
153
154
155
156
157
158
159
160 
     | 
    
      # File 'frontend/app/controllers/digital_object_components_controller.rb', line 152
def rde
  flash.clear
  @parent = JSONModel(:digital_object_component).find(params[:id])
  @children = DigitalObjectComponentChildren.new
  @exceptions = []
  render_aspace_partial :partial => "shared/rde"
end
 
     | 
  
 
    
      
  
  
    - (Object) show 
  
  
  
  
    
      
91
92
93
94
95
96
97
98 
     | 
    
      # File 'frontend/app/controllers/digital_object_components_controller.rb', line 91
def show
  @digital_object_id = params['digital_object_id']
  @digital_object_component = JSONModel(:digital_object_component).find(params[:id], find_opts)
  flash.now[:info] = I18n.t("digital_object_component._frontend.messages.suppressed_info", JSONModelI18nWrapper.new(:digital_object_component => @digital_object_component)) if @digital_object_component.suppressed
  render_aspace_partial :partial => "digital_object_components/show_inline" if inline?
end
     | 
  
 
    
      
  
  
    - (Object) suppress 
  
  
  
  
    
      
215
216
217
218
219
220
221 
     | 
    
      # File 'frontend/app/controllers/digital_object_components_controller.rb', line 215
def suppress
  digital_object_component = JSONModel(:digital_object_component).find(params[:id])
  digital_object_component.set_suppressed(true)
  flash[:success] = I18n.t("digital_object_component._frontend.messages.suppressed", JSONModelI18nWrapper.new(:digital_object_component => digital_object_component))
  redirect_to(:controller => :digital_objects, :action => :show, :id => JSONModel(:digital_object).id_for(digital_object_component['digital_object']['ref']), :anchor => "tree::digital_object_component_#{params[:id]}")
end
     | 
  
 
    
      
  
  
    - (Object) unsuppress 
  
  
  
  
    
      
224
225
226
227
228
229
230 
     | 
    
      # File 'frontend/app/controllers/digital_object_components_controller.rb', line 224
def unsuppress
  digital_object_component = JSONModel(:digital_object_component).find(params[:id])
  digital_object_component.set_suppressed(false)
  flash[:success] = I18n.t("digital_object_component._frontend.messages.unsuppressed", JSONModelI18nWrapper.new(:digital_object_component => digital_object_component))
  redirect_to(:controller => :digital_objects, :action => :show, :id => JSONModel(:digital_object).id_for(digital_object_component['digital_object']['ref']), :anchor => "tree::digital_object_component_#{params[:id]}")
end
     | 
  
 
    
      
  
  
    - (Object) update 
  
  
  
  
    
      
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88 
     | 
    
      # File 'frontend/app/controllers/digital_object_components_controller.rb', line 68
def update
  params['digital_object_component']['position'] = params['digital_object_component']['position'].to_i if params['digital_object_component']['position']
  @digital_object_component = JSONModel(:digital_object_component).find(params[:id], find_opts)
  digital_object = @digital_object_component['digital_object']['_resolved']
  parent = @digital_object_component['parent'] ? @digital_object_component['parent']['_resolved'] : false
  handle_crud(:instance => :digital_object_component,
              :obj => @digital_object_component,
              :on_invalid => ->(){ return render_aspace_partial :partial => "edit_inline" },
              :on_valid => ->(id){
                success_message = parent ?
                  I18n.t("digital_object_component._frontend.messages.updated_with_parent", JSONModelI18nWrapper.new(:digital_object_component => @digital_object_component, :digital_object => digital_object, :parent => parent)) :
                  I18n.t("digital_object_component._frontend.messages.updated", JSONModelI18nWrapper.new(:digital_object_component => @digital_object_component, :digital_object => digital_object))
                flash.now[:success] = success_message
                @refresh_tree_node = true
                render_aspace_partial :partial => "edit_inline"
              })
end
     | 
  
 
    
      
  
  
    - (Object) update_defaults 
  
  
  
  
    
      
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149 
     | 
    
      # File 'frontend/app/controllers/digital_object_components_controller.rb', line 129
def update_defaults
  begin
    DefaultValues.from_hash({
                              "record_type" => "digital_object_component",
                              "lock_version" => params[:digital_object_component].delete('lock_version'),
                              "defaults" => cleanup_params_for_schema(
                                                                      params[:digital_object_component],
                                                                      JSONModel(:digital_object_component).schema
                                                                      )
                            }).save
    flash[:success] = I18n.t("default_values.messages.defaults_updated")
    redirect_to :controller => :digital_object_components, :action => :defaults
  rescue Exception => e
    flash[:error] = e.message
    redirect_to :controller => :digital_object_components, :action => :defaults
  end
end
     | 
  
 
    
      
  
  
    - (Object) validate_rows 
  
  
  
  
    
      
163
164
165
166
167
168
169
170
171 
     | 
    
      # File 'frontend/app/controllers/digital_object_components_controller.rb', line 163
def validate_rows
  row_data = cleanup_params_for_schema(params[:digital_record_children], JSONModel(:digital_record_children).schema)
  
  do_children = DigitalObjectComponentChildren.from_hash(row_data, false, true)
  
  render :json => do_children.children.collect{|c| JSONModel(:digital_object_component).from_hash(c, false)._exceptions}
end
     |