This commit is contained in:
unknown 2012-02-15 10:37:07 +08:00
parent 6b551defce
commit 778a85ca2b
7 changed files with 38 additions and 52 deletions

View File

@ -21,4 +21,8 @@ class I18nVariable
I18nVariable.first(:conditions => {:key => locale})[I18n.locale] I18nVariable.first(:conditions => {:key => locale})[I18n.locale]
end end
def self.from_locale(locale)
I18nVariable.first(:conditions => {:key => locale})[I18n.locale]
end
end end

View File

@ -1,18 +0,0 @@
# encoding: utf-8
class Announcement
include Mongoid::Document
include Mongoid::Timestamps
field :category, :type => String
field :title, :type => String
field :subtitle, :type => String
field :text, :type => String
field :postdate , :type => Date
field :deadline , :type => Date
# embeds_many :comments
validates_presence_of :category, :title, :subtitle, :text
end

View File

@ -41,38 +41,38 @@ class Bulletin
def self.search( search = nil, category_id = nil ) def self.search( search = nil, category_id = nil )
if category_id.to_s.size > 0 and search.to_s.size > 0 if category_id.to_s.size > 0 and search.to_s.size > 0
key = /#{search}/ key = /#{search}/
find(:all, :conditions => {title: key, bulletin_category_id: category_id}).desc( :is_top, :postdate ) find(:all, :conditions => {title: key, bulletin_category_id: category_id}).desc( :is_top, :postdate )
elsif category_id.to_s.size > 0 and search.to_s.size < 1 elsif category_id.to_s.size > 0 and search.to_s.size < 1
find(:all, :conditions => {bulletin_category_id: category_id}).desc( :is_top, :postdate ) find(:all, :conditions => {bulletin_category_id: category_id}).desc( :is_top, :postdate )
elsif search.to_s.size > 0 and category_id.to_s.size < 1 elsif search.to_s.size > 0 and category_id.to_s.size < 1
key = /#{search}/ key = /#{search}/
find(:all, :conditions => {title: key}).desc( :is_top, :postdate ) find(:all, :conditions => {title: key}).desc( :is_top, :postdate )
else else
find(:all).desc( :is_top, :postdate) find(:all).desc( :is_top, :postdate)
end end
end end
def self.widget_datas def self.widget_datas
date_now = Time.now date_now = Time.now
# find(:all, :conditions => {:postdate => {"$lte" => Date.today}, deadline: nil} ).desc( :is_top, :postdate) # find(:all, :conditions => {:postdate => {"$lte" => Date.today}, deadline: nil} ).desc( :is_top, :postdate)
# where( :postdate.lte => date_now ).where( :deadline => nil ).desc(:is_top, :postdate) # where( :postdate.lte => date_now ).where( :deadline => nil ).desc(:is_top, :postdate)
# any_of({ :title => "test" },{:deadline => nil, :title => "123"}) # any_of({ :title => "test" },{:deadline => nil, :title => "123"})
any_of( {deadline: nil,:postdate.lte => date_now} , {:deadline.gte => date_now,:postdate.lte => date_now} ).desc( :is_top, :postdate) any_of( {deadline: nil,:postdate.lte => date_now} , {:deadline.gte => date_now,:postdate.lte => date_now} ).desc( :is_top, :postdate)
end end
@ -94,7 +94,7 @@ class Bulletin
def title def title
@title ||= I18nVariable.first(:conditions => {:key => 'title', :language_value_id => self.id, :language_value_type => self.class}) rescue nil @title ||= I18nVariable.first(:conditions => {:key => 'title', :language_value_id => self.id, :language_value_type => self.class}) rescue nil
end end
def subtitle def subtitle
@subtitle ||= I18nVariable.first(:conditions => {:key => 'subtitle', :language_value_id => self.id, :language_value_type => self.class}) rescue nil @subtitle ||= I18nVariable.first(:conditions => {:key => 'subtitle', :language_value_id => self.id, :language_value_type => self.class}) rescue nil
end end

View File

@ -15,7 +15,7 @@
<%= t('announcement.刪除已上傳檔案') %> <%= t('announcement.刪除已上傳檔案') %>
<% end %> <% end %>
</div> </div>
<div class="field"> <div class="field">
<%= f.label :title %> <%= f.label :title %>
<%= f.fields_for :title, (@bulletin.new_record? ? @bulletin.build_title : @bulletin.title ) do |f| %> <%= f.fields_for :title, (@bulletin.new_record? ? @bulletin.build_title : @bulletin.title ) do |f| %>

View File

@ -18,7 +18,7 @@
<tr> <tr>
<td><%= post.postdate %></td> <td><%= post.postdate %></td>
<td><%= post.bulletin_category.i18n_variable[I18n.locale] %></td> <td><%= post.bulletin_category.i18n_variable[I18n.locale] %></td>
<td><%= link_to post.title, panel_announcement_front_end_bulletin_path(post) %> <td><%= link_to post.title[I18n.locale], panel_announcement_front_end_bulletin_path(post) %>
<%#= link_to post.title, panel_announcement_back_end_bulletin_path(post) %> <%#= link_to post.title, panel_announcement_back_end_bulletin_path(post) %>
</td> </td>
</tr> </tr>

View File

@ -17,19 +17,19 @@
</li> </li>
<li> <li>
<b><%= t('announcement.title') %></b> <b><%= t('announcement.title') %></b>
<%= @bulletin.title %> <%= @bulletin.title[I18n.locale] %>
</li> </li>
<li> <li>
<%#= image_tag(@bulletin.image.url, :size => "320x240") if @bulletin.image.file %> <%#= image_tag(@bulletin.image.url, :size => "320x240") if @bulletin.image.file %>
<%= link_to image_tag(@bulletin.image.url, :size => "320x240"), @bulletin.image.url, {:target => '_blank', :title => @bulletin.image_filename} if @bulletin.image.file %> <%= link_to image_tag(@bulletin.image.url, :size => "320x240"), @bulletin.image.url, {:target => '_blank', :title => @bulletin.image_identifier} if @bulletin.image.file %>
</li> </li>
<li> <li>
<b><%= t('announcement.subtitle') %></b> <b><%= t('announcement.subtitle') %></b>
<%= @bulletin.subtitle %> <%= @bulletin.subtitle[I18n.locale] %>
</li> </li>
<li> <li>
<b><%= t('announcement.text') %></b> <b><%= t('announcement.text') %></b>
<%= @bulletin.text %> <%= @bulletin.text[I18n.locale] %>
</li> </li>
<li> <li>
<li> <li>
@ -54,4 +54,4 @@
</li> </li>
<%= link_back %> <%#= link_back %>

View File

@ -10,8 +10,8 @@
<% @bulletins.each do |post| %> <% @bulletins.each do |post| %>
<li> <li>
<div class="news_img"><%= image_tag(post.image.url, :size => "290x130") if post.image.file %></div> <div class="news_img"><%= image_tag(post.image.url, :size => "290x130") if post.image.file %></div>
<h3 class="h3 news_title"><%= post.title %></h3> <h3 class="h3 news_title"><%= post.title[I18n.locale] %></h3>
<p class="news_wrap"><%= post.subtitle %></p> <p class="news_wrap"><%= post.subtitle[I18n.locale] %></p>
</li> </li>
<% end %> <% end %>
</ul> </ul>