Class: TopContainersController
  
  
  
  
    - Inherits:
 
    - 
      ApplicationController
      
        
        show all
      
      
 
    
  
  
    
  
    
      - Includes:
 
      - ApplicationHelper
 
      
    
  
  
  
    - Defined in:
 
    - frontend/app/controllers/top_containers_controller.rb
 
  
Defined Under Namespace
  
    
  
    
      Classes: MissingFilterException
    
  
    
  
  
    
      Instance Method Summary
      (collapse)
    
    
  
  
  
  
  
  
  
  
  
  
  #add_new_event_url, #button_confirm_action, #button_delete_action, #button_delete_multiple_action, #button_edit_multiple_action, #clean_mixed_content, #current_repo, #current_user, #display_audit_info, #has_permission_for_controller?, #include_controller_js, #include_theme_css, #inline?, #link_to_help, #proxy_localhost?, #render_aspace_partial, #render_token, #set_title, #setup_context, #show_external_ids?, #wrap_with_tooltip
  
  
  
  
  
  
  
  
  
  can_access?, permission_mappings, set_access_control
  
  
    Instance Method Details
    
      
  
  
    - (Object) batch_delete 
  
  
  
  
    
      
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86 
     | 
    
      # File 'frontend/app/controllers/top_containers_controller.rb', line 72
def batch_delete
  response = JSONModel::HTTP.post_form("/batch_delete",
                                       {
                              "record_uris[]" => Array(params[:record_uris])
                                       })
  if response.code === "200"
    flash[:success] = I18n.t("top_container.batch_delete.success")
    deleted_uri_param = params[:record_uris].map{|uri| "deleted_uri[]=#{uri}"}.join("&")
    redirect_to "#{request.referrer}?#{deleted_uri_param}"
  else
    flash[:error] = "#{I18n.t("top_container.batch_delete.error")}<br/> #{ASUtils.json_parse(response.body)["error"]["failures"].map{|err| "#{err["response"]} [#{err["uri"]}]"}.join("<br/>")}".html_safe
    redirect_to request.referrer
  end
end
     | 
  
 
    
      
  
  
    - (Object) bulk_operation_search 
  
  
  
  
    
      
102
103
104
105
106
107
108
109
110 
     | 
    
      # File 'frontend/app/controllers/top_containers_controller.rb', line 102
def bulk_operation_search
  begin
    results = perform_search
  rescue MissingFilterException
    return render :text => I18n.t("top_container._frontend.messages.filter_required"), :status => 500
  end
  render_aspace_partial :partial => "top_containers/bulk_operations/results", :locals => {:results => results}
end
     | 
  
 
    
      
  
  
    - (Object) bulk_operation_update 
  
  
  
  
    
      
124
125
126
127
128
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/top_containers_controller.rb', line 124
def bulk_operation_update
  post_params = {'ids[]' => params['update_uris'].map {|uri| JSONModel(:top_container).id_for(uri)}}
  post_uri = "/repositories/#{session[:repo_id]}/top_containers/batch/"
  if params['ils_holding_id']
    post_params['ils_holding_id'] = params['ils_holding_id']
    post_uri += 'ils_holding_id'
  elsif params['container_profile_uri']
    post_params['container_profile_uri'] = params['container_profile'] ? params['container_profile']['ref'] : ""
    post_uri += 'container_profile'
  elsif params['location_uri']
    post_params['location_uri'] = params['location'] ? params['location']['ref'] : ""
    post_uri += 'location'
  else
    render :text => "You must provide a field to update.", :status => 500
  end
    
  response = JSONModel::HTTP::post_form(post_uri, post_params)
  result = ASUtils.json_parse(response.body)
  if result.has_key?('records_updated')
    render_aspace_partial :partial => "top_containers/bulk_operations/bulk_action_success", :locals => {:result => result}
  else
    render :text => "There seems to have been a problem with the update: #{result['error']}", :status => 500
  end
end
     | 
  
 
    
      
  
  
    - (Object) bulk_operations_browse 
  
  
  
  
    
      
113
114
115
116
117
118
119
120
121 
     | 
    
      # File 'frontend/app/controllers/top_containers_controller.rb', line 113
def bulk_operations_browse
  begin
    results = perform_search if params.has_key?("q")
  rescue MissingFilterException
    flash[:error] = I18n.t("top_container._frontend.messages.filter_required")
  end
  render_aspace_partial :partial => "top_containers/bulk_operations/browse", :locals => {:results => results}
