Class: PreferencesController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- PreferencesController
- Defined in:
- frontend/app/controllers/preferences_controller.rb
Instance Method Summary collapse
Methods inherited from ApplicationController
#archivesspace, can_access?, permission_mappings, set_access_control
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 |
# File 'frontend/app/controllers/preferences_controller.rb', line 5 def edit opts, user_scope = setup_defaults 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
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'frontend/app/controllers/preferences_controller.rb', line 57 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
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'frontend/app/controllers/preferences_controller.rb', line 30 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 |