Class: EventsController
Constant Summary
Constants included
from Searchable
Searchable::ABSTRACT
Instance Method Summary
collapse
#csv_response, #xml_response
#archivesspace, can_access?, permission_mappings, set_access_control
Methods included from JsonHelper
#merge_notes, #process_json_notes
Methods included from Searchable
#default_search_opts, #get_filter_years, #handle_results, #html_notes, #process_results, #process_search_results, #repo_context, #search_terms, #set_up_advanced_search, #set_up_and_run_search, #set_up_search, #strip_facet_fields
#fetch_only_facets, #get_pretty_facet_value, #strip_facets
#inheritance, #process_mixed_content, #strip_mixed_content
Instance Method Details
#create ⇒ Object
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
|
# File 'frontend/app/controllers/events_controller.rb', line 70
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] = I18n.t("event._frontend.messages.created")
return redirect_to :controller => :events, :action => :new if params.has_key?(:plus_one)
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
25
26
27
|
# File 'frontend/app/controllers/events_controller.rb', line 25
def current_record
@event
end
|
#defaults ⇒ Object
121
122
123
124
125
126
127
128
129
|
# File 'frontend/app/controllers/events_controller.rb', line 121
def defaults
defaults = DefaultValues.get 'event'
values = defaults ? defaults.form_values : {}
@event = JSONModel(:event).new(values)._always_valid!
render "defaults"
end
|
#delete ⇒ Object
112
113
114
115
116
117
118
|
# File 'frontend/app/controllers/events_controller.rb', line 112
def delete
event = JSONModel(:event).find(params[:id])
event.delete
flash[:success] = I18n.t("event._frontend.messages.deleted", JSONModelI18nWrapper.new(:event => event))
redirect_to(:controller => :events, :action => :index, :deleted_uri => event.uri)
end
|
#edit ⇒ Object
62
63
64
65
66
67
68
|
# File 'frontend/app/controllers/events_controller.rb', line 62
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
|
# 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"
uri = "/repositories/#{session[:repo_id]}/search"
csv_response( uri, Search.build_filters(search_params), "#{I18n.t('event._plural').downcase}." )
}
end
end
|
#new ⇒ Object
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
# File 'frontend/app/controllers/events_controller.rb', line 35
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)
@event.linked_records = []
record = JSONModel(params[:record_type]).find_by_uri(params[:record_uri])
@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
29
30
31
32
33
|
# File 'frontend/app/controllers/events_controller.rb', line 29
def show
@event = JSONModel(:event).find(params[:id], find_opts)
flash.now[:info] = I18n.t("event._frontend.messages.suppressed_info") if @event.suppressed
end
|
#update ⇒ Object
100
101
102
103
104
105
106
107
108
109
|
# File 'frontend/app/controllers/events_controller.rb', line 100
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] = I18n.t("event._frontend.messages.updated")
redirect_to :controller => :events, :action => :edit, :id => id
})
end
|
#update_defaults ⇒ Object
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
|
# File 'frontend/app/controllers/events_controller.rb', line 131
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] = I18n.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
|