Add only display editable announcement in the backend setting.

This commit is contained in:
BoHung Chiu 2020-05-15 22:25:58 +08:00
parent 5c7e1fa3dd
commit 308302fdb9
5 changed files with 24 additions and 4 deletions

View File

@ -17,13 +17,24 @@ class Admin::AnnouncementsController < OrbitAdminController
@categories = @module_app.categories.enabled @categories = @module_app.categories.enabled
@filter_fields = filter_fields(@categories, @tags) @filter_fields = filter_fields(@categories, @tags)
@table_fields = [:status, :category, :title, :start_date, :end_date, :last_modified] @table_fields = [:status, :category, :title, :start_date, :end_date, :last_modified]
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]) @bulletins = Bulletin.where(:title.ne => "",:is_preview.in=>[false,nil])
.order_by(sort) .order_by(sort)
.with_categories(filters("category")) .with_categories(filters("category"))
.with_tags(filters("tag")) .with_tags(filters("tag"))
.with_status(filters("status")) .with_status(filters("status"))
end
@bulletins = search_data(@bulletins,[:title]).page(params[:page]).per(10) @bulletins = search_data(@bulletins,[:title]).page(params[:page]).per(10)
if request.xhr? if request.xhr?
@ -102,7 +113,7 @@ class Admin::AnnouncementsController < OrbitAdminController
def updatesettings def updatesettings
setting = @announcement_setting 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'] v['_id']
end.compact end.compact
AnnsStatusSetting.where(:id.nin=>ids).destroy AnnsStatusSetting.where(:id.nin=>ids).destroy

View File

@ -6,6 +6,7 @@ class AnnouncementSetting
field :pro_enabled, type: Boolean, :default => false field :pro_enabled, type: Boolean, :default => false
field :approvers, type: Array, :default => [] field :approvers, type: Array, :default => []
field :email_to, type: Array, :default => ["admins","managers","approvers"] 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 has_many :anns_status_settings, :autosave => true, :dependent => :destroy
accepts_nested_attributes_for :anns_status_settings, :allow_destroy => true accepts_nested_attributes_for :anns_status_settings, :allow_destroy => true
def self.check_limit_for_user(user_id, b_id = nil) def self.check_limit_for_user(user_id, b_id = nil)

View File

@ -121,6 +121,12 @@
<div id="notification"><%= t("announcement.click_on_submit") %></div> <div id="notification"><%= t("announcement.click_on_submit") %></div>
<%= form_for @setting, url: (@setting.new_record? ? admin_announcement_createsettings_path : admin_announcement_updatesettings_path), html: {class: "form-horizontal main-forms"} do |f| %> <%= form_for @setting, url: (@setting.new_record? ? admin_announcement_createsettings_path : admin_announcement_updatesettings_path), html: {class: "form-horizontal main-forms"} do |f| %>
<div class="input-area"> <div class="input-area">
<div class="control-group">
<%= f.label :is_display_edit_only, t("announcement.is_display_edit_only"), :class => "control-label muted" %>
<div class="controls">
<%= f.check_box :is_display_edit_only %>
</div>
</div>
<div class="control-group"> <div class="control-group">
<%= f.label :top_limit, t("announcement.top_limit"), :class => "control-label muted" %> <%= f.label :top_limit, t("announcement.top_limit"), :class => "control-label muted" %>
<div class="controls"> <div class="controls">

View File

@ -113,3 +113,4 @@ en:
external_link_hint: "Make sure URL starts with http://" external_link_hint: "Make sure URL starts with http://"
display_subtitle: Display Subtitle in Content Page display_subtitle: Display Subtitle in Content Page
display_img: Display Cover Image in Content Page display_img: Display Cover Image in Content Page
is_display_edit_only: Only display editable announcements

View File

@ -117,3 +117,4 @@ zh_tw:
external_link_hint: "確定連結開頭為http://" external_link_hint: "確定連結開頭為http://"
display_subtitle: 內容頁顯示副標題 display_subtitle: 內容頁顯示副標題
display_img: 內容頁顯示封面圖片 display_img: 內容頁顯示封面圖片
is_display_edit_only: 只顯示可更新的公告