2010-05-24 00:18:23 +00:00
|
|
|
module Admin
|
|
|
|
class ContentsController < BaseController
|
2010-07-23 20:09:54 +00:00
|
|
|
|
2010-05-24 00:18:23 +00:00
|
|
|
sections 'contents'
|
2010-07-23 20:09:54 +00:00
|
|
|
|
2010-07-13 00:46:17 +00:00
|
|
|
before_filter :set_content_type
|
2010-07-23 20:09:54 +00:00
|
|
|
|
2011-06-26 00:01:11 +00:00
|
|
|
respond_to :json, :only => [:update, :sort]
|
2010-07-23 20:09:54 +00:00
|
|
|
|
2011-06-26 00:01:11 +00:00
|
|
|
skip_load_and_authorize_resource
|
|
|
|
|
|
|
|
before_filter :authorize_content
|
2011-06-25 16:25:31 +00:00
|
|
|
|
2011-08-11 20:45:46 +00:00
|
|
|
helper_method :breadcrumb_root, :breadcrumb_url, :back_url
|
|
|
|
|
2010-05-24 00:18:23 +00:00
|
|
|
def index
|
2010-06-16 14:43:29 +00:00
|
|
|
@contents = @content_type.list_or_group_contents
|
2010-05-24 00:18:23 +00:00
|
|
|
end
|
2010-07-23 20:09:54 +00:00
|
|
|
|
2011-08-11 20:45:46 +00:00
|
|
|
def new
|
|
|
|
new! { @content.attributes = params[:content] }
|
|
|
|
end
|
|
|
|
|
2010-05-24 00:18:23 +00:00
|
|
|
def create
|
2011-08-11 20:45:46 +00:00
|
|
|
create! { after_create_or_update_url }
|
|
|
|
end
|
|
|
|
|
|
|
|
def edit
|
|
|
|
edit! { @content.attributes = params[:content] }
|
2010-05-24 00:18:23 +00:00
|
|
|
end
|
2010-07-23 20:09:54 +00:00
|
|
|
|
2010-07-13 00:46:17 +00:00
|
|
|
def update
|
2011-08-11 20:45:46 +00:00
|
|
|
update! { after_create_or_update_url }
|
2010-05-24 00:18:23 +00:00
|
|
|
end
|
2010-07-23 20:09:54 +00:00
|
|
|
|
2010-05-25 00:32:12 +00:00
|
|
|
def sort
|
2011-06-26 00:01:11 +00:00
|
|
|
@content_type.sort_contents!(params[:children])
|
2010-07-23 20:09:54 +00:00
|
|
|
|
2010-07-13 00:46:17 +00:00
|
|
|
respond_with(@content_type, :location => admin_contents_url(@content_type.slug))
|
2010-07-23 20:09:54 +00:00
|
|
|
end
|
|
|
|
|
2010-05-24 00:18:23 +00:00
|
|
|
def destroy
|
2010-07-13 00:46:17 +00:00
|
|
|
destroy! { admin_contents_url(@content_type.slug) }
|
2010-05-24 00:18:23 +00:00
|
|
|
end
|
2010-07-23 20:09:54 +00:00
|
|
|
|
2010-05-24 00:18:23 +00:00
|
|
|
protected
|
2010-07-23 20:09:54 +00:00
|
|
|
|
2010-05-24 00:18:23 +00:00
|
|
|
def set_content_type
|
2010-07-13 00:46:17 +00:00
|
|
|
@content_type ||= current_site.content_types.where(:slug => params[:slug]).first
|
2010-05-24 00:18:23 +00:00
|
|
|
end
|
2010-07-23 20:09:54 +00:00
|
|
|
|
2010-07-13 00:46:17 +00:00
|
|
|
def begin_of_association_chain
|
|
|
|
set_content_type
|
2010-07-23 20:09:54 +00:00
|
|
|
end
|
|
|
|
|
2011-08-11 20:45:46 +00:00
|
|
|
def after_create_or_update_url
|
|
|
|
if params[:breadcrumb_alias].blank?
|
|
|
|
edit_admin_content_url(@content_type.slug, @content.id)
|
|
|
|
else
|
|
|
|
self.breadcrumb_url
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-06-26 00:01:11 +00:00
|
|
|
def authorize_content
|
|
|
|
authorize! params[:action].to_sym, ContentInstance
|
|
|
|
end
|
|
|
|
|
2011-08-11 20:45:46 +00:00
|
|
|
def breadcrumb_root
|
|
|
|
return nil if params[:breadcrumb_alias].blank?
|
|
|
|
|
|
|
|
@breadcrumb_root ||= resource.send(params[:breadcrumb_alias].to_sym)
|
|
|
|
end
|
|
|
|
|
|
|
|
def breadcrumb_url
|
|
|
|
edit_admin_content_url(self.breadcrumb_root._parent.slug, self.breadcrumb_root)
|
|
|
|
end
|
|
|
|
|
|
|
|
def back_url
|
|
|
|
self.breadcrumb_root ? self.breadcrumb_url : admin_contents_url(@content_type.slug)
|
|
|
|
end
|
|
|
|
|
2010-05-24 00:18:23 +00:00
|
|
|
end
|
2010-07-23 20:09:54 +00:00
|
|
|
end
|