Class: EventsController
Instance Method Summary
collapse
#archivesspace, can_access?, permission_mappings, set_access_control
Instance Method Details
#create ⇒ Object
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
|
# File 'frontend/app/controllers/events_controller.rb', line 77
def create
handle_crud(:instance => :event,
:model => JSONModel(:event),
:on_invalid => ->() {
if params.has_key?(:redirect_action)
@redirect_action = params[:redirect_action]
end
render :action => :new
},
:on_valid => ->(id) {
flash[:success] = t("event._frontend.messages.created")
if params.has_key?(:plus_one)
if params.has_key?(:redirect_record)
return redirect_to(
:controller => :events,
:action => :new,
:record_uri => params[:redirect_record],
:record_type => JSONModel.parse_reference(params[:redirect_record])[:type])
else
return redirect_to(:controller => :events, :action => :new)
end
end
if params.has_key?(:redirect_record) && JSONModel.parse_reference(params[:redirect_record])
if params[:redirect_action].blank?
redirect_action = :show
else
redirect_action = params[:redirect_action].intern
end
redirect_to(:controller => :resolver,
:action => (redirect_action == :edit) ? :resolve_edit : :resolve_readonly,
:uri => params[:redirect_record])
else
redirect_to :controller => :events, :action => :edit, :id => id
end
})
end
|
#current_record ⇒ Object
32
33
34
|
# File 'frontend/app/controllers/events_controller.rb', line 32
def current_record
@event
end
|
#defaults ⇒ Object
148
149
150
151
152
153
154
155
156
|
# File 'frontend/app/controllers/events_controller.rb', line 148
def defaults
defaults = DefaultValues.get 'event'
values = defaults ? defaults.form_values : {}
@event = JSONModel(:event).new(values)._always_valid!
render "defaults"
end
|
#delete ⇒ Object
140
141
142
143
144
145
|
# File 'frontend/app/controllers/events_controller.rb', line 140
def delete
event = JSONModel(:event).find(params[:id])
event.delete
flash[:success] = t("event._frontend.messages.deleted")
redirect_to(:controller => :events, :action => :index, :deleted_uri => event.uri)
end
|
#edit ⇒ Object
69
70
71
72
73
74
75
|
# File 'frontend/app/controllers/events_controller.rb', line 69
def edit
@event = JSONModel(:event).find(params[:id], find_opts)
if @event.suppressed
redirect_to(:controller => :events, :action => :show, :id => params[:id])
end
end
|
#index ⇒ Object
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
# File 'frontend/app/controllers/events_controller.rb', line 11
def index
respond_to do |format|
format.html {
@search_data = Search.for_type(session[:repo_id], "event", params_for_backend_search.merge({"facet[]" => SearchResultData.EVENT_FACETS}))
}
format.csv {
search_params = params_for_backend_search.merge({"facet[]" => SearchResultData.EVENT_FACETS})
search_params["type[]"] = "event"
if search_params["fields[]"].include?("linked_records")
search_params["fields[]"].delete("linked_records")
search_params["fields[]"].push("linked_record_titles")
end
uri = "/repositories/#{session[:repo_id]}/search"
csv_response( uri, Search.build_filters(search_params), "#{t('event._plural').downcase}." )
}
end
end
|
#new ⇒ Object
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
# File 'frontend/app/controllers/events_controller.rb', line 42
def new
@event = JSONModel(:event).new._always_valid!
@event.linked_agents = [{}]
@event.linked_records = [{}]
if user_prefs['default_values']
defaults = DefaultValues.get 'event'
@event.update(defaults.values) if defaults
end
if params.has_key?(:event_type)
@event.event_type = params[:event_type]
end
if params.has_key?(:record_uri)
record = JSONModel(params[:record_type]).find_by_uri(params[:record_uri])
@event.linked_records = []
@event.linked_records << {'ref' => record.uri, '_resolved' => record.to_hash, 'role' => 'source'}
if request.referrer.end_with?("/edit")
@redirect_action = 'edit'
end
end
end
|
#show ⇒ Object
36
37
38
39
40
|
# File 'frontend/app/controllers/events_controller.rb', line 36
def show
@event = JSONModel(:event).find(params[:id], find_opts)
flash.now[:info] = t("event._frontend.messages.suppressed_info") if @event.suppressed
end
|
#update ⇒ Object
128
129
130
131
132
133
134
135
136
137
|
# File 'frontend/app/controllers/events_controller.rb', line 128
def update
handle_crud(:instance => :event,
:model => JSONModel(:event),
:obj => JSONModel(:event).find(params[:id]),
:on_invalid => ->() { render :action => :edit },
:on_valid => ->(id) {
flash[:success] = t("event._frontend.messages.updated")
redirect_to :controller => :events, :action => :edit, :id => id
})
end
|
#update_defaults ⇒ Object
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
|
# File 'frontend/app/controllers/events_controller.rb', line 158
def update_defaults
begin
DefaultValues.from_hash({
"record_type" => "event",
"lock_version" => params[:event].delete('lock_version'),
"defaults" => cleanup_params_for_schema(
params[:event],
JSONModel(:event).schema)
}).save
flash[:success] = t("default_values.messages.defaults_updated")
redirect_to :controller => :events, :action => :defaults
rescue Exception => e
flash[:error] = e.message
redirect_to :controller => :events, :action => :defaults
end
end
|