Commit 99c763b5bcab185a3ecda4a8938cf1eac8f7a798

Authored by Tallys Martins
1 parent e6c0328a

Added new attribute to Work_assignment article type

Added default email message attribute to be sent when user choose to notify somebody.
Refactored build_email_message method that attaches the URL of the uploaded files to the email message.
Added Java Script to fill in the email field with  an example.
Removed destroy action method on plugin cms controller, now using the existent in the core cms controller.
lib/noosfero/plugin.rb
@@ -417,6 +417,8 @@ class Noosfero::Plugin @@ -417,6 +417,8 @@ class Noosfero::Plugin
417 nil 417 nil
418 end 418 end
419 419
  420 + # -> Adds adicional fields to a view
  421 + # returns = proc block that creates html code
420 def article_extra_fields(article) 422 def article_extra_fields(article)
421 nil 423 nil
422 end 424 end
@@ -532,12 +534,6 @@ class Noosfero::Plugin @@ -532,12 +534,6 @@ class Noosfero::Plugin
532 params 534 params
533 end 535 end
534 536
535 - # -> Checks adicional parameters passed through html  
536 - # by the work_assignment plugin  
537 - def check_extra_parameters(uploaded_files, params = {})  
538 - nil  
539 - end  
540 -  
541 # -> Finds objects by their contents 537 # -> Finds objects by their contents
542 # returns = {:results => [a, b, c, ...], ...} 538 # returns = {:results => [a, b, c, ...], ...}
543 # P.S.: The plugin might add other informations on the return hash for its 539 # P.S.: The plugin might add other informations on the return hash for its
plugins/work_assignment/controllers/myprofile/work_assignment_plugin_cms_controller.rb
1 class WorkAssignmentPluginCmsController < CmsController 1 class WorkAssignmentPluginCmsController < CmsController
2 append_view_path File.join(File.dirname(__FILE__) + '/../../views') 2 append_view_path File.join(File.dirname(__FILE__) + '/../../views')
3 3
4 - def destroy  
5 - @article = profile.articles.find(params[:id])  
6 - if request.post?  
7 - @article.destroy  
8 - session[:notice] = _("\"#{@article.name}\" was removed.")  
9 - referer = Rails.application.routes.recognize_path URI.parse(request.referer).path rescue nil  
10 - redirect_to referer  
11 - end  
12 - end  
13 end 4 end
14 \ No newline at end of file 5 \ No newline at end of file
plugins/work_assignment/lib/ext/email_contact.rb
@@ -53,18 +53,14 @@ class EmailContact @@ -53,18 +53,14 @@ 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>" 56 + def build_mail_message(environment, uploaded_files, parent_id)
  57 + @article = environment.articles.find_by_id(parent_id)
  58 + @message = ""
  59 + if !@article.nil? && @article.type == "WorkAssignmentPlugin::WorkAssignment"
  60 + @message = @article.default_email + "<br>"
  61 + end
  62 + uploaded_files.each do |file|
  63 + @real_file_url = "http://#{file.url[:host]}:#{file.url[:port]}/#{file.url[:profile]}/#{file.path}"
68 @message += "<br><a href='#{@real_file_url}'>#{@real_file_url}</a>" 64 @message += "<br><a href='#{@real_file_url}'>#{@real_file_url}</a>"
69 end 65 end
70 @message 66 @message
plugins/work_assignment/lib/work_assignment_plugin.rb
@@ -53,15 +53,16 @@ class WorkAssignmentPlugin &lt; Noosfero::Plugin @@ -53,15 +53,16 @@ class WorkAssignmentPlugin &lt; Noosfero::Plugin
53 53
54 def cms_controller_filters 54 def cms_controller_filters
55 block = proc do 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') 56 + if request.post? && params[:uploaded_files]
  57 + @email_notification = params[:article_email_notification]
  58 + unless @email_notification.include? "example@example.com, example2@example.com.br"
  59 + @email_contact = user.build_email_contact(:name => user.name, :subject => @parent.name, :email => user.email, :receiver => @email_notification, :sender => user)
  60 + @email_contact.message = @email_contact.build_mail_message(environment, @uploaded_files, @parent.id)
  61 + if @email_contact.deliver
  62 + session[:notice] = _('Notification successfully sent')
  63 + else
  64 + session[:notice] = _('Notification not sent')
  65 + end
