From a2e60944be2fd3e8fcd9e9e1f6fc6316164c9406 Mon Sep 17 00:00:00 2001 From: cxt Date: Tue, 23 Feb 2016 11:04:19 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B7=B2=E5=8F=91=E5=B8=83=E8=B5=84=E6=BA=90?= =?UTF-8?q?=E7=9A=84=E5=BB=B6=E6=9C=9F=E5=8F=91=E5=B8=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/files_controller.rb | 27 +++++++- app/helpers/courses_helper.rb | 2 +- app/views/files/_course_list.html.erb | 80 +---------------------- app/views/files/_hidden_file.html.erb | 54 +++++++++++++++ app/views/files/_resource_detail.html.erb | 77 ++++++++++++++++++++++ app/views/files/_upload_course_files.erb | 2 +- app/views/files/file_hidden.js.erb | 6 ++ app/views/files/republish_file.js.erb | 2 + config/routes.rb | 3 + 9 files changed, 173 insertions(+), 80 deletions(-) create mode 100644 app/views/files/_hidden_file.html.erb create mode 100644 app/views/files/_resource_detail.html.erb create mode 100644 app/views/files/file_hidden.js.erb create mode 100644 app/views/files/republish_file.js.erb diff --git a/app/controllers/files_controller.rb b/app/controllers/files_controller.rb index e83a13ad9..b18612243 100644 --- a/app/controllers/files_controller.rb +++ b/app/controllers/files_controller.rb @@ -26,7 +26,7 @@ class FilesController < ApplicationController before_filter :authorize, :except => [:create,:getattachtype,:quote_resource_show,:search,:searchone4reload,:search_project,:quote_resource_show_project, :search_tag_attachment,:subfield_upload_file,:search_org_subfield_tag_attachment, :search_tag_attachment,:quote_resource_show_org_subfield,:find_org_subfield_attache, - :search_files_in_subfield,:upload_files_menu] + :search_files_in_subfield,:upload_files_menu,:file_hidden,:republish_file] helper :sort include SortHelper @@ -96,6 +96,31 @@ class FilesController < ApplicationController end end + def file_hidden + @file = Attachment.find params[:id] + @course = Course.find params[:course_id] + respond_to do |format| + format.js + end + end + + def republish_file + @file = Attachment.find params[:id] + @course = Course.find params[:course_id] + if params[:publish_time] + unless params[:publish_time] == "" + @file.publish_time = params[:publish_time] + end + end + if @file.publish_time > Date.today + @file.is_publish = 0 + end + @file.save + respond_to do |format| + format.js + end + end + def search_project sort = "" @sort = "" diff --git a/app/helpers/courses_helper.rb b/app/helpers/courses_helper.rb index 6d0066fbc..2cdb277be 100644 --- a/app/helpers/courses_helper.rb +++ b/app/helpers/courses_helper.rb @@ -746,7 +746,7 @@ module CoursesHelper return[] unless course result = [] course.attachments.each do |attachment| - if attachment.is_public? ||User.current.allowed_to?(:as_teacher,Course.find(attachment.container_id))|| (User.current.member_of_course?(course) && attachment.is_publish == 1) || User.current.admin? + if attachment.is_public? ||User.current == attachment.author ||User.current.allowed_to?(:as_teacher,Course.find(attachment.container_id))|| (User.current.member_of_course?(course) && attachment.is_publish == 1) || User.current.admin? result << attachment end end diff --git a/app/views/files/_course_list.html.erb b/app/views/files/_course_list.html.erb index d7aade6c2..7724bb861 100644 --- a/app/views/files/_course_list.html.erb +++ b/app/views/files/_course_list.html.erb @@ -1,82 +1,8 @@ - -<% delete_allowed = User.current.allowed_to?(:manage_files, course) %> <% curse_attachments.each do |file| %> <% if file.is_public? || User.current.member_of_course?(course) || User.current.admin? %> -
-
-
- <%= link_to image_tag(url_to_avatar(file.author), :width => 50, :height => 50), user_path(file.author) %> -
-
-
- <%= link_to truncate(file.filename,length: 35, omission: '...'), - download_named_attachment_path(file.id, file.filename), - :title => file.filename+"\n"+file.description.to_s, :style => "overflow: hidden; white-space: nowrap;text-overflow: ellipsis;",:class => "linkBlue f_14 f_b" %> - <%= file_preview_eye(file, class: 'preview') %> - - <% if file.is_public? == false%> - 私有 - <%end %> - - <% if file.is_publish == 0 %> - <%=file.publish_time %>  0点发布 - <% end %> -
-
- 上传时间:<%= format_time(file.created_on)%> - <% if file.tag_list.length > 0%> - 上传类型:<%= file.tag_list[0] %> - <% end %> -

