From 114ca5493acfc5e042ccba1c8c996afd023252cb Mon Sep 17 00:00:00 2001 From: Rueshyna Date: Wed, 28 Nov 2012 13:43:48 +0800 Subject: [PATCH] replace rss format with json in announcement --- .../back_end/bulletin_categorys_controller.rb | 13 +++++-- .../front_end/bulletins_controller.rb | 35 ++++++++++--------- .../front_end/bulletins/index.rss.builder | 14 ++++---- .../announcement/config/routes.rb | 6 ++-- 4 files changed, 40 insertions(+), 28 deletions(-) diff --git a/vendor/built_in_modules/announcement/app/controllers/panel/announcement/back_end/bulletin_categorys_controller.rb b/vendor/built_in_modules/announcement/app/controllers/panel/announcement/back_end/bulletin_categorys_controller.rb index 0151d4c0..1802db62 100644 --- a/vendor/built_in_modules/announcement/app/controllers/panel/announcement/back_end/bulletin_categorys_controller.rb +++ b/vendor/built_in_modules/announcement/app/controllers/panel/announcement/back_end/bulletin_categorys_controller.rb @@ -1,6 +1,7 @@ class Panel::Announcement::BackEnd::BulletinCategorysController < OrbitBackendController include OrbitControllerLib::DivisionForDisable - before_filter :for_app_manager,:except => [:index,:get_categorys_json,:get_bulletins_json] + # if someone want to use json format replace with rss, please add :get_bulletins_json to below + before_filter :for_app_manager,:except => [:index,:get_categorys_json] def index @bulletin_categorys = get_categories_for_index("BulletinCategory") @@ -22,7 +23,15 @@ class Panel::Announcement::BackEnd::BulletinCategorysController < OrbitBackendCo categorys.each do |c| data << { category: c.title, - link: "http://#{request.host_with_port}#{panel_announcement_back_end_bulletin_category_get_bulletins_json_path(c)}" + # this is a json format + # link: "http://#{request.host_with_port}#{panel_announcement_back_end_bulletin_category_get_bulletins_json_path(c)}" + # remember to uncommand a rule in route.rb, too + link: "#{url_for( :action => "index", + :controller => "panel/announcement/front_end/bulletins", + :format => :rss, + :only_path => false, + :inner=>true, + :category_id => c )}" } end diff --git a/vendor/built_in_modules/announcement/app/controllers/panel/announcement/front_end/bulletins_controller.rb b/vendor/built_in_modules/announcement/app/controllers/panel/announcement/front_end/bulletins_controller.rb index 8fa7af68..456d57d9 100644 --- a/vendor/built_in_modules/announcement/app/controllers/panel/announcement/front_end/bulletins_controller.rb +++ b/vendor/built_in_modules/announcement/app/controllers/panel/announcement/front_end/bulletins_controller.rb @@ -1,10 +1,10 @@ class Panel::Announcement::FrontEnd::BulletinsController < OrbitWidgetController - + def initialize super @app_title = 'announcement' end - + # GET /bulletins # GET /bulletins.xml def index_bulletins_by_unit @@ -14,14 +14,15 @@ class Panel::Announcement::FrontEnd::BulletinsController < OrbitWidgetController end def index - @item = Page.find(params[:page_id]) - - if @item.frontend_data_count - @page_num = @item.frontend_data_count - else - @page_num = 15 - end - @frontend_style = @item.frontend_style + @item = Page.find(params[:page_id]) rescue nil + if @item + if @item.frontend_data_count + @page_num = @item.frontend_data_count + else + @page_num = 15 + end + @frontend_style = @item.frontend_style + end @page = Page.find(params[:page_id]) rescue nil if !params[:search_query].blank? @@ -54,9 +55,9 @@ class Panel::Announcement::FrontEnd::BulletinsController < OrbitWidgetController end impressionist(@tag) if @tag end - + end - + def show @page = Page.find(params[:page_id]) rescue nil if params[:preview] == "true" @@ -71,22 +72,22 @@ class Panel::Announcement::FrontEnd::BulletinsController < OrbitWidgetController render :text => "
#{t('sys.can_not_display_due_to_no_context')}
".html_safe end else - render :nothing => true, :status => 403 + render :nothing => true, :status => 403 end end end - + def preview_content @bulletin = Bulletin.find params[:id] rescue nil @bulletin = Preview.find(params[:id]).get_virtual_object if @bulletin.nil? get_categorys end - + protected - + def get_categorys @bulletin_categorys = BulletinCategory.all end - + end diff --git a/vendor/built_in_modules/announcement/app/views/panel/announcement/front_end/bulletins/index.rss.builder b/vendor/built_in_modules/announcement/app/views/panel/announcement/front_end/bulletins/index.rss.builder index ca4719c6..40698bfc 100644 --- a/vendor/built_in_modules/announcement/app/views/panel/announcement/front_end/bulletins/index.rss.builder +++ b/vendor/built_in_modules/announcement/app/views/panel/announcement/front_end/bulletins/index.rss.builder @@ -1,13 +1,13 @@ xml.instruct! :xml, :version => "1.0" xml.rss :version => "2.0" do xml.channel do - if @current_category - xml.title @current_category.title_translations[I18n.locale.to_s] - else - xml.title t('announcement.announcement') - end + if @current_category + xml.title @current_category.title_translations[I18n.locale.to_s] + else + xml.title t('announcement.announcement') + end xml.link url_for(:action=>"index", :controller=>"panel/announcement/front_end/bulletins",:format=> :rss,:only_path=>false,:inner=>true) - + for bulletin in @bulletins xml.item do xml.title bulletin.title_translations[I18n.locale.to_s] @@ -18,4 +18,4 @@ xml.rss :version => "2.0" do end end end -end \ No newline at end of file +end diff --git a/vendor/built_in_modules/announcement/config/routes.rb b/vendor/built_in_modules/announcement/config/routes.rb index 35500ac3..8c11ebd0 100644 --- a/vendor/built_in_modules/announcement/config/routes.rb +++ b/vendor/built_in_modules/announcement/config/routes.rb @@ -6,7 +6,7 @@ Rails.application.routes.draw do match 'approval_setting' => "approvals#setting" ,:as => :approval_setting,:via => :get match 'approval_setting' => "approvals#update_setting" ,:as => :approval_setting,:via => :post match 'approval_setting' => "approvals#user_list" ,:as => :approval_user_list,:via => :put - #match 'get_bulletins_json' => "bulletins#get_bulletins_json" ,:as => :bulletins_json_list,:via => :get + resources :bulletins do match "approve/:bulletin_id" => "approvals#preview_and_approve",:as => :approval_preview,:via => :put match "approve/:bulletin_id" => "approvals#approve",:as => :approve,:via => :post @@ -29,7 +29,9 @@ Rails.application.routes.draw do collection do get 'get_categorys_json' end - match "get_bulletins_json/" => "bulletin_categorys#get_bulletins_json", :as => :get_bulletins_json + # if want to use json + # please uncommand below line + # match "get_bulletins_json/" => "bulletin_categorys#get_bulletins_json", :as => :get_bulletins_json end resources :bulletin_links, :controller => 'bulletin_links' do