2014-09-25 11:32:08 -04:00
|
|
|
class Admin::UserFieldsController < Admin::AdminController
|
|
|
|
|
2014-10-08 14:38:18 -04:00
|
|
|
def self.columns
|
2015-01-29 17:38:39 -05:00
|
|
|
[:name, :field_type, :editable, :description, :required, :show_on_profile]
|
2014-10-08 14:38:18 -04:00
|
|
|
end
|
|
|
|
|
2014-09-25 11:32:08 -04:00
|
|
|
def create
|
2014-10-08 14:38:18 -04:00
|
|
|
field = UserField.new(params.require(:user_field).permit(*Admin::UserFieldsController.columns))
|
2014-10-14 17:21:34 -04:00
|
|
|
field.required = params[:required] == "true"
|
2014-10-02 15:56:28 -04:00
|
|
|
json_result(field, serializer: UserFieldSerializer) do
|
|
|
|
field.save
|
|
|
|
end
|
2014-09-25 11:32:08 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def index
|
|
|
|
render_serialized(UserField.all, UserFieldSerializer, root: 'user_fields')
|
|
|
|
end
|
|
|
|
|
|
|
|
def update
|
|
|
|
field_params = params.require(:user_field)
|
|
|
|
|
|
|
|
field = UserField.where(id: params.require(:id)).first
|
2014-10-08 14:38:18 -04:00
|
|
|
|
|
|
|
Admin::UserFieldsController.columns.each do |col|
|
|
|
|
field.send("#{col}=", field_params[col] || false)
|
|
|
|
end
|
2014-09-25 11:32:08 -04:00
|
|
|
|
2014-10-02 15:56:28 -04:00
|
|
|
json_result(field, serializer: UserFieldSerializer) do
|
|
|
|
field.save
|
|
|
|
end
|
2014-09-25 11:32:08 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def destroy
|
|
|
|
field = UserField.where(id: params.require(:id)).first
|
|
|
|
field.destroy if field.present?
|
|
|
|
render nothing: true
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|