Commit 94d6333bcc9f9b0547b63a02b6defdfb53c5b392
Committed by
Tallys Martins
1 parent
e42003f5
Exists in
master
and in
27 other branches
Refactored send_email to a new method.
Showing
1 changed file
with
12 additions
and
31 deletions
Show diff stats
plugins/work_assignment/controllers/myprofile/work_assignment_plugin_cms_controller.rb
@@ -51,28 +51,12 @@ class WorkAssignmentPluginCmsController < CmsController | @@ -51,28 +51,12 @@ class WorkAssignmentPluginCmsController < CmsController | ||
51 | @target = ['',@parent.url[:profile], @parent.url[:page]].join('/') | 51 | @target = ['',@parent.url[:profile], @parent.url[:page]].join('/') |
52 | @email_contact | 52 | @email_contact |
53 | if request.post? && params[:confirm] == 'true' | 53 | if request.post? && params[:confirm] == 'true' |
54 | - @files_paths = [] | ||
55 | - @files_string = params[:self_files_id] | ||
56 | - @files_id_list = @files_string.split(' ') | ||
57 | - | ||
58 | - @files_id_list.each do |file_id| | ||
59 | - @file = environment.articles.find_by_id(file_id) | ||
60 | - @real_file_url = "http://#{@file.url[:host]}:#{@file.url[:port]}/#{@file.url[:profile]}/#{@file.path}" | ||
61 | - @files_paths << @real_file_url | ||
62 | - unless params[:email_contact][:message].include? "#{@real_file_url}" | ||
63 | - params[:email_contact][:message] += "<br> Clique <a href='#{@real_file_url}'>aqui</a> para acessar o arquivo ou acesse pela URL: <br>" | ||
64 | - params[:email_contact][:message] += "<br><a href='#{@real_file_url}'>#{@real_file_url}</a>" | ||
65 | - end | ||
66 | - end | ||
67 | - @message = "AVISO: O aluno deve imprimir este email e entrega-lo na secretaria como comprovante do envio!" | ||
68 | - unless params[:email_contact][:message].include? "#{@message}" | ||
69 | - params[:email_contact][:message] += "<br><br>#{@message}" | ||
70 | - end | ||
71 | - @email_contact = user.build_email_contact(params[:email_contact]) | 54 | + params[:email_contact][:message] = build_mail_message(params[:self_files_id],params[:email_contact][:message]) |
55 | + @email_contact = user.build_email_contact(params[:email_contact]) | ||
72 | if @email_contact.deliver | 56 | if @email_contact.deliver |
73 | session[:notice] = _('Contact successfully sent') | 57 | session[:notice] = _('Contact successfully sent') |
74 | redirect_to @target | 58 | redirect_to @target |
75 | - else | 59 | + else |
76 | session[:notice] = _('Contact not sent') | 60 | session[:notice] = _('Contact not sent') |
77 | end | 61 | end |
78 | elsif request.post? && params[:confirm] == 'false' | 62 | elsif request.post? && params[:confirm] == 'false' |
@@ -99,28 +83,25 @@ class WorkAssignmentPluginCmsController < CmsController | @@ -99,28 +83,25 @@ class WorkAssignmentPluginCmsController < CmsController | ||
99 | end | 83 | end |
100 | end | 84 | end |
101 | 85 | ||
102 | -#TODO | ||
103 | -#Refatorar o método send_email para utilizar o build_mail_message para inserir o link dos arquivos | ||
104 | -=begin | ||
105 | - def build_mail_message | 86 | + def build_mail_message(files_ids, message) |
106 | @files_paths = [] | 87 | @files_paths = [] |
107 | - @files_string = params[:self_files_id] | 88 | + @files_string = files_ids |
108 | @files_id_list = @files_string.split(' ') | 89 | @files_id_list = @files_string.split(' ') |
109 | 90 | ||
110 | @files_id_list.each do |file_id| | 91 | @files_id_list.each do |file_id| |
111 | @file = environment.articles.find_by_id(file_id) | 92 | @file = environment.articles.find_by_id(file_id) |
112 | @real_file_url = "http://#{@file.url[:host]}:#{@file.url[:port]}/#{@file.url[:profile]}/#{@file.path}" | 93 | @real_file_url = "http://#{@file.url[:host]}:#{@file.url[:port]}/#{@file.url[:profile]}/#{@file.path}" |
113 | @files_paths << @real_file_url | 94 | @files_paths << @real_file_url |
114 | - unless params[:email_contact][:message].include? "#{@real_file_url}" | ||
115 | - params[:email_contact][:message] += "<br> Clique <a href='#{@real_file_url}'>aqui</a> para acessar o arquivo ou acesse pela URL: <br>" | ||
116 | - params[:email_contact][:message] += "<br><a href='#{@real_file_url}'>#{@real_file_url}</a>" | 95 | + unless message.include? "#{@real_file_url}" |
96 | + message += "<br> Clique <a href='#{@real_file_url}'>aqui</a> para acessar o arquivo ou acesse pela URL: <br>" | ||
97 | + message += "<br><a href='#{@real_file_url}'>#{@real_file_url}</a>" | ||
117 | end | 98 | end |
118 | end | 99 | end |
119 | - @message = "AVISO: O aluno deve imprimir este email e entrega-lo na secretaria como comprovante do envio!" | ||
120 | - unless params[:email_contact][:message].include? "#{@message}" | ||
121 | - params[:email_contact][:message] += "<br><br>#{@message}" | 100 | + @warning_message = "AVISO: O aluno deve imprimir este email e entrega-lo na secretaria como comprovante do envio!" |
101 | + unless message.include? "#{@warning_message}" | ||
102 | + message += "<br><br>#{@warning_message}" | ||
122 | end | 103 | end |
104 | + message | ||
123 | end | 105 | end |
124 | -=end | ||
125 | 106 | ||
126 | end | 107 | end |
127 | \ No newline at end of file | 108 | \ No newline at end of file |