From ad429af58c3e6f271a14b3959883adeb8e464562 Mon Sep 17 00:00:00 2001 From: Rueshyna Date: Wed, 14 Nov 2012 12:01:18 +0800 Subject: [PATCH] modified announcement json format but it have some bugs... --- .../back_end/bulletins_controller.rb | 50 +++++++++++-------- .../announcement/config/routes.rb | 1 + 2 files changed, 30 insertions(+), 21 deletions(-) diff --git a/vendor/built_in_modules/announcement/app/controllers/panel/announcement/back_end/bulletins_controller.rb b/vendor/built_in_modules/announcement/app/controllers/panel/announcement/back_end/bulletins_controller.rb index 679a6b05..c06892a1 100644 --- a/vendor/built_in_modules/announcement/app/controllers/panel/announcement/back_end/bulletins_controller.rb +++ b/vendor/built_in_modules/announcement/app/controllers/panel/announcement/back_end/bulletins_controller.rb @@ -23,11 +23,26 @@ class Panel::Announcement::BackEnd::BulletinsController < OrbitBackendController end def get_bulletins_json - @bulletins = Bulletin.all - @data = Hash.new - @data[I18n.t("category")] = Hash.new + categorys = BulletinCategory.all + data = Array.new - @bulletins.each do |b| + categorys.each do |c| + data << { + category: c.title + link: path_get_bulletin_json(c) + } + end + + #render :json => @data.to_json + #to print readable json + render :json => JSON.pretty_generate(@data) + end + + def get_bulletin_json + bulletin = Bulletin.find(params[:category_id]) + data = Array.new + + bulletin.each do |b| deadline = b.deadline if not deadline.nil? @@ -35,24 +50,17 @@ class Panel::Announcement::BackEnd::BulletinsController < OrbitBackendController else deadline = I18n.t("no_deadline") end - if @data[I18n.t("category")][b.bulletin_category.title].nil? - @data[I18n.t("category")][b.bulletin_category.title] = Array.new - @data[I18n.t("category")][b.bulletin_category.title] << { title: b.title, - postdate: display_date_time(b.postdate), - deadline: deadline, - tag: b.sorted_tags.to_a, - } - else - @data[I18n.t("category")][b.bulletin_category.title] << { title: b.title, - postdate: display_date_time(b.postdate), - deadline: deadline, - tag: b.sorted_tags.to_a, - } - end + + data << { + title: b.title, + link: panel_announcement_front_end_bulletin_path(bulletin, :category_id => b.bulletin_category.id) + postdate: display_date_time(b.postdate), + deadline: deadline, + tag: b.sorted_tags.to_a, + } end - #render :json => @data.to_json - #to print readable json - render :json => JSON.pretty_generate(@data) + + render :json => JSON.pretty_generate(data) end def index diff --git a/vendor/built_in_modules/announcement/config/routes.rb b/vendor/built_in_modules/announcement/config/routes.rb index 857a4ac6..5b9dd6a4 100644 --- a/vendor/built_in_modules/announcement/config/routes.rb +++ b/vendor/built_in_modules/announcement/config/routes.rb @@ -12,6 +12,7 @@ Rails.application.routes.draw do match "approve/:bulletin_id" => "approvals#approve",:as => :approve,:via => :post match "link_quick_add/:bulletin_id" => "bulletins#link_quick_add" ,:as => :link_quick_add match "link_quick_edit/:bulletin_id" => "bulletins#link_quick_edit" ,:as => :link_quick_edit + match 'get_bulletin_json/:category_id' => "bulletins#get_bulletin_json", :as => :get_bulletin_json member do get 'load_quick_edit' end