Commit 99c763b5bcab185a3ecda4a8938cf1eac8f7a798
1 parent
e6c0328a
Exists in
master
and in
29 other branches
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.
Showing
9 changed files
with
56 additions
and
42 deletions
Show diff stats
lib/noosfero/plugin.rb
... | ... | @@ -417,6 +417,8 @@ class Noosfero::Plugin |
417 | 417 | nil |
418 | 418 | end |
419 | 419 | |
420 | + # -> Adds adicional fields to a view | |
421 | + # returns = proc block that creates html code | |
420 | 422 | def article_extra_fields(article) |
421 | 423 | nil |
422 | 424 | end |
... | ... | @@ -532,12 +534,6 @@ class Noosfero::Plugin |
532 | 534 | params |
533 | 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 | 537 | # -> Finds objects by their contents |
542 | 538 | # returns = {:results => [a, b, c, ...], ...} |
543 | 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 | 1 | class WorkAssignmentPluginCmsController < CmsController |
2 | 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 | 4 | end |
14 | 5 | \ No newline at end of file | ... | ... |
plugins/work_assignment/lib/ext/email_contact.rb
... | ... | @@ -53,18 +53,14 @@ class EmailContact |
53 | 53 | end |
54 | 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 | 64 | @message += "<br><a href='#{@real_file_url}'>#{@real_file_url}</a>" |
69 | 65 | end |
70 | 66 | @message | ... | ... |
plugins/work_assignment/lib/work_assignment_plugin.rb
... | ... | @@ -53,15 +53,16 @@ class WorkAssignmentPlugin < Noosfero::Plugin |
53 | 53 | |
54 | 54 | def cms_controller_filters |
55 | 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 | 66 | end |
66 | 67 | end |
67 | 68 | end |
... | ... | @@ -76,8 +77,8 @@ class WorkAssignmentPlugin < Noosfero::Plugin |
76 | 77 | proc do |
77 | 78 | @article = Article.find_by_id(article) |
78 | 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 | 82 | end |
82 | 83 | end |
83 | 84 | ... | ... |
plugins/work_assignment/lib/work_assignment_plugin/helper.rb
... | ... | @@ -64,6 +64,6 @@ module WorkAssignmentPlugin::Helper |
64 | 64 | end |
65 | 65 | |
66 | 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 | 68 | end |
69 | 69 | end | ... | ... |
plugins/work_assignment/lib/work_assignment_plugin/work_assignment.rb
1 | 1 | class WorkAssignmentPlugin::WorkAssignment < Folder |
2 | 2 | |
3 | 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 | 6 | attr_accessible :publish_submissions |
7 | - attr_accessible :email_notification | |
7 | + attr_accessible :default_email | |
8 | 8 | |
9 | 9 | def self.icon_name(article = nil) |
10 | 10 | 'work-assignment' | ... | ... |
... | ... | @@ -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 | 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 | 7 | \ No newline at end of file | ... | ... |
plugins/work_assignment/views/cms/work_assignment_plugin/_work_assignment.html.erb
1 | 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 | 5 | <%=labelled_check_box(_('Publish submissions'), 'article[publish_submissions]', true, @article.publish_submissions) %> |
6 | + | ... | ... |