From c2302dc0c7372b8f7b49bb68f351c4e84a03204e Mon Sep 17 00:00:00 2001 From: baiyu <1554253403@qq.com> Date: Wed, 18 Sep 2013 22:56:01 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E4=BA=86=E9=99=84=E4=BB=B6?= =?UTF-8?q?=E5=88=A0=E9=99=A4=E5=8A=9F=E8=83=BD=20=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=E7=94=A8=E6=88=B7=E4=B8=BB=E9=A1=B5=E4=B8=AD=E8=AF=BE=E7=A8=8B?= =?UTF-8?q?=E4=B8=8E=E9=A1=B9=E7=9B=AE=E4=B9=8B=E9=97=B4=E7=9A=84=E5=85=B3?= =?UTF-8?q?=E7=B3=BB=20=E7=94=A8=E6=88=B7=E8=AF=BE=E7=A8=8B=E9=A1=B5?= =?UTF-8?q?=E9=9D=A2=E4=B8=AD=E7=9A=84=E4=BD=9C=E4=B8=9A=E8=BF=9B=E8=A1=8C?= =?UTF-8?q?=E4=BA=86=E6=8C=89=E8=AF=BE=E7=A8=8B=E5=88=86=E7=BB=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/attachments_controller.rb | 15 +++++++++++++++ app/controllers/users_controller.rb | 1 + app/helpers/attachments_helper.rb | 9 +++++++++ app/views/attachments/_links.html.erb | 8 ++++++++ app/views/attachments/delete.js.erb | 1 + app/views/bids/_homework_list.html.erb | 2 +- app/views/users/_my_homework.html.erb | 6 +++++- config/routes.rb | 1 + ...4629_add_technical_title_to_user_extensions.rb | 5 +++++ db/schema.rb | 5 ++++- lib/redmine.rb | 3 ++- 11 files changed, 52 insertions(+), 4 deletions(-) create mode 100644 app/views/attachments/delete.js.erb create mode 100644 db/migrate/20130918004629_add_technical_title_to_user_extensions.rb diff --git a/app/controllers/attachments_controller.rb b/app/controllers/attachments_controller.rb index 686070e70..ebf3c3ba5 100644 --- a/app/controllers/attachments_controller.rb +++ b/app/controllers/attachments_controller.rb @@ -115,6 +115,21 @@ class AttachmentsController < ApplicationController format.js end end + + def delete_homework + @bid = @attachment.container.bid + # Make sure association callbacks are called + container = @attachment.container + @attachment.container.attachments.delete(@attachment) + if container.attachments.empty? + container.delete + end + + respond_to do |format| + format.html { redirect_to_referer_or respond_path(@bid) } + format.js + end + end private def find_project diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 0596f9693..80838947f 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -135,6 +135,7 @@ class UsersController < ApplicationController @memberships.each do |membership| @bid += membership.project.homeworks end + @bid = @bid.group_by {|bid| bid.courses.first.id} @state = 1 else @membership = @user.memberships.all(:conditions => Project.visible_condition(User.current)) diff --git a/app/helpers/attachments_helper.rb b/app/helpers/attachments_helper.rb index a4925343f..f61399c85 100644 --- a/app/helpers/attachments_helper.rb +++ b/app/helpers/attachments_helper.rb @@ -31,6 +31,15 @@ module AttachmentsHelper :locals => {:attachments => container.attachments, :options => options, :thumbnails => (options[:thumbnails] && Setting.thumbnails_enabled?)} end end + + def attach_delete(project) + if User.current.logged? && (User.current.admin? || (!Member.where('user_id = ? and project_id = ?', User.current.id, project.bid.courses.first.id).first.nil? && (Member.where('user_id = ? and project_id = ?', User.current.id, project.bid.courses.first.id).first.roles&Role.where('id = ? or id = ?', 3, 7)).size >0) || project.user_id == User.current.id) + true + else + false + end + + end def render_api_attachment(attachment, api) api.attachment do diff --git a/app/views/attachments/_links.html.erb b/app/views/attachments/_links.html.erb index d2ab22ced..81eb416af 100644 --- a/app/views/attachments/_links.html.erb +++ b/app/views/attachments/_links.html.erb @@ -9,11 +9,19 @@ <%= h(" - #{attachment.description}") unless attachment.description.blank? %> (<%= number_to_human_size attachment.filesize %>) <% if options[:deletable] %> + <% unless attachment.container_type == 'HomeworkAttach' %> <%= link_to image_tag('delete.png'), attachment_path(attachment), :data => {:confirm => l(:text_are_you_sure)}, :method => :delete, :class => 'delete', :title => l(:button_delete) %> + <% else %> + <%= link_to image_tag('delete.png'), {:controller => 'attachments', :action => 'delete_homework', :id => attachment.id}, + :data => {:confirm => l(:text_are_you_sure)}, + :method => :delete, + :class => 'delete', + :title => l(:button_delete) %> + <% end %> <% end %> <% if options[:author] %> diff --git a/app/views/attachments/delete.js.erb b/app/views/attachments/delete.js.erb new file mode 100644 index 000000000..3cfb5845f --- /dev/null +++ b/app/views/attachments/delete.js.erb @@ -0,0 +1 @@ +$('#attachments_<%= j params[:attachment_id] %>').remove(); diff --git a/app/views/bids/_homework_list.html.erb b/app/views/bids/_homework_list.html.erb index 62f5005c2..3e9713bdd 100644 --- a/app/views/bids/_homework_list.html.erb +++ b/app/views/bids/_homework_list.html.erb @@ -15,7 +15,7 @@
- <% options = {:author => true} %> + <% options = {:author => true, :deletable => attach_delete(homework)} %> <%= render :partial => 'attachments/links', :locals => {:attachments => homework.attachments, :options => options} %> <% end %> diff --git a/app/views/users/_my_homework.html.erb b/app/views/users/_my_homework.html.erb index a075fb6d2..d78c5dc0c 100644 --- a/app/views/users/_my_homework.html.erb +++ b/app/views/users/_my_homework.html.erb @@ -1,7 +1,10 @@ <% if @bid.size > 0%> -<% for bid in @bid%> +<% @bid.each do |bids|%> +