rejection now included with email systems.
This commit is contained in:
parent
b67730775c
commit
026fef47af
|
@ -149,6 +149,8 @@ class Admin::AnnouncementsController < OrbitAdminController
|
|||
if AnnouncementSetting.is_pro?
|
||||
if user_can_approve?
|
||||
bulletin.approved = true
|
||||
else
|
||||
send_notification_mail_to_managers(bulletin,"approval")
|
||||
end
|
||||
else
|
||||
bulletin.approved = true
|
||||
|
@ -162,7 +164,16 @@ class Admin::AnnouncementsController < OrbitAdminController
|
|||
def approve_bulletin
|
||||
id = params[:id]
|
||||
bulletin = Bulletin.find(id)
|
||||
bulletin.approved = true
|
||||
if params["approved"] == "true"
|
||||
bulletin.approved = true
|
||||
bulletin.rejected = false
|
||||
bulletin.reapproval = false
|
||||
else
|
||||
bulletin.rejected = true
|
||||
bulletin.reapproval = false
|
||||
bulletin.rejection_reason = params["reason"]
|
||||
send_rejection_email(bulletin) rescue ""
|
||||
end
|
||||
bulletin.save
|
||||
redirect_to admin_announcements_path
|
||||
end
|
||||
|
@ -197,7 +208,13 @@ class Admin::AnnouncementsController < OrbitAdminController
|
|||
end
|
||||
|
||||
bulletin.update_attributes(bps)
|
||||
bulletin.save
|
||||
if bulletin.rejected
|
||||
bulletin.reapproval = true
|
||||
bulletin.save
|
||||
send_notification_mail_to_managers(bulletin,"reapproval")
|
||||
else
|
||||
bulletin.save
|
||||
end
|
||||
build_email(bulletin)
|
||||
redirect_to params['referer_url']
|
||||
end
|
||||
|
|
|
@ -119,6 +119,40 @@ module Admin::AnnouncementsHelper
|
|||
anns.save
|
||||
end
|
||||
|
||||
def send_rejection_email(announcement)
|
||||
user = User.find(announcement.create_user_id) rescue nil
|
||||
if !user.nil?
|
||||
email = user.member_profile.email
|
||||
if !email.nil? && email != ""
|
||||
url = page_for_bulletin(announcement)
|
||||
mail = Email.new(:mail_to => email, :mail_subject => "Announcement rejected : #{announcement.title}.", :template => "email/rejection_email.html.erb", :template_data => {"url" => url, "rejector" => current_user.name, "name" => user.name, "reason" => announcement.rejection_reason})
|
||||
mail.deliver rescue nil
|
||||
end
|
||||
end
|
||||
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
|
||||
end
|
||||
users.delete(nil)
|
||||
users.each do |user|
|
||||
email = user.member_profile.email
|
||||
if !email.nil? && email != ""
|
||||
send_email(user.name, email, announcement, type)
|
||||
sleep(1)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def send_email(name, useremail, announcement, type)
|
||||
url = page_for_bulletin(announcement)
|
||||
template = (type == "approval" ? "email/new_announcement_email.html.erb" : "email/reapproval_announcement_email.html.erb")
|
||||
email = Email.new(:mail_to => useremail, :mail_subject => "New announcement : #{announcement.title}.", :template => template, :template_data => {"url" => url, "submitter" => current_user.name, "name" => name})
|
||||
email.deliver rescue nil
|
||||
end
|
||||
|
||||
def download_tmp_xml(url)
|
||||
xml = File.join(Rails.root, "tmp", "ann_cc_ntu.xml")
|
||||
open(xml, 'wb') do |fo|
|
||||
|
|
|
@ -21,6 +21,9 @@ class Bulletin
|
|||
field :approved, :type => Boolean, :default => false
|
||||
field :is_preview, :type => Boolean, :default => false
|
||||
field :expirable_created_at, type: DateTime
|
||||
field :rejected, :type => Boolean, :default => false
|
||||
field :reapproval, :type => Boolean, :default => false
|
||||
field :rejection_reason
|
||||
|
||||
field :email_id
|
||||
field :email_sent, :type => Boolean, :default => false
|
||||
|
|
|
@ -0,0 +1,122 @@
|
|||
<style>
|
||||
#approvalModal {
|
||||
width: 90%;
|
||||
height: 600px;
|
||||
top: 0;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
left: 0;
|
||||
margin: auto;
|
||||
position: absolute;
|
||||
}
|
||||
#approvalModal .preview-iframe {
|
||||
border: 0;
|
||||
outline: none;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
}
|
||||
#approvalModal .modal-body {
|
||||
background-color: #fff;
|
||||
padding: 0;
|
||||
max-height: none;
|
||||
height: 100%;
|
||||
overflow: hidden;
|
||||
}
|
||||
#approvalModal .modal-left {
|
||||
overflow: auto;
|
||||
float: left;
|
||||
width: 19.8%;
|
||||
border-right: 1px solid #DFDFDF;
|
||||
height: 100%;
|
||||
padding: 1em;
|
||||
margin: 0;
|
||||
-webkit-box-sizing: border-box;
|
||||
-moz-box-sizing: border-box;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
#approvalModal .modal-right {
|
||||
float: right;
|
||||
width: 80%;
|
||||
height: 100%;
|
||||
}
|
||||
.approvalModal__form {
|
||||
padding: 0 10px;
|
||||
margin: 0;
|
||||
}
|
||||
label.approvalModal__radio {
|
||||
display: inline-block;
|
||||
}
|
||||
label.control-label {
|
||||
display: inline-block;
|
||||
}
|
||||
|
||||
.approvalModal__controls {
|
||||
display: inline-block;
|
||||
vertical-align: middle;
|
||||
}
|
||||
|
||||
.approvalModal__group {
|
||||
display: inline-block;
|
||||
vertical-align: middle;
|
||||
}
|
||||
|
||||
label.approvalModal__label {
|
||||
display: inline-block;
|
||||
margin: 0 4px 0 7px;
|
||||
position: relative;
|
||||
top: -1px;
|
||||
}
|
||||
.approvalModal__controls .approvalModal__privacy {
|
||||
margin: 0 5px;
|
||||
}
|
||||
.approvalModal__controls .approvalModal__large {
|
||||
}
|
||||
#approvalModal .modal-footer {
|
||||
text-align: left;
|
||||
padding: 15px 10px 10px;
|
||||
}
|
||||
.approvalModal__group.confirm {
|
||||
float: right;
|
||||
}
|
||||
</style>
|
||||
<div id="approvalModal" class="modal hide fade" role="dialog">
|
||||
<div class="modal-header">
|
||||
<a class="close" data-dismiss="modal">×</a>
|
||||
<h3>預覽</h3>
|
||||
</div>
|
||||
<div class="modal-body clearfix">
|
||||
<div class="modal-left">
|
||||
<label for="____">寄送對象</label>
|
||||
</div>
|
||||
<div class="modal-right">
|
||||
<iframe class="preview-iframe"></iframe>
|
||||
</div>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<%= form_tag "/admin/announcement/approve_bulletin", :class=>"approvalModal__form" do %>
|
||||
<div class="approvalModal__group">
|
||||
<label class="control-label" for="bulletin_approval_stat">審核狀態</label>
|
||||
<div class="approvalModal__controls">
|
||||
<label class="approvalModal__radio">
|
||||
<input class="approvalModal__privacy" id="bulletin_is_checked_true" name="approved" type="radio" value="true">已認可
|
||||
</label>
|
||||
<label class="approvalModal__radio">
|
||||
<input checked="checked" class="approvalModal__privacy" id="bulletin_approved_false" name="approved" type="radio" value="false">拒絕
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
<div class="approvalModal__group group--reject">
|
||||
<label class="approvalModal__label" for="is_checked_false_拒絕原因">拒絕原因</label>
|
||||
<div class="approvalModal__controls">
|
||||
<input class="approvalModal__large" id="bulletin_not_checked_reason" name="reason" size="30" type="text">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="approvalModal__group confirm">
|
||||
<input class="approvalModal__btn btn btn-primary" name="commit" type="submit" value="送出">
|
||||
<input type="hidden" id="object_id" name="id" />
|
||||
<button class="approvalModal__btn btn" data-dismiss="modal" aria-hidden="true">關閉</button>
|
||||
</div>
|
||||
<% end %>
|
||||
</div>
|
||||
</div>
|
|
@ -23,21 +23,24 @@
|
|||
<% end %>
|
||||
</td>
|
||||
<td>
|
||||
<% if b.expired? %>
|
||||
<%= b.title %> <span class='label'><%= t(:expired) %></span>
|
||||
<% elsif !b.approved? %>
|
||||
<% if (b.category.disable rescue false)%>
|
||||
<%= b.title %>
|
||||
<% else %>
|
||||
<a href="<%=page_for_bulletin(b)%>" target="_blank"><%= b.title %></a>
|
||||
<% end %>
|
||||
<span class='label'><%= t(:pending) %></span>
|
||||
<% if b.expired? || (b.category.disable rescue false)%>
|
||||
<%= b.title %>
|
||||
<% else %>
|
||||
<% if (b.category.disable rescue false) %>
|
||||
<%= b.title %>
|
||||
<% else %>
|
||||
<a href="<%=page_for_bulletin(b)%>" target="_blank"><%= b.title %></a>
|
||||
<% end %>
|
||||
<a href="<%= page_for_bulletin(b) %>" target="_blank"><%= b.title %></a>
|
||||
<% end %>
|
||||
|
||||
<% if b.expired? %>
|
||||
<span class='label'><%= t(:expired) %></span>
|
||||
<% end %>
|
||||
|
||||
<% if b.reapproval %>
|
||||
<span class='label'><%= t("announcement.reapproval") + " " + t(:pending) %></span>
|
||||
<% end %>
|
||||
<% if b.rejected %>
|
||||
<span class='label'><%= t(:rejected) %> : <%= b.rejection_reason rescue "" %></span>
|
||||
<% end %>
|
||||
<% if !b.approved? && !b.rejected %>
|
||||
<span class='label'><%= t(:pending) %></span>
|
||||
<% end %>
|
||||
<div class="quick-edit">
|
||||
<ul class="nav nav-pills">
|
||||
|
@ -45,8 +48,8 @@
|
|||
<% 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 && user_can_approve? %>
|
||||
<li><a href="<%= admin_announcement_approve_bulletin_path(:id => b.id.to_s) %>"><%= t("announcement.approve") %></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.approve") %></a></li>
|
||||
<% end %>
|
||||
<% end %>
|
||||
</ul>
|
||||
|
|
|
@ -4,3 +4,18 @@
|
|||
</span>
|
||||
|
||||
<%= render 'layouts/delete_modal', delete_options: @delete_options %>
|
||||
|
||||
<% if AnnouncementSetting.is_pro? && (@access_level == "admin" || @access_level == "manager") %>
|
||||
<%= render :partial=> "approval_modal" %>
|
||||
|
||||
<script type="text/javascript">
|
||||
$(document).on("click", ".approval_button",function(){
|
||||
var url = $(this).attr("href"),
|
||||
modal = $("#approvalModal");
|
||||
modal.find("iframe").attr("src", url);
|
||||
modal.find("#object_id").val($(this).data("id"));
|
||||
modal.modal("show");
|
||||
return false;
|
||||
})
|
||||
</script>
|
||||
<% end %>
|
|
@ -0,0 +1,3 @@
|
|||
<h3>Hello <%= @data["name"] %>,</h3>
|
||||
<p><%= @data["submitter"] %> submitted a new announcement.
|
||||
<a href="<%= @data['url'] %>" > Please click here to view the announcement.</a>
|
|
@ -0,0 +1,3 @@
|
|||
<h3>Hello <%= @data["name"] %>,</h3>
|
||||
<p><%= @data["submitter"] %> updated the announcement.
|
||||
<a href="<%= @data['url'] %>" > Please click here to view the annoucement.</a>
|
|
@ -0,0 +1,3 @@
|
|||
<h3>Hello <%= @data["name"] %>,</h3>
|
||||
<p><%= @data["rejector"] %> has rejected your announcement<%= @data["reason"].nil? || @data["reason"] == "" ? "." : ", because #{@data["reason"]}" %></p>
|
||||
<a href="<%= @data['url'] %>" > Please click here to view the annoucement.</a>
|
|
@ -12,7 +12,7 @@ Rails.application.routes.draw do
|
|||
patch 'announcement/updatefeed', to: 'announcements#updatefeed'
|
||||
delete 'announcement/deletefeed', to: 'announcements#deletefeed'
|
||||
get 'announcement/destroy_preview/:slug_title-:uid', to: 'announcements#destroy_preview'
|
||||
get 'announcement/approve_bulletin', to: 'announcements#approve_bulletin'
|
||||
post 'announcement/approve_bulletin', to: 'announcements#approve_bulletin'
|
||||
get 'announcement/feed', to: 'announcements#feed'
|
||||
get 'announcements/feedform', to: 'announcements#feedform'
|
||||
get 'announcement/settings', to: 'announcements#settings'
|
||||
|
|
Loading…
Reference in New Issue