Orbit/app/controllers/admin/pages_controller.rb

197 lines
5.6 KiB
Ruby

class Admin::PagesController < Admin::ItemsController
helper Admin::PagePartsHelper
def show
@item = Page.find(params[:id])
respond_to do |format|
format.html {
render 'admin/items/index'
}
format.js {}
end
end
def new
@item = Page.new
@item.parent = Item.find(params[:parent_id]) rescue nil
@apps = ModuleApp.excludes(app_pages: nil).entries
@designs = Design.all.entries
@design = Design.first
end
def edit
@item =Page.find(params[:id])
@user_choose = @item.app_frontend_url
@apps = ModuleApp.excludes(app_pages: nil).entries
@module_apps = ModuleApp.excludes(widgets: nil).where(enable_frontend: true).order_by(:title, :asc)
@designs = Design.all.entries
@design = @item.design ? @item.design : @designs.first
if @item.module_app
@app_frontend_urls = @item.module_app.app_pages.map{|t| [I18n.t(t[0]),t[1]]}
@app_frontend_urls << [I18n.t('default_widget.name'),'default_widget'] if @item.module_app.has_default_widget?
end
if @item.module_app
@module_app = @item.module_app
@frontend_path = @item.app_frontend_url
if @module_app && @module_app.widgets && @module_app.widgets.any?{|b| b.class == Array}
@frontend_style = @module_app.widgets[@frontend_path] if !@frontend_path.blank? && !@module_app.widgets.blank?
end
case @item.module_app.key
when 'announcement'
@categories = BulletinCategory.all
@tags = AnnouncementTag.all
when 'news'
@categories = NewsBulletinCategory.all
@tags = NewsTag.all
when 'web_resource'
@categories = WebLinkCategory.all
@tags = WebResourceTag.all
when 'archive'
@categories = ArchiveFileCategory.all
@tags = ArchiveTag.all
end
else
@categories = nil
@module_app = @module_apps[0]
end
end
def create
@item = Page.new(params[:page])
if @item.module_app && @item.module_app.key == 'page_content'
@item.page_contexts.build(:create_user_id => current_user.id, :update_user_id => current_user.id )
end
if @item.save
flash.now[:notice] = t('create.success.page')
respond_to do |format|
format.html {
redirect_to admin_page_url(@item)
}
format.js {}
end
else
flash.now[:error] = t('create.error.page')
@apps = ModuleApp.all
@designs = Design.all.entries
@design = Design.first
render :action => "new"
end
end
def update
@item = Page.find(params[:id])
if @item.module_app && @item.module_app.key == 'page_content' && @item.page_contexts.blank?
@item.page_contexts.build(:create_user_id => current_user.id, :update_user_id => current_user.id )
end
params[:page][:frontend_field] = params[:page][:frontend_field].zip( params[:page][:frontend_field_type], params[:page][:frontend_field_is_link] ) if params[:page][:frontend_field]
params[:page][:frontend_field_type] = nil
params[:page][:frontend_field_is_link] = nil
if params[:page][:tag] && params[:page][:tag].include?("nil")
params[:page][:tag] = []
end
if params[:page][:category] && params[:page][:category].include?("nil")
params[:page][:category] = []
end
params[:page][:frontend_field].each{|t| t[2] = (t[2]=="true" ? true : false )} if !params[:page][:frontend_field].blank?
if @item.update_attributes(params[:page])
flash[:notice] = t('update.success.page')
respond_to do |format|
format.html {
redirect_to admin_page_url(@item)
}
format.js {}
end
else
render :action => "edit"
end
end
def destroy
@item = Page.find(params[:id])
@item.destroy
respond_to do |format|
format.html {
redirect_to admin_items_url( :parent_id => @item.parent_id )
}
format.js { redirect_to admin_items_url }
end
end
def delete
@item = Page.find(params[:id])
@item.destroy
respond_to do |format|
format.html {}
format.js { @item = @item.parent }
end
end
def reload_front_end_setting
@item = Page.find params[:id]
@module_app = ModuleApp.find params[:module_app_id]
@chosen_frontend = @user_choose = params[:frontend]
end
def reload_frontend_pages
@item = Page.find params[:id] rescue nil
# @categories =[]
@module_app = ModuleApp.find(params[:module_app_id]) rescue nil
@app_frontend_urls = @module_app.nil? ? nil : @module_app.app_pages.map{|t| [I18n.t(t[0]),t[1]]}
@app_frontend_urls << [I18n.t('default_widget.name'),'default_widget'] if(@module_app && @module_app.has_default_widget?)
case (@module_app.nil? ? nil : @module_app.key )
when 'announcement'
@categories = BulletinCategory.all
@tags = AnnouncementTag.all
when 'news'
@categories = NewsBulletinCategory.all
@tags = NewsTag.all
when 'web_resource'
@categories = WebLinkCategory.all
@tags = WebResourceTag.all
when 'archive'
@categories = ArchiveFileCategory.all
@tags = ArchiveTag.all
else
@categories = []
@tags = []
end
respond_to do |format|
format.js {}
end
end
def reload_themes
@design = Design.find(params[:id])
@themes = @design.themes
respond_to do |format|
format.js {}
end
end
def reload_widget_field
@index = params[:field_seri].to_i
@item = Page.find params[:id]
@choosen_field = params[:widget_field_value]
@module_app = @page.module_app
@module_app = ModuleApp.find params[:module_app_id] if @module_app.nil?
end
end