added settings for approver election and also for sending emails
This commit is contained in:
parent
239eca2f0d
commit
f8f70e0ebe
|
@ -4,7 +4,7 @@ class Admin::AnnouncementsController < OrbitAdminController
|
|||
include Admin::AnnouncementsHelper
|
||||
before_action ->(module_app = @app_title) { set_variables module_app }
|
||||
before_action :set_bulletin, only: [:edit, :destroy]
|
||||
before_action :load_access_level
|
||||
before_action :load_access_level, :load_settings
|
||||
|
||||
def initialize
|
||||
super
|
||||
|
@ -38,10 +38,7 @@ class Admin::AnnouncementsController < OrbitAdminController
|
|||
end
|
||||
|
||||
def settings
|
||||
@setting = AnnouncementSetting.first rescue nil
|
||||
if @setting.nil?
|
||||
@setting = AnnouncementSetting.new
|
||||
end
|
||||
@setting = @announcement_setting
|
||||
end
|
||||
|
||||
def import
|
||||
|
@ -86,7 +83,7 @@ class Admin::AnnouncementsController < OrbitAdminController
|
|||
end
|
||||
|
||||
def updatesettings
|
||||
setting = AnnouncementSetting.first
|
||||
setting = @announcement_setting
|
||||
setting.update_attributes(settings_params)
|
||||
setting.save
|
||||
redirect_to admin_announcement_settings_path
|
||||
|
@ -339,6 +336,13 @@ class Admin::AnnouncementsController < OrbitAdminController
|
|||
|
||||
private
|
||||
|
||||
def load_settings
|
||||
@announcement_setting = AnnouncementSetting.first rescue nil
|
||||
if @announcement_setting.nil?
|
||||
@announcement_setting = AnnouncementSetting.create
|
||||
end
|
||||
end
|
||||
|
||||
def set_bulletin
|
||||
@bulletin = Bulletin.find(params[:id])
|
||||
end
|
||||
|
|
|
@ -255,7 +255,9 @@ class AnnouncementsController < ApplicationController
|
|||
access_level = OrbitHelper.user_access_level?
|
||||
|
||||
if !announcement.approved && (access_level != "manager" && access_level != "admin")
|
||||
return {}
|
||||
if !(access_level == "sub_manager" && AnnouncementSetting.first.approvers.include?(OrbitHelper.current_user.id.to_s))
|
||||
return {}
|
||||
end
|
||||
end
|
||||
|
||||
return {} if announcement.category.disable
|
||||
|
|
|
@ -133,14 +133,23 @@ module Admin::AnnouncementsHelper
|
|||
end
|
||||
|
||||
def send_notification_mail_to_managers(announcement, type)
|
||||
authorizations = Authorization.where(:module_app_id => @module_app.id)
|
||||
users = authorizations.collect do |auth|
|
||||
auth.user
|
||||
users = []
|
||||
if @announcement_setting.email_to.include?("managers")
|
||||
authorizations = Authorization.where(:module_app_id => @module_app.id)
|
||||
users = authorizations.collect do |auth|
|
||||
auth.user
|
||||
end
|
||||
end
|
||||
if @announcement_setting.email_to.include?("admins")
|
||||
wg = Workgroup.where(:key => "admin").first
|
||||
admins = User.where(:workgroup_id => wg.id)
|
||||
users.delete(nil)
|
||||
users = users.concat(admins.to_a)
|
||||
end
|
||||
if @announcement_setting.email_to.include?("approvers")
|
||||
approvers = User.find(@announcement_setting.approvers) rescue []
|
||||
users = users.concat(approvers.to_a)
|
||||
end
|
||||
wg = Workgroup.where(:key => "admin").first
|
||||
admins = User.where(:workgroup_id => wg.id)
|
||||
users.delete(nil)
|
||||
users = users.concat(admins.to_a)
|
||||
users.each do |user|
|
||||
email = user.member_profile.email
|
||||
if !email.nil? && email != ""
|
||||
|
@ -210,15 +219,29 @@ module Admin::AnnouncementsHelper
|
|||
end
|
||||
end
|
||||
|
||||
def user_can_approve?
|
||||
def user_can_approve?(anns=nil)
|
||||
can_approve = false
|
||||
setting = AnnouncementSetting.first
|
||||
case @access_level
|
||||
when "admin"
|
||||
return true
|
||||
can_approve = true
|
||||
when "manager"
|
||||
return true
|
||||
can_approve = true
|
||||
else
|
||||
return false
|
||||
can_approve = false
|
||||
end
|
||||
if !can_approve
|
||||
if !anns.nil?
|
||||
if setting.approvers.include?(current_user.id.to_s)
|
||||
if (current_user.approved_categories_for_module(@module_app).include?(anns.category) rescue false)
|
||||
can_approve = true
|
||||
end
|
||||
end
|
||||
else
|
||||
can_approve = setting.approvers.include?(current_user.id.to_s)
|
||||
end
|
||||
end
|
||||
can_approve
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -4,6 +4,8 @@ class AnnouncementSetting
|
|||
|
||||
field :top_limit, type: Integer, :default => 0
|
||||
field :pro_enabled, type: Boolean, :default => false
|
||||
field :approvers, type: Array, :default => []
|
||||
field :email_to, type: Array, :default => ["admins","managers","approvers"]
|
||||
|
||||
def self.check_limit_for_user(user_id, b_id = nil)
|
||||
limit = self.first.top_limit rescue 0
|
||||
|
|
|
@ -48,9 +48,9 @@
|
|||
<% if can_edit_or_delete?(b) %>
|
||||
<li><a href="/admin/announcements/<%=b.id.to_s%>/edit"><%= t(:edit) %></a></li>
|
||||
<li><a href="#" class="delete text-error" rel="/admin/announcements/<%=b.id.to_s%>"><%= t(:delete_) %></a></li>
|
||||
<% if (!b.approved || b.reapproval) && user_can_approve? %>
|
||||
<li><a href="<%= page_for_bulletin(b) %>" class="approval_button" data-id="<%= b.id.to_s %>" ><%= t("announcement.approval_waiting") %></a></li>
|
||||
<% end %>
|
||||
<% end %>
|
||||
<% if ((!b.approved && !b.rejected && !b.reapproval) || (b.rejected && b.reapproval)) && user_can_approve?(b) %>
|
||||
<li><a href="<%= page_for_bulletin(b) %>" class="approval_button" data-id="<%= b.id.to_s %>" ><%= t("announcement.approval_waiting") %></a></li>
|
||||
<% end %>
|
||||
</ul>
|
||||
</div>
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
|
||||
<%= render 'layouts/delete_modal', delete_options: @delete_options %>
|
||||
|
||||
<% if AnnouncementSetting.is_pro? && (@access_level == "admin" || @access_level == "manager") %>
|
||||
<% if AnnouncementSetting.is_pro? && user_can_approve? %>
|
||||
<%= render :partial=> "approval_modal" %>
|
||||
|
||||
<script type="text/javascript">
|
||||
|
|
|
@ -1,3 +1,53 @@
|
|||
<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;
|
||||
}
|
||||
|
||||
</style>
|
||||
<% sub_managers = @module_app.sub_managers %>
|
||||
<div id="notification">Click on Submit to save the changes.</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">
|
||||
|
@ -7,8 +57,89 @@
|
|||
<span class="help-block">Put 0 for unlimited.</span>
|
||||
</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">Approvers List</a>
|
||||
<span class="badge badge-info"><%= @setting.approvers.count %></span>
|
||||
</div>
|
||||
</div>
|
||||
<% else %>
|
||||
<div class="control-group">
|
||||
<a href="/admin/authorizations/announcement">Click here to set Sub Managers for this module</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" : "" %>> Admins
|
||||
<input type="checkbox" name="announcement_setting[email_to][]" value="managers" <%= @setting.email_to.include?("managers") ? "checked=checked" : "" %>> Managers
|
||||
<input type="checkbox" name="announcement_setting[email_to][]" value="approvers" <%= @setting.email_to.include?("approvers") ? "checked=checked" : "" %>> Approvers
|
||||
</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 %>
|
||||
</div>
|
||||
<div class="form-actions">
|
||||
<%= f.submit t('submit'), class: 'btn btn-primary' %>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
<div id="approverModal" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="approverModalLabel" aria-hidden="true">
|
||||
<div class="modal-header">
|
||||
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
|
||||
<h3 id="approverModalLabel">Sub Managers</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 %>">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);
|
||||
})
|
||||
|
||||
</script>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue