Class: ContainerProfilesController

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

Instance Method Summary collapse

Methods inherited from ApplicationController

#archivesspace, can_access?, permission_mappings, set_access_control

Instance Method Details

#createObject



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'frontend/app/controllers/container_profiles_controller.rb', line 43

def create
  handle_crud(:instance => :container_profile,
              :model => JSONModel(:container_profile),
              :on_invalid => ->() {
                return render_aspace_partial :partial => "container_profiles/new" if inline?
                return render :action => :new
              },
              :on_valid => ->(id) {
                if inline?
                  @container_profile.refetch
                  render :json => @container_profile.to_hash if inline?
                else
                  flash[:success] = t("container_profile._frontend.messages.created")
                  return redirect_to :controller => :container_profiles, :action => :new if params.has_key?(:plus_one)
                  redirect_to(:controller => :container_profiles, :action => :show, :id => id)
                end
              })
end

#current_recordObject



29
30
31
# File 'frontend/app/controllers/container_profiles_controller.rb', line 29

def current_record
  @container_profile
end

#deleteObject



77
78
79
80
81
82
# File 'frontend/app/controllers/container_profiles_controller.rb', line 77

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

  redirect_to(:controller => :container_profiles, :action => :index, :deleted_uri => container_profile.uri)
end

#editObject



38
39
40
# File 'frontend/app/controllers/container_profiles_controller.rb', line 38

def edit
  @container_profile = JSONModel(:container_profile).find(params[:id])
end

#indexObject



15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'frontend/app/controllers/container_profiles_controller.rb', line 15

def index
  respond_to do |format|
    format.html {
      @search_data = Search.for_type(session[:repo_id], "container_profile", params_for_backend_search.merge({"facet[]" => SearchResultData.CONTAINER_PROFILE_FACETS}))
    }
    format.csv {
      search_params = params_for_backend_search.merge({"facet[]" => SearchResultData.CONTAINER_PROFILE_FACETS})
      search_params["type[]"] = "container_profile"
      uri = "/repositories/#{session[:repo_id]}/search"
      csv_response( uri, Search.build_filters(search_params), "#{t('container_profile._plural').downcase}." )
    }
  end
end

#newObject



8
9
10
11
12
# File 'frontend/app/controllers/container_profiles_controller.rb', line 8

def new
  @container_profile = JSONModel(:container_profile).new._always_valid!

  render_aspace_partial :partial => "container_profiles/new" if inline?
end

#showObject



33
34
35
# File 'frontend/app/controllers/container_profiles_controller.rb', line 33

def show
  @container_profile = JSONModel(:container_profile).find(params[:id])
end

#typeaheadObject



85
86
87
88
89
90
91
# File 'frontend/app/controllers/container_profiles_controller.rb', line 85

def typeahead
  search_params = params_for_backend_search

  search_params = search_params.merge("sort" => "typeahead_sort_key_u_sort asc")

  render :json => Search.all(session[:repo_id], search_params)
end

#updateObject



63
64
65
66
67
68
69
70
71
72
73
74
# File 'frontend/app/controllers/container_profiles_controller.rb', line 63

def update
  handle_crud(:instance => :container_profile,
              :model => JSONModel(:container_profile),
              :obj => JSONModel(:container_profile).find(params[:id]),
              :replace => true,
              :on_invalid => ->() {
                return render :action => :edit
              },
              :on_valid => ->(id) {
                redirect_to(:controller => :container_profiles, :action => :show, :id => id)
              })
end