2010-06-10 13:30:32 +00:00
|
|
|
module Admin
|
|
|
|
class ApiContentsController < ActionController::Base
|
2010-07-23 20:09:54 +00:00
|
|
|
|
2010-06-10 13:30:32 +00:00
|
|
|
include Locomotive::Routing::SiteDispatcher
|
2010-07-23 20:09:54 +00:00
|
|
|
|
2010-06-10 13:30:32 +00:00
|
|
|
before_filter :require_site
|
2010-07-23 20:09:54 +00:00
|
|
|
|
2010-06-10 13:30:32 +00:00
|
|
|
before_filter :set_content_type
|
2010-07-23 20:09:54 +00:00
|
|
|
|
2010-06-10 13:30:32 +00:00
|
|
|
def create
|
|
|
|
@content = @content_type.contents.build(params[:content])
|
|
|
|
|
|
|
|
respond_to do |format|
|
|
|
|
if @content.save
|
|
|
|
format.json { render :json => { :content => @content } }
|
2010-10-28 23:36:45 +00:00
|
|
|
format.html do
|
|
|
|
flash[@content_type.slug.singularize] = @content.aliased_attributes
|
|
|
|
redirect_to params[:success_callback]
|
|
|
|
end
|
2010-06-10 13:30:32 +00:00
|
|
|
else
|
|
|
|
format.json { render :json => { :content => @content, :errors => @content.errors } }
|
2010-10-28 23:36:45 +00:00
|
|
|
format.html do
|
|
|
|
flash[@content_type.slug.singularize] = @content.aliased_attributes
|
|
|
|
flash[:errors] = content.errors
|
|
|
|
redirect_to params[:error_callback]
|
|
|
|
end
|
2010-06-10 13:30:32 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2010-07-23 20:09:54 +00:00
|
|
|
|
2010-06-10 13:30:32 +00:00
|
|
|
protected
|
2010-07-23 20:09:54 +00:00
|
|
|
|
2010-06-10 13:30:32 +00:00
|
|
|
def set_content_type
|
2010-07-23 20:09:54 +00:00
|
|
|
@content_type = current_site.content_types.where(:slug => params[:slug]).first
|
2010-10-29 14:19:41 +00:00
|
|
|
render :json => { :error => 'Api not enabled' } and return false unless @content_type.api_enabled
|
2010-06-10 13:30:32 +00:00
|
|
|
end
|
2010-07-23 20:09:54 +00:00
|
|
|
|
2010-06-10 13:30:32 +00:00
|
|
|
end
|
2010-07-23 20:09:54 +00:00
|
|
|
end
|