Commit 94d6333bcc9f9b0547b63a02b6defdfb53c5b392
Committed by
Tallys Martins
1 parent
e42003f5
Exists in
master
and in
29 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 | 51 | @target = ['',@parent.url[:profile], @parent.url[:page]].join('/') |
| 52 | 52 | @email_contact |
| 53 | 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 | 56 | if @email_contact.deliver |
| 73 | 57 | session[:notice] = _('Contact successfully sent') |
| 74 | 58 | redirect_to @target |
| 75 | - else | |
| 59 | + else | |
| 76 | 60 | session[:notice] = _('Contact not sent') |
| 77 | 61 | end |
| 78 | 62 | elsif request.post? && params[:confirm] == 'false' |
| ... | ... | @@ -99,28 +83,25 @@ class WorkAssignmentPluginCmsController < CmsController |
| 99 | 83 | end |
| 100 | 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 | 87 | @files_paths = [] |
| 107 | - @files_string = params[:self_files_id] | |
| 88 | + @files_string = files_ids | |
| 108 | 89 | @files_id_list = @files_string.split(' ') |
| 109 | 90 | |
| 110 | 91 | @files_id_list.each do |file_id| |
| 111 | 92 | @file = environment.articles.find_by_id(file_id) |
| 112 | 93 | @real_file_url = "http://#{@file.url[:host]}:#{@file.url[:port]}/#{@file.url[:profile]}/#{@file.path}" |
| 113 | 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 | 98 | end |
| 118 | 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 | 103 | end |
| 104 | + message | |
| 123 | 105 | end |
| 124 | -=end | |
| 125 | 106 | |
| 126 | 107 | end |
| 127 | 108 | \ No newline at end of file | ... | ... |