fix some error and add new feature to let user can set role's is_top limit
and is_hot limit
This commit is contained in:
parent
5ab900e6e3
commit
6a5712500d
|
@ -102,6 +102,10 @@ class Admin::AnnouncementsController < OrbitAdminController
|
|||
|
||||
def updatesettings
|
||||
setting = @announcement_setting
|
||||
ids = params['announcement_setting']['anns_status_settings'].collect do |i,v|
|
||||
v['_id']
|
||||
end.compact
|
||||
AnnsStatusSetting.where(:id.nin=>ids).destroy
|
||||
setting.update_attributes(settings_params)
|
||||
setting.save
|
||||
redirect_to admin_announcement_settings_path
|
||||
|
@ -144,6 +148,7 @@ class Admin::AnnouncementsController < OrbitAdminController
|
|||
@statuses = []
|
||||
@bulletin = Bulletin.new
|
||||
@bulletin.email_sentdate = Time.now
|
||||
@reach_limit = @bulletin.check_status_limit(current_user,true)
|
||||
end
|
||||
|
||||
def create
|
||||
|
@ -195,6 +200,7 @@ class Admin::AnnouncementsController < OrbitAdminController
|
|||
|
||||
def edit
|
||||
if can_edit_or_delete?(@bulletin)
|
||||
@reach_limit = @bulletin.check_status_limit(current_user,true)
|
||||
@tags = @module_app.tags
|
||||
@categories = @module_app.categories.enabled
|
||||
@statuses = []
|
||||
|
@ -223,6 +229,7 @@ class Admin::AnnouncementsController < OrbitAdminController
|
|||
end
|
||||
|
||||
bulletin.update_attributes(bps)
|
||||
bulletin.update_user_id = current_user.id
|
||||
if bulletin.rejected
|
||||
bulletin.reapproval = true
|
||||
bulletin.save
|
||||
|
@ -231,7 +238,10 @@ class Admin::AnnouncementsController < OrbitAdminController
|
|||
bulletin.save
|
||||
end
|
||||
build_email(bulletin)
|
||||
redirect_to params['referer_url']
|
||||
now_bulletin_page = Bulletin.where(:title.ne => "",:is_preview.in=>[false,nil])
|
||||
.order_by(sort).map(&:id).map.with_index.select{|v,i| v==bulletin.id}[0][1] rescue nil
|
||||
now_bulletin_page = now_bulletin_page.nil? ? 0 : ((now_bulletin_page+1).to_f/10).ceil
|
||||
redirect_to "/zh_tw/admin/announcements?page=#{now_bulletin_page}"
|
||||
end
|
||||
|
||||
def destroy
|
||||
|
|
|
@ -133,8 +133,9 @@ class AnnouncementsController < ApplicationController
|
|||
sorted_anns = sorted_anns.sample(widget_data_count)
|
||||
end
|
||||
else
|
||||
sorted_anns = Bulletin.find(anns_cache.first.filter_result)
|
||||
sorted_anns = sorted_anns.sort_by{|v| [(v.is_top==true ? 1 : 0),v['postdate']]}.reverse
|
||||
sorted_ann_ids = anns_cache.first.filter_result
|
||||
sorted_anns = Bulletin.find(sorted_ann_ids)
|
||||
sorted_anns = sorted_ann_ids.map{|v1| sorted_anns.find{|v2| v2.id==v1}}
|
||||
end
|
||||
if (defined? SiteFeed).nil? || is_random
|
||||
anns = sorted_anns.map{|v| data_to_human_type(v)}
|
||||
|
|
|
@ -100,19 +100,19 @@ module AnnouncementsHelper
|
|||
end
|
||||
fans
|
||||
end
|
||||
def filter_by_keywords(sorted,keywords,postdate)
|
||||
sorted.select{|anns|
|
||||
flag1 = true
|
||||
if !keywords.nil?
|
||||
if anns["source-site"].present?
|
||||
title = Nokogiri::HTML(anns["title"].to_s).text
|
||||
else
|
||||
title = Nokogiri::HTML(anns.title.to_s).text
|
||||
end
|
||||
flag1 = title.include?(keywords.to_s)
|
||||
end
|
||||
flag1
|
||||
}
|
||||
def filter_by_keywords(sorted,keywords)
|
||||
if !keywords.nil?
|
||||
sorted.select{|anns|
|
||||
if anns["source-site"].present?
|
||||
title = Nokogiri::HTML(anns["title"].to_s).text
|
||||
else
|
||||
title = Nokogiri::HTML(anns.title.to_s).text
|
||||
end
|
||||
title.include?(keywords.to_s)
|
||||
}
|
||||
else
|
||||
sorted
|
||||
end
|
||||
end
|
||||
def get_sorted_annc
|
||||
params = OrbitHelper.params
|
||||
|
@ -145,9 +145,9 @@ module AnnouncementsHelper
|
|||
else
|
||||
all_sorted = feeds_anns.sort_by{|v| v["postdate"] }
|
||||
end
|
||||
all_filter = filter_by_keywords(all_sorted,params[:keywords],params[:postdate])
|
||||
all_filter = filter_by_keywords(all_sorted,params[:keywords])
|
||||
else
|
||||
all_filter = filter_by_keywords(announcements,params[:keywords],params[:postdate])
|
||||
all_filter = filter_by_keywords(announcements,params[:keywords])
|
||||
end
|
||||
if page_data_count != 0
|
||||
sorted = all_filter[(page_number-1)*page_data_count...page_number*page_data_count]
|
||||
|
|
|
@ -6,7 +6,8 @@ class AnnouncementSetting
|
|||
field :pro_enabled, type: Boolean, :default => false
|
||||
field :approvers, type: Array, :default => []
|
||||
field :email_to, type: Array, :default => ["admins","managers","approvers"]
|
||||
|
||||
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)
|
||||
limit = self.first.top_limit rescue 0
|
||||
return true if limit == 0
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
class AnnsStatusSetting
|
||||
include Mongoid::Document
|
||||
field :role_id
|
||||
field :status
|
||||
field :top_limit
|
||||
belongs_to :announcement_setting
|
||||
end
|
|
@ -54,7 +54,42 @@ class Bulletin
|
|||
scope :is_approved, ->{where(:approved => true)}
|
||||
|
||||
before_create :set_expire
|
||||
|
||||
before_save :check_limit
|
||||
def check_limit
|
||||
check_status_limit(update_user)
|
||||
end
|
||||
def check_status_limit(user,check_only=false)
|
||||
role_ids = user.member_profile.roles.map(&:id) rescue []
|
||||
status_settings = (role_ids.collect do |role_id|
|
||||
AnnouncementSetting.first.anns_status_settings.select{|v| v.role_id.to_s == role_id.to_s}
|
||||
end.flatten rescue [])
|
||||
reach_limit = []
|
||||
if status_settings.count != 0
|
||||
reach_limit = status_settings.collect do |status_setting|
|
||||
status = status_setting.status
|
||||
if status_setting.top_limit.to_i <= Bulletin.where(:update_user_id.in => Role.find(status_setting.role_id).member_profiles.collect(&:user).flatten.uniq.map{|v| v.id},status => true).count
|
||||
if !check_only
|
||||
if self[status] && !Bulletin.where(id:self.id).first[status]
|
||||
self[status] = false
|
||||
nil
|
||||
end
|
||||
else
|
||||
status
|
||||
end
|
||||
else
|
||||
nil
|
||||
end
|
||||
end.compact
|
||||
reach_limit = reach_limit.group_by{|v| v}.collect do |k,v|
|
||||
if v.count >= user.member_profile.roles.count
|
||||
k
|
||||
else
|
||||
nil
|
||||
end
|
||||
end.compact
|
||||
end
|
||||
reach_limit
|
||||
end
|
||||
def slug_title
|
||||
doc = Nokogiri::HTML(self.title)
|
||||
title = doc.text.gsub('/','-')
|
||||
|
|
|
@ -3,6 +3,17 @@
|
|||
<%= stylesheet_link_tag "lib/fileupload" %>
|
||||
<%= stylesheet_link_tag "lib/main-list" %>
|
||||
<% end %>
|
||||
<style type="text/css">
|
||||
.reach_limit{
|
||||
background: #a90c0c;
|
||||
color: white;
|
||||
padding: 4px 12px;
|
||||
font-family: 'Varela Round';
|
||||
letter-spacing: -.4px;
|
||||
cursor: default;
|
||||
display: inline-block;
|
||||
}
|
||||
</style>
|
||||
<% content_for :page_specific_javascript do %>
|
||||
<%= javascript_include_tag "lib/bootstrap-fileupload" %>
|
||||
<%= javascript_include_tag "lib/bootstrap-datetimepicker" %>
|
||||
|
@ -87,17 +98,28 @@
|
|||
|
||||
<!-- Status Module -->
|
||||
<div class="tab-pane fade" id="status">
|
||||
|
||||
<!-- Status -->
|
||||
<div class="control-group">
|
||||
<label class="control-label muted"><%= t(:status) %></label>
|
||||
<div class="controls" data-toggle="buttons-checkbox">
|
||||
<label class="checkbox inline btn <%= 'active' if @bulletin.is_top? || (!@bulletin.top_end_date.nil? && @bulletin.top_end_date > Time.now) %>">
|
||||
<%= f.check_box :is_top %> <%= t(:top) %>
|
||||
</label>
|
||||
<label class="checkbox inline btn <%= 'active' if @bulletin.is_hot? %>">
|
||||
<%= f.check_box :is_hot %> <%= t(:hot) %>
|
||||
</label>
|
||||
<% if !(@reach_limit.include?('is_top') && @bulletin.is_top != true) || current_user.is_admin? %>
|
||||
<label class="checkbox inline btn <%= 'active' if @bulletin.is_top? || (!@bulletin.top_end_date.nil? && @bulletin.top_end_date > Time.now) %>">
|
||||
<%= f.check_box :is_top %> <%= t(:top) %>
|
||||
</label>
|
||||
<% else %>
|
||||
<label class="reach_limit">
|
||||
<%= t(:top) %>
|
||||
</label>
|
||||
<% end %>
|
||||
<% if !(@reach_limit.include?('is_hot') && @bulletin.is_hot != true) || current_user.is_admin? %>
|
||||
<label class="checkbox inline btn <%= 'active' if @bulletin.is_hot? %>">
|
||||
<%= f.check_box :is_hot %> <%= t(:hot) %>
|
||||
</label>
|
||||
<% else %>
|
||||
<label class="reach_limit">
|
||||
<%= t(:hot) %>
|
||||
</label>
|
||||
<% end %>
|
||||
<label class="checkbox inline btn <%= 'active' if @bulletin.is_hidden? %>">
|
||||
<%= f.check_box :is_hidden %> <%= t(:hide) %>
|
||||
</label>
|
||||
|
|
|
@ -24,7 +24,7 @@
|
|||
</td>
|
||||
<td>
|
||||
<% if b.expired? || (b.category.disable rescue false)%>
|
||||
<%= b.title %>
|
||||
<%= b.title.html_safe %>
|
||||
<% else %>
|
||||
<a href="<%= page_for_bulletin(b) %>" target="_blank"><%= b.title.html_safe %></a>
|
||||
<% end %>
|
||||
|
|
|
@ -1,94 +1,203 @@
|
|||
<style type="text/css">
|
||||
#notification{
|
||||
background-color: #ececec;
|
||||
font-size: 14px;
|
||||
left: 40%;
|
||||
padding: 10px;
|
||||
position: absolute;
|
||||
text-align: center;
|
||||
top: 40px;
|
||||
width: auto;
|
||||
z-index: 1200;
|
||||
display: none;
|
||||
}
|
||||
.badge-info{
|
||||
margin-left: 10px;
|
||||
}
|
||||
#approver-list{
|
||||
list-style: none;
|
||||
margin-left: 5px;
|
||||
}
|
||||
#approver-list li {
|
||||
border-bottom: 1px solid #efefef;
|
||||
margin-bottom: 10px;
|
||||
padding-bottom: 10px;
|
||||
}
|
||||
#approver-list .approver-avatar{
|
||||
width: 60px;
|
||||
height: 60px;
|
||||
border-radius: 50px;
|
||||
margin-right: 20px;
|
||||
}
|
||||
#approver-list .approver-check{
|
||||
vertical-align: middle;
|
||||
margin-top: 25px;
|
||||
}
|
||||
#approver-list .approver-check input{
|
||||
margin-right: 5px;
|
||||
vertical-align: middle;
|
||||
}
|
||||
#approver-list .approver-check label{
|
||||
display: inline;
|
||||
vertical-align: middle;
|
||||
}
|
||||
#approver-list .approver-title{
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
#notification{
|
||||
background-color: #ececec;
|
||||
font-size: 14px;
|
||||
left: 40%;
|
||||
padding: 10px;
|
||||
position: absolute;
|
||||
text-align: center;
|
||||
top: 40px;
|
||||
width: auto;
|
||||
z-index: 1200;
|
||||
display: none;
|
||||
}
|
||||
.badge-info{
|
||||
margin-left: 10px;
|
||||
}
|
||||
#approver-list{
|
||||
list-style: none;
|
||||
margin-left: 5px;
|
||||
}
|
||||
#approver-list li {
|
||||
border-bottom: 1px solid #efefef;
|
||||
margin-bottom: 10px;
|
||||
padding-bottom: 10px;
|
||||
}
|
||||
#approver-list .approver-avatar{
|
||||
width: 60px;
|
||||
height: 60px;
|
||||
border-radius: 50px;
|
||||
margin-right: 20px;
|
||||
}
|
||||
#approver-list .approver-check{
|
||||
vertical-align: middle;
|
||||
margin-top: 25px;
|
||||
}
|
||||
#approver-list .approver-check input{
|
||||
margin-right: 5px;
|
||||
vertical-align: middle;
|
||||
}
|
||||
#approver-list .approver-check label{
|
||||
display: inline;
|
||||
vertical-align: middle;
|
||||
}
|
||||
#approver-list .approver-title{
|
||||
font-size: 14px;
|
||||
}
|
||||
.table{
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
.table-row,.role_limit_tr,.role_limit_add {
|
||||
width: 100%;
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
margin-bottom: 0.5em;
|
||||
}
|
||||
.td{
|
||||
width: 30%;
|
||||
display: inline-flex;
|
||||
justify-content: center;
|
||||
}
|
||||
.table{
|
||||
border: #2d4cd0 0.1em solid;
|
||||
}
|
||||
.td-3{
|
||||
width: 100%;
|
||||
display: inline-flex;
|
||||
justify-content: center;
|
||||
}
|
||||
.td>*{
|
||||
max-width: 95%;
|
||||
}
|
||||
.td-delete{
|
||||
width: 10%;
|
||||
}
|
||||
</style>
|
||||
<%
|
||||
sub_managers = @module_app.sub_managers
|
||||
sub_managers.delete(nil)
|
||||
sub_managers = @module_app.sub_managers
|
||||
sub_managers.delete(nil)
|
||||
all_statuses = [[t('top'),'is_top'],[t('hot'),'is_hot']]
|
||||
tp1 = select_tag("announcement_setting[anns_status_settings][-1][status]",options_for_select(all_statuses))
|
||||
tp2 = select_tag("announcement_setting[anns_status_settings][-1][role_id]",options_for_select(Role.all.map{|r| [r.title,r.id]}))
|
||||
tp3 = number_field_tag("announcement_setting[anns_status_settings][-1][top_limit]",nil, min: 0,required: true)
|
||||
tp4 = "<button type='button' onclick='delete_limit_role(this)'' class='btn'>#{t('delete_')}</button>"
|
||||
all_tp = "<div class='role_limit_tr'><div class='td'>#{tp1}</div><div class='td'>#{tp2}</div><div class='td'>#{tp3}</div><div class='td-delete'>#{tp4}</div></div>"
|
||||
%>
|
||||
<script type="text/javascript">
|
||||
function add_limit_role(){
|
||||
var role_limit_l = $('.role_limit_tr').length
|
||||
var role_limit_tp = '<%= all_tp.inspect %>'
|
||||
role_limit_tp = role_limit_tp.replace(/-1/g,role_limit_l)
|
||||
$('.role_limit_add').before($('<div/>').html(role_limit_tp).text().slice(1,-2))
|
||||
}
|
||||
function delete_limit_role(ele){
|
||||
var now_index = $(ele).parents('.role_limit_tr').index('.role_limit_tr')
|
||||
console.log(now_index)
|
||||
$(ele).parents('.role_limit_tr').remove()
|
||||
$('.role_limit_tr').each(function(i,v){
|
||||
if (i >= now_index){
|
||||
$(v).find('[name^="announcement_setting[anns_status_settings]"]').each(function(i1,v1){
|
||||
console.log($(v1).attr('name'))
|
||||
$(v1).attr('name',$(v1).attr('name').replace(/\d+/g,i.toString()))
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
var approverList = $(".hidden-approver-list");
|
||||
$(".approver-check input").on("click",function(){
|
||||
var el = $(this);
|
||||
if(el.is(":checked")){
|
||||
var t = $("<input type='hidden'>");
|
||||
t.val(el.val());
|
||||
t.attr("name", "announcement_setting[approvers][]");
|
||||
t.attr("id", "check_" + el.val());
|
||||
approverList.append(t);
|
||||
}else{
|
||||
approverList.find("#check_" + el.val()).remove();
|
||||
}
|
||||
})
|
||||
</script>
|
||||
<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| %>
|
||||
<div class="input-area">
|
||||
<div class="control-group">
|
||||
<div class="control-group">
|
||||
<%= f.label :top_limit, t("announcement.top_limit"), :class => "control-label muted" %>
|
||||
<div class="controls">
|
||||
<%= f.number_field :top_limit, :min => "0" %>
|
||||
<span class="help-block"><%= t("announcement.for_unlimited") %></span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="control-group">
|
||||
<div class="table">
|
||||
<div class="table-row">
|
||||
<div class="td">
|
||||
<%= t('status') %>
|
||||
</div>
|
||||
<div class="td">
|
||||
<%= t('role') %>
|
||||
</div>
|
||||
<div class="td">
|
||||
<%= t('announcement.top_limit') %>
|
||||
</div>
|
||||
</div>
|
||||
<% (AnnouncementSetting.first.anns_status_settings rescue []).each_with_index do |v,i| %>
|
||||
<div class="role_limit_tr">
|
||||
<%= hidden_field_tag("announcement_setting[anns_status_settings][#{i}][_id]",v.id) %>
|
||||
<div class="td">
|
||||
<%= select_tag("announcement_setting[anns_status_settings][#{i}][status]",options_for_select(all_statuses,:selected => v['status'])) %>
|
||||
</div>
|
||||
<div class="td">
|
||||
<%= select_tag("announcement_setting[anns_status_settings][#{i}][role_id]",options_for_select(Role.all.map{|r| [r.title,r.id]},:selected => v['role_id'])) %>
|
||||
</div>
|
||||
<div class="td">
|
||||
<%= number_field_tag("announcement_setting[anns_status_settings][#{i}][top_limit]",v['top_limit'], min: 0,required: true) %>
|
||||
</div>
|
||||
<div class="td-delete">
|
||||
<button type="button" onclick="delete_limit_role(this)" class="btn">
|
||||
<%= t('delete_') %>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<% end %>
|
||||
<div class="role_limit_add">
|
||||
<div class="td-3">
|
||||
<button type="button" onclick="add_limit_role()" class="btn">
|
||||
<%= t('add') %>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<% if AnnouncementSetting.is_pro? %>
|
||||
<% if !sub_managers.blank? %>
|
||||
<div class="control-group">
|
||||
<%= f.label "Approver Setting", :class => "control-label muted" %>
|
||||
<div class="controls">
|
||||
<a href="#approverModal" role="button" class="btn" data-toggle="modal"><%= t("announcement.approvers_list") %></a>
|
||||
<span class="badge badge-info"><%= @setting.approvers.count %></span>
|
||||
</div>
|
||||
</div>
|
||||
<% else %>
|
||||
<div class="control-group">
|
||||
<a href="/admin/authorizations/announcement"><%= t("announcement.click_set_sub_manager") %></a>
|
||||
</div>
|
||||
<% end %>
|
||||
<div class="control-group">
|
||||
<%= f.label "Send emails to", :class => "control-label muted" %>
|
||||
<div class="controls">
|
||||
<input type="checkbox" name="announcement_setting[email_to][]" value="admins" <%= @setting.email_to.include?("admins") ? "checked=checked" : "" %>> <%= t("admin") %>
|
||||
<input type="checkbox" name="announcement_setting[email_to][]" value="managers" <%= @setting.email_to.include?("managers") ? "checked=checked" : "" %>> <%= t("manager") %>
|
||||
<input type="checkbox" name="announcement_setting[email_to][]" value="approvers" <%= @setting.email_to.include?("approvers") ? "checked=checked" : "" %>> <%= t("announcement.approver") %>
|
||||
</div>
|
||||
</div>
|
||||
<% if !sub_managers.blank? %>
|
||||
<div class="control-group">
|
||||
<%= f.label "Approver Setting", :class => "control-label muted" %>
|
||||
<div class="controls">
|
||||
<a href="#approverModal" role="button" class="btn" data-toggle="modal"><%= t("announcement.approvers_list") %></a>
|
||||
<span class="badge badge-info"><%= @setting.approvers.count %></span>
|
||||
</div>
|
||||
</div>
|
||||
<% else %>
|
||||
<div class="control-group">
|
||||
<a href="/admin/authorizations/announcement"><%= t("announcement.click_set_sub_manager") %></a>
|
||||
</div>
|
||||
<% end %>
|
||||
<div class="control-group">
|
||||
<%= f.label "Send emails to", :class => "control-label muted" %>
|
||||
<div class="controls">
|
||||
<input type="checkbox" name="announcement_setting[email_to][]" value="admins" <%= @setting.email_to.include?("admins") ? "checked=checked" : "" %>> <%= t("admin") %>
|
||||
<input type="checkbox" name="announcement_setting[email_to][]" value="managers" <%= @setting.email_to.include?("managers") ? "checked=checked" : "" %>> <%= t("manager") %>
|
||||
<input type="checkbox" name="announcement_setting[email_to][]" value="approvers" <%= @setting.email_to.include?("approvers") ? "checked=checked" : "" %>> <%= t("announcement.approver") %>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="hidden-approver-list">
|
||||
<% sub_managers.each do |sm| %>
|
||||
<% if @setting.approvers.include?(sm.id.to_s) %>
|
||||
<input type="hidden" id="check_<%= sm.id.to_s %>" value="<%= sm.id.to_s %>" name="announcement_setting[approvers][]">
|
||||
<% end %>
|
||||
<% end %>
|
||||
<% sub_managers.each do |sm| %>
|
||||
<% if @setting.approvers.include?(sm.id.to_s) %>
|
||||
<input type="hidden" id="check_<%= sm.id.to_s %>" value="<%= sm.id.to_s %>" name="announcement_setting[approvers][]">
|
||||
<% end %>
|
||||
<% end %>
|
||||
</div>
|
||||
<% end %>
|
||||
<div class="form-actions">
|
||||
|
@ -102,41 +211,28 @@
|
|||
<h3 id="approverModalLabel"><%= t("sub_manager") %></h3>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<ul id="approver-list">
|
||||
<% sub_managers.each do |sm| %>
|
||||
<li>
|
||||
<%= image_tag sm.member_profile.avatar.thumb, :class => "approver-avatar" %>
|
||||
<span class="approver-title"><%= sm.name %></span>
|
||||
<span class="pull-right approver-check">
|
||||
<input id="checkbox_<%= sm.id %>" type="checkbox" value="<%= sm.id %>" <%= @setting.approvers.include?(sm.id.to_s) ? "checked=checked" : "" %>>
|
||||
<label for="checkbox_<%= sm.id %>"><%= t("announcement.approver") %></label>
|
||||
</span>
|
||||
</li>
|
||||
<% end %>
|
||||
</ul>
|
||||
<ul id="approver-list">
|
||||
<% sub_managers.each do |sm| %>
|
||||
<li>
|
||||
<%= image_tag sm.member_profile.avatar.thumb, :class => "approver-avatar" %>
|
||||
<span class="approver-title"><%= sm.name %></span>
|
||||
<span class="pull-right approver-check">
|
||||
<input id="checkbox_<%= sm.id %>" type="checkbox" value="<%= sm.id %>" <%= @setting.approvers.include?(sm.id.to_s) ? "checked=checked" : "" %>>
|
||||
<label for="checkbox_<%= sm.id %>"><%= t("announcement.approver") %></label>
|
||||
</span>
|
||||
</li>
|
||||
<% end %>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button class="btn btn-primary" data-dismiss="modal" aria-hidden="true">Ok</button>
|
||||
</div>
|
||||
</div>
|
||||
<script type="text/javascript">
|
||||
var approverList = $(".hidden-approver-list");
|
||||
$(".approver-check input").on("click",function(){
|
||||
var el = $(this);
|
||||
if(el.is(":checked")){
|
||||
var t = $("<input type='hidden'>");
|
||||
t.val(el.val());
|
||||
t.attr("name", "announcement_setting[approvers][]");
|
||||
t.attr("id", "check_" + el.val());
|
||||
approverList.append(t);
|
||||
}else{
|
||||
approverList.find("#check_" + el.val()).remove();
|
||||
}
|
||||
})
|
||||
$("#approverModal").on("hidden",function(){
|
||||
$("#notification").slideDown();
|
||||
$(".badge-info").text($(".hidden-approver-list input").length);
|
||||
})
|
||||
$("#approverModal").on("hidden",function(){
|
||||
$("#notification").slideDown();
|
||||
$(".badge-info").text($(".hidden-approver-list input").length);
|
||||
})
|
||||
|
||||
</script>
|
||||
<% end %>
|
||||
|
|
Loading…
Reference in New Issue