end
     | 
  
 
    
      
  
  
    - (Object) create 
  
  
  
  
    
      
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38 
     | 
    
      # File 'frontend/app/controllers/top_containers_controller.rb', line 22
def create
  handle_crud(:instance => :top_container,
              :model => JSONModel(:top_container),
              :on_invalid => ->(){
                return render_aspace_partial :partial => "top_containers/new" if inline?
                return render :action => :new
              },
              :on_valid => ->(id){
                if inline?
                  @top_container.refetch
                  render :json => @top_container.to_hash if inline?
                else
                  flash[:success] = I18n.t("top_container._frontend.messages.created")
                  redirect_to :controller => :top_containers, :action => :show, :id => id
                end
              })
end
     | 
  
 
    
      
  
  
    - (Object) delete 
  
  
  
  
    
      
65
66
67
68
69
70 
     | 
    
      # File 'frontend/app/controllers/top_containers_controller.rb', line 65
def delete
  top_container = JSONModel(:top_container).find(params[:id])
  top_container.delete
  redirect_to(:controller => :top_containers, :action => :index, :deleted_uri => top_container.uri)
end
 
     | 
  
 
    
      
  
  
    - (Object) edit 
  
  
  
  
    
      
46
47
48 
     | 
    
      # File 'frontend/app/controllers/top_containers_controller.rb', line 46
def edit
  @top_container = JSONModel(:top_container).find(params[:id], find_opts)
end
 
     | 
  
 
    
      
  
  
    - (Object) index 
  
  
  
  
    
      
11
12 
     | 
    
      # File 'frontend/app/controllers/top_containers_controller.rb', line 11
def index
end
 
     | 
  
 
    
      
  
  
    - (Object) new 
  
  
  
  
    
      
15
16
17
18
19 
     | 
    
      # File 'frontend/app/controllers/top_containers_controller.rb', line 15
def new
  @top_container = JSONModel(:top_container).new._always_valid!
  render_aspace_partial :partial => "top_containers/new" if inline?
end
 
     | 
  
 
    
      
  
  
    - (Object) show 
  
  
  
  
    
      
41
42
43 
     | 
    
      # File 'frontend/app/controllers/top_containers_controller.rb', line 41
def show
  @top_container = JSONModel(:top_container).find(params[:id], find_opts)
end
 
     | 
  
 
    
      
  
  
    - (Object) typeahead 
  
  
  
  
    
      
89
90
91
92
93
94
95
96 
     | 
    
      # File 'frontend/app/controllers/top_containers_controller.rb', line 89
def typeahead
  search_params = params_for_backend_search
  search_params = search_params.merge(search_filter_for(params[:uri]))
  search_params = search_params.merge("sort" => "typeahead_sort_key_u_sort asc")
  render :json => Search.all(session[:repo_id], search_params)
end
     | 
  
 
    
      
  
  
    - (Object) update 
  
  
  
  
    
      
51
52
53
54
55
56
57
58
59
60
61
62 
     | 
    
      # File 'frontend/app/controllers/top_containers_controller.rb', line 51
def update
  handle_crud(:instance => :top_container,
              :model => JSONModel(:top_container),
              :obj => JSONModel(:top_container).find(params[:id], find_opts),
              :on_invalid => ->(){
                return render action: "edit"
              },
              :on_valid => ->(id){
                flash[:success] = I18n.t("top_container._frontend.messages.updated")
                redirect_to :controller => :top_containers, :action => :show, :id => id
              })
end
     | 
  
 
    
      
  
  
    - (Object) update_barcodes 
  
  
  
  
    
      
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167 
     | 
    
      # File 'frontend/app/controllers/top_containers_controller.rb', line 152
def update_barcodes
  update_uris = params[:update_uris]
  barcode_data = {}
  update_uris.map{|uri| barcode_data[uri] = params[uri].blank? ? nil : params[uri]}
  post_uri = "#{JSONModel::HTTP.backend_url}/repositories/#{session[:repo_id]}/top_containers/bulk/barcodes"
  response = JSONModel::HTTP::post_json(URI(post_uri), barcode_data.to_json)
  result = ASUtils.json_parse(response.body)
  if response.code =~ /^4/
    return render_aspace_partial :partial => 'top_containers/bulk_operations/error_messages', :locals => {:exceptions => result, :jsonmodel => "top_container"}, :status => 500
  end
  render_aspace_partial :partial => "top_containers/bulk_operations/bulk_action_success", :locals => {:result => result}
end
     |