2010-05-10 22:39:52 +00:00
|
|
|
module Admin
|
|
|
|
class PagesController < BaseController
|
2010-04-24 00:32:36 +00:00
|
|
|
|
2010-05-10 22:39:52 +00:00
|
|
|
sections 'contents'
|
2010-04-24 00:32:36 +00:00
|
|
|
|
2010-05-10 22:39:52 +00:00
|
|
|
def index
|
|
|
|
@pages = current_site.pages.roots
|
|
|
|
end
|
2010-04-25 00:33:38 +00:00
|
|
|
|
2010-05-10 22:39:52 +00:00
|
|
|
def new
|
|
|
|
@page = current_site.pages.build
|
|
|
|
@page.parts << PagePart.build_body_part
|
|
|
|
end
|
2010-04-25 00:33:38 +00:00
|
|
|
|
2010-05-10 22:39:52 +00:00
|
|
|
def edit
|
|
|
|
@page = current_site.pages.find(params[:id])
|
|
|
|
end
|
2010-04-25 00:33:38 +00:00
|
|
|
|
2010-05-10 22:39:52 +00:00
|
|
|
def create
|
|
|
|
@page = current_site.pages.build(params[:page])
|
2010-04-25 00:33:38 +00:00
|
|
|
|
2010-05-10 22:39:52 +00:00
|
|
|
if @page.save
|
|
|
|
flash_success!
|
|
|
|
redirect_to edit_admin_page_url(@page)
|
|
|
|
else
|
|
|
|
flash_error!
|
|
|
|
render :action => 'new'
|
|
|
|
end
|
2010-04-25 00:33:38 +00:00
|
|
|
end
|
|
|
|
|
2010-05-10 22:39:52 +00:00
|
|
|
def update
|
|
|
|
@page = current_site.pages.find(params[:id])
|
2010-04-25 00:33:38 +00:00
|
|
|
|
2010-05-10 22:39:52 +00:00
|
|
|
if @page.update_attributes(params[:page])
|
|
|
|
flash_success!
|
|
|
|
redirect_to edit_admin_page_url(@page)
|
|
|
|
else
|
|
|
|
flash_error!
|
|
|
|
render :action => "edit"
|
|
|
|
end
|
2010-04-25 00:33:38 +00:00
|
|
|
end
|
|
|
|
|
2010-05-10 22:39:52 +00:00
|
|
|
def sort
|
|
|
|
@page = current_site.pages.find(params[:id])
|
|
|
|
@page.sort_children!(params[:children])
|
2010-05-02 23:33:17 +00:00
|
|
|
|
2010-05-10 22:39:52 +00:00
|
|
|
render :json => { :message => translate_flash_msg(:successful) }
|
|
|
|
end
|
2010-05-02 23:33:17 +00:00
|
|
|
|
2010-05-10 22:39:52 +00:00
|
|
|
def get_path
|
|
|
|
page = current_site.pages.build(:parent => current_site.pages.find(params[:parent_id]), :slug => params[:slug].slugify)
|
2010-05-02 23:33:17 +00:00
|
|
|
|
2010-05-10 22:39:52 +00:00
|
|
|
render :json => { :url => page.url, :slug => page.slug }
|
|
|
|
end
|
2010-05-02 23:33:17 +00:00
|
|
|
|
2010-05-10 22:39:52 +00:00
|
|
|
def destroy
|
|
|
|
@page = current_site.pages.find(params[:id])
|
2010-04-25 00:33:38 +00:00
|
|
|
|
2010-05-10 22:39:52 +00:00
|
|
|
begin
|
|
|
|
@page.destroy
|
|
|
|
flash_success!
|
|
|
|
rescue Exception => e
|
|
|
|
flash[:error] = e.to_s
|
|
|
|
end
|
2010-04-25 00:33:38 +00:00
|
|
|
|
2010-05-10 22:39:52 +00:00
|
|
|
redirect_to admin_pages_url
|
|
|
|
end
|
2010-04-24 00:32:36 +00:00
|
|
|
|
2010-05-10 22:39:52 +00:00
|
|
|
end
|
2010-04-24 00:32:36 +00:00
|
|
|
end
|