Commit 6ef3eef0052f55a39ebe5f3197bc84d383946889
Committed by
Tallys Martins
1 parent
46a4526b
Exists in
master
and in
29 other branches
Creating new EmailContact model for sending work assignment notifications.
(work_assignment_rails3) Signed-off-by: Tallys Martins <tallysmartins@gmail.com> Signed-off-by: Andre Bernardes <andrebsguedes@gmail.com>
Showing
4 changed files
with
81 additions
and
16 deletions
Show diff stats
plugins/work_assignment/controllers/myprofile/work_assignment_plugin_cms_controller.rb
... | ... | @@ -43,27 +43,27 @@ class WorkAssignmentPluginCmsController < CmsController |
43 | 43 | @parent = check_parent(params[:id]) |
44 | 44 | @files_id_list = params[:files_id] |
45 | 45 | @target = ['',@parent.url[:profile], @parent.url[:page]].join('/') |
46 | - @contact | |
46 | + @email_contact | |
47 | 47 | if request.post? && params[:confirm] == 'true' |
48 | 48 | @files_paths = [] |
49 | - @files_id_list = params[:self_files_id] | |
49 | + @files_string = params[:self_files_id] | |
50 | + @files_id_list = @files_string.split(' ') | |
50 | 51 | |
51 | 52 | @files_id_list.each do |file_id| |
52 | 53 | @file = environment.articles.find_by_id(file_id) |
53 | - @real_file_url = "http://#{@file.url[:host]}:#{@file.url[:port]}/ #{@file.url[:profile]}/#{@file.path}" | |
54 | + @real_file_url = "http://#{@file.url[:host]}:#{@file.url[:port]}/#{@file.url[:profile]}/#{@file.path}" | |
54 | 55 | @files_paths << @real_file_url |
55 | - unless params[:contact][:message].include? "#{@real_file_url}" | |
56 | - params[:contact][:message] += "<br> Clique <a href='#{@real_file_url}'>aqui</a> para acessar o arquivo ou acesse pela URL: <br>" | |
57 | - params[:contact][:message] += "<br><a href='#{@real_file_url}'>#{@real_file_url}</a>" | |
56 | + unless params[:email_contact][:message].include? "#{@real_file_url}" | |
57 | + params[:email_contact][:message] += "<br> Clique <a href='#{@real_file_url}'>aqui</a> para acessar o arquivo ou acesse pela URL: <br>" | |
58 | + params[:email_contact][:message] += "<br><a href='#{@real_file_url}'>#{@real_file_url}</a>" | |
58 | 59 | end |
59 | 60 | end |
60 | 61 | @message = "AVISO: O aluno deve imprimir este email e entrega-lo na secretaria como comprovante do envio!" |
61 | - unless params[:contact][:message].include? "#{@message}" | |
62 | - params[:contact][:message] += "<br><br>#{@message}" | |
62 | + unless params[:email_contact][:message].include? "#{@message}" | |
63 | + params[:email_contact][:message] += "<br><br>#{@message}" | |
63 | 64 | end |
64 | - | |
65 | - @contact = user.build_contact(profile, params[:contact]) | |
66 | - if @contact.deliver | |
65 | + @email_contact = user.build_email_contact(params[:email_contact]) | |
66 | + if @email_contact.deliver | |
67 | 67 | session[:notice] = _('Contact successfully sent') |
68 | 68 | redirect_to @target |
69 | 69 | else |
... | ... | @@ -79,7 +79,7 @@ class WorkAssignmentPluginCmsController < CmsController |
79 | 79 | redirect_to :action => 'index' |
80 | 80 | end |
81 | 81 | else |
82 | - @contact = user.build_contact(profile) | |
82 | + @email_contact = user.build_email_contact() | |
83 | 83 | end |
84 | 84 | end |
85 | 85 | ... | ... |
... | ... | @@ -0,0 +1,58 @@ |
1 | +class EmailContact | |
2 | + | |
3 | + include ActiveModel::Validations | |
4 | + | |
5 | + def initialize(attributes = nil) | |
6 | + if attributes | |
7 | + attributes.each do |attr,value| | |
8 | + self.send("#{attr}=", value) | |
9 | + end | |
10 | + end | |
11 | + end | |
12 | + | |
13 | + attr_accessor :name | |
14 | + attr_accessor :subject | |
15 | + attr_accessor :message | |
16 | + attr_accessor :email | |
17 | + attr_accessor :receive_a_copy | |
18 | + attr_accessor :reciever | |
19 | + attr_accessor :sender | |
20 | + | |
21 | + N_('Subject'); N_('Message'); N_('e-Mail'); N_('Name') | |
22 | + | |
23 | + validates_presence_of :subject, :email, :message, :name | |
24 | + validates_format_of :email, :with => Noosfero::Constants::EMAIL_FORMAT, :if => (lambda {|o| !o.email.blank?}) | |
25 | + | |
26 | + def deliver | |
27 | + return false unless self.valid? | |
28 | + EmailContact::EmailSender.notification(self).deliver | |
29 | + end | |
30 | + | |
31 | + class EmailSender < ActionMailer::Base | |
32 | + def notification(email_contact) | |
33 | + @name = email_contact.name | |
34 | + @email = email_contact.email | |
35 | + @message = email_contact.message | |
36 | + @target = email_contact.reciever | |
37 | + | |
38 | + options = { | |
39 | + content_type: 'text/html', | |
40 | + to: email_contact.reciever, | |
41 | + reply_to: email_contact.email, | |
42 | + subject: email_contact.subject, | |
43 | + from: "#{email_contact.name} <#{email_contact.email}>" | |
44 | + } | |
45 | + | |
46 | + if email_contact.sender | |
47 | + options.merge!('X-Noosfero-Sender' => email_contact.sender.identifier) | |
48 | + end | |
49 | + | |
50 | + if email_contact.receive_a_copy | |
51 | + options.merge!(cc: "#{email_contact.name} <#{email_contact.email}>") | |
52 | + end | |
53 | + | |
54 | + mail(options) | |
55 | + end | |
56 | + end | |
57 | + | |
58 | +end | ... | ... |
plugins/work_assignment/views/work_assignment_plugin_cms/send_email.html.erb
1 | 1 | |
2 | -<%= error_messages_for 'contact' %> | |
2 | +<%= error_messages_for 'email_contact' %> | |
3 | 3 | |
4 | -<%=labelled_form_for :contact do |f| %> | |
4 | +<%=labelled_form_for :email_contact do |f| %> | |
5 | 5 | <%= hidden_field_tag(:confirm, 'false') %> |
6 | 6 | <%= hidden_field_tag(:self_files_id, @files_id_list) %> |
7 | 7 | |
8 | 8 | <%= required_fields_message %> |
9 | 9 | |
10 | 10 | <%= required f.text_field(:subject) %> |
11 | - <%# required f.text_field(:dest) %> | |
11 | + <%= required f.text_field(:reciever) %> | |
12 | 12 | <%= required f.text_field(:name) %> |
13 | 13 | |
14 | 14 | <%= render :file => 'shared/tiny_mce' %> |
15 | 15 | <%= required f.text_area(:message, :class => 'mceEditor') %> |
16 | 16 | |
17 | - <%= labelled_form_field check_box(:contact, :receive_a_copy) + _('I want to receive a copy of the message in my e-mail.'), '' %> | |
17 | + <%= labelled_form_field check_box(:email_contact, :receive_a_copy) + _('I want to receive a copy of the message in my e-mail.'), '' %> | |
18 | 18 | |
19 | 19 | <%= submit_button(:send, _('Send'), :onclick => "$('confirm').value = 'true'") %> |
20 | 20 | <%= submit_button(:cancel, _('Cancel'), :onclick =>"$('confirm').value = 'false'") %> | ... | ... |