65 end 66 end
66 end 67 end
67 end 68 end
@@ -76,8 +77,8 @@ class WorkAssignmentPlugin &lt; Noosfero::Plugin @@ -76,8 +77,8 @@ class WorkAssignmentPlugin &lt; Noosfero::Plugin
76 proc do 77 proc do
77 @article = Article.find_by_id(article) 78 @article = Article.find_by_id(article)
78 if params[:parent_id] && !@article.nil? && @article.type == "WorkAssignmentPlugin::WorkAssignment" 79 if params[:parent_id] && !@article.nil? && @article.type == "WorkAssignmentPlugin::WorkAssignment"
79 - render :partial => 'notify_text_field', :locals => { :size => '45'}  
80 - end 80 + render :partial => 'notify_text_field', :locals => { :size => '45'}
  81 + end
81 end 82 end
82 end 83 end
83 84
plugins/work_assignment/lib/work_assignment_plugin/helper.rb
@@ -64,6 +64,6 @@ module WorkAssignmentPlugin::Helper @@ -64,6 +64,6 @@ module WorkAssignmentPlugin::Helper
64 end 64 end
65 65
66 def display_delete_button(article) 66 def display_delete_button(article)
67 - expirable_button article, :delete, _('Delete'), {:controller =>'work_assignment_plugin_cms', :action => 'destroy', :id => article.id }, :method => :post, :confirm => delete_article_message(article) 67 + expirable_button article, :delete, _('Delete'), {:controller =>'cms', :action => 'destroy', :id => article.id }, :method => :post, :confirm => delete_article_message(article)
68 end 68 end
69 end 69 end
plugins/work_assignment/lib/work_assignment_plugin/work_assignment.rb
1 class WorkAssignmentPlugin::WorkAssignment < Folder 1 class WorkAssignmentPlugin::WorkAssignment < Folder
2 2
3 settings_items :publish_submissions, :type => :boolean, :default => false 3 settings_items :publish_submissions, :type => :boolean, :default => false
4 - settings_items :email_notification, :type => :boolean, :default => false 4 + settings_items :default_email, :type => :string, :default => ""
5 5
6 attr_accessible :publish_submissions 6 attr_accessible :publish_submissions
7 - attr_accessible :email_notification 7 + attr_accessible :default_email
8 8
9 def self.icon_name(article = nil) 9 def self.icon_name(article = nil)
10 'work-assignment' 10 'work-assignment'
plugins/work_assignment/public/text_field_css.js 0 → 100644
@@ -0,0 +1,22 @@ @@ -0,0 +1,22 @@
  1 + var element = jQuery("input[name='article_email_notification']");
  2 + var initialVal="example@example.com, example2@example.com.br";
  3 + var isEdited=false;
  4 + element.val(initialVal);
  5 +
  6 + element.focus(function(){
  7 + if(!isEdited){
  8 + element.val("");
  9 + isEdited=true;
  10 + }
  11 +
  12 + });
  13 +
  14 + element.blur(function(){
  15 + if(element.val()==""){
  16 + element.val(initialVal);
  17 + isEdited=false;
  18 + }
  19 +
  20 + });
  21 +
  22 +
plugins/work_assignment/views/cms/_notify_text_field.html.erb
1 -<%= labelled_text_field(_('Send notification to: '), 'article_email_notification') %>  
2 \ No newline at end of file 1 \ No newline at end of file
  2 +<h5><%= _('If you want to notify someone about this action, fill the field below with the emails of the destinies, separated by comma.') %></h5>
  3 +
  4 +<%= labelled_text_field(_('Send notification to: '), 'article_email_notification', "", :style => 'width: 60%;') %>
  5 +
  6 +<%= javascript_include_tag '../plugins/work_assignment/text_field_css' %>
3 \ No newline at end of file 7 \ No newline at end of file
plugins/work_assignment/views/cms/work_assignment_plugin/_work_assignment.html.erb
1 <%= render :partial => 'folder', :locals => {:f => f} %> 1 <%= render :partial => 'folder', :locals => {:f => f} %>
  2 +
  3 +<%= labelled_form_field(_('Default email message:'), text_area(:article, :default_email, :rows => 3, :cols => 64)) %>
  4 +
2 <%=labelled_check_box(_('Publish submissions'), 'article[publish_submissions]', true, @article.publish_submissions) %> 5 <%=labelled_check_box(_('Publish submissions'), 'article[publish_submissions]', true, @article.publish_submissions) %>
  6 +