X-Git-Url: https://git.openstreetmap.org./rails.git/blobdiff_plain/2403630da87df8a3b57913e8949ae0ff8f611d22..dfc843e7af602350cb240c17b98319f9fa00d08a:/app/controllers/preferences_controller.rb?ds=sidebyside diff --git a/app/controllers/preferences_controller.rb b/app/controllers/preferences_controller.rb index 6839bf37a..910f6a24f 100644 --- a/app/controllers/preferences_controller.rb +++ b/app/controllers/preferences_controller.rb @@ -11,8 +11,6 @@ class PreferencesController < ApplicationController def show; end - def edit; end - def update current_user.languages = params[:user][:languages].split(",") @@ -21,12 +19,26 @@ class PreferencesController < ApplicationController else params[:user][:preferred_editor] end - if current_user.save - flash[:notice] = t ".success" + + success = current_user.save + + if params[:site_color_scheme] + site_color_scheme_preference = current_user.preferences.find_or_create_by(:k => "site.color_scheme") + success &= site_color_scheme_preference.update(:v => params[:site_color_scheme]) + end + + if params[:map_color_scheme] + map_color_scheme_preference = current_user.preferences.find_or_create_by(:k => "map.color_scheme") + success &= map_color_scheme_preference.update(:v => params[:map_color_scheme]) + end + + if success + # Use a partial so that it is rendered during the next page load in the correct language. + flash[:notice] = { :partial => "preferences/update_success_flash" } redirect_to preferences_path else - flash[:error] = t ".failure" - render :edit + flash.now[:error] = t ".failure" + render :show end end end