This commit is contained in:
nccu 2015-02-24 14:13:42 +08:00
parent cac763a816
commit 93f103094e
3 changed files with 22 additions and 12 deletions

View File

@ -6,13 +6,13 @@ class NewsController < ApplicationController
if params[:keywords]
!params[:sort].blank? ? sort = {params[:sort].to_sym=>params[:order]} : sort = {:is_top=>"desc",:postdate=>"desc"}
news = NewsBulletin.where(:title.ne => "").any_of(:title => /#{params[:keywords].to_s}/i).is_approved.order_by(sort).filter_by_categories(["all"]).per(15) if !params[:keywords].nil?
news = NewsBulletin.where(:title.ne => "").any_of(:title => /#{params[:keywords].to_s}/i).can_display_postdate.is_approved.order_by(sort).filter_by_categories(["all"]).per(15) if !params[:keywords].nil?
news_count = ",共有" + news.count.to_s + "筆資料"
keyword = "搜尋標題有關 ' " + params[:keywords] + " '"
elsif params[:department]
!params[:sort].blank? ? sort = {params[:sort].to_sym=>params[:order]} : sort = {:is_top=>"desc",:postdate=>"desc"}
dept = Department.find_by(:uid => params["department"].split("-").last) rescue nil
news = NewsBulletin.where(:title.ne => "" ,:department => dept).is_approved.order_by(sort).filter_by_categories(["all"]) if !dept.nil?
news = NewsBulletin.where(:title.ne => "" ,:department => dept).can_display_postdate.is_approved.order_by(sort).filter_by_categories(["all"]) if !dept.nil?
news_count = ",共有" + news.count.to_s + "筆資料"
keywords = params[:department].split("-")
@ -26,7 +26,7 @@ class NewsController < ApplicationController
elsif params[:unit]
unit = Unit.find_by(:uid => params["unit"].split("-").last) rescue nil
!params[:sort].blank? ? sort = {params[:sort].to_sym=>params[:order]} : sort = {:is_top=>"desc",:postdate=>"desc"}
news = NewsBulletin.where(:title.ne => "" ,:unit => unit).is_approved.order_by(sort).filter_by_categories(["all"]) if !unit.nil?
news = NewsBulletin.where(:title.ne => "" ,:unit => unit).can_display_postdate.is_approved.order_by(sort).filter_by_categories(["all"]) if !unit.nil?
news_count = ",共有" + news.count.to_s + "筆資料"
keywords = params[:unit].split("-")
@ -39,7 +39,7 @@ class NewsController < ApplicationController
elsif params["category"]
!params[:sort].blank? ? sort = {params[:sort].to_sym=>params[:order]} : sort = {:is_top=>"desc",:postdate=>"desc"}
category = Category.find_by(:uid => params["category"].split("-").last) rescue nil
news = NewsBulletin.all.where(:title.ne => "").is_approved.order_by(sort).filter_by_categories([category.id.to_s]) if !category.nil?
news = NewsBulletin.all.where(:title.ne => "").can_display_postdate.is_approved.order_by(sort).filter_by_categories([category.id.to_s]) if !category.nil?
news_count = ",共有" + news.count.to_s + "筆資料"
keywords = params[:category].split("-")
@ -51,7 +51,7 @@ class NewsController < ApplicationController
end
end
!params[:sort].blank? ? sort = {params[:sort].to_sym=>params[:order]} : sort = {:is_top=>"desc",:postdate=>"desc"}
news = NewsBulletin.where(:title.ne => "" ,:is_preview.in=>[false,nil]).is_approved.order_by(sort).filter_by_categories.filter_by_tags(OrbitHelper.params['tags']) if news.nil?
news = NewsBulletin.where(:title.ne => "" ,:is_preview.in=>[false,nil]).can_display_postdate.is_approved.order_by(sort).filter_by_categories.filter_by_tags(OrbitHelper.params['tags']) if news.nil?
page = Page.where(:module => "news").first rescue nil
ma = ModuleApp.find_by_key("news") rescue nil
categories = ma.categories.enabled.collect do |cat|
@ -60,13 +60,13 @@ class NewsController < ApplicationController
"category-link" => "/#{I18n.locale.to_s + page.url}/?category=#{cat.to_param}"
}
end
anns = news.collect do |a|
if a.image_description.nil?
image_description = "裝飾性圖片"
else
image_description = a.image_description
end
statuses = a.statuses_with_classname.collect do |status|
{
"status" => status["name"],

View File

@ -46,6 +46,7 @@ class NewsBulletin
before_destroy :destroy_email
scope :can_display, ->{where(:is_hidden=>false).any_of({:postdate.lt=>Time.now, :deadline.gt=>Time.now},{:postdate.lt=>Time.now, :deadline=>nil}).order_by([:is_top, :desc])}
scope :can_display_postdate, ->{where(:is_hidden=>false).any_of({:postdate.lt=>Time.now},{:postdate.lt=>Time.now, :deadline=>nil}).order_by([:is_top, :desc])}
scope :is_approved, ->{where(:approved => true)}
def update_user

View File

@ -19,11 +19,20 @@
<td><%= b.category.title rescue "" %></td>
<td>
<% if b.expired? %>
<% if !b.title_translations["zh_tw"].blank? %>
<%= b.title_translations["zh_tw"] %> <span class='label'><%= t(:expired) %></span><br />
<% end %>
<% if !b.title_translations["en"].blank? %>
<%= b.title_translations["en"] %> <span class='label'><%= t(:expired) %></span>
<% if b.rejected %>
<% if !b.title_translations["zh_tw"].blank? %>
<%= b.title_translations["zh_tw"] %><span class='label'><%= t(:expired)+''+t(:rejected) %> : <%= b.rejection_reason rescue "" %></span><br />
<% end %>
<% if !b.title_translations["en"].blank? %>
<%= b.title_translations["en"] %><span class='label'><%= t(:expired)+''+t(:rejected) %> : <%= b.rejection_reason rescue "" %></span>
<% end %>
<% else %>
<% if !b.title_translations["zh_tw"].blank? %>
<%= b.title_translations["zh_tw"] %> <span class='label'><%= t(:expired) %></span><br />
<% end %>
<% if !b.title_translations["en"].blank? %>
<%= b.title_translations["en"] %> <span class='label'><%= t(:expired) %></span>
<% end %>
<% end %>
<% elsif b.rejected %>
<% url = page_for_bulletin(b) %>
@ -56,7 +65,7 @@
<% if can_edit_or_delete?(b) %>
<li><a href="/admin/news/<%=b.id.to_s%>/edit"><%= t(:edit) %></a></li>
<li><a href="#" class="delete text-error" rel="/admin/news/<%=b.id.to_s%>"><%= t(:delete_) %></a></li>
<% if !b.approved && user_can_approve? %>
<% if !b.approved && user_can_approve? && !b.expired? %>
<li><a href="#" class="appoval_button" data-approve-link="<%= "/#{I18n.locale.to_s}/news/#{b.to_param}" %>" data-id="<%= b.id.to_s %>"><%= t("news.approve") %></a></li>
<% end %>
<% end %>