Class: PreferencesController
Instance Method Summary
collapse
#archivesspace, can_access?, permission_mappings, session_can?, session_repo, set_access_control, user_preferences
Instance Method Details
#edit ⇒ Object
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
# File 'frontend/app/controllers/preferences_controller.rb', line 5
def edit
opts, user_scope = setup_defaults
repos = JSONModel::HTTP.get_json("/repositories")
if repos.empty?
flash[:error] = I18n.t("preference._frontend.messages.no_access_to_preferences")
redirect_to(:controller => :welcome, :action => :index)
return
end
if @current_prefs[user_scope]
pref = JSONModel(:preference).from_hash(@current_prefs[user_scope])
else
pref = JSONModel(:preference).new({
:defaults => {},
:user_id => params['repo'] ? nil : JSONModel(:user).id_for(session[:user_uri])
})
pref.save(opts)
end
if params['id'] == pref.id.to_s
@preference = pref
else
redirect_to(:controller => :preferences,
:action => :edit,
:id => pref.id,
:global => params['global'],
:repo => params['repo'])
end
end
|
#reset ⇒ Object
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
|
# File 'frontend/app/controllers/preferences_controller.rb', line 65
def reset
redirect_params = {
:controller => :preferences,
:action => :edit,
:id => 0,
:global => params['global'],
:repo => params['repo']
}
begin
_, global_repo_id = current_preferences
opts = {}
opts[:repo_id] = global_repo_id if params['global']
preference = JSONModel(:preference).find(params[:id], opts)
preference.update({:defaults => {}})
preference.save(opts)
flash[:success] = t("preference._frontend.messages.reset")
redirect_to(redirect_params)
rescue Exception => e
flash[:error] = t("preference._frontend.messages.reset_error", :exception => e)
redirect_to(redirect_params)
return
end
end
|
#update ⇒ Object
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
# File 'frontend/app/controllers/preferences_controller.rb', line 38
def update
prefs, global_repo_id = current_preferences
opts = {}
opts[:repo_id] = global_repo_id if params['global']
handle_crud(:instance => :preference,
:model => JSONModel(:preference),
:obj => JSONModel(:preference).find(params['id'], opts),
:find_opts => opts,
:save_opts => opts,
:replace => false,
:on_invalid => ->() {
setup_defaults
return render action: "edit"
},
:on_valid => ->(id) {
flash[:success] = t("preference._frontend.messages.updated",
**JSONModelI18nWrapper.new(:preference => @preference))
redirect_to(:controller => :preferences,
:action => :edit,
:id => id,
:global => params['global'],
:repo => params['repo'])
})
end
|