文件大小:<%= number_to_human_size(file.filesize) %>

-

下载<%= file.downloads%>  |  引用<%= file.quotes.nil? ? 0:file.quotes %>

-
-
-
- - <%= render :partial => 'tags/tag_new', :locals => {:obj => file, :object_flag => "6",:tag_name => @tag_name} %> - <%= render :partial => 'tags/tag_add', :locals => {:obj => file, :object_flag => "6",:tag_name => @tag_name} %> -
-
- -
    -
  • - <% if User.current.logged? %> - - <% if (is_course_teacher(User.current,@course) || file.author_id == User.current.id) && course_contains_attachment?(@course,file) %> - <% if (delete_allowed || User.current.id == file.author_id) && file.container_id == @course.id && file.container_type == "Course" %> -
      - -
    • <%= link_to("发       送".html_safe, 'javascript:void(0)',:class => "postOptionLink",:onclick=>"show_send('#{file.id}','#{User.current.id}','file')") %>
    • -
    • <%= link_to '更新版本',attachments_versions_path(file),:class => "postOptionLink",:remote=>true %>
    • - <% if @course.is_public? %> -
    • - - <%= link_to (file.is_public? ? "设为私有":"设为公开"), update_file_dense_attachments_path(:attachmentid=>file.id,:newtype=>(file.is_public? ? 0:1)),:remote=>true,:class=>"postOptionLink",:method => :post %> - -
    • - <%end%> -
    • - <%= link_to( '删除资源', attachment_path(file), - :data => {:confirm => l(:text_are_you_sure)}, :method => :delete,:class => "postOptionLink") if (delete_allowed || User.current.id == file.author_id) && file.container_id == @course.id && file.container_type == "Course" && file.destroyable %> -
    • -
    - - <% end %> - <%else%> -
      -
    • <%= link_to("发  送".html_safe, 'javascript:void(0)',:class => "postOptionLink2",:onclick=>"show_send('#{file.id}','#{User.current.id}','file')") %>
    • -
    - <% end %> - <% end %> -
  • -
- -
-
-
-
-
-
+
+ <%=render :partial=>'files/resource_detail',:locals => {:file => file} %> +
<% else %>
<%= file.filename %>是私有资源
<% end %> diff --git a/app/views/files/_hidden_file.html.erb b/app/views/files/_hidden_file.html.erb new file mode 100644 index 000000000..eb0f366a3 --- /dev/null +++ b/app/views/files/_hidden_file.html.erb @@ -0,0 +1,54 @@ +发布设置 + +<%= form_tag(republish_file_course_file_path(@course,@file), :multipart => true,:remote => !ie8?,:name=>"upload_form") do %> +
+ +
+ + <%#= calendar_for('attachment_publish_time')%> +
+ +
+
+ +
+ + +
+<% end %> +
+ \ No newline at end of file diff --git a/app/views/files/_resource_detail.html.erb b/app/views/files/_resource_detail.html.erb new file mode 100644 index 000000000..fd0a165aa --- /dev/null +++ b/app/views/files/_resource_detail.html.erb @@ -0,0 +1,77 @@ +<% delete_allowed = User.current.allowed_to?(:manage_files, @course) %> +
+
+
+ <%= link_to image_tag(url_to_avatar(file.author), :width => 50, :height => 50), user_path(file.author) %> +
+
+
+ <%= link_to truncate(file.filename,length: 35, omission: '...'), + download_named_attachment_path(file.id, file.filename), + :title => file.filename+"\n"+file.description.to_s, :style => "overflow: hidden; white-space: nowrap;text-overflow: ellipsis;",:class => "linkBlue f_14 f_b" %> + <%= file_preview_eye(file, class: 'preview') %> + + <% if file.is_public? == false%> + 私有 + <%end %> + + <% if file.is_publish == 0 %> + <%=file.publish_time %>  0点发布 + <% end %> +
+
+ 上传时间:<%= format_time(file.created_on)%> + <% if file.tag_list.length > 0%> + 上传类型:<%= file.tag_list[0] %> + <% end %> +

