2010-06-10 13:30:32 +00:00
|
|
|
module Admin
|
|
|
|
class CustomFieldsController < BaseController
|
|
|
|
|
|
|
|
layout false
|
|
|
|
|
2010-06-22 13:04:40 +00:00
|
|
|
before_filter :set_parent_and_fields
|
2010-06-10 13:30:32 +00:00
|
|
|
|
|
|
|
def edit
|
2010-06-22 13:04:40 +00:00
|
|
|
@field = @fields.find(params[:id])
|
2010-06-10 13:30:32 +00:00
|
|
|
render :action => "edit_#{@field.kind.downcase}"
|
|
|
|
end
|
|
|
|
|
|
|
|
def update
|
2010-06-22 13:04:40 +00:00
|
|
|
@field = @fields.find(params[:id])
|
2010-06-10 13:30:32 +00:00
|
|
|
@field.updated_at = Time.now # forces mongoid to save the object
|
|
|
|
|
|
|
|
params[:custom_field][:category_items_attributes].delete('-1')
|
|
|
|
|
|
|
|
if @field.update_attributes(params[:custom_field])
|
|
|
|
render :json => @field.attributes
|
|
|
|
else
|
2010-07-13 00:46:17 +00:00
|
|
|
render :json => { :error => t('flash.admin.custom_fields.update.alert') }
|
2010-06-10 13:30:32 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
protected
|
|
|
|
|
2010-06-22 13:04:40 +00:00
|
|
|
def set_parent_and_fields
|
|
|
|
if params[:parent] == 'asset_collection'
|
|
|
|
@parent = current_site.asset_collections.where(:slug => params[:slug]).first
|
|
|
|
@fields = @parent.asset_custom_fields
|
|
|
|
else
|
|
|
|
@parent = current_site.content_types.where(:slug => params[:slug]).first
|
|
|
|
@fields = @parent.content_custom_fields
|
|
|
|
end
|
2010-06-10 13:30:32 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|