diff --git a/app/controllers/my_profile/cms_controller.rb b/app/controllers/my_profile/cms_controller.rb
index 838226b..c70285a 100644
--- a/app/controllers/my_profile/cms_controller.rb
+++ b/app/controllers/my_profile/cms_controller.rb
@@ -212,8 +212,7 @@ class CmsController < MyProfileController
if @errors.any?
render :action => 'upload_files', :parent_id => @parent_id
else
- session[:notice] = _('File(s) successfully uploaded')
- @plugins.dispatch(:check_extra_parameters, @upload_files, params).collect { |content| instance_exec(&content) }
+ session[:notice] = _('File(s) successfully uploaded')
if @back_to
redirect_to @back_to
elsif @parent
diff --git a/app/views/cms/upload_files.html.erb b/app/views/cms/upload_files.html.erb
index 18afa20..d47a73e 100644
--- a/app/views/cms/upload_files.html.erb
+++ b/app/views/cms/upload_files.html.erb
@@ -21,7 +21,7 @@
<%= form_for('uploaded_file', :url => {:action => 'upload_files' }, :html => {:multipart => true}) do |f| %>
- <%= @plugins.dispatch(:article_extra_contents, params[:parent_id]).collect { |content| instance_exec(&content) }.join("") %>
+ <%= @plugins.dispatch(:article_extra_fields, params[:parent_id]).collect { |content| instance_exec(&content) }.join("") %>
<%= render :partial => 'upload_file_form', :locals => { :size => '45'} %>
diff --git a/lib/noosfero/plugin.rb b/lib/noosfero/plugin.rb
index 87b0ce0..58ba780 100644
--- a/lib/noosfero/plugin.rb
+++ b/lib/noosfero/plugin.rb
@@ -417,6 +417,9 @@ class Noosfero::Plugin
nil
end
+ def article_extra_fields(article)
+ nil
+ end
# -> Adds fields to the signup form
# returns = proc that creates html code
def signup_extra_contents
diff --git a/plugins/work_assignment/controllers/myprofile/work_assignment_plugin_cms_controller.rb b/plugins/work_assignment/controllers/myprofile/work_assignment_plugin_cms_controller.rb
index 58ae738..277cb30 100644
--- a/plugins/work_assignment/controllers/myprofile/work_assignment_plugin_cms_controller.rb
+++ b/plugins/work_assignment/controllers/myprofile/work_assignment_plugin_cms_controller.rb
@@ -1,35 +1,6 @@
class WorkAssignmentPluginCmsController < CmsController
-
append_view_path File.join(File.dirname(__FILE__) + '/../../views')
- def send_email
- @parent = check_parent(params[:id])
- @files_id_list = params[:files_id]
- @target = ['',@parent.url[:profile], @parent.url[:page]].join('/')
- @email_contact
- if request.post? && params[:confirm] == 'true'
- params[:email_contact][:message] = build_mail_message(params[:self_files_id],params[:email_contact][:message])
- @email_contact = user.build_email_contact(params[:email_contact])
- if @email_contact.deliver
- session[:notice] = _('Contact successfully sent')
- redirect_to @target
- else
- session[:notice] = _('Contact not sent')
- end
- elsif request.post? && params[:confirm] == 'false'
- if @target
- session[:notice] = _('Email not sent')
- redirect_to @target
- elsif @parent
- redirect_to :action => 'view', :id => @parent.id, :paths_list => @paths_list
- else
- redirect_to :action => 'index'
- end
- else
- @email_contact = user.build_email_contact()
- end
- end
-
def destroy
@article = profile.articles.find(params[:id])
if request.post?
@@ -39,26 +10,4 @@ class WorkAssignmentPluginCmsController < CmsController
redirect_to referer
end
end
-
- def build_mail_message(files_ids, message)
- @files_paths = []
- @files_string = files_ids
- @files_id_list = @files_string.split(' ')
-
- @files_id_list.each do |file_id|
- @file = environment.articles.find_by_id(file_id)
- @real_file_url = "http://#{@file.url[:host]}:#{@file.url[:port]}/#{@file.url[:profile]}/#{@file.path}"
- @files_paths << @real_file_url
- unless message.include? "#{@real_file_url}"
- message += "
Clique aqui para acessar o arquivo ou acesse pela URL:
"
- message += "
#{@real_file_url}"
- end
- end
- @warning_message = "AVISO: O aluno deve imprimir este email e entrega-lo na secretaria como comprovante do envio!"
- unless message.include? "#{@warning_message}"
- message += "
#{@warning_message}"
- end
- message
- end
-
end
\ No newline at end of file
diff --git a/plugins/work_assignment/lib/ext/email_contact.rb b/plugins/work_assignment/lib/ext/email_contact.rb
index 096ed93..c4f6182 100644
--- a/plugins/work_assignment/lib/ext/email_contact.rb
+++ b/plugins/work_assignment/lib/ext/email_contact.rb
@@ -15,7 +15,7 @@ class EmailContact
attr_accessor :message
attr_accessor :email
attr_accessor :receive_a_copy
- attr_accessor :reciever
+ attr_accessor :receiver
attr_accessor :sender
N_('Subject'); N_('Message'); N_('e-Mail'); N_('Name')
@@ -34,11 +34,11 @@ class EmailContact
@name = email_contact.name
@email = email_contact.email
@message = email_contact.message
- @target = email_contact.reciever
+ @target = email_contact.receiver
options = {
content_type: 'text/html',
- to: email_contact.reciever,
+ to: email_contact.receiver,
reply_to: email_contact.email,
subject: email_contact.subject,
body: email_contact.message,
@@ -53,4 +53,21 @@ class EmailContact
end
end
+ def build_mail_message(environment, files_ids, parent_name)
+ @files_paths = []
+ @message
+ @files_string = files_ids
+ @files_id_list = @files_string.split(' ')
+
+ @files_id_list.each do |file_id|
+ @file = environment.articles.find_by_id(file_id)
+ @real_file_url = "http://#{@file.url[:host]}:#{@file.url[:port]}/#{@file.url[:profile]}/#{@file.path}"
+ @files_paths << @real_file_url
+ @message = "
A file was sent to #{parent_name} and you are being notified."
+ @message += "
Click here to access the file or use the URL below:
"
+ @message += "
#{@real_file_url}"
+ end
+ @message
+ end
+
end
diff --git a/plugins/work_assignment/lib/work_assignment_plugin.rb b/plugins/work_assignment/lib/work_assignment_plugin.rb
index 94c1274..b04eba6 100644
--- a/plugins/work_assignment/lib/work_assignment_plugin.rb
+++ b/plugins/work_assignment/lib/work_assignment_plugin.rb
@@ -51,25 +51,34 @@ class WorkAssignmentPlugin < Noosfero::Plugin
:block => block }
end
+ def cms_controller_filters
+ block = proc do
+ @email_notification = params[:article_email_notification]
+ if !@email_notification.nil? and @email_notification.include? "@"
+ @subject = "#{@parent.name} file submission"
+ @email_contact = user.build_email_contact(:name => user.name, :subject => @subject, :email => user.email, :receiver => @email_notification, :sender => user)
+ @email_contact.message = @email_contact.build_mail_message(environment, @uploaded_files, @parent.name)
+ if @email_contact.deliver
+ session[:notice] = _('Notification successfully sent')
+ else
+ session[:notice] = _('Notification not sent')
+ end
+ end
+ end
+
+ { :type => 'after_filter',
+ :method_name => 'send_email_after_upload_file',
+ :options => {:only => 'upload_files'},
+ :block => block }
+ end
- def article_extra_contents(article_id)
+ def article_extra_fields(article)
proc do
- @article = Article.find_by_id(article_id)
+ @article = Article.find_by_id(article)
if params[:parent_id] && !@article.nil? && @article.type == "WorkAssignmentPlugin::WorkAssignment"
- render :partial => 'notify_checkbox', :locals => { :size => '45'}
+ render :partial => 'notify_text_field', :locals => { :size => '45'}
end
end
end
- def check_extra_parameters (uploaded_files, params = {})
- @email_notification = params[:article_email_notification]
- # uploaded_files = params[:uploaded_files]
- id = params[:parent_id]
- if @email_notification == 'true'
- proc do
- @back_to = url_for :controller => 'work_assignment_plugin_cms', :action => 'send_email', :id => id, :files_id => uploaded_files, :confirm => true
- end
- end
- end
-
end
\ No newline at end of file
diff --git a/plugins/work_assignment/lib/work_assignment_plugin/helper.rb b/plugins/work_assignment/lib/work_assignment_plugin/helper.rb
index d693cb1..abef4bc 100644
--- a/plugins/work_assignment/lib/work_assignment_plugin/helper.rb
+++ b/plugins/work_assignment/lib/work_assignment_plugin/helper.rb
@@ -36,7 +36,6 @@ module WorkAssignmentPlugin::Helper
),
:class => "submission-from-#{submission.parent.id}",
:style => 'display: none'
- #content_tag('button', _('Destroy file'), :class => 'button icon-delete ',
)
end
diff --git a/plugins/work_assignment/views/cms/_notify_checkbox.html.erb b/plugins/work_assignment/views/cms/_notify_checkbox.html.erb
deleted file mode 100644
index 40b5712..0000000
--- a/plugins/work_assignment/views/cms/_notify_checkbox.html.erb
+++ /dev/null
@@ -1 +0,0 @@
-<%= labelled_check_box(_('Send notification'), 'article_email_notification', true) %>
\ No newline at end of file
diff --git a/plugins/work_assignment/views/cms/_notify_text_field.html.erb b/plugins/work_assignment/views/cms/_notify_text_field.html.erb
new file mode 100644
index 0000000..6298005
--- /dev/null
+++ b/plugins/work_assignment/views/cms/_notify_text_field.html.erb
@@ -0,0 +1 @@
+<%= labelled_text_field(_('Send notification to: '), 'article_email_notification') %>
\ No newline at end of file
diff --git a/plugins/work_assignment/views/work_assignment_plugin_cms/send_email.html.erb b/plugins/work_assignment/views/work_assignment_plugin_cms/send_email.html.erb
deleted file mode 100644
index 8c64ac5..0000000
--- a/plugins/work_assignment/views/work_assignment_plugin_cms/send_email.html.erb
+++ /dev/null
@@ -1,21 +0,0 @@
-
-<%= error_messages_for 'email_contact' %>
-
-<%=labelled_form_for :email_contact do |f| %>
- <%= hidden_field_tag(:confirm, 'false') %>
- <%= hidden_field_tag(:self_files_id, @files_id_list) %>
-
- <%= required_fields_message %>
-
- <%= required f.text_field(:subject) %>
- <%= required f.text_field(:reciever) %>
- <%= required f.text_field(:name) %>
-
- <%= render :file => 'shared/tiny_mce' %>
- <%= required f.text_area(:message, :class => 'mceEditor') %>
-
-<%= labelled_form_field check_box(:email_contact, :receive_a_copy) + _('I want to receive a copy of the message in my e-mail.'), '' %>
-
- <%= submit_button(:send, _('Send'), :onclick => "$('confirm').value = 'true'") %>
- <%= submit_button(:cancel, _('Cancel'), :onclick =>"$('confirm').value = 'false'") %>
-<% end %>
--
libgit2 0.21.2