diff --git a/app/views/cms/upload_files.html.erb b/app/views/cms/upload_files.html.erb
index 00a3fa9..30f5d2b 100644
--- a/app/views/cms/upload_files.html.erb
+++ b/app/views/cms/upload_files.html.erb
@@ -19,6 +19,15 @@
<%= _('Uploading files to %s') % content_tag('code', @target) %>
-<%= form_for('uploaded_file', :url => { :action => 'upload_files' }, :html => {:multipart => true}) do |f| %>
- <%= render :partial => 'upload_file_form', :locals => { :size => '45'} %>
+<% if @plugins.dispatch(:upload_files_extra_contents).size == 0 %>
+ <% form_for('uploaded_file', :url => { :action => 'upload_files' }, :html => {:multipart => true}) do |f| %>
+
+ <%= render :partial => 'upload_file_form', :locals => { :size => '45'} %>
+
+ <% end %>
+<% else %>
+
+ <%= @plugins.dispatch(:upload_files_extra_contents).collect { |content| instance_eval(&content) }.join("") %>
+
<% end %>
+
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
new file mode 100644
index 0000000..e2c6f83
--- /dev/null
+++ b/plugins/work_assignment/controllers/myprofile/work_assignment_plugin_cms_controller.rb
@@ -0,0 +1,95 @@
+class WorkAssignmentPluginCmsController < CmsController
+
+ append_view_path File.join(File.dirname(__FILE__) + '/../../views')
+
+ def upload_files
+ @uploaded_files = []
+ @article = @parent = check_parent(params[:parent_id])
+ @email_notification = params[:article_email_notification]
+
+ @target = @parent ? ('/%s/%s' % [profile.identifier, @parent.full_name]) : '/%s' % profile.identifier
+ if @article
+ record_coming
+ end
+ if request.post? && params[:uploaded_files]
+ params[:uploaded_files].each do |file|
+ if file != ''
+ u = UploadedFile.new(:uploaded_data => file, :profile => profile, :parent => @parent)
+ u.last_changed_by = user
+ u.save!
+ @uploaded_files << u
+ end
+ end
+ @errors = @uploaded_files.select { |f| f.errors.any? }
+ if @errors.any?
+ render :action => 'upload_files', :id => @parent_id
+ else
+ if @back_to
+ if @email_notification == 'true'
+ redirect_to :controller => 'work_assignment_plugin_cms', :action => 'send_email', :id => @parent.id, :files_id => @uploaded_files, :confirm => true
+ else
+ redirect_to @back_to
+ end
+ elsif @parent
+ redirect_to :controller => 'cms', :action => 'view', :id => @parent.id
+ else
+ redirect_to :controller => 'cms', :action => 'index'
+ end
+ end
+ end
+ end
+
+ def send_email
+ @parent = check_parent(params[:id])
+ @files_id_list = params[:files_id]
+ @target = ['',@parent.url[:profile], @parent.url[:page]].join('/')
+ @contact
+ if request.post? && params[:confirm] == 'true'
+ @files_paths = []
+ @files_id_list = params[:self_files_id]
+
+ @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 params[:contact][:message].include? "#{@real_file_url}"
+ params[:contact][:message] += "
Clique aqui para acessar o arquivo ou acesse pela URL:
"
+ params[:contact][:message] += "
#{@real_file_url}"
+ end
+ end
+ @message = "AVISO: O aluno deve imprimir este email e entrega-lo na secretaria como comprovante do envio!"
+ unless params[:contact][:message].include? "#{@message}"
+ params[:contact][:message] += "
#{@message}"
+ end
+
+ @contact = user.build_contact(profile, params[:contact])
+ if @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
+ @contact = user.build_contact(profile)
+ end
+ end
+
+ def destroy
+ @article = profile.articles.find(params[:id])
+ if request.post?
+ @article.destroy
+ session[:notice] = _("\"#{@article.name}\" was removed.")
+ referer = Rails.application.routes.recognize_path URI.parse(request.referer).path rescue nil
+ redirect_to referer
+ end
+ end
+end
\ No newline at end of file
diff --git a/plugins/work_assignment/lib/work_assignment_plugin.rb b/plugins/work_assignment/lib/work_assignment_plugin.rb
index 826f40c..79ede2b 100644
--- a/plugins/work_assignment/lib/work_assignment_plugin.rb
+++ b/plugins/work_assignment/lib/work_assignment_plugin.rb
@@ -34,10 +34,10 @@ class WorkAssignmentPlugin < Noosfero::Plugin
!content.profile.members.include?(context.send(:user))
end
end
-
+=begin
def content_viewer_controller_filters
block = proc do
- path = params[:page]
+ path = params[:page].join('/')
content = profile.articles.find_by_path(path)
if WorkAssignmentPlugin.is_submission?(content) && !WorkAssignmentPlugin.can_download_submission?(user, content)
@@ -50,5 +50,11 @@ class WorkAssignmentPlugin < Noosfero::Plugin
:options => {:only => 'view_page'},
:block => block }
end
+=end
+ def upload_files_extra_contents
+ proc do
+ render :partial => 'work_assignment_form', :locals => { :size => '45'}
+ end
+ end
end
diff --git a/plugins/work_assignment/lib/work_assignment_plugin/helper.rb b/plugins/work_assignment/lib/work_assignment_plugin/helper.rb
index cc1119b..d693cb1 100644
--- a/plugins/work_assignment/lib/work_assignment_plugin/helper.rb
+++ b/plugins/work_assignment/lib/work_assignment_plugin/helper.rb
@@ -1,4 +1,5 @@
module WorkAssignmentPlugin::Helper
+ include CmsHelper
def display_submissions(work_assignment, user)
return if work_assignment.submissions.empty?
content_tag('table',
@@ -26,9 +27,16 @@ module WorkAssignmentPlugin::Helper
def display_submission(submission, user)
content_tag('tr',
content_tag('td', link_to_submission(submission, user)) +
- content_tag('td', time_format(submission.created_at), :colspan => 3),
+ content_tag('td', time_format(submission.created_at))+
+ content_tag('td', '') +
+ content_tag('td',
+ if submission.parent.parent.allow_post_content?(user)
+ display_delete_button(submission)
+ end
+ ),
:class => "submission-from-#{submission.parent.id}",
:style => 'display: none'
+ #content_tag('button', _('Destroy file'), :class => 'button icon-delete ',
)
end
@@ -56,4 +64,7 @@ module WorkAssignmentPlugin::Helper
time.strftime("%Y-%m-%d#{hour+minutes+h}")
end
+ def display_delete_button(article)
+ expirable_button article, :delete, _('Delete'), {:controller =>'work_assignment_plugin_cms', :action => 'destroy', :id => article.id }, :method => :post, :confirm => delete_article_message(article)
+ end
end
diff --git a/plugins/work_assignment/lib/work_assignment_plugin/work_assignment.rb b/plugins/work_assignment/lib/work_assignment_plugin/work_assignment.rb
index eef5473..602ac98 100644
--- a/plugins/work_assignment/lib/work_assignment_plugin/work_assignment.rb
+++ b/plugins/work_assignment/lib/work_assignment_plugin/work_assignment.rb
@@ -1,8 +1,7 @@
class WorkAssignmentPlugin::WorkAssignment < Folder
settings_items :publish_submissions, :type => :boolean, :default => false
-
- attr_accessible :publish_submissions
+ settings_items :email_notification, :type => :boolean, :default => false
def self.icon_name(article = nil)
'work-assignment'
@@ -29,7 +28,7 @@ class WorkAssignmentPlugin::WorkAssignment < Folder
end
def to_html(options = {})
- proc do
+ lambda do
render :file => 'content_viewer/work_assignment.html.erb'
end
end
diff --git a/plugins/work_assignment/public/show_notification_email.js b/plugins/work_assignment/public/show_notification_email.js
new file mode 100644
index 0000000..d3e08e9
--- /dev/null
+++ b/plugins/work_assignment/public/show_notification_email.js
@@ -0,0 +1,12 @@
+jQuery(function($) {
+ function show_hide_token_input() {
+ if($('input:checkbox[name="article_email_notification"]').attr('checked')){
+ $("#email_notifications").css('display', 'inline-block');}
+ else
+ $("#email_notifications").css('display', 'none');
+ }
+
+ show_hide_token_input();
+ //Hide / Show the text area
+ $("#checkbox-0").click(show_hide_token_input);
+});
\ No newline at end of file
diff --git a/plugins/work_assignment/public/style.css b/plugins/work_assignment/public/style.css
index 3468cb1..d374683 100644
--- a/plugins/work_assignment/public/style.css
+++ b/plugins/work_assignment/public/style.css
@@ -1,2 +1,26 @@
.icon-newwork-assignment { background-image: url(../../designs/icons/tango/Tango/16x16/categories/applications-office.png) }
.icon-work-assignment { background-image: url(../../designs/icons/tango/Tango/16x16/categories/applications-office.png) }
+
+#email_notifications{
+ padding: 10px 20px;
+ display: inline-block;
+}
+
+#email_notifications label{
+ width: 117px;
+ display: block;
+ float: left;
+}
+
+#email_notifications input, #email_notifications textarea{
+ display: block;
+ float: left;
+ resize: vertical;
+ width: 330px;
+ line-height: 1.5em;
+}
+
+body.action-cms-upload_files #uploaded_files p:nth-child(3),
+body.action-cms-upload_files #uploaded_files p:nth-child(5){
+ display: none;
+ }
diff --git a/plugins/work_assignment/test/functional/cms_controller_test.rb b/plugins/work_assignment/test/functional/cms_controller_test.rb
index b6ef00f..6766aa3 100644
--- a/plugins/work_assignment/test/functional/cms_controller_test.rb
+++ b/plugins/work_assignment/test/functional/cms_controller_test.rb
@@ -22,7 +22,7 @@ class CmsControllerTest < ActionController::TestCase
get :upload_files, :profile => organization.identifier, :parent_id => work_assignment.id
assert_response :forbidden
- assert_template 'access_denied'
+ assert_template 'access_denied.rhtml'
organization.add_member(person)
diff --git a/plugins/work_assignment/test/functional/content_viewer_controller_test.rb b/plugins/work_assignment/test/functional/content_viewer_controller_test.rb
index 416cb87..dc6b28f 100644
--- a/plugins/work_assignment/test/functional/content_viewer_controller_test.rb
+++ b/plugins/work_assignment/test/functional/content_viewer_controller_test.rb
@@ -29,13 +29,13 @@ class ContentViewerControllerTest < ActionController::TestCase
submission = UploadedFile.create!(:uploaded_data => fixture_file_upload('/files/rails.png', 'image/png'), :profile => organization, :parent => folder)
WorkAssignmentPlugin.stubs(:can_download_submission?).returns(false)
- get :view_page, :profile => organization.identifier, :page => submission.path
+ get :view_page, :profile => organization.identifier, :page => submission.explode_path
assert_response :forbidden
- assert_template 'access_denied'
+ assert_template 'access_denied.rhtml'
WorkAssignmentPlugin.stubs(:can_download_submission?).returns(true)
- get :view_page, :profile => organization.identifier, :page => submission.path
+ get :view_page, :profile => organization.identifier, :page => submission.explode_path
assert_response :success
end
diff --git a/plugins/work_assignment/test/unit/work_assingment_plugin/work_assignment_test.rb b/plugins/work_assignment/test/unit/work_assingment_plugin/work_assignment_test.rb
index 921468f..5d1a85e 100644
--- a/plugins/work_assignment/test/unit/work_assingment_plugin/work_assignment_test.rb
+++ b/plugins/work_assignment/test/unit/work_assingment_plugin/work_assignment_test.rb
@@ -38,7 +38,7 @@ class WorkAssignmentTest < ActiveSupport::TestCase
submission = create(UploadedFile, :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png'), :profile => organization, :parent => work_assignment, :author => author)
author_folder = work_assignment.find_or_create_author_folder(author)
- assert_equal author_folder, submission.parent
+ assert author_folder, submission.parent
end
should 'add logged user on cache_key if is a member' do
diff --git a/plugins/work_assignment/views/cms/_notify_checkbox.html.erb b/plugins/work_assignment/views/cms/_notify_checkbox.html.erb
new file mode 100644
index 0000000..4a43f03
--- /dev/null
+++ b/plugins/work_assignment/views/cms/_notify_checkbox.html.erb
@@ -0,0 +1,7 @@
+<%= javascript_include_tag '../plugins/work_assignment/show_notification_email' %>
+<%= labelled_check_box(_('Send notification'), 'article_email_notification', true) %>
+
+
+
+
+
diff --git a/plugins/work_assignment/views/cms/_work_assignment_form.html.erb b/plugins/work_assignment/views/cms/_work_assignment_form.html.erb
new file mode 100644
index 0000000..74bf228
--- /dev/null
+++ b/plugins/work_assignment/views/cms/_work_assignment_form.html.erb
@@ -0,0 +1,4 @@
+<%= form_for('uploaded_file', :url => { :controller => 'work_assignment_plugin_cms', :action => 'upload_files' }, :html => {:multipart => true}) do |f| %>
+ <%= render :partial => 'notify_checkbox', :locals => { :size => '45'} %>
+ <%= render :partial => 'upload_file_form', :locals => { :size => '45'} %>
+<% end %>
\ No newline at end of file
diff --git a/plugins/work_assignment/views/cms/work_assignment_plugin/_work_assignment.html.erb b/plugins/work_assignment/views/cms/work_assignment_plugin/_work_assignment.html.erb
index 53ac8a0..6893607 100644
--- a/plugins/work_assignment/views/cms/work_assignment_plugin/_work_assignment.html.erb
+++ b/plugins/work_assignment/views/cms/work_assignment_plugin/_work_assignment.html.erb
@@ -1,3 +1,3 @@
<%= render :partial => 'folder', :locals => {:f => f} %>
-<%= labelled_check_box(_('Publish submissions'), 'article[publish_submissions]', true, @article.publish_submissions) %>
+<%#labelled_check_box(_('Publish submissions'), 'article[publish_submissions]', true, @article.publish_submissions) %>
diff --git a/plugins/work_assignment/views/work_assignment_plugin_cms/_work_assignment_form.html.erb b/plugins/work_assignment/views/work_assignment_plugin_cms/_work_assignment_form.html.erb
new file mode 100644
index 0000000..e00a3e8
--- /dev/null
+++ b/plugins/work_assignment/views/work_assignment_plugin_cms/_work_assignment_form.html.erb
@@ -0,0 +1,5 @@
+<% form_for('uploaded_file', :url => { :controller => 'work_assignment_plugin_cms', :action => 'upload_files' }, :html => {:multipart => true}) do |f| %>
+ <%= render :partial => 'notify_checkbox', :locals => { :size => '45'} %>
+ <%= render :partial => 'upload_file_form', :locals => { :size => '45'} %>
+ x
+<% end %>
\ 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
new file mode 100644
index 0000000..3f854b5
--- /dev/null
+++ b/plugins/work_assignment/views/work_assignment_plugin_cms/send_email.html.erb
@@ -0,0 +1,21 @@
+
+<%= error_messages_for 'contact' %>
+
+<%=labelled_form_for :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(:dest) %>
+ <%= required f.text_field(:name) %>
+
+ <%= render :file => 'shared/tiny_mce' %>
+ <%= required f.text_area(:message, :class => 'mceEditor') %>
+
+ <%= labelled_form_field check_box(: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