2011-10-30 23:02:41 +00:00
|
|
|
module Locomotive
|
2012-01-02 13:54:01 +00:00
|
|
|
class ContentEntriesController < 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
|
|
|
|
2012-01-26 15:51:32 +00:00
|
|
|
before_filter :back_to_default_site_locale, :only => %w(new create)
|
|
|
|
|
2010-07-13 00:46:17 +00:00
|
|
|
before_filter :set_content_type
|
2010-07-23 20:09:54 +00:00
|
|
|
|
2012-01-02 13:54:01 +00:00
|
|
|
respond_to :json, :only => [:edit, :create, :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
|
|
|
|
2010-05-24 00:18:23 +00:00
|
|
|
def index
|
2012-01-04 01:07:53 +00:00
|
|
|
@content_entries = @content_type.list_or_group_entries
|
2011-12-22 23:45:32 +00:00
|
|
|
respond_with @content_entries
|
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
|
2011-12-22 23:45:32 +00:00
|
|
|
@content_entry = @content_type.entries.build
|
2012-01-02 13:54:01 +00:00
|
|
|
respond_with @content_entry
|
2011-08-11 20:45:46 +00:00
|
|
|
end
|
|
|
|
|
2010-05-24 00:18:23 +00:00
|
|
|
def create
|
2011-12-22 23:45:32 +00:00
|
|
|
@content_entry = @content_type.entries.create(params[:content_entry])
|
2012-01-02 13:54:01 +00:00
|
|
|
respond_with @content_entry, :location => edit_content_entry_url(@content_type.slug, @content_entry._id)
|
2011-08-11 20:45:46 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def edit
|
2011-12-22 23:45:32 +00:00
|
|
|
@content_entry = @content_type.entries.find(params[:id])
|
2012-01-02 13:54:01 +00:00
|
|
|
respond_with @content_entry
|
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-12-22 23:45:32 +00:00
|
|
|
@content_entry = @content_type.entries.find(params[:id])
|
|
|
|
@content_entry.update_attributes(params[:content_entry])
|
2012-01-02 13:54:01 +00:00
|
|
|
respond_with @content_entry, :location => edit_content_entry_url(@content_type.slug, @content_entry._id)
|
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
|
2012-01-04 01:07:53 +00:00
|
|
|
@content_type.klass_with_custom_fields(:entries).sort_entries!(params[:entries])
|
2011-12-22 22:28:12 +00:00
|
|
|
respond_with @content_type
|
2010-07-23 20:09:54 +00:00
|
|
|
end
|
|
|
|
|
2010-05-24 00:18:23 +00:00
|
|
|
def destroy
|
2011-12-22 23:45:32 +00:00
|
|
|
@content_entry = @content_type.entries.find(params[:id])
|
|
|
|
@content_entry.destroy
|
2012-01-04 01:07:53 +00:00
|
|
|
respond_with @content_entry, :location => content_entries_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
|
|
|
|
2011-06-26 00:01:11 +00:00
|
|
|
def authorize_content
|
2011-12-22 23:45:32 +00:00
|
|
|
authorize! params[:action].to_sym, ContentEntry
|
2011-06-26 00:01:11 +00:00
|
|
|
end
|
|
|
|
|
2010-05-24 00:18:23 +00:00
|
|
|
end
|
2010-07-23 20:09:54 +00:00
|
|
|
end
|