Add fixed_category_positions site setting to handle whether categories are ordered by specified positions or by activity.

This commit is contained in:
Neil Lalonde
2014-05-16 11:33:44 -04:00
parent 417fdeaad8
commit 27cbc06563
17 changed files with 91 additions and 101 deletions

View File

@ -50,19 +50,19 @@ class CategoriesController < ApplicationController
def create
guardian.ensure_can_create!(Category)
position = category_params.delete(:position)
@category = Category.create(category_params.merge(user: current_user))
return render_json_error(@category) unless @category.save
@category.move_to(category_params[:position].to_i) if category_params[:position]
@category.move_to(position.to_i) if position
render_serialized(@category, CategorySerializer)
end
def update
guardian.ensure_can_edit!(@category)
json_result(@category, serializer: CategorySerializer) { |cat|
if category_params[:position]
category_params[:position] == 'default' ? cat.use_default_position : cat.move_to(category_params[:position].to_i)
end
cat.move_to(category_params[:position].to_i) if category_params[:position]
if category_params.key? :email_in and category_params[:email_in].length == 0
# properly null the value so the database constrain doesn't catch us
category_params[:email_in] = nil