diff --git a/app/controllers/admin/announcements_controller.rb b/app/controllers/admin/announcements_controller.rb index 76dc253..98dcae1 100644 --- a/app/controllers/admin/announcements_controller.rb +++ b/app/controllers/admin/announcements_controller.rb @@ -17,13 +17,24 @@ class Admin::AnnouncementsController < OrbitAdminController @categories = @module_app.categories.enabled @filter_fields = filter_fields(@categories, @tags) @table_fields = [:status, :category, :title, :start_date, :end_date, :last_modified] - - @bulletins = Bulletin.where(:title.ne => "",:is_preview.in=>[false,nil]) + if AnnouncementSetting.first.is_display_edit_only && !current_user.is_admin? && !current_user.is_manager?(@module_app) + current_user_is_sub_manager = !current_user.is_manager?(@module_app) && (current_user.is_sub_manager?(@module_app) || current_user.is_sub_manager_with_role?(@module_app)) rescue false + if current_user_is_sub_manager + @bulletins = Bulletin.where(:create_user_id=>current_user.id,:title.ne => "",:is_preview.in=>[false,nil]) .order_by(sort) .with_categories(filters("category")) .with_tags(filters("tag")) .with_status(filters("status")) - + else + @bulletins = Bulletin.where(:uid=>nil) + end + else + @bulletins = Bulletin.where(:title.ne => "",:is_preview.in=>[false,nil]) + .order_by(sort) + .with_categories(filters("category")) + .with_tags(filters("tag")) + .with_status(filters("status")) + end @bulletins = search_data(@bulletins,[:title]).page(params[:page]).per(10) if request.xhr? @@ -102,7 +113,7 @@ class Admin::AnnouncementsController < OrbitAdminController def updatesettings setting = @announcement_setting - ids = params['announcement_setting']['anns_status_settings'].collect do |i,v| + ids = params['announcement_setting']['anns_status_settings'].to_a.collect do |i,v| v['_id'] end.compact AnnsStatusSetting.where(:id.nin=>ids).destroy diff --git a/app/models/announcement_setting.rb b/app/models/announcement_setting.rb index 5e76839..f1c6af1 100644 --- a/app/models/announcement_setting.rb +++ b/app/models/announcement_setting.rb @@ -6,6 +6,7 @@ class AnnouncementSetting field :pro_enabled, type: Boolean, :default => false field :approvers, type: Array, :default => [] field :email_to, type: Array, :default => ["admins","managers","approvers"] + field :is_display_edit_only, type: Boolean, :default => false has_many :anns_status_settings, :autosave => true, :dependent => :destroy accepts_nested_attributes_for :anns_status_settings, :allow_destroy => true def self.check_limit_for_user(user_id, b_id = nil) diff --git a/app/views/admin/announcements/settings.html.erb b/app/views/admin/announcements/settings.html.erb index cbe030c..d95a3f0 100644 --- a/app/views/admin/announcements/settings.html.erb +++ b/app/views/admin/announcements/settings.html.erb @@ -121,6 +121,12 @@
<%= t("announcement.click_on_submit") %>
<%= form_for @setting, url: (@setting.new_record? ? admin_announcement_createsettings_path : admin_announcement_updatesettings_path), html: {class: "form-horizontal main-forms"} do |f| %>
+
+ <%= f.label :is_display_edit_only, t("announcement.is_display_edit_only"), :class => "control-label muted" %> +
+ <%= f.check_box :is_display_edit_only %> +
+
<%= f.label :top_limit, t("announcement.top_limit"), :class => "control-label muted" %>
diff --git a/config/locales/en.yml b/config/locales/en.yml index 757d271..12a8586 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -113,3 +113,4 @@ en: external_link_hint: "Make sure URL starts with http://" display_subtitle: Display Subtitle in Content Page display_img: Display Cover Image in Content Page + is_display_edit_only: Only display editable announcements diff --git a/config/locales/zh_tw.yml b/config/locales/zh_tw.yml index 971ee3d..0997549 100644 --- a/config/locales/zh_tw.yml +++ b/config/locales/zh_tw.yml @@ -117,3 +117,4 @@ zh_tw: external_link_hint: "確定連結開頭為http://" display_subtitle: 內容頁顯示副標題 display_img: 內容頁顯示封面圖片 + is_display_edit_only: 只顯示可更新的公告