diff --git a/app/controllers/announcements_controller.rb b/app/controllers/announcements_controller.rb index 458ad7e..52b77b1 100644 --- a/app/controllers/announcements_controller.rb +++ b/app/controllers/announcements_controller.rb @@ -14,6 +14,37 @@ class AnnouncementsController < ApplicationController def index @type = 'index' Bulletin.remove_expired_status + params = @params = OrbitHelper.params + page = @page || Page.where(url: params['url']).first + @enable_search_flag = false + @image_version = 'orignal' + if page.methods.include? 'select_option_items'.to_sym + ModuleApp.all.select{|tmp| tmp.key.to_s=='announcement'}.each do |modile_app| + @show_option_items = modile_app.show_option_items rescue nil + end + I18n.with_locale(:en) do + page.select_option_items.each do |select_option_item| + if !(@show_option_items.nil?) + case select_option_item.field_name + when @show_option_items.keys[1].to_s + value = YAML.load(select_option_item.value) + if value[:en] == t('announcement.yes') + @enable_search_flag = true + end + when @show_option_items.keys[2].to_s + if tmp == t('announcement.small_size') + @image_version = 'thumb' + elsif tmp == t('announcement.medium_size') + @image_version = 'mobile' + elsif tmp == t('announcement.orignal_size') + @image_version = 'orignal' + end + end + end + end + end + end + sorted,total_pages = get_sorted_annc if sorted.nil? sorted = [] @@ -37,6 +68,13 @@ class AnnouncementsController < ApplicationController target = a.is_external_link ? "_blank" : "_self" doc = Nokogiri::HTML(a.title) title = doc.text.empty? ? 'no content' : doc.text + if @image_version == 'thumb' + image_url = a.image.thumb.url + elsif @image_version == 'mobile' + image_url = a.image.mobile.url + else + image_url = a.image.url + end { "department" => author, "bulletin_links" => links, @@ -53,7 +91,7 @@ class AnnouncementsController < ApplicationController "is_top" => (a.is_top? ? 1 : 0), "link_to_show" => link_to_show+"\" #{(link_to_show[0] == '/' rescue true) ? '' : 'target="_blank"'} title=\"#{title}", "target" => target, - "img_src" => a.image.thumb.url || "/assets/announcement-default.jpg", + "img_src" => image_url || "/assets/announcement-default.jpg", "img_description" => desc, "more" => t("announcement.more"), "view_count" => a.view_count @@ -62,7 +100,6 @@ class AnnouncementsController < ApplicationController a end end - params = OrbitHelper.params if anns.count == 0 && params.any?{|k,v| v.class==Array ? v.any?{|v1| v1.to_s.match(/\*|\(|\)/)} : v.to_s.match(/\*|\(|\)/)} return nil end @@ -417,11 +454,11 @@ class AnnouncementsController < ApplicationController ModuleApp.all.select{|tmp| tmp.key.to_s=='announcement'}.each do |modile_app| @show_options = modile_app.show_options rescue nil end - subpart.select_options.each do |select_option| - if !(@show_options.nil?) - value = YAML.load(select_option.value) - tmp = value[:en] - I18n.with_locale(:en) do + I18n.with_locale(:en) do + subpart.select_options.each do |select_option| + if !(@show_options.nil?) + value = YAML.load(select_option.value) + tmp = value[:en] case select_option.field_name when @show_options.keys[0].to_s if tmp == t('announcement.small_size') diff --git a/app/helpers/announcements_helper.rb b/app/helpers/announcements_helper.rb index 7b5ed6e..2f60a21 100644 --- a/app/helpers/announcements_helper.rb +++ b/app/helpers/announcements_helper.rb @@ -183,8 +183,8 @@ module AnnouncementsHelper .can_display_and_sorted.is_approved .filter_by_categories(categories,false).filter_by_tags(tags).to_a else - member_prfile = MemberProfile.any_in(:uid=>params[:uids]) - user_ids = member_prfile.map{|m| m.user.id rescue nil}.select{|id| !id.nil?} + member_profile = MemberProfile.any_in(:uid=>params[:uids]) + user_ids = member_profile.map{|m| m.user.id rescue nil}.select{|id| !id.nil?} announcements = Bulletin.where(:title.nin => ["",nil],:is_preview.in=>[false,nil],:create_user_id.in=>user_ids) .can_display_and_sorted.is_approved .filter_by_categories(categories,false).filter_by_tags(tags).to_a diff --git a/app/views/announcements/index.html.erb b/app/views/announcements/index.html.erb index 1afe306..2d923a1 100644 --- a/app/views/announcements/index.html.erb +++ b/app/views/announcements/index.html.erb @@ -1,21 +1,4 @@ -<% params = OrbitHelper.params - page = Page.where(url:params['url']).first - enable_search_flag = false - if page.methods.include? 'select_option_items'.to_sym - ModuleApp.all.select{|tmp| tmp.key.to_s=='announcement'}.each do |modile_app| - @show_option_items = modile_app.show_option_items rescue nil - end - page.select_option_items.each do |select_option_item| - if !(@show_option_items.nil?) && select_option_item.field_name == @show_option_items.keys[1].to_s - value = YAML.load(select_option_item.value) - if value[I18n.locale] == t('announcement.yes') - enable_search_flag = true - end - end - end - end -%> -<% if enable_search_flag %> +<% if @enable_search_flag %>