2010-05-24 00:18:23 +00:00
|
|
|
module Admin
|
|
|
|
class ContentsController < BaseController
|
|
|
|
|
|
|
|
sections 'contents'
|
|
|
|
|
|
|
|
before_filter :set_content_type
|
|
|
|
|
|
|
|
def index
|
2010-05-26 00:41:10 +00:00
|
|
|
@contents = @content_type.ordered_contents
|
2010-05-24 00:18:23 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def new
|
|
|
|
@content = @content_type.contents.build
|
|
|
|
end
|
|
|
|
|
|
|
|
def edit
|
|
|
|
@content = @content_type.contents.find(params[:id])
|
|
|
|
end
|
|
|
|
|
|
|
|
def create
|
2010-05-25 00:32:12 +00:00
|
|
|
@content = @content_type.contents.build(params[:content_instance])
|
2010-05-24 00:18:23 +00:00
|
|
|
|
|
|
|
if @content.save
|
|
|
|
flash_success!
|
|
|
|
redirect_to edit_admin_content_url(@content_type.slug, @content)
|
|
|
|
else
|
|
|
|
flash_error!
|
|
|
|
render :action => 'new'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def update
|
|
|
|
@content = @content_type.contents.find(params[:id])
|
|
|
|
|
2010-05-25 00:32:12 +00:00
|
|
|
if @content.update_attributes(params[:content_instance])
|
2010-05-24 00:18:23 +00:00
|
|
|
flash_success!
|
|
|
|
redirect_to edit_admin_content_url(@content_type.slug, @content)
|
|
|
|
else
|
|
|
|
flash_error!
|
|
|
|
render :action => "edit"
|
|
|
|
end
|
|
|
|
end
|
2010-05-25 00:32:12 +00:00
|
|
|
|
|
|
|
def sort
|
2010-05-26 00:41:10 +00:00
|
|
|
@content_type.sort_contents!(params[:order])
|
2010-05-25 00:32:12 +00:00
|
|
|
|
2010-05-26 00:41:10 +00:00
|
|
|
flash_success!
|
|
|
|
|
|
|
|
redirect_to admin_contents_url(@content_type.slug)
|
2010-05-25 00:32:12 +00:00
|
|
|
end
|
2010-05-24 00:18:23 +00:00
|
|
|
|
|
|
|
def destroy
|
|
|
|
@content = @content_type.contents.find(params[:id])
|
|
|
|
|
|
|
|
begin
|
|
|
|
@content.destroy
|
|
|
|
flash_success!
|
|
|
|
rescue Exception => e
|
|
|
|
flash[:error] = e.to_s
|
|
|
|
end
|
|
|
|
|
|
|
|
redirect_to admin_contents_url(@content_type.slug)
|
|
|
|
end
|
|
|
|
|
|
|
|
protected
|
|
|
|
|
|
|
|
def set_content_type
|
|
|
|
@content_type = current_site.content_types.where(:slug => params[:slug]).first
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|