文件大小:<%= number_to_human_size(file.filesize) %>

+

下载<%= file.downloads%>  |  引用<%= file.quotes.nil? ? 0:file.quotes %>

+
+
+
+ + <%= render :partial => 'tags/tag_new', :locals => {:obj => file, :object_flag => "6",:tag_name => @tag_name} %> + <%= render :partial => 'tags/tag_add', :locals => {:obj => file, :object_flag => "6",:tag_name => @tag_name} %> +
+
+ +
    +
  • + <% if User.current.logged? %> + + <% if (is_course_teacher(User.current,@course) || file.author_id == User.current.id) && course_contains_attachment?(@course,file) %> + <% if (delete_allowed || User.current.id == file.author_id) && file.container_id == @course.id && file.container_type == "Course" %> +
      + +
    • <%= link_to("发       送".html_safe, 'javascript:void(0)',:class => "postOptionLink",:onclick=>"show_send('#{file.id}','#{User.current.id}','file')") %>
    • +
    • <%= link_to '延期发布',file_hidden_course_file_path(@course,file),:class => "postOptionLink",:remote=>true %>
    • +
    • <%= link_to '更新版本',attachments_versions_path(file),:class => "postOptionLink",:remote=>true %>
    • + <% if @course.is_public? %> +
    • + + <%= link_to (file.is_public? ? "设为私有":"设为公开"), update_file_dense_attachments_path(:attachmentid=>file.id,:newtype=>(file.is_public? ? 0:1)),:remote=>true,:class=>"postOptionLink",:method => :post %> + +
    • + <%end%> +
    • + <%= link_to( '删除资源', attachment_path(file), + :data => {:confirm => l(:text_are_you_sure)}, :method => :delete,:class => "postOptionLink") if (delete_allowed || User.current.id == file.author_id) && file.container_id == @course.id && file.container_type == "Course" && file.destroyable %> +
    • +
    + + <% end %> + <%else%> +
      +
    • <%= link_to("发  送".html_safe, 'javascript:void(0)',:class => "postOptionLink2",:onclick=>"show_send('#{file.id}','#{User.current.id}','file')") %>
    • +
    + <% end %> + <% end %> +
  • +
+ +
+
+
+
+
+
\ No newline at end of file diff --git a/app/views/files/_upload_course_files.erb b/app/views/files/_upload_course_files.erb index 2e53f05d2..1b8b140a5 100644 --- a/app/views/files/_upload_course_files.erb +++ b/app/views/files/_upload_course_files.erb @@ -28,7 +28,7 @@ <%#= calendar_for('attachment_publish_time')%> - +
<% end %> diff --git a/app/views/files/file_hidden.js.erb b/app/views/files/file_hidden.js.erb new file mode 100644 index 000000000..b95ab5104 --- /dev/null +++ b/app/views/files/file_hidden.js.erb @@ -0,0 +1,6 @@ +$('#ajax-modal').html('<%= escape_javascript(render :partial => 'files/hidden_file',:locals => {:course => @course,:course_attachment_type => 1}) %>'); +showModal('ajax-modal', '311px'); +$('#ajax-modal').siblings().remove(); +$('#ajax-modal').before(""); +$('#ajax-modal').parent().css("top","").css("left","").css("border","3px solid #269ac9"); +$('#ajax-modal').parent().addClass("popbox_polls"); \ No newline at end of file diff --git a/app/views/files/republish_file.js.erb b/app/views/files/republish_file.js.erb new file mode 100644 index 000000000..e85e5eb50 --- /dev/null +++ b/app/views/files/republish_file.js.erb @@ -0,0 +1,2 @@ +hideModal(); +$("#resource_detail_<%=@file.id %>").html("<%= escape_javascript(render :partial=>'files/resource_detail',:locals => {:file => @file}) %>") \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index 7060e4eb6..095470139 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -695,6 +695,7 @@ RedmineApp::Application.routes.draw do end member do match "quote_resource_show", :via => [:get] + get "file_hidden" end end @@ -1015,6 +1016,8 @@ RedmineApp::Application.routes.draw do end member do match "quote_resource_show", :via => [:get] + get "file_hidden" + post "republish_file" end end resources :memberships, :shallow => true, :controller => 'members', :only => [:index, :show, :new, :create, :update, :destroy] do