Commit 27831399b97b54c91d9375f01b8b62c794c7b4a1
1 parent
94d6333b
Exists in
master
and in
29 other branches
Fixing bugs on Work Assignment plugin
- Removed useless view. - Fixed problem on page render when file error(e.g. over max size) is detected. - Fixed bug when no file selected. - Refactored dispatch on upload_files.html.erb to have less impact on core. - Added java script to modify the form action to use the plugin controller on upload_files form. - Fixed Work Assignment not sending e-mails - Removing duplicated code - Added new 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
13 changed files
with
34 additions
and
124 deletions
Show diff stats
app/controllers/my_profile/cms_controller.rb
@@ -212,6 +212,8 @@ class CmsController < MyProfileController | @@ -212,6 +212,8 @@ 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 | if @back_to | 217 | if @back_to |
216 | redirect_to @back_to | 218 | redirect_to @back_to |
217 | elsif @parent | 219 | elsif @parent |
app/views/cms/upload_files.html.erb
@@ -19,15 +19,11 @@ | @@ -19,15 +19,11 @@ | ||
19 | 19 | ||
20 | <h5><%= _('Uploading files to %s') % content_tag('code', @target) %></h5> | 20 | <h5><%= _('Uploading files to %s') % content_tag('code', @target) %></h5> |
21 | 21 | ||
22 | -<% if @plugins.dispatch(:upload_files_extra_contents).size == 0 %> | ||
23 | - <%= 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| %> |
24 | 23 | ||
25 | - <%= render :partial => 'upload_file_form', :locals => { :size => '45'} %> | ||
26 | - | ||
27 | - <% end %> | ||
28 | -<% else %> | 24 | + <%= @plugins.dispatch(:article_extra_contents, params[:parent_id]).collect { |content| instance_exec(&content) }.join("") %> |
29 | 25 | ||
30 | - <%= @plugins.dispatch(:upload_files_extra_contents).collect { |content| instance_eval(&content) }.join("") %> | 26 | + <%= render :partial => 'upload_file_form', :locals => { :size => '45'} %> |
31 | 27 | ||
32 | -<% end %> | 28 | +<% end %> |
33 | 29 |
lib/noosfero/plugin.rb
@@ -529,6 +529,12 @@ class Noosfero::Plugin | @@ -529,6 +529,12 @@ class Noosfero::Plugin | ||
529 | params | 529 | params |
530 | end | 530 | end |
531 | 531 | ||
532 | + # -> Checks adicional parameters passed through html | ||
533 | + # by the work_assignment plugin | ||
534 | + def check_extra_parameters(uploaded_files, params = {}) | ||
535 | + nil | ||
536 | + end | ||
537 | + | ||
532 | # -> Finds objects by their contents | 538 | # -> Finds objects by their contents |
533 | # returns = {:results => [a, b, c, ...], ...} | 539 | # returns = {:results => [a, b, c, ...], ...} |
534 | # P.S.: The plugin might add other informations on the return hash for its | 540 | # 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
@@ -2,49 +2,6 @@ class WorkAssignmentPluginCmsController < CmsController | @@ -2,49 +2,6 @@ class WorkAssignmentPluginCmsController < CmsController | ||
2 | 2 | ||
3 | append_view_path File.join(File.dirname(__FILE__) + '/../../views') | 3 | append_view_path File.join(File.dirname(__FILE__) + '/../../views') |
4 | 4 | ||
5 | - def upload_files | ||
6 | - @uploaded_files = [] | ||
7 | - @article = @parent = check_parent(params[:parent_id]) | ||
8 | - @email_notification = params[:article_email_notification] | ||
9 | - | ||
10 | - @target = @parent ? ('/%s/%s' % [profile.identifier, @parent.full_name]) : '/%s' % profile.identifier | ||
11 | - if @article | ||
12 | - record_coming | ||
13 | - end | ||
14 | - if request.post? && params[:uploaded_files] | ||
15 | - params[:uploaded_files].each do |file| | ||
16 | - unless file == '' | ||
17 | - @uploaded_files << UploadedFile.create( | ||
18 | - { | ||
19 | - :uploaded_data => file, | ||
20 | - :profile => profile, | ||
21 | - :parent => @parent, | ||
22 | - :last_changed_by => user, | ||
23 | - :author => user, | ||
24 | - }, | ||
25 | - :without_protection => true | ||
26 | - ) | ||
27 | - end | ||
28 | - end | ||
29 | - @errors = @uploaded_files.select { |f| f.errors.any? } | ||
30 | - if @errors.any? | ||
31 | - render :action => 'upload_files', :id => @parent_id | ||
32 | - else | ||
33 | - if @back_to | ||
34 | - if @email_notification == 'true' | ||
35 | - redirect_to :controller => 'work_assignment_plugin_cms', :action => 'send_email', :id => @parent.id, :files_id => @uploaded_files, :confirm => true | ||
36 | - else | ||
37 | - redirect_to @back_to | ||
38 | - end | ||
39 | - elsif @parent | ||
40 | - redirect_to :controller => 'cms', :action => 'view', :id => @parent.id | ||
41 | - else | ||
42 | - redirect_to :controller => 'cms', :action => 'index' | ||
43 | - end | ||
44 | - end | ||
45 | - end | ||
46 | - end | ||
47 | - | ||
48 | def send_email | 5 | def send_email |
49 | @parent = check_parent(params[:id]) | 6 | @parent = check_parent(params[:id]) |
50 | @files_id_list = params[:files_id] | 7 | @files_id_list = params[:files_id] |
plugins/work_assignment/lib/ext/email_contact.rb
@@ -29,6 +29,7 @@ class EmailContact | @@ -29,6 +29,7 @@ class EmailContact | ||
29 | end | 29 | end |
30 | 30 | ||
31 | class EmailSender < ActionMailer::Base | 31 | class EmailSender < ActionMailer::Base |
32 | + | ||
32 | def notification(email_contact) | 33 | def notification(email_contact) |
33 | @name = email_contact.name | 34 | @name = email_contact.name |
34 | @email = email_contact.email | 35 | @email = email_contact.email |
@@ -40,16 +41,12 @@ class EmailContact | @@ -40,16 +41,12 @@ class EmailContact | ||
40 | to: email_contact.reciever, | 41 | to: email_contact.reciever, |
41 | reply_to: email_contact.email, | 42 | reply_to: email_contact.email, |
42 | subject: email_contact.subject, | 43 | subject: email_contact.subject, |
43 | - message: email_contact.message, | 44 | + body: email_contact.message, |
44 | from: "#{email_contact.name} <#{email_contact.email}>" | 45 | from: "#{email_contact.name} <#{email_contact.email}>" |
45 | } | 46 | } |
46 | 47 | ||
47 | - if email_contact.sender | ||
48 | - options.merge!('X-Noosfero-Sender' => email_contact.sender.identifier) | ||
49 | - end | ||
50 | - | ||
51 | - if email_contact.receive_a_copy | ||
52 | - options.merge!(cc: "#{email_contact.name} <#{email_contact.email}>") | 48 | + if email_contact.receive_a_copy == "1" |
49 | + options.merge!(cc: "#{email_contact.email}") | ||
53 | end | 50 | end |
54 | 51 | ||
55 | mail(options) | 52 | mail(options) |
plugins/work_assignment/lib/work_assignment_plugin.rb
@@ -52,20 +52,24 @@ class WorkAssignmentPlugin < Noosfero::Plugin | @@ -52,20 +52,24 @@ class WorkAssignmentPlugin < Noosfero::Plugin | ||
52 | end | 52 | end |
53 | 53 | ||
54 | 54 | ||
55 | - def upload_files_extra_contents | 55 | + def article_extra_contents(article_id) |
56 | proc do | 56 | proc do |
57 | - if params[:parent_id] | ||
58 | - parent_id = params[:parent_id] | ||
59 | - path = Article.find_by_id(parent_id).path.split("/")[0] | ||
60 | - content = profile.articles.find_by_path(path) | 57 | + @article = Article.find_by_id(article_id) |
58 | + if params[:parent_id] && !@article.nil? && @article.type == "WorkAssignmentPlugin::WorkAssignment" | ||
59 | + render :partial => 'notify_checkbox', :locals => { :size => '45'} | ||
60 | + end | ||
61 | + end | ||
62 | + end | ||
61 | 63 | ||
62 | - if content.type == "WorkAssignmentPlugin::WorkAssignment" | ||
63 | - render :partial => 'work_assignment_form', :locals => { :size => '45'} | ||
64 | - end | ||
65 | - else | ||
66 | - render :partial => 'upload_file_form', :locals => { :size => '45'} | 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 | ||
67 | end | 71 | end |
68 | end | 72 | end |
69 | end | 73 | end |
70 | 74 | ||
71 | -end | 75 | -end |
76 | +end | ||
72 | \ No newline at end of file | 77 | \ No newline at end of file |
plugins/work_assignment/public/show_notification_email.js
@@ -1,12 +0,0 @@ | @@ -1,12 +0,0 @@ | ||
1 | -jQuery(function($) { | ||
2 | - function show_hide_token_input() { | ||
3 | - if($('input:checkbox[name="article_email_notification"]').attr('checked')){ | ||
4 | - $("#email_notifications").css('display', 'inline-block');} | ||
5 | - else | ||
6 | - $("#email_notifications").css('display', 'none'); | ||
7 | - } | ||
8 | - | ||
9 | - show_hide_token_input(); | ||
10 | - //Hide / Show the text area | ||
11 | - $("#checkbox-0").click(show_hide_token_input); | ||
12 | -}); | ||
13 | \ No newline at end of file | 0 | \ No newline at end of file |
plugins/work_assignment/public/style.css
1 | .icon-newwork-assignment { background-image: url(../../designs/icons/tango/Tango/16x16/categories/applications-office.png) } | 1 | .icon-newwork-assignment { background-image: url(../../designs/icons/tango/Tango/16x16/categories/applications-office.png) } |
2 | -.icon-work-assignment { background-image: url(../../designs/icons/tango/Tango/16x16/categories/applications-office.png) } | ||
3 | - | ||
4 | -#email_notifications{ | ||
5 | - padding: 10px 20px; | ||
6 | - display: inline-block; | ||
7 | -} | ||
8 | - | ||
9 | -#email_notifications label{ | ||
10 | - width: 117px; | ||
11 | - display: block; | ||
12 | - float: left; | ||
13 | -} | ||
14 | - | ||
15 | -#email_notifications input, #email_notifications textarea{ | ||
16 | - display: block; | ||
17 | - float: left; | ||
18 | - resize: vertical; | ||
19 | - width: 330px; | ||
20 | - line-height: 1.5em; | ||
21 | -} | ||
22 | - | ||
23 | -body.action-cms-upload_files #uploaded_files p:nth-child(3), | ||
24 | -body.action-cms-upload_files #uploaded_files p:nth-child(5){ | ||
25 | - display: none; | ||
26 | - } | 2 | +.icon-work-assignment { background-image: url(../../designs/icons/tango/Tango/16x16/categories/applications-office.png) } |
27 | \ No newline at end of file | 3 | \ No newline at end of file |
plugins/work_assignment/views/cms/_notify_checkbox.html.erb
1 | -<%= javascript_include_tag '../plugins/work_assignment/show_notification_email' %> | ||
2 | -<%= labelled_check_box(_('Send notification'), 'article_email_notification', true) %> | ||
3 | - | ||
4 | -<div id='email_notifications'> | ||
5 | - | ||
6 | - | ||
7 | -</div> | 1 | +<%= labelled_check_box(_('Send notification'), 'article_email_notification', true) %> |
8 | \ No newline at end of file | 2 | \ No newline at end of file |
plugins/work_assignment/views/cms/_work_assignment_form.html.erb
@@ -1,4 +0,0 @@ | @@ -1,4 +0,0 @@ | ||
1 | -<%= form_for('uploaded_file', :url => { :controller => 'work_assignment_plugin_cms', :action => 'upload_files' }, :html => {:multipart => true}) do |f| %> | ||
2 | - <%= render :partial => 'notify_checkbox', :locals => { :size => '45'} %> | ||
3 | - <%= render :partial => 'upload_file_form', :locals => { :size => '45'} %> | ||
4 | -<% end %> | ||
5 | \ No newline at end of file | 0 | \ 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_check_box(_('Publish submissions'), 'article[publish_submissions]', true, @article.publish_submissions) %> | 2 | <%=labelled_check_box(_('Publish submissions'), 'article[publish_submissions]', true, @article.publish_submissions) %> |
plugins/work_assignment/views/work_assignment_plugin_cms/_work_assignment_form.html.erb
@@ -1,5 +0,0 @@ | @@ -1,5 +0,0 @@ | ||
1 | -<% form_for('uploaded_file', :url => { :controller => 'work_assignment_plugin_cms', :action => 'upload_files' }, :html => {:multipart => true}) do |f| %> | ||
2 | - <%= render :partial => 'notify_checkbox', :locals => { :size => '45'} %> | ||
3 | - <%= render :partial => 'upload_file_form', :locals => { :size => '45'} %> | ||
4 | - | ||
5 | -<% end %> | ||
6 | \ No newline at end of file | 0 | \ No newline at end of file |
plugins/work_assignment/views/work_assignment_plugin_cms/send_email.html.erb
@@ -14,7 +14,7 @@ | @@ -14,7 +14,7 @@ | ||
14 | <%= render :file => 'shared/tiny_mce' %> | 14 | <%= render :file => 'shared/tiny_mce' %> |
15 | <%= required f.text_area(:message, :class => 'mceEditor') %> | 15 | <%= required f.text_area(:message, :class => 'mceEditor') %> |
16 | 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.'), '' %> | 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 | 18 | ||
19 | <%= submit_button(:send, _('Send'), :onclick => "$('confirm').value = 'true'") %> | 19 | <%= submit_button(:send, _('Send'), :onclick => "$('confirm').value = 'true'") %> |
20 | <%= submit_button(:cancel, _('Cancel'), :onclick =>"$('confirm').value = 'false'") %> | 20 | <%= submit_button(:cancel, _('Cancel'), :onclick =>"$('confirm').value = 'false'") %> |