This repository has been archived on 2024-03-16. You can view files and clone it, but cannot push or open issues or pull requests.
orbit-4-1/app/controllers/admin/pages_controller.rb

192 lines
5.4 KiB
Ruby
Raw Normal View History

class Admin::PagesController < Admin::ItemsController
helper Admin::PagePartsHelper
def show
@item = Page.find(params[:id])
2011-05-13 01:08:42 +00:00
respond_to do |format|
format.html {
render 'admin/items/index'
}
format.js {}
end
end
def new
@item = Page.new
2012-02-17 06:54:11 +00:00
@item.parent = Item.find(params[:parent_id]) rescue nil
@apps = ModuleApp.excludes(app_pages: nil).entries
@designs = Design.all.entries
2012-02-17 06:54:11 +00:00
@design = Design.first
end
def edit
2013-01-21 08:56:37 +00:00
@item = @page =Page.find(params[:id])
@user_choose = @item.app_frontend_url
@apps = ModuleApp.excludes(app_pages: nil).entries
2012-08-09 07:25:30 +00:00
@module_apps = ModuleApp.excludes(widgets: nil).where(enable_frontend: true).order_by(:title, :asc)
@designs = Design.all.entries
2012-02-17 06:54:11 +00:00
@design = @item.design ? @item.design : @designs.first
2013-01-21 08:56:37 +00:00
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?
2013-01-21 08:56:37 +00:00
end
2012-04-29 22:27:38 +00:00
if @item.module_app
2012-08-09 07:25:30 +00:00
@module_app = @item.module_app
@frontend_path = @item.app_frontend_url
2012-08-20 09:14:13 +00:00
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
2012-08-20 09:14:13 +00:00
2012-04-29 22:27:38 +00:00
case @item.module_app.key
when 'announcement'
@categories = BulletinCategory.all
2012-05-13 16:33:52 +00:00
@tags = AnnouncementTag.all
2012-04-29 22:27:38 +00:00
when 'news'
@categories = NewsBulletinCategory.all
2012-05-13 16:33:52 +00:00
@tags = NewsTag.all
2012-04-29 22:27:38 +00:00
when 'web_resource'
@categories = WebLinkCategory.all
2012-05-13 16:33:52 +00:00
@tags = WebResourceTag.all
2012-08-21 09:37:25 +00:00
when 'archive'
@categories = ArchiveFileCategory.all
@tags = ArchiveTag.all
2012-04-29 22:27:38 +00:00
end
else
@categories = nil
@module_app = @module_apps[0]
2012-04-29 22:27:38 +00:00
end
end
def create
@item = Page.new(params[:page])
2012-02-21 11:22:42 +00:00
2012-05-22 06:45:49 +00:00
if @item.module_app && @item.module_app.key == 'page_content'
2012-02-21 11:22:42 +00:00
@item.page_contexts.build(:create_user_id => current_user.id, :update_user_id => current_user.id )
end
if @item.save
2012-09-12 11:12:50 +00:00
flash.now[:notice] = t('create.success.page')
2011-06-01 02:24:14 +00:00
respond_to do |format|
format.html {
2011-06-01 04:00:41 +00:00
redirect_to admin_page_url(@item)
2011-06-01 02:24:14 +00:00
}
format.js {}
2011-06-01 02:24:14 +00:00
end
2010-01-04 09:49:55 +00:00
else
2012-09-12 11:12:50 +00:00
flash.now[:error] = t('create.error.page')
2012-02-17 06:54:11 +00:00
@apps = ModuleApp.all
@designs = Design.all.entries
@design = Design.first
2011-06-01 02:24:14 +00:00
render :action => "new"
end
end
def update
@item = Page.find(params[:id])
2012-02-24 11:11:51 +00:00
2013-01-21 08:56:37 +00:00
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
2012-08-09 07:25:30 +00:00
2013-01-21 08:56:37 +00:00
params[:page][:frontend_field] = params[:page][:frontend_field].zip( params[:page][:frontend_field_type] ) if params[:page][:frontend_field]
params[:page][:frontend_field_type] = nil
if params[:page][:tag].include?("nil")
params[:page][:tag] = []
end
if params[:page][:category].include?("nil")
params[:page][:category] = []
end
if @item.update_attributes(params[:page])
2012-09-12 11:12:50 +00:00
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
2011-06-01 04:00:41 +00:00
respond_to do |format|
format.html {
redirect_to admin_items_url( :parent_id => @item.parent_id )
}
2012-05-22 06:45:49 +00:00
format.js { redirect_to admin_items_url }
2011-06-01 04:00:41 +00:00
end
end
def delete
2012-05-22 06:45:49 +00:00
@item = Page.find(params[:id])
@item.destroy
2011-06-01 04:00:41 +00:00
respond_to do |format|
format.html {}
2012-05-22 06:45:49 +00:00
format.js { @item = @item.parent }
2011-06-01 04:00:41 +00:00
end
end
2013-01-21 08:56:37 +00:00
def reload_front_end_setting
@page = Page.find params[:id]
@module_app = ModuleApp.find params[:module_app_id]
@chosen_frontend = @user_choose = params[:frontend]
end
def reload_frontend_pages
2013-01-23 10:51:18 +00:00
@page = Page.find params[:id] rescue nil
2013-01-21 08:56:37 +00:00
# @categories =[]
2013-01-23 10:51:18 +00:00
@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?)
2013-01-21 08:56:37 +00:00
2013-01-23 10:51:18 +00:00
case (@module_app.nil? ? nil : @module_app.key )
2013-01-21 08:56:37 +00:00
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
2013-02-25 04:49:06 +00:00
def reload_widget_field
@index = params[:field_seri].to_i
@page = 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