2017-01-12 19:46:24 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-04-10 20:27:03 +01:00
|
|
|
module Admin
|
|
|
|
class SettingsController < BaseController
|
2017-04-20 16:18:09 +01:00
|
|
|
BOOLEAN_SETTINGS = %w(open_registrations).freeze
|
|
|
|
|
2017-04-10 20:27:03 +01:00
|
|
|
def index
|
|
|
|
@settings = Setting.all_as_records
|
|
|
|
end
|
2017-01-12 19:46:24 +00:00
|
|
|
|
2017-04-10 20:27:03 +01:00
|
|
|
def update
|
|
|
|
@setting = Setting.where(var: params[:id]).first_or_initialize(var: params[:id])
|
2017-04-20 16:18:09 +01:00
|
|
|
@setting.update(value: value_for_update)
|
2017-04-04 14:26:57 +01:00
|
|
|
|
2017-04-10 20:27:03 +01:00
|
|
|
respond_to do |format|
|
|
|
|
format.html { redirect_to admin_settings_path }
|
|
|
|
format.json { respond_with_bip(@setting) }
|
|
|
|
end
|
2017-01-12 19:46:24 +00:00
|
|
|
end
|
|
|
|
|
2017-04-10 20:27:03 +01:00
|
|
|
private
|
2017-04-04 14:26:57 +01:00
|
|
|
|
2017-04-10 20:27:03 +01:00
|
|
|
def settings_params
|
|
|
|
params.require(:setting).permit(:value)
|
|
|
|
end
|
2017-04-20 16:18:09 +01:00
|
|
|
|
|
|
|
def value_for_update
|
|
|
|
if updating_boolean_setting?
|
|
|
|
settings_params[:value] == 'true'
|
|
|
|
else
|
|
|
|
settings_params[:value]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def updating_boolean_setting?
|
|
|
|
BOOLEAN_SETTINGS.include?(params[:id])
|
|
|
|
end
|
2017-04-04 14:26:57 +01:00
|
|
|
end
|
2017-01-12 19:46:24 +00:00
|
|
|
end
|