1.Remove category column when category is specified

2.Showing category if not in category browsing
3.Redirect to home and show error if app page is not available for user language
4.Showing no context to display if object has no language for it.
5.Browse new and announcement by unit is now applicable.
This commit is contained in:
Matthew K. Fu JuYuan authored and Christophe Vilayphiou committed 2012-08-08 14:46:08 +08:00
1 parent b4c2dfe0ef
commit e8317e0a4b
21 files changed
+130 -42

No files matched your search

+23 -13
View File
@@ -1,9 +1,6 @@
class PagesController < ApplicationController
include ApplicationHelper
before_filter :get_item, :only => [:index_from_link, :show_from_link]
# caches_page :index
def index
@@ -11,7 +8,7 @@ class PagesController < ApplicationController
if @item
impressionist(@item)
render_page
render_page
else
render :text => 'You need a home page'
end
@@ -19,14 +16,15 @@ class PagesController < ApplicationController
def show
#begin
@item = Item.first(:conditions => {:path => params[:page_name]})
if @item && @item.is_published && (@item.enabled_for.nil? ? true : @item.enabled_for.include?(I18n.locale.to_s))
if @item && @item.is_published #&& (@item.enabled_for.nil? ? true : @item.enabled_for.include?(I18n.locale.to_s))
impressionist(@item)
case @item.class.to_s
when 'Page'
render_page
when 'Page'
render_page unless save_from_no_lang_for_page
when 'Link'
redirect_to @item[:url]
redirect_to(@item[:url]) unless save_from_no_lang_for_page
end
else
render :file => "#{Rails.root}/public/404.html", :status => :not_found
@@ -43,15 +41,17 @@ class PagesController < ApplicationController
options << "#{options.blank? ? '?' : '&'}category_id=#{params[:category_id]}" unless params[:category_id].blank?
options << "#{options.blank? ? '?' : '&'}tag_id=#{params[:tag_id]}" unless params[:tag_id].blank?
options << "#{options.blank? ? '?' : '&'}search_query=#{params[:search_query]}" unless params[:search_query].blank?
options << "#{options.blank? ? '?' : '&'}name=#{params[:name]}" unless params[:name].blank?
uri = URI::escape(url + options)
redirect_to uri
#uri = URI::escape("#{url}?" + params.collect{|k,v| "#{k}=#{v}"}.join('&'))
redirect_to(uri)unless save_from_no_lang_for_page
end
def show_from_link
url = "/#{@item.path}?id=#{params[:id]}"
options = ''
options << "&preview=#{params[:preview]}" unless params[:preview].blank?
redirect_to url + options
redirect_to(url + options) unless save_from_no_lang_for_page
end
def load_orbit_bar
@@ -66,12 +66,22 @@ class PagesController < ApplicationController
@item = Item.first(:conditions => {:module_app_id => module_app.id, :app_frontend_url => params[:app_action], :category => params[:category_id], :tag => params[:tag_id]})
@item = Item.first(:conditions => {:module_app_id => module_app.id, :app_frontend_url => params[:app_action], :category => params[:category_id], :tag => ''}) unless @item
elsif !params[:category_id].blank?
@item = Item.first(:conditions => {:module_app_id => module_app.id, :app_frontend_url => params[:app_action], :category => params[:category_id], :tag => ''})
@item = Item.where(module_app_id: module_app.id,app_frontend_url:params[:app_action],category: params[:category_id]).any_in(tag: [nil,'']).first
elsif !params[:tag_id].blank?
@item = Item.first(:conditions => {:module_app_id => module_app.id, :app_frontend_url => params[:app_action], :category => '', :tag => params[:tag_id]})
@item = Item.where(module_app_id: module_app.id,app_frontend_url:params[:app_action],tag: params[:tag_id]).any_in(category: [nil,'']).first
end
@item = Item.first(:conditions => {:module_app_id => module_app.id, :app_frontend_url => params[:app_action], :category => '', :tag => ''}) unless @item
@item = Item.where(module_app_id: module_app.id,app_frontend_url:params[:app_action]).all_of("tag" => {"$in" => [nil,'']},"category" => { "$in" => [nil,'']}).first unless @item
#TODO 需要做 error handler 處理沒有新增該模組頁面導致錯誤的可能性
end
protected
def save_from_no_lang_for_page
if @item.nil? or !@item.enabled_for_lang(I18n.locale.to_s)
flash[:notice] = t('sys.module_page_lang_not_support')
redirect_to '/'
return true
else
return false
end
end
end
+4 -1
View File
@@ -23,7 +23,10 @@ class Item
before_destroy :destroy_children
after_rearrange :rebuild_path, :if => "parent_id_changed? || name_changed?"
def enabled_for_lang(lang)
enabled_for.include?(lang)
end
def self.find_by_name(item_name)
Item.first(:conditions => { :name => item_name, :is_published => true })
end
+2 -2
View File
@@ -6,8 +6,8 @@ class Page < Item
field :content
field :app_frontend_url
field :theme_id, :type => BSON::ObjectId, :default => nil
field :category
field :tag
field :category, :default => ''
field :tag, :default => ''
field :view_count, :type => Integer, :default => 0
field :page_title, localize: true
-5
View File
@@ -31,12 +31,7 @@ class User
VALID_LOCALES.each do |loc|
locale = loc.to_sym
# debugger
# if(self.cache_dept.nil?)
# self.build_cache_dept key: "dept_cache_user_#{self.id}"
# end
dept_hash[locale] = sub_roles.collect{|sr| sr.title}.join(',')
# self.cache_dept[locale] = sub_roles.collect{|sr| sr.title}.join(',')
end
self.cache_dept = dept_hash
self.save!
+12 -1
View File
@@ -12,6 +12,17 @@
<%= page_javascripts(@item).html_safe %>
</head>
<body>
<%= yield %>
<%= yield %>
<% if !flash.empty? %>
<div class="modal alert alert-error hide" id="myModal">
<p type="button" class="close" data-dismiss="modal">×</p>
<% flash.each do |key, msg| %>
<%= "<strong>#{msg}</strong><br/>".html_safe%>
<% end%>
</div>
<script>
$('#myModal').modal('show')
</script>
<% end -%>
</body>
</html>