pagecontent/app/controllers/admin/wiki_pages_controller.rb

64 lines
1.7 KiB
Ruby
Raw Normal View History

2016-08-24 13:28:22 +00:00
class Admin::WikiPagesController < OrbitAdminController
before_action ->(module_app = @app_title) { set_variables module_app }
def initialize
super
@app_title = "page_content"
end
def index
@table_fields = [:title, :created_at, "page_content.parent_page", :last_modified]
@filter_fields = {}
@page = Page.find(params[:page_id]) rescue nil
if !@page.nil?
@wikis = @page.wiki_pages.order_by(sort)
@wikis = search_data(@wikis,[:name, :page_id]).page(params[:page]).per(10)
else
@wikis = WikiPage.all.order_by(sort)
@wikis = search_data(@wikis,[:title]).page(params[:page]).per(10)
end
render :partial => "index" if request.xhr?
end
def create_on_the_go
wiki = WikiPage.create(wiki_page_params)
render :json => {"title" => wiki.title_translations, "id" => wiki.id.to_s}.to_json
end
def new
@page = Page.find(params[:page_id]) rescue nil
@wiki = WikiPage.new
@options = {}
@site_in_use_locales.each do |l|
@options[l.to_s] = @page.wiki_pages.collect{|wp|[wp.title_translations[l], wp.uid]}
end
end
def edit
@page = Page.find(params[:page_id]) rescue nil
@wiki = WikiPage.find(params[:id])
@options = {}
@site_in_use_locales.each do |l|
t = @page.wiki_pages.collect{|wp|[wp.title_translations[l], wp.uid] if wp.id != @wiki.id}
t.delete(nil)
@options[l.to_s] = t
end
end
def create
wiki = WikiPage.create(wiki_page_params)
redirect_to admin_wiki_pages_path(:page_id => wiki.page.id)
end
def update
wiki = WikiPage.find(params[:id])
wiki.update_attributes(wiki_page_params)
redirect_to admin_wiki_pages_path(:page_id => wiki.page.id)
end
private
def wiki_page_params
params.require(:wiki_page).permit!
end
end