From 778a85ca2bc5eefe9bf49aab0fd420b8b09d5a86 Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 15 Feb 2012 10:37:07 +0800 Subject: [PATCH] add tags --- app/models/i18n_variable.rb | 4 ++ .../announcement/app/models/announcement.rb | 18 ------- .../announcement/app/models/bulletin.rb | 50 +++++++++---------- .../back_end/bulletins/_form.html.erb | 2 +- .../front_end/bulletins/index.html.erb | 2 +- .../front_end/bulletins/show.html.erb | 10 ++-- .../widget/bulletins/index.html.erb | 4 +- 7 files changed, 38 insertions(+), 52 deletions(-) delete mode 100644 vendor/built_in_modules/announcement/app/models/announcement.rb diff --git a/app/models/i18n_variable.rb b/app/models/i18n_variable.rb index 563ba791..1583d20e 100644 --- a/app/models/i18n_variable.rb +++ b/app/models/i18n_variable.rb @@ -21,4 +21,8 @@ class I18nVariable I18nVariable.first(:conditions => {:key => locale})[I18n.locale] end + def self.from_locale(locale) + I18nVariable.first(:conditions => {:key => locale})[I18n.locale] + end + end diff --git a/vendor/built_in_modules/announcement/app/models/announcement.rb b/vendor/built_in_modules/announcement/app/models/announcement.rb deleted file mode 100644 index fdd2e353..00000000 --- a/vendor/built_in_modules/announcement/app/models/announcement.rb +++ /dev/null @@ -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 \ No newline at end of file diff --git a/vendor/built_in_modules/announcement/app/models/bulletin.rb b/vendor/built_in_modules/announcement/app/models/bulletin.rb index 79ed113c..e5ff381b 100644 --- a/vendor/built_in_modules/announcement/app/models/bulletin.rb +++ b/vendor/built_in_modules/announcement/app/models/bulletin.rb @@ -41,38 +41,38 @@ class Bulletin 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}/ - - 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 - - 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 - + + 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 + + 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 + key = /#{search}/ - - find(:all, :conditions => {title: key}).desc( :is_top, :postdate ) - else - - find(:all).desc( :is_top, :postdate) - - end - + + find(:all, :conditions => {title: key}).desc( :is_top, :postdate ) + else + + find(:all).desc( :is_top, :postdate) + + end + end 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) - # where( :postdate.lte => date_now ).where( :deadline => nil ).desc(:is_top, :postdate) - # 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) + # where( :postdate.lte => date_now ).where( :deadline => nil ).desc(:is_top, :postdate) + # 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) end @@ -94,7 +94,7 @@ class Bulletin def title @title ||= I18nVariable.first(:conditions => {:key => 'title', :language_value_id => self.id, :language_value_type => self.class}) rescue nil end - + def subtitle @subtitle ||= I18nVariable.first(:conditions => {:key => 'subtitle', :language_value_id => self.id, :language_value_type => self.class}) rescue nil end diff --git a/vendor/built_in_modules/announcement/app/views/panel/announcement/back_end/bulletins/_form.html.erb b/vendor/built_in_modules/announcement/app/views/panel/announcement/back_end/bulletins/_form.html.erb index 5c2b930b..93b7e75e 100644 --- a/vendor/built_in_modules/announcement/app/views/panel/announcement/back_end/bulletins/_form.html.erb +++ b/vendor/built_in_modules/announcement/app/views/panel/announcement/back_end/bulletins/_form.html.erb @@ -15,7 +15,7 @@ <%= t('announcement.刪除已上傳檔案') %> <% end %> - +
<%= f.label :title %> <%= f.fields_for :title, (@bulletin.new_record? ? @bulletin.build_title : @bulletin.title ) do |f| %> diff --git a/vendor/built_in_modules/announcement/app/views/panel/announcement/front_end/bulletins/index.html.erb b/vendor/built_in_modules/announcement/app/views/panel/announcement/front_end/bulletins/index.html.erb index 5717b071..52ec119a 100644 --- a/vendor/built_in_modules/announcement/app/views/panel/announcement/front_end/bulletins/index.html.erb +++ b/vendor/built_in_modules/announcement/app/views/panel/announcement/front_end/bulletins/index.html.erb @@ -18,7 +18,7 @@ <%= post.postdate %> <%= post.bulletin_category.i18n_variable[I18n.locale] %> - <%= link_to post.title, panel_announcement_front_end_bulletin_path(post) %> + <%= link_to post.title[I18n.locale], panel_announcement_front_end_bulletin_path(post) %> <%#= link_to post.title, panel_announcement_back_end_bulletin_path(post) %> diff --git a/vendor/built_in_modules/announcement/app/views/panel/announcement/front_end/bulletins/show.html.erb b/vendor/built_in_modules/announcement/app/views/panel/announcement/front_end/bulletins/show.html.erb index a15822db..3366451d 100644 --- a/vendor/built_in_modules/announcement/app/views/panel/announcement/front_end/bulletins/show.html.erb +++ b/vendor/built_in_modules/announcement/app/views/panel/announcement/front_end/bulletins/show.html.erb @@ -17,19 +17,19 @@
  • <%= t('announcement.title') %> - <%= @bulletin.title %> + <%= @bulletin.title[I18n.locale] %>
  • <%#= 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 %>
  • <%= t('announcement.subtitle') %> - <%= @bulletin.subtitle %> + <%= @bulletin.subtitle[I18n.locale] %>
  • <%= t('announcement.text') %> - <%= @bulletin.text %> + <%= @bulletin.text[I18n.locale] %>
  • @@ -54,4 +54,4 @@
  • -<%= link_back %> +<%#= link_back %> diff --git a/vendor/built_in_modules/announcement/app/views/panel/announcement/widget/bulletins/index.html.erb b/vendor/built_in_modules/announcement/app/views/panel/announcement/widget/bulletins/index.html.erb index 52255b2a..76c6edfb 100644 --- a/vendor/built_in_modules/announcement/app/views/panel/announcement/widget/bulletins/index.html.erb +++ b/vendor/built_in_modules/announcement/app/views/panel/announcement/widget/bulletins/index.html.erb @@ -10,8 +10,8 @@ <% @bulletins.each do |post| %>
  • <%= image_tag(post.image.url, :size => "290x130") if post.image.file %>
    -

    <%= post.title %>

    -

    <%= post.subtitle %>

    +

    <%= post.title[I18n.locale] %>

    +

    <%= post.subtitle[I18n.locale] %>

  • <% end %>