style for front end

This commit is contained in:
Fu Matthew 2013-03-11 18:21:17 +08:00
parent e53ad9f5d1
commit 311d741f92
5 changed files with 64 additions and 55 deletions

View File

@ -19,45 +19,28 @@ helper Admin::PagePartsHelper
end
def edit
@item = @page =Page.find(params[:id])
@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 = []
setup_app_frontend_and_style
@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
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
else
@categories = nil
@module_app = @module_apps[0]
end
end
@ -138,35 +121,43 @@ helper Admin::PagePartsHelper
end
def reload_front_end_setting
@page = Page.find params[:id]
@item = Page.find params[:id] rescue nil
@module_app = ModuleApp.find params[:module_app_id]
@chosen_frontend = @user_choose = params[:frontend]
@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
end
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]}
else
@module_app.app_pages.each{|name,data| @app_frontend_urls << [I18n.t(data["i18n"]),name]}
end
@frontend_styles = @module_app.app_pages[params["frontend"]]["style"] rescue nil
@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
@frontend_styles = @module_app.app_pages.first[1]["style"] if @frontend_styles.nil?
end
def reload_frontend_pages
@page = Page.find params[:id] rescue nil
# @categories =[]
@item = Page.find params[:id] rescue nil
@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 = []
setup_app_frontend_and_style
@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
get_categories_and_tags
respond_to do |format|
format.js {}
end
@ -182,7 +173,7 @@ helper Admin::PagePartsHelper
def reload_widget_field
@index = params[:field_seri].to_i
@page = Page.find params[:id]
@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?

View File

@ -11,7 +11,7 @@ module Admin::PagePartsHelper
def get_widget_field_rel(local_item=nil)
local_item = @part if local_item.nil? && @part
local_item = @page if local_item.nil? && @page
local_item = @item if local_item.nil? && @page
case local_item
when Page
@ -23,7 +23,7 @@ module Admin::PagePartsHelper
def link_to_field_switch(i,object_name,field_name,local_item=nil,prefill_value=nil) #link_to_field is for showing
local_item = @part if local_item.nil? && @part
local_item = @page if local_item.nil? && @page
local_item = @item if local_item.nil? && @page
res = ''
choosen_value = prefill_value || (local_item[:widget_field][i][0] rescue nil)
@ -53,7 +53,7 @@ module Admin::PagePartsHelper
def widget_field_options(i,local_item=nil)
local_item = @part if local_item.nil? && @part
local_item = @page if local_item.nil? && @page
local_item = @item if local_item.nil? && @page
options = @module_app.widget_fields.collect do |widget_field|
label = I18n.t("#{@module_app.key}.default_widget.#{widget_field[0]}")
@ -71,7 +71,7 @@ module Admin::PagePartsHelper
def widget_fiield_type_options(i,local_item=nil)
options = LIST[:widget_field_type].collect{|widget_field| [widget_field.humanize, widget_field]}
local_item = @part if local_item.nil? && @part
local_item = @page if local_item.nil? && @page
local_item = @item if local_item.nil? && @page
case local_item
when Page

View File

@ -3,6 +3,10 @@
<%= t("default_widget.select_widget_style") %>
</label>
<div class="controls well">
<% if @frontend_styles%>
<%= select('page', 'frontend_style', @frontend_styles) %>
<% else %>
<%= t("default_widget.no_support_setting")%>
<% end %>
</div>
</div>

View File

@ -33,15 +33,20 @@ module OrbitApp
end
def to_module_app_format #For ModuleApp to fetch data
@frontend_pages.collect{|t| [t.get_i18n,t.name]}
result = {}
@frontend_pages.collect do |t|
result[t.name] = {:i18n=>t.get_i18n,:style=>t.get_style}
end
result
end
end
class AppPage
attr_reader :name
attr_reader :style
def initialize(name,&block)
@style
@name = name
@frontend_i18n = 'rulingcom.errors.init.app_page_noname'
block.arity < 1 ? instance_eval(&block) : block.call(self) if block_given?
@ -59,6 +64,14 @@ module OrbitApp
end
def get_style
@style
end
def style(ary)# []
@style = ary
end
protected
end# of AppPage

View File

@ -14,6 +14,7 @@ module Announcement
front_end do
app_page 'bulletins' do
frontend_i18n "announcement.frontend.bulletins"
style ["1","2","3"]
end
end