实时发送:发布作业邮件通知
This commit is contained in:
parent
cf9455e465
commit
28e9c090ec
|
@ -3,7 +3,6 @@ class HomeworkCommonController < ApplicationController
|
|||
before_filter :find_course, :only => [:index,:new,:create]
|
||||
before_filter :find_homework, :only => [:edit,:update,:alert_anonymous_comment,:start_anonymous_comment,:stop_anonymous_comment,:destroy]
|
||||
before_filter :teacher_of_course, :only => [:new, :create, :edit, :update, :destroy, :start_anonymous_comment, :stop_anonymous_comment, :alert_anonymous_comment]
|
||||
after_create :send_mail
|
||||
|
||||
def index
|
||||
homeworks = @course.homework_commons.order("created_at desc")
|
||||
|
@ -184,10 +183,6 @@ class HomeworkCommonController < ApplicationController
|
|||
end
|
||||
end
|
||||
|
||||
def send_mail
|
||||
Mailer.run.homework_added(self)
|
||||
end
|
||||
|
||||
private
|
||||
#获取课程
|
||||
def find_course
|
||||
|
|
|
@ -85,7 +85,7 @@ class Document < ActiveRecord::Base
|
|||
# Description 新创建的document要在公共表ForgeActivity中记录
|
||||
def act_as_forge_activity
|
||||
self.forge_acts << ForgeActivity.new(:user_id => self.user_id,
|
||||
:project_id => self.project_id)
|
||||
:project_id => self.project_id)
|
||||
end
|
||||
|
||||
def send_mail
|
||||
|
|
|
@ -18,7 +18,7 @@ class HomeworkCommon < ActiveRecord::Base
|
|||
:description => :description,
|
||||
:author => :author,
|
||||
:url => Proc.new {|o| {:controller => 'student_work', :action => 'index', :homework => o.id}}
|
||||
after_create :act_as_activity
|
||||
after_create :act_as_activity, :send_mail
|
||||
after_destroy :delete_kindeditor_assets
|
||||
|
||||
def act_as_activity
|
||||
|
@ -28,4 +28,9 @@ class HomeworkCommon < ActiveRecord::Base
|
|||
def delete_kindeditor_assets
|
||||
delete_kindeditor_assets_from_disk self.id,OwnerTypeHelper::HOMEWORKCOMMON
|
||||
end
|
||||
|
||||
def send_mail
|
||||
Mailer.run.homework_added(self)
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -517,13 +517,46 @@ class Mailer < ActionMailer::Base
|
|||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
def forum_message_added(memo)
|
||||
@memo = memo
|
||||
redmine_headers 'Memo' => memo.id
|
||||
@forum = memo.forum
|
||||
@author = memo.author
|
||||
@forum_url = url_for(:controller => 'forums', :action => 'show', :id => @forum.id)
|
||||
@issue_author_url = url_for(user_activities_url(@author))
|
||||
recipients ||= []
|
||||
#将帖子创建者邮箱地址加入数组
|
||||
recipients << @forum.creator.mail
|
||||
#回复人邮箱地址加入数组
|
||||
recipients << @author.mail
|
||||
# cc = wiki_content.page.wiki.watcher_recipients - recipients
|
||||
|
||||
@memo_url = url_for(forum_memo_url(@forum, (@memo.parent_id.nil? ? @memo : @memo.parent_id)))
|
||||
mail :to => recipients,
|
||||
:subject => "[ #{l(:label_message_plural)} : #{memo.subject} #{l(:label_memo_create_succ)}]",
|
||||
:filter => true
|
||||
end
|
||||
|
||||
# Builds a Mail::Message object used to email recipients of a course when an homework are posted.
|
||||
#
|
||||
# Example:
|
||||
# attachments_added(attachments) => Mail::Message object
|
||||
# Mailer.attachments_added(attachments).deliver => sends an email to the project's recipients
|
||||
def homework_added
|
||||
|
||||
def homework_added(homework_common)
|
||||
@homework_common = homework_common
|
||||
@author = homework_common.user
|
||||
@homework_common_url = url_for(:controller => "homework_common", :action =>"index", :homework => @homework_common.id)
|
||||
@homework_author_url = url_for(user_activities_url(@author))
|
||||
recipients ||= []
|
||||
#将帖子创建者邮箱地址加入数组
|
||||
@homework_common.course.members.each do |member|
|
||||
recipients << member.user.mail
|
||||
end
|
||||
mail :to => recipients,
|
||||
:subject => "[ #{l(:label_user_homework)} : #{homework_common.name} #{l(:label_memo_create_succ)}]",
|
||||
:filter => true
|
||||
end
|
||||
|
||||
# Builds a Mail::Message object used to email recipients of a news' project when a news item is added.
|
||||
|
|
|
@ -1,25 +1,25 @@
|
|||
|
||||
<p>
|
||||
<span class="c_blue" style="color:#1b55a7;">
|
||||
<%= link_to(h("#{@author.login}(#{@author.show_name})"), @issue_author_url , :style=>'color:#1b55a7; font-weight:bold;') %>
|
||||
</span><%= l(:mail_issue_title_userin)%>
|
||||
<span class="c_blue" style="color:#1b55a7;">
|
||||
<%= link_to(h(@forum.name), @forum_url,:style=>'color:#1b55a7; font-weight:bold;') %>
|
||||
|
||||
</span><%= l(:mail_issue_title_active)%></p>
|
||||
<%= link_to(h("#{@author.login}(#{@author.show_name})"), @issue_author_url , :style=>'color:#1b55a7; font-weight:bold;') %>
|
||||
</span>
|
||||
<%= l(:mail_issue_title_userin)%>
|
||||
<span class="c_blue" style="color:#1b55a7;">
|
||||
<%= link_to(h(@forum.name), @forum_url,:style=>'color:#1b55a7; font-weight:bold;') %>
|
||||
</span>
|
||||
<%= l(:mail_issue_title_active) %>
|
||||
</p>
|
||||
<div class="mail_box" style="border:1px solid #c8c8c8; width:570px; height: auto; padding:15px; margin-top:10px; margin-bottom:10px;">
|
||||
<ul style="list-style-type:none; margin:0; padding:0;">
|
||||
<li style="list-style-type:none; margin:0; padding:0;"><span style="float: left;"><strong><%= l(:mail_issue_subject)%></strong></span>
|
||||
<li style="list-style-type:none; margin:0; padding:0;"><span style="float: left;"><strong><%= l(:mail_issue_subject) %></strong></span>
|
||||
<span style="float: left; width: 526px"> <%= link_to(h(@memo.subject), @memo_url,:style=>'color:#1b55a7; font-weight:bold;') %></span></li>
|
||||
<li style="list-style-type:none; margin:0; padding:0;"><span style="float: left;"><strong><%= l(:mail_issue_sent_from)%></strong></span>
|
||||
<li style="list-style-type:none; margin:0; padding:0;"><span style="float: left;"><strong><%= l(:mail_issue_sent_from) %></strong></span>
|
||||
<%= link_to(h(@forum.name), @forum_url,:style=>'color:#1b55a7; font-weight:bold;') %>
|
||||
</li>
|
||||
<li style="list-style-type:none; margin:0; padding:0;"><span style="float: left;"><strong><%= l(:mail_issue_content)%></strong></span>
|
||||
<li style="list-style-type:none; margin:0; padding:0;"><span style="float: left;"><strong><%= l(:mail_issue_content) %></strong></span>
|
||||
<span style="float: left; width: 526px">
|
||||
<%= @memo.content.html_safe %>
|
||||
</span>
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
<div class="cl" style="margin-top: 30px; clear:both; overflow:hidden;"></div>
|
||||
<label class="mail_reply">
|
||||
|
|
|
@ -0,0 +1,30 @@
|
|||
<p>
|
||||
<span class="c_blue" style="color:#1b55a7;">
|
||||
<%= link_to(h("#{@homework_common.user.login}(#{@homework_common.user.show_name})"), @homework_author_url , :style=>'color:#1b55a7; font-weight:bold;') %>
|
||||
</span><%= l(:mail_course_title_userin)%>
|
||||
<span class="c_blue" style="color:#1b55a7;">
|
||||
<%=h @homework_common.course.name %>
|
||||
</span>
|
||||
<%= l(:mail_course_homework_active) %> :
|
||||
<span class="c_blue" style="color:#1b55a7;">
|
||||
<%= link_to(h(@homework_common.name), @homework_common_url,:style=>'color:#1b55a7; font-weight:bold;') %>
|
||||
</span>
|
||||
<%= l(:mail_attention) %>
|
||||
</p>
|
||||
<div class="mail_box" style="border:1px solid #c8c8c8; width:570px; height: auto; padding:15px; margin-top:10px; margin-bottom:10px;">
|
||||
<ul style="list-style-type:none; margin:0; padding:0;">
|
||||
<li style="list-style-type:none; margin:0; padding:0;"><span style="float: left;"><strong><%= l(:mail_issue_subject)%></strong></span>
|
||||
<span style="float: left; width: 526px"> <%= link_to(h(@homework_common.name), @homework_common_url, :style=>'color:#1b55a7; font-weight:bold;') %></span>
|
||||
</li>
|
||||
<li style="list-style-type:none; margin:0; padding:0;"><span style="float: left;"><strong><%= l(:mail_issue_sent_from)%></strong></span>
|
||||
<span style="float: left; width: 526px"><%=h @homework_common.course.name %></span>
|
||||
</li>
|
||||
<li style="list-style-type:none; margin:0; padding:0;"><span style="float: left;"><strong><%= l(:mail_issue_content)%></strong></span>
|
||||
<span style="float: left; width: 526px">
|
||||
<%= @homework_common.description.html_safe %>
|
||||
</span>
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
<div class="cl" style="margin-top: 30px; clear:both; overflow:hidden;"></div>
|
||||
</div>
|
|
@ -0,0 +1,17 @@
|
|||
<%= link_to(h("#{@homework_common.user.login}(#{@homework_common.user.show_name})"), @homework_author_url ) %>
|
||||
<%= l(:mail_course_title_userin)%>
|
||||
|
||||
<%=h @homework_common.course.name %>
|
||||
<%= l(:mail_course_homework_active) %> :
|
||||
<%= link_to(h(@homework_common.name), @homework_common_url) %>
|
||||
|
||||
<%= l(:mail_attention) %>
|
||||
<%= l(:mail_issue_subject)%>
|
||||
<%= link_to(h(@homework_common.name), @homework_common_url) %>
|
||||
<%= l(:mail_issue_sent_from)%>
|
||||
<%=h @homework_common.course.name %>
|
||||
<%= l(:mail_issue_content)%>
|
||||
|
||||
<%= @homework_common.description.html_safe %>
|
||||
|
||||
|
|
@ -21,3 +21,6 @@ zh:
|
|||
mail_issue_from_project: "项目问题跟踪"
|
||||
mail_issue_attachments: "附件:"
|
||||
mail_issue_reply: "我要回复"
|
||||
mail_course_title_userin: "在课程"
|
||||
mail_course_homework_active: "中发布了作业"
|
||||
mail_attention: "请您关注!"
|
||||
|
|
Loading…
Reference in New Issue