2012-11-15 07:51:44 +00:00
|
|
|
class Admin::PagesController < Admin::ItemsController
|
2013-01-09 03:23:18 +00:00
|
|
|
helper Admin::PagePartsHelper
|
2009-05-07 17:18:16 +00:00
|
|
|
def show
|
2011-05-25 06:50:56 +00:00
|
|
|
@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
|
2009-05-07 17:18:16 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def new
|
2011-05-25 06:50:56 +00:00
|
|
|
@item = Page.new
|
2012-02-17 06:54:11 +00:00
|
|
|
@item.parent = Item.find(params[:parent_id]) rescue nil
|
2013-03-22 06:19:10 +00:00
|
|
|
@apps = ModuleApp.where(:key.in => OrbitApp::Module::FrontendUtility.all.keys)
|
2011-08-23 18:06:27 +00:00
|
|
|
@designs = Design.all.entries
|
2012-02-17 06:54:11 +00:00
|
|
|
@design = Design.first
|
2009-05-07 17:18:16 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def edit
|
2013-03-11 10:21:17 +00:00
|
|
|
@item = Page.find(params[:id])
|
2013-01-21 08:56:37 +00:00
|
|
|
@user_choose = @item.app_frontend_url
|
2013-03-22 06:19:10 +00:00
|
|
|
@apps = ModuleApp.where(:key.in => OrbitApp::Module::FrontendUtility.all.keys)
|
2012-08-09 07:25:30 +00:00
|
|
|
@module_apps = ModuleApp.excludes(widgets: nil).where(enable_frontend: true).order_by(:title, :asc)
|
|
|
|
|
2011-08-23 18:34:24 +00:00
|
|
|
@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
|
2013-03-13 09:53:11 +00:00
|
|
|
@app_frontend_urls = []
|
|
|
|
setup_app_frontend_and_style
|
2013-01-29 12:33:40 +00:00
|
|
|
@app_frontend_urls << [I18n.t('default_widget.name'),'default_widget'] if @item.module_app.has_default_widget?
|
2013-03-13 09:53:11 +00:00
|
|
|
|
2012-08-09 07:25:30 +00:00
|
|
|
@module_app = @item.module_app
|
2013-02-08 04:56:35 +00:00
|
|
|
@frontend_path = @item.app_frontend_url
|
2012-08-20 09:14:13 +00:00
|
|
|
|
2013-03-13 09:53:11 +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
|
|
|
|
get_categories_and_tags
|
|
|
|
|
2012-04-29 22:27:38 +00:00
|
|
|
else
|
2013-02-08 04:56:35 +00:00
|
|
|
@module_app = @module_apps[0]
|
2012-04-29 22:27:38 +00:00
|
|
|
end
|
2009-05-07 17:18:16 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def create
|
2011-05-25 06:50:56 +00:00
|
|
|
@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
|
|
|
|
|
2011-05-25 06:50:56 +00:00
|
|
|
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
|
|
|
}
|
2011-06-10 02:31:50 +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')
|
2013-03-22 06:19:10 +00:00
|
|
|
@apps = ModuleApp.where(:key.in => OrbitApp::Module::FrontendUtility.all.keys)
|
2012-02-17 06:54:11 +00:00
|
|
|
@designs = Design.all.entries
|
|
|
|
@design = Design.first
|
2011-06-01 02:24:14 +00:00
|
|
|
render :action => "new"
|
2009-05-07 17:18:16 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def update
|
2011-08-23 18:34:24 +00:00
|
|
|
@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-03-13 09:53:11 +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
|
2013-01-21 08:56:37 +00:00
|
|
|
|
2013-03-13 09:53:11 +00:00
|
|
|
if params[:page][:tag].nil? || params[:page][:tag].include?("nil")
|
2013-02-06 11:51:53 +00:00
|
|
|
params[:page][:tag] = []
|
|
|
|
end
|
|
|
|
|
2013-03-13 09:53:11 +00:00
|
|
|
if params[:page][:category].nil? || params[:page][:category].include?("nil")
|
2013-02-06 11:51:53 +00:00
|
|
|
params[:page][:category] = []
|
|
|
|
end
|
|
|
|
|
2011-08-25 00:13:38 +00:00
|
|
|
if @item.update_attributes(params[:page])
|
2012-09-12 11:12:50 +00:00
|
|
|
flash[:notice] = t('update.success.page')
|
2011-08-23 18:34:24 +00:00
|
|
|
respond_to do |format|
|
|
|
|
format.html {
|
|
|
|
redirect_to admin_page_url(@item)
|
|
|
|
}
|
|
|
|
format.js {}
|
|
|
|
end
|
|
|
|
else
|
|
|
|
render :action => "edit"
|
|
|
|
end
|
2009-05-07 17:18:16 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def destroy
|
2011-05-25 06:50:56 +00:00
|
|
|
@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
|
2009-05-07 17:18:16 +00:00
|
|
|
end
|
2013-01-21 08:56:37 +00:00
|
|
|
|
|
|
|
def reload_front_end_setting
|
2013-03-13 09:53:11 +00:00
|
|
|
@item = Page.find params[:id] rescue nil
|
2013-01-21 08:56:37 +00:00
|
|
|
@module_app = ModuleApp.find params[:module_app_id]
|
2013-03-13 09:53:11 +00:00
|
|
|
@user_choose = params[:frontend] #choosen frontend
|
|
|
|
|
|
|
|
@app_frontend_urls = @module_app.nil? ? nil : @module_app.app_pages.each{|name,data| [I18n.t(data["i18n"]),name]}
|
|
|
|
@frontend_styles = @module_app.app_pages[params["frontend"]]["style"] rescue nil
|
2013-01-21 08:56:37 +00:00
|
|
|
end
|
|
|
|
|
2013-03-13 09:53:11 +00:00
|
|
|
def get_categories_and_tags
|
|
|
|
unless @module_app.nil?
|
|
|
|
@categories = @module_app.get_categories
|
|
|
|
@tags = @module_app.get_tags
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def setup_app_frontend_and_style
|
|
|
|
if @module_app.nil?
|
|
|
|
@item.module_app.app_pages.each{|name,data| @app_frontend_urls << [I18n.t(data["i18n"]),name]}
|
2013-03-26 08:29:35 +00:00
|
|
|
@frontend_styles = @item.module_app.app_pages[@item.frontend_style]["style"] if @frontend_styles.nil? && @item && @item.module_app.app_pages[@item.frontend_style]
|
|
|
|
@frontend_styles = @item.module_app.app_pages.first[1]["style"] if @frontend_styles.nil? && @item
|
2013-03-13 09:53:11 +00:00
|
|
|
else
|
|
|
|
@module_app.app_pages.each{|name,data| @app_frontend_urls << [I18n.t(data["i18n"]),name]}
|
2013-03-26 08:29:35 +00:00
|
|
|
@frontend_styles = @module_app.app_pages[params["frontend"]]["style"] rescue nil
|
|
|
|
@frontend_styles = @module_app.app_pages.first[1]["style"] if @frontend_styles.nil?
|
2013-03-13 09:53:11 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-01-21 08:56:37 +00:00
|
|
|
def reload_frontend_pages
|
2013-03-19 09:49:46 +00:00
|
|
|
@item = Page.find params[:id] rescue nil
|
2013-01-23 10:51:18 +00:00
|
|
|
@module_app = ModuleApp.find(params[:module_app_id]) rescue nil
|
2013-03-13 09:53:11 +00:00
|
|
|
@app_frontend_urls = []
|
|
|
|
setup_app_frontend_and_style
|
2013-01-29 12:33:40 +00:00
|
|
|
@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-03-13 09:53:11 +00:00
|
|
|
get_categories_and_tags
|
|
|
|
|
2013-01-21 08:56:37 +00:00
|
|
|
respond_to do |format|
|
|
|
|
format.js {}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-08-25 00:13:38 +00:00
|
|
|
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
|
2013-03-19 09:49:46 +00:00
|
|
|
@item = Page.find params[:id]
|
2013-02-25 04:49:06 +00:00
|
|
|
@choosen_field = params[:widget_field_value]
|
|
|
|
@module_app = @page.module_app
|
|
|
|
@module_app = ModuleApp.find params[:module_app_id] if @module_app.nil?
|
|
|
|
end
|
|
|
|
|
2009-05-07 17:18:16 +00:00
|
|
|
end
|