From ae2cbb728eafb09a6a757b2961195400f7a2cf45 Mon Sep 17 00:00:00 2001 From: "Matthew K. Fu JuYuan" Date: Wed, 4 Jul 2012 17:36:51 +0800 Subject: [PATCH] archive for announcement --- app/views/layouts/_side_bar.html.erb | 5 +++++ lib/orbit_core_lib.rb | 2 +- .../back_end/bulletin_categorys_controller.rb | 19 +++++++++++++------ .../back_end/bulletins_controller.rb | 17 ++++++++--------- .../back_end/bulletin_categorys_helper.rb | 4 ++++ .../app/models/bulletin_category.rb | 15 +++++++++++++-- .../_bulletin_category.html.erb | 2 +- .../bulletin_categorys/destroy.js.erb | 2 +- .../announcement/config/locales/zh_tw.yml | 5 +++++ 9 files changed, 51 insertions(+), 20 deletions(-) diff --git a/app/views/layouts/_side_bar.html.erb b/app/views/layouts/_side_bar.html.erb index 26925aee..c0507e67 100644 --- a/app/views/layouts/_side_bar.html.erb +++ b/app/views/layouts/_side_bar.html.erb @@ -75,3 +75,8 @@ <%#= content_tag :li, link_to(t('admin.tags'), admin_asset_tags_path), :class => active_for_action('/admin/asset_tags', 'index') %> <%# end -%> <%# end -%> +
+ <% flash.each do |key, msg| %> + <%= content_tag :span, msg, :class => [key, "notice label label-warning"] %> + <% end%> +
\ No newline at end of file diff --git a/lib/orbit_core_lib.rb b/lib/orbit_core_lib.rb index f3cd2cd5..8e333b7e 100644 --- a/lib/orbit_core_lib.rb +++ b/lib/orbit_core_lib.rb @@ -14,7 +14,7 @@ module OrbitCoreLib query1 = auth_object_space.any_in({sub_role_ids: sub_role_ids_ary}).excludes(blocked_user_ids: user.id) query2 = auth_object_space.any_of({all: true},{privilege_user_ids: user.id},{role_ids: user.role.id}).excludes(blocked_user_ids: user.id) result = (query1 + query2).uniq - result.collect{|t| t.obj_authable} + result.collect{|t| t.obj_authable}.delete_if{|val| val==nil} end end 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 b1ce1718..9ba78b90 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 @@ -107,13 +107,20 @@ class Panel::Announcement::BackEnd::BulletinCategorysController < OrbitBackendCo # DELETE /bulletins/1 # DELETE /bulletins/1.xml def destroy - @bulletin_category = BulletinCategory.find(params[:id]) - @bulletin_category.destroy + @bulletin_category = BulletinCategory.find(params[:id]).first + @bulletin_category.disable = @bulletin_category.disable ? false : true - respond_to do |format| - format.html { redirect_to(panel_announcement_back_end_bulletin_categorys_url) } - # format.xml { head :ok } - format.js + if @bulletin_category.save! + respond_to do |format| + flash[:notice] = t("bulletin_category.update_success") + # flash[:error] += @bulletin_category.disable ? t("bulletin_category.disable_change_to_true") : t("bulletin_category.disable_change_to_false") + format.html { redirect_to(panel_announcement_back_end_bulletin_categorys_url) } + # format.xml { head :ok } + format.js + end + else + flash[:error] = t("bulletin_category.update_failed") + format.html { render :action => "index" } end end end 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 f47b41bb..1b6b4336 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 @@ -3,6 +3,7 @@ class Panel::Announcement::BackEnd::BulletinsController < OrbitBackendController layout 'new_admin' before_filter :authenticate_user! + before_filter :get_categorys ,:only => [ :new,:edit,:update] # before_filter :for_admin_only,:only => [:] # before_filter :for_app_manager,:only => [:index,:show,] before_filter :for_app_sub_manager,:except => [:index,:show,:get_sorted_and_filtered_bulletins] @@ -83,15 +84,10 @@ class Panel::Announcement::BackEnd::BulletinsController < OrbitBackendController # @bulletin.bulletin_files.build # @bulletin.bulletin_files.new - if get_categorys.empty? - flash[:alert] = t("announcement.error.no_avilb_cate_for_posting") - redirect_to :action => :index - else get_tags respond_to do |format| format.html # new.html.erb format.xml { render :xml => @bulletin } - end end end @@ -105,7 +101,6 @@ class Panel::Announcement::BackEnd::BulletinsController < OrbitBackendController @link_url = panel_announcement_back_end_bulletin_path(@bulletin) - get_categorys get_tags end end @@ -268,7 +263,7 @@ class Panel::Announcement::BackEnd::BulletinsController < OrbitBackendController format.xml { head :ok } else get_tags - get_categorys + format.html { render :action => "edit" } format.xml { render :xml => @bulletin.errors, :status => :unprocessable_entity } end @@ -333,9 +328,13 @@ class Panel::Announcement::BackEnd::BulletinsController < OrbitBackendController @bulletin_categorys = [] #@unit_list_for_anc = UnitListForAnc.all if(is_manager? || is_admin?) - @bulletin_categorys = (id ? BulletinCategory.find(id).to_a : BulletinCategory.excludes('disabled' => true)) + @bulletin_categorys = (id ? BulletinCategory.available.find(id).to_a : BulletinCategory.available) elsif is_sub_manager? - @bulletin_categorys = BulletinCategory.authed_for_user(current_user,'submit') + @bulletin_categorys = BulletinCategory.available.authed_for_user(current_user,'submit') + end + if @bulletin_categorys.empty? && params[:action] != "index" + flash[:alert] = t("announcement.error.no_avilb_cate_for_posting") + redirect_to :action => :index end end diff --git a/vendor/built_in_modules/announcement/app/helpers/panel/announcement/back_end/bulletin_categorys_helper.rb b/vendor/built_in_modules/announcement/app/helpers/panel/announcement/back_end/bulletin_categorys_helper.rb index 92604985..ea413b54 100644 --- a/vendor/built_in_modules/announcement/app/helpers/panel/announcement/back_end/bulletin_categorys_helper.rb +++ b/vendor/built_in_modules/announcement/app/helpers/panel/announcement/back_end/bulletin_categorys_helper.rb @@ -13,4 +13,8 @@ include ActionView::Helpers::UrlHelper link_to t('announcement.bulletin.cate_auth'),admin_object_auth_ob_auth_path(oa) end + def show_toggle_archive_btn(bulletin_category) + bulletin_category.disable ? t("bulletin_category.disable_change_to_true") : t("bulletin_category.disable_change_to_false") + end + end \ No newline at end of file diff --git a/vendor/built_in_modules/announcement/app/models/bulletin_category.rb b/vendor/built_in_modules/announcement/app/models/bulletin_category.rb index feb39edb..a5686cc1 100644 --- a/vendor/built_in_modules/announcement/app/models/bulletin_category.rb +++ b/vendor/built_in_modules/announcement/app/models/bulletin_category.rb @@ -14,11 +14,22 @@ class BulletinCategory field :key field :display - + field :disable,type: Boolean,:default => false + has_one :i18n_variable, :as => :language_value, :autosave => true, :dependent => :destroy - has_many :bulletins,:dependent => :destroy + has_many :bulletins + scope :available,where(disable: false) + + def self.find(*args) + if args ==[:all] + unscoped + else + unscoped.find(args) + end + end + def pp_object i18n_variable[I18n.locale] end diff --git a/vendor/built_in_modules/announcement/app/views/panel/announcement/back_end/bulletin_categorys/_bulletin_category.html.erb b/vendor/built_in_modules/announcement/app/views/panel/announcement/back_end/bulletin_categorys/_bulletin_category.html.erb index 6b98e466..58a9a5f9 100644 --- a/vendor/built_in_modules/announcement/app/views/panel/announcement/back_end/bulletin_categorys/_bulletin_category.html.erb +++ b/vendor/built_in_modules/announcement/app/views/panel/announcement/back_end/bulletin_categorys/_bulletin_category.html.erb @@ -6,7 +6,7 @@