Commit e6c0328a50fb1f89b69460c93dca29c80052b43a
1 parent
27831399
Exists in
master
and in
29 other branches
Refactoring Work Assignment
Added filters to cms controller to send email Removed unecessary dispatch on cms controller Signed-off-by: Andre Bernardes <andrebsguedes@gmail.com> Signed-off-by: Marcos Ronaldo <marcos.rpj2@gmail.com> Signed-off-by: Tallys Martins <tallysmartins@gmail.com>
Showing
10 changed files
with
49 additions
and
94 deletions
Show diff stats
app/controllers/my_profile/cms_controller.rb
| @@ -212,8 +212,7 @@ class CmsController < MyProfileController | @@ -212,8 +212,7 @@ class CmsController < MyProfileController | ||
| 212 | if @errors.any? | 212 | if @errors.any? |
| 213 | render :action => 'upload_files', :parent_id => @parent_id | 213 | render :action => 'upload_files', :parent_id => @parent_id |
| 214 | else | 214 | else |
| 215 | - session[:notice] = _('File(s) successfully uploaded') | ||
| 216 | - @plugins.dispatch(:check_extra_parameters, @upload_files, params).collect { |content| instance_exec(&content) } | 215 | + session[:notice] = _('File(s) successfully uploaded') |
| 217 | if @back_to | 216 | if @back_to |
| 218 | redirect_to @back_to | 217 | redirect_to @back_to |
| 219 | elsif @parent | 218 | elsif @parent |
app/views/cms/upload_files.html.erb
| @@ -21,7 +21,7 @@ | @@ -21,7 +21,7 @@ | ||
| 21 | 21 | ||
| 22 | <%= form_for('uploaded_file', :url => {:action => 'upload_files' }, :html => {:multipart => true}) do |f| %> | 22 | <%= form_for('uploaded_file', :url => {:action => 'upload_files' }, :html => {:multipart => true}) do |f| %> |
| 23 | 23 | ||
| 24 | - <%= @plugins.dispatch(:article_extra_contents, params[:parent_id]).collect { |content| instance_exec(&content) }.join("") %> | 24 | + <%= @plugins.dispatch(:article_extra_fields, params[:parent_id]).collect { |content| instance_exec(&content) }.join("") %> |
| 25 | 25 | ||
| 26 | <%= render :partial => 'upload_file_form', :locals => { :size => '45'} %> | 26 | <%= render :partial => 'upload_file_form', :locals => { :size => '45'} %> |
| 27 | 27 |
lib/noosfero/plugin.rb
| @@ -417,6 +417,9 @@ class Noosfero::Plugin | @@ -417,6 +417,9 @@ class Noosfero::Plugin | ||
| 417 | nil | 417 | nil |
| 418 | end | 418 | end |
| 419 | 419 | ||
| 420 | + def article_extra_fields(article) | ||
| 421 | + nil | ||
| 422 | + end | ||
| 420 | # -> Adds fields to the signup form | 423 | # -> Adds fields to the signup form |
| 421 | # returns = proc that creates html code | 424 | # returns = proc that creates html code |
| 422 | def signup_extra_contents | 425 | def signup_extra_contents |
plugins/work_assignment/controllers/myprofile/work_assignment_plugin_cms_controller.rb
| 1 | class WorkAssignmentPluginCmsController < CmsController | 1 | class WorkAssignmentPluginCmsController < CmsController |
| 2 | - | ||
| 3 | append_view_path File.join(File.dirname(__FILE__) + '/../../views') | 2 | append_view_path File.join(File.dirname(__FILE__) + '/../../views') |
| 4 | 3 | ||
| 5 | - def send_email | ||
| 6 | - @parent = check_parent(params[:id]) | ||
| 7 | - @files_id_list = params[:files_id] | ||
| 8 | - @target = ['',@parent.url[:profile], @parent.url[:page]].join('/') | ||
| 9 | - @email_contact | ||
| 10 | - if request.post? && params[:confirm] == 'true' | ||
| 11 | - params[:email_contact][:message] = build_mail_message(params[:self_files_id],params[:email_contact][:message]) | ||
| 12 | - @email_contact = user.build_email_contact(params[:email_contact]) | ||
| 13 | - if @email_contact.deliver | ||
| 14 | - session[:notice] = _('Contact successfully sent') | ||
| 15 | - redirect_to @target | ||
| 16 | - else | ||
| 17 | - session[:notice] = _('Contact not sent') | ||
| 18 | - end | ||
| 19 | - elsif request.post? && params[:confirm] == 'false' | ||
| 20 | - if @target | ||
| 21 | - session[:notice] = _('Email not sent') | ||
| 22 | - redirect_to @target | ||
| 23 | - elsif @parent | ||
| 24 | - redirect_to :action => 'view', :id => @parent.id, :paths_list => @paths_list | ||
| 25 | - else | ||
| 26 | - redirect_to :action => 'index' | ||
| 27 | - end | ||
| 28 | - else | ||
| 29 | - @email_contact = user.build_email_contact() | ||
| 30 | - end | ||
| 31 | - end | ||
| 32 | - | ||
| 33 | def destroy | 4 | def destroy |
| 34 | @article = profile.articles.find(params[:id]) | 5 | @article = profile.articles.find(params[:id]) |
| 35 | if request.post? | 6 | if request.post? |
| @@ -39,26 +10,4 @@ class WorkAssignmentPluginCmsController < CmsController | @@ -39,26 +10,4 @@ class WorkAssignmentPluginCmsController < CmsController | ||
| 39 | redirect_to referer | 10 | redirect_to referer |
| 40 | end | 11 | end |
| 41 | end | 12 | end |
| 42 | - | ||
| 43 | - def build_mail_message(files_ids, message) | ||
| 44 | - @files_paths = [] | ||
| 45 | - @files_string = files_ids | ||
| 46 | - @files_id_list = @files_string.split(' ') | ||
| 47 | - | ||
| 48 | - @files_id_list.each do |file_id| | ||
| 49 | - @file = environment.articles.find_by_id(file_id) | ||
| 50 | - @real_file_url = "http://#{@file.url[:host]}:#{@file.url[:port]}/#{@file.url[:profile]}/#{@file.path}" | ||
| 51 | - @files_paths << @real_file_url | ||
| 52 | - unless message.include? "#{@real_file_url}" | ||
| 53 | - message += "<br> Clique <a href='#{@real_file_url}'>aqui</a> para acessar o arquivo ou acesse pela URL: <br>" | ||
| 54 | - message += "<br><a href='#{@real_file_url}'>#{@real_file_url}</a>" | ||
| 55 | - end | ||
| 56 | - end | ||
| 57 | - @warning_message = "AVISO: O aluno deve imprimir este email e entrega-lo na secretaria como comprovante do envio!" | ||
| 58 | - unless message.include? "#{@warning_message}" | ||
| 59 | - message += "<br><br>#{@warning_message}" | ||
| 60 | - end | ||
| 61 | - message | ||
| 62 | - end | ||
| 63 | - | ||
| 64 | end | 13 | end |
| 65 | \ No newline at end of file | 14 | \ No newline at end of file |
plugins/work_assignment/lib/ext/email_contact.rb
| @@ -15,7 +15,7 @@ class EmailContact | @@ -15,7 +15,7 @@ class EmailContact | ||
| 15 | attr_accessor :message | 15 | attr_accessor :message |
| 16 | attr_accessor :email | 16 | attr_accessor :email |
| 17 | attr_accessor :receive_a_copy | 17 | attr_accessor :receive_a_copy |
| 18 | - attr_accessor :reciever | 18 | + attr_accessor :receiver |
| 19 | attr_accessor :sender | 19 | attr_accessor :sender |
| 20 | 20 | ||
| 21 | N_('Subject'); N_('Message'); N_('e-Mail'); N_('Name') | 21 | N_('Subject'); N_('Message'); N_('e-Mail'); N_('Name') |
| @@ -34,11 +34,11 @@ class EmailContact | @@ -34,11 +34,11 @@ class EmailContact | ||
| 34 | @name = email_contact.name | 34 | @name = email_contact.name |
| 35 | @email = email_contact.email | 35 | @email = email_contact.email |
| 36 | @message = email_contact.message | 36 | @message = email_contact.message |
| 37 | - @target = email_contact.reciever | 37 | + @target = email_contact.receiver |
| 38 | 38 | ||
| 39 | options = { | 39 | options = { |
| 40 | content_type: 'text/html', | 40 | content_type: 'text/html', |
| 41 | - to: email_contact.reciever, | 41 | + to: email_contact.receiver, |
| 42 | reply_to: email_contact.email, | 42 | reply_to: email_contact.email, |
| 43 | subject: email_contact.subject, | 43 | subject: email_contact.subject, |
| 44 | body: email_contact.message, | 44 | body: email_contact.message, |
| @@ -53,4 +53,21 @@ class EmailContact | @@ -53,4 +53,21 @@ class EmailContact | ||
| 53 | end | 53 | end |
| 54 | end | 54 | end |
| 55 | 55 | ||
| 56 | + def build_mail_message(environment, files_ids, parent_name) | ||
| 57 | + @files_paths = [] | ||
| 58 | + @message | ||
| 59 | + @files_string = files_ids | ||
| 60 | + @files_id_list = @files_string.split(' ') | ||
| 61 | + | ||
| 62 | + @files_id_list.each do |file_id| | ||
| 63 | + @file = environment.articles.find_by_id(file_id) | ||
| 64 | + @real_file_url = "http://#{@file.url[:host]}:#{@file.url[:port]}/#{@file.url[:profile]}/#{@file.path}" | ||
| 65 | + @files_paths << @real_file_url | ||
| 66 | + @message = "<br>A file was sent to #{parent_name} and you are being notified." | ||
| 67 | + @message += "<br> Click <a href='#{@real_file_url}'>here</a> to access the file or use the URL below: <br>" | ||
| 68 | + @message += "<br><a href='#{@real_file_url}'>#{@real_file_url}</a>" | ||
| 69 | + end | ||
| 70 | + @message | ||
| 71 | + end | ||
| 72 | + | ||
| 56 | end | 73 | end |
plugins/work_assignment/lib/work_assignment_plugin.rb
| @@ -51,25 +51,34 @@ class WorkAssignmentPlugin < Noosfero::Plugin | @@ -51,25 +51,34 @@ class WorkAssignmentPlugin < Noosfero::Plugin | ||
| 51 | :block => block } | 51 | :block => block } |
| 52 | end | 52 | end |
| 53 | 53 | ||
| 54 | + def cms_controller_filters | ||
| 55 | + block = proc do | ||
| 56 | + @email_notification = params[:article_email_notification] | ||
| 57 | + if !@email_notification.nil? and @email_notification.include? "@" | ||
| 58 | + @subject = "#{@parent.name} file submission" | ||
| 59 | + @email_contact = user.build_email_contact(:name => user.name, :subject => @subject, :email => user.email, :receiver => @email_notification, :sender => user) | ||
| 60 | + @email_contact.message = @email_contact.build_mail_message(environment, @uploaded_files, @parent.name) | ||
| 61 | + if @email_contact.deliver | ||
| 62 | + session[:notice] = _('Notification successfully sent') | ||
| 63 | + else | ||
| 64 | + session[:notice] = _('Notification not sent') | ||
| 65 | + end | ||
| 66 | + end | ||
| 67 | + end | ||
| 68 | + | ||
| 69 | + { :type => 'after_filter', | ||
| 70 | + :method_name => 'send_email_after_upload_file', | ||
| 71 | + :options => {:only => 'upload_files'}, | ||
| 72 | + :block => block } | ||
| 73 | + end | ||
| 54 | 74 | ||
| 55 | - def article_extra_contents(article_id) | 75 | + def article_extra_fields(article) |
| 56 | proc do | 76 | proc do |
| 57 | - @article = Article.find_by_id(article_id) | 77 | + @article = Article.find_by_id(article) |
| 58 | if params[:parent_id] && !@article.nil? && @article.type == "WorkAssignmentPlugin::WorkAssignment" | 78 | if params[:parent_id] && !@article.nil? && @article.type == "WorkAssignmentPlugin::WorkAssignment" |
| 59 | - render :partial => 'notify_checkbox', :locals => { :size => '45'} | 79 | + render :partial => 'notify_text_field', :locals => { :size => '45'} |
| 60 | end | 80 | end |
| 61 | end | 81 | end |
| 62 | end | 82 | end |
| 63 | 83 | ||
| 64 | - def check_extra_parameters (uploaded_files, params = {}) | ||
| 65 | - @email_notification = params[:article_email_notification] | ||
| 66 | - # uploaded_files = params[:uploaded_files] | ||
| 67 | - id = params[:parent_id] | ||
| 68 | - if @email_notification == 'true' | ||
| 69 | - proc do | ||
| 70 | - @back_to = url_for :controller => 'work_assignment_plugin_cms', :action => 'send_email', :id => id, :files_id => uploaded_files, :confirm => true | ||
| 71 | - end | ||
| 72 | - end | ||
| 73 | - end | ||
| 74 | - | ||
| 75 | end | 84 | end |
| 76 | \ No newline at end of file | 85 | \ No newline at end of file |
plugins/work_assignment/lib/work_assignment_plugin/helper.rb
| @@ -36,7 +36,6 @@ module WorkAssignmentPlugin::Helper | @@ -36,7 +36,6 @@ module WorkAssignmentPlugin::Helper | ||
| 36 | ), | 36 | ), |
| 37 | :class => "submission-from-#{submission.parent.id}", | 37 | :class => "submission-from-#{submission.parent.id}", |
| 38 | :style => 'display: none' | 38 | :style => 'display: none' |
| 39 | - #content_tag('button', _('Destroy file'), :class => 'button icon-delete ', | ||
| 40 | ) | 39 | ) |
| 41 | end | 40 | end |
| 42 | 41 |
plugins/work_assignment/views/cms/_notify_checkbox.html.erb
plugins/work_assignment/views/cms/_notify_text_field.html.erb
0 → 100644
plugins/work_assignment/views/work_assignment_plugin_cms/send_email.html.erb
| @@ -1,21 +0,0 @@ | @@ -1,21 +0,0 @@ | ||
| 1 | - | ||
| 2 | -<%= error_messages_for 'email_contact' %> | ||
| 3 | - | ||
| 4 | -<%=labelled_form_for :email_contact do |f| %> | ||
| 5 | - <%= hidden_field_tag(:confirm, 'false') %> | ||
| 6 | - <%= hidden_field_tag(:self_files_id, @files_id_list) %> | ||
| 7 | - | ||
| 8 | - <%= required_fields_message %> | ||
| 9 | - | ||
| 10 | - <%= required f.text_field(:subject) %> | ||
| 11 | - <%= required f.text_field(:reciever) %> | ||
| 12 | - <%= required f.text_field(:name) %> | ||
| 13 | - | ||
| 14 | - <%= render :file => 'shared/tiny_mce' %> | ||
| 15 | - <%= required f.text_area(:message, :class => 'mceEditor') %> | ||
| 16 | - | ||
| 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 | - | ||
| 19 | - <%= submit_button(:send, _('Send'), :onclick => "$('confirm').value = 'true'") %> | ||
| 20 | - <%= submit_button(:cancel, _('Cancel'), :onclick =>"$('confirm').value = 'false'") %> | ||
| 21 | -<% end %> |