Date: Fri, 11 Dec 2015 16:30:50 +0800
Subject: [PATCH 05/11] =?UTF-8?q?=E6=A0=8F=E7=9B=AE=E5=A2=9E=E5=8A=A0?=
=?UTF-8?q?=E8=B5=84=E6=BA=90=E7=B1=BB=E5=9E=8B=EF=BC=8C=E5=8F=AF=E4=BB=A5?=
=?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=96=87=E4=BB=B6=E3=80=81=E5=88=A0=E9=99=A4?=
=?UTF-8?q?=E6=96=87=E4=BB=B6=E3=80=81=E6=98=BE=E7=A4=BA=E6=96=87=E4=BB=B6?=
=?UTF-8?q?=E7=AD=89?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
app/controllers/application_controller.rb | 2 +
app/controllers/attachments_controller.rb | 2 +
app/controllers/files_controller.rb | 37 ++++++-
app/controllers/org_subfields_controller.rb | 4 +
app/helpers/files_helper.rb | 3 +-
app/models/attachment.rb | 1 +
app/models/org_subfield.rb | 5 +
app/views/files/_attachement_list.html.erb | 19 ++++
app/views/files/_org_subfield_list.html.erb | 56 +++++++++++
app/views/files/_subfield_files.html.erb | 97 +++++++++++++++++++
app/views/files/_subfield_files_list.html.erb | 55 +++++++++++
.../files/_upload_subfield_file.html.erb | 31 ++++++
app/views/files/create.js.erb | 11 +++
app/views/files/index.html.erb | 6 +-
app/views/org_subfields/_resource.html.erb | 96 ++++++++++++++++++
.../_org_left_subfield_list.html.erb | 2 +-
config/routes.rb | 12 ++-
public/stylesheets/courses.css | 6 +-
public/stylesheets/org.css | 15 ++-
19 files changed, 452 insertions(+), 8 deletions(-)
create mode 100644 app/views/files/_org_subfield_list.html.erb
create mode 100644 app/views/files/_subfield_files.html.erb
create mode 100644 app/views/files/_subfield_files_list.html.erb
create mode 100644 app/views/files/_upload_subfield_file.html.erb
create mode 100644 app/views/org_subfields/_resource.html.erb
diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb
index 6387a97a4..cbf2c30bb 100644
--- a/app/controllers/application_controller.rb
+++ b/app/controllers/application_controller.rb
@@ -418,6 +418,8 @@ class ApplicationController < ActionController::Base
@project = Project.find(params[:project_id])
elsif params[:course_id]
@course = Course.find(params[:course_id])
+ elsif params[:org_subfield_id]
+ @org_subfield = OrgSubfield.find(params[:org_subfield_id])
end
rescue ActiveRecord::RecordNotFound
render_404
diff --git a/app/controllers/attachments_controller.rb b/app/controllers/attachments_controller.rb
index 37182dbcf..d371ed4cb 100644
--- a/app/controllers/attachments_controller.rb
+++ b/app/controllers/attachments_controller.rb
@@ -240,6 +240,8 @@ class AttachmentsController < ApplicationController
format.html { redirect_to_referer_or respond_path(@attachment.container) }
elsif !@attachment.container.nil? && @attachment.container.is_a?(PhoneAppVersion)
format.html { redirect_to_referer_or mobile_version_path }
+ elsif !@attachment.container.nil? && @attachment.container.is_a?(OrgSubfield)
+ format.html {redirect_to_referer_or org_subfield_files_path(@attachment.container)}
else
if @project.nil?
format.html { redirect_to_referer_or forum_memo_path(@attachment.container.forum, @attachment.container) }
diff --git a/app/controllers/files_controller.rb b/app/controllers/files_controller.rb
index c894680a6..328446fbb 100644
--- a/app/controllers/files_controller.rb
+++ b/app/controllers/files_controller.rb
@@ -299,6 +299,10 @@ class FilesController < ApplicationController
render :layout => 'base_courses'
elsif params[:org_subfield_id]
@container_type = 2
+ @organization = Organization.find(params[:organization_id])
+ @containers = [ OrgSubfield.includes(:attachments).reorder(sort).find(@org_subfield.id)]
+ show_attachments @containers
+ render :layout => 'base_org'
# @subfield = params[:org_subfield_id]
end
@@ -424,8 +428,39 @@ class FilesController < ApplicationController
redirect_to course_files_url(@course)
}
end
- end
+ elsif @org_subfield
+ @addTag=false
+ # if params[:in_org_subfield_toolbar]
+ # @in_org_subfield_toolbar = params[:in_org_subfield_toolbar]
+ # end
+ attachments = Attachment.attach_filesex(@org_subfield, params[:attachments], params[:org_subfield_attachment_type])
+ # if !attachments.empty? && !attachments[:files].blank? && Setting.notified_events.include?('file_added')
+ # Mailer.run.attachments_added(attachments[:files])
+ # end
+
+ # TODO: 临时用 nyan
+ sort_init 'created_on', 'desc'
+ sort_update 'created_on' => "#{Attachment.table_name}.created_on",
+ 'filename' => "#{Attachment.table_name}.filename",
+ 'size' => "#{Attachment.table_name}.filesize",
+ 'downloads' => "#{Attachment.table_name}.downloads"
+
+ @containers = [OrgSubfield.includes(:attachments).reorder("#{Attachment.table_name}.created_on DESC").find(@org_subfield.id)] #modify by Long Jun
+ # @containers += @org_subfield.versions.includes(:attachments).reorder("#{Attachment.table_name}.created_on DESC").all.sort
+
+ show_attachments @containers
+
+ @attachtype = 0
+ @contenttype = 0
+
+ respond_to do |format|
+ format.js
+ format.html {
+ redirect_to org_subfield_files_url(@org_subfield)
+ }
+ end
+ end
end
end
diff --git a/app/controllers/org_subfields_controller.rb b/app/controllers/org_subfields_controller.rb
index 00b88fdaa..1dc7885fe 100644
--- a/app/controllers/org_subfields_controller.rb
+++ b/app/controllers/org_subfields_controller.rb
@@ -17,4 +17,8 @@ class OrgSubfieldsController < ApplicationController
@organization = Organization.find(@subfield.organization_id)
@subfield.update_attributes(:name => params[:name])
end
+
+ def show
+
+ end
end
diff --git a/app/helpers/files_helper.rb b/app/helpers/files_helper.rb
index 9a1765ddc..cf9cbcc32 100644
--- a/app/helpers/files_helper.rb
+++ b/app/helpers/files_helper.rb
@@ -113,7 +113,8 @@ module FilesHelper
if attachment.is_public? ||
(attachment.container_type == "Project" && User.current.member_of?(attachment.project)) ||
(attachment.container_type == "Course" && User.current.member_of_course?(Course.find(attachment.container_id)))||
- attachment.author_id == User.current.id
+ attachment.author_id == User.current.id ||
+ attachment.container_type == "OrgSubfield"
result << attachment
end
end
diff --git a/app/models/attachment.rb b/app/models/attachment.rb
index 999cefdaa..57b6af0ce 100644
--- a/app/models/attachment.rb
+++ b/app/models/attachment.rb
@@ -22,6 +22,7 @@ class Attachment < ActiveRecord::Base
belongs_to :container, :polymorphic => true
belongs_to :project, foreign_key: 'container_id', conditions: "attachments.container_type = 'Project'"
belongs_to :course, foreign_key: 'container_id', conditions: "attachments.container_type = 'Course'"
+ belongs_to :org_subfield, foreign_key: 'container_id', conditions: "attachements.container_type = 'OrgSubfield'"
belongs_to :softapplication, foreign_key: 'container_id', conditions: "attachments.container_type = 'Softapplication'"
belongs_to :author, :class_name => "User", :foreign_key => "author_id"
belongs_to :attachmentstype, :foreign_key => "attachtype",:primary_key => "id"
diff --git a/app/models/org_subfield.rb b/app/models/org_subfield.rb
index efe9699c3..f95bb3eba 100644
--- a/app/models/org_subfield.rb
+++ b/app/models/org_subfield.rb
@@ -1,4 +1,9 @@
class OrgSubfield < ActiveRecord::Base
belongs_to :organization, :foreign_key => :organization_id
has_many :org_document_comments, :dependent => :destroy
+ has_many :files
+ acts_as_attachable
+
+ def project
+ end
end
\ No newline at end of file
diff --git a/app/views/files/_attachement_list.html.erb b/app/views/files/_attachement_list.html.erb
index 25cc7f68a..a9d399511 100644
--- a/app/views/files/_attachement_list.html.erb
+++ b/app/views/files/_attachement_list.html.erb
@@ -20,6 +20,25 @@
:lebel_file_uploding => l(:lebel_file_uploding),
:delete_all_files => l(:text_are_you_sure_all)
} %>
+<% elsif @project %>
+ <%= file_field_tag 'attachments[dummy][file]',
+ :id => '_file',
+ :class => ie8? ? '':'file_selector',
+ :multiple => true,
+ :onchange => 'addInputFiles(this);',
+ :style => ie8? ? '': 'display:none',
+ :data => {
+ :max_file_size => Setting.attachment_max_size.to_i.kilobytes,
+ :max_file_size_message => l(:error_attachment_too_big, :max_size => number_to_human_size(Setting.attachment_max_size.to_i.kilobytes)),
+ :max_concurrent_uploads => Redmine::Configuration['max_concurrent_ajax_uploads'].to_i,
+ :upload_path => uploads_path(:format => 'js'),
+ :description_placeholder => l(:label_optional_description),
+ :field_is_public => l(:field_is_public),
+ :are_you_sure => l(:text_are_you_sure),
+ :file_count => l(:label_file_count),
+ :lebel_file_uploding => l(:lebel_file_uploding),
+ :delete_all_files => l(:text_are_you_sure_all)
+ } %>
<% else %>
<%= file_field_tag 'attachments[dummy][file]',
:id => '_file',
diff --git a/app/views/files/_org_subfield_list.html.erb b/app/views/files/_org_subfield_list.html.erb
new file mode 100644
index 000000000..a8aa13458
--- /dev/null
+++ b/app/views/files/_org_subfield_list.html.erb
@@ -0,0 +1,56 @@
+<% delete_allowed = User.current.admin? %>
+
+
共有 <%= all_attachments.count%> 个资源
+
+ <% if order == "asc" %>
+ 按 <%= link_to "时间",params.merge(:sort=>"created_on:desc"),:class => "f_b c_grey",:remote => @is_remote %><%= render partial: 'files/arrow_show',locals: { sort: sort,order:order,current:"created_on"} %> /
+ <%= link_to "下载次数",params.merge(:sort=>"downloads:desc"),:class => "f_b c_grey",:remote => @is_remote %><%= render partial: 'files/arrow_show',locals: { sort: sort,order:order,current:"downloads"} %> /
+ <%= link_to "引用次数",params.merge(:sort=>"quotes:desc"),:class => "f_b c_grey",:remote => @is_remote %><%= render partial: 'files/arrow_show',locals: { sort: sort,order:order,current:"quotes"} %> 排序
+ <% else %>
+ 按 <%= link_to "时间",params.merge(:sort=>"created_on:asc"),:class => "f_b c_grey" ,:remote => @is_remote %><%= render partial: 'files/arrow_show',locals: { sort: sort,order:order,current:"created_on"} %> /
+ <%= link_to "下载次数",params.merge(:sort=>"downloads:asc"),:class => "f_b c_grey",:remote => @is_remote %><%= render partial: 'files/arrow_show',locals: { sort: sort,order:order,current:"downloads"} %> /
+ <%= link_to "引用次数",params.merge(:sort=>"quotes:asc"),:class => "f_b c_grey",:remote => @is_remote %><%= render partial: 'files/arrow_show',locals: { sort: sort,order:order,current:"quotes"} %> 排序
+ <% end %>
+
+
+
+
+
+
+
+
+
+
+ <% org_subfield_attachments.each do |file| %>
+ <% if 1 %>
+
+
+ <%= 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 => "c_dblue f_14 f_b f_l" %>
+ <% if User.current.logged? %>
+ <%= file_preview_tag(file, class: 'f_l re_open', style:'text-align: center;') %>
+ <% end %>
+
+
+
+
文件大小:<%= number_to_human_size(file.filesize) %>
+ <%= link_to( l(:button_delete), attachment_path(file),
+ :data => {:confirm => l(:text_are_you_sure)}, :method => :delete,:class => "f_r re_de") if (delete_allowed || User.current.id == file.author_id) && file.container_id == @org_subfield.id && file.container_type == "OrgSubfield"%>
+
<%= time_tag(file.created_on).html_safe %><%= l(:label_bids_published_ago) %> | 下载<%= file.downloads %> | 引用<%= file.quotes.nil? ? 0:file.quotes %>
+
+
+
+
+
+
+
+
+
+ <% end %>
+ <% end %>
+
+
+ <%= pagination_links_full @obj_pages, @obj_count, :per_page_links => false, :remote => @is_remote, :flag => true%>
+
+
diff --git a/app/views/files/_subfield_files.html.erb b/app/views/files/_subfield_files.html.erb
new file mode 100644
index 000000000..ea408c7a6
--- /dev/null
+++ b/app/views/files/_subfield_files.html.erb
@@ -0,0 +1,97 @@
+<%= stylesheet_link_tag 'courses' %>
+
+
+
+
+
+ <%= form_tag( search_org_subfield_files_path(@org_subfield), method: 'get',:class => "re_search f_l",:remote=>true) do %>
+ <%= text_field_tag 'name', params[:name], name: "name", :class => 're_schbox',:style=>"padding: 0px"%>
+ <%= submit_tag "栏目内搜索", :class => "re_schbtn b_lblue",:name => "inorg_subfield",:id => "inorg_subfield", :onmouseover => "presscss('inorg_subfield')",:onmouseout =>"buttoncss()" %>
+ <%= submit_tag "全站搜索", :class => "re_schbtn b_lblue",:name => "insite",:id => "insite",:onmouseover => "presscss('insite')",:onmouseout =>"buttoncss()" %>
+ <% end %>
+ <%# if is_org_subfield_teacher(User.current,@org_subfield) || (@org_subfield.publish_resource==1 && User.current.member_of_org_subfield?(@org_subfield) ) %>
+
+
+ 上传:
+ 课件 |
+ 软件 |
+ 媒体 |
+ 代码 |
+ 论文 |
+ 其他
+
+ <%# end %>
+
+
+
+
+ <%= render :partial => 'org_subfield_list',:locals => {org_subfield: @org_subfield,all_attachments: @all_attachments,sort:@sort,order:@order,org_subfield_attachments:@obj_attachments} %>
+
+
+
+
+<% html_title(l(:label_attachment_plural)) -%>
\ No newline at end of file
diff --git a/app/views/files/_subfield_files_list.html.erb b/app/views/files/_subfield_files_list.html.erb
new file mode 100644
index 000000000..d762743ad
--- /dev/null
+++ b/app/views/files/_subfield_files_list.html.erb
@@ -0,0 +1,55 @@
+<% delete_allowed = User.current.admin? %>
+
+
共有 <%= all_attachments.count%> 个资源
+
+ <% if order == "asc" %>
+ 按 <%= link_to "时间",params.merge(:sort=>"created_on:desc"),:class => "f_b c_grey",:remote => @is_remote %><%= render partial: 'files/arrow_show',locals: { sort: sort,order:order,current:"created_on"} %> /
+ <%= link_to "下载次数",params.merge(:sort=>"downloads:desc"),:class => "f_b c_grey",:remote => @is_remote %><%= render partial: 'files/arrow_show',locals: { sort: sort,order:order,current:"downloads"} %> /
+ <%= link_to "引用次数",params.merge(:sort=>"quotes:desc"),:class => "f_b c_grey",:remote => @is_remote %><%= render partial: 'files/arrow_show',locals: { sort: sort,order:order,current:"quotes"} %> 排序
+ <% else %>
+ 按 <%= link_to "时间",params.merge(:sort=>"created_on:asc"),:class => "f_b c_grey" ,:remote => @is_remote %><%= render partial: 'files/arrow_show',locals: { sort: sort,order:order,current:"created_on"} %> /
+ <%= link_to "下载次数",params.merge(:sort=>"downloads:asc"),:class => "f_b c_grey",:remote => @is_remote %><%= render partial: 'files/arrow_show',locals: { sort: sort,order:order,current:"downloads"} %> /
+ <%= link_to "引用次数",params.merge(:sort=>"quotes:asc"),:class => "f_b c_grey",:remote => @is_remote %><%= render partial: 'files/arrow_show',locals: { sort: sort,order:order,current:"quotes"} %> 排序
+ <% end %>
+
+
+
+
+
+ <%= render :partial => "files/tag_yun", :locals => {:tag_list => @tag_list,:course => course,:tag_name => @tag_name}%>
+
+
+
+
+ <% curse_attachments.each do |file| %>
+ <% if file.is_public? || User.current.admin? %>
+
+
+ <%= 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 => "c_dblue f_14 f_b f_l" %>
+
+
+
+
文件大小:<%= number_to_human_size(file.filesize) %>
+ <%= link_to( l(:button_delete), attachment_path(file),
+ :data => {:confirm => l(:text_are_you_sure)}, :method => :delete,:class => "f_r re_de") if (delete_allowed || User.current.id == file.author_id) && file.container_id == @org_subfield.id && file.container_type == "OrgSubfield"%>
+
<%= time_tag(file.created_on).html_safe %><%= l(:label_bids_published_ago) %> | 下载<%= 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} %>
+
+
+
+ <% else %>
+
<%= file.filename %>是私有资源
+ <% end %>
+ <% end %>
+
+
+ <%= pagination_links_full @obj_pages, @obj_count, :per_page_links => false, :remote => @is_remote, :flag => true%>
+
+
diff --git a/app/views/files/_upload_subfield_file.html.erb b/app/views/files/_upload_subfield_file.html.erb
new file mode 100644
index 000000000..c3ca72ecd
--- /dev/null
+++ b/app/views/files/_upload_subfield_file.html.erb
@@ -0,0 +1,31 @@
+
+
+
+
<%= l(:label_upload_files)%>
+
+ <%= error_messages_for 'attachment' %>
+
<%= l(:label_file_upload_error_messages)%>
+
+ <%= form_tag(org_subfield_files_path(org_subfield), :multipart => true,:remote => !ie8?,:name=>"upload_form") do %>
+
+
+
+ <%= render :partial => 'files/attachement_list',:locals => {:org_subfield => org_subfield} %>
+
+
<%= l(:button_cancel)%>
+
<%= l(:button_confirm)%>
+ <% end %>
+
+
+
+ <% content_for :header_tags do %>
+ <%= javascript_include_tag 'attachments' %>
+ <% end %>
+
+
+
\ No newline at end of file
diff --git a/app/views/files/create.js.erb b/app/views/files/create.js.erb
index 9de7aa042..4d8bb26ca 100644
--- a/app/views/files/create.js.erb
+++ b/app/views/files/create.js.erb
@@ -52,6 +52,17 @@ $('#upload_file_div').slideToggle('slow');
setTimeout( function(){div.remove();},3000)
<% end %>
<%end%>
+ <% elsif @org_subfield %>
+ hideModal();
+ $("#resource_list").html('<%= j(render partial: "subfield_files" ,locals: {org_subfield: @org_subfield}) %>');
+// $("#courses_files_count_info").html("<%#= @all_attachments.count%>");
+// $("#courses_files_count_nav").html("(<%#= @all_attachments.count%>)")
+ // 添加文件上传成功提示,
+ <% unless params[:attachments].nil? %>
+ var div = $('文件上传成功!
');
+ $("#org_subfield_list").prepend(div);
+ setTimeout( function(){div.remove();},3000)
+ <% end %>
<% end %>
<% end %>
$(document).ready(img_thumbnails);
diff --git a/app/views/files/index.html.erb b/app/views/files/index.html.erb
index 3dad88868..d442b9112 100644
--- a/app/views/files/index.html.erb
+++ b/app/views/files/index.html.erb
@@ -1,8 +1,10 @@
- <% if @isproject %>
+ <% if @container_type == 0 %>
<%= render :partial => 'project_file_new', locals: {project: @project} %>
- <% else %>
+ <% elsif @container_type == 1 %>
<%= render :partial => 'course_file', locals: {course: @course} %>
+ <% elsif @container_type == 2 %>
+ <%= render :partial => 'files/subfield_files', locals: {org_subfield: @org_subfield} %>
<% end %>
diff --git a/app/views/org_subfields/_resource.html.erb b/app/views/org_subfields/_resource.html.erb
new file mode 100644
index 000000000..3cce9748f
--- /dev/null
+++ b/app/views/org_subfields/_resource.html.erb
@@ -0,0 +1,96 @@
+
+
+
+
+
+ <%= form_tag( search_course_files_path(@course), method: 'get',:class => "re_search f_l",:remote=>true) do %>
+ <%= text_field_tag 'name', params[:name], name: "name", :class => 're_schbox',:style=>"padding: 0px"%>
+ <%= submit_tag "课内搜索", :class => "re_schbtn b_lblue",:name => "incourse",:id => "incourse", :onmouseover => "presscss('incourse')",:onmouseout =>"buttoncss()" %>
+ <%= submit_tag "全站搜索", :class => "re_schbtn b_lblue",:name => "insite",:id => "insite",:onmouseover => "presscss('insite')",:onmouseout =>"buttoncss()" %>
+ <% end %>
+ <% if is_course_teacher(User.current,@course) || (@course.publish_resource==1 && User.current.member_of_course?(@course) ) %>
+
+
+ 上传:
+ 课件 |
+ 软件 |
+ 媒体 |
+ 代码 |
+ 论文 |
+ 其他
+
+ <% end %>
+
+
+
+
+ <%= render :partial => 'course_list',:locals => {course: @course,all_attachments: @all_attachments,sort:@sort,order:@order,curse_attachments:@obj_attachments} %>
+
+
+
+
+<% html_title(l(:label_attachment_plural)) -%>
\ No newline at end of file
diff --git a/app/views/organizations/_org_left_subfield_list.html.erb b/app/views/organizations/_org_left_subfield_list.html.erb
index 57ea46658..dbeaa6117 100644
--- a/app/views/organizations/_org_left_subfield_list.html.erb
+++ b/app/views/organizations/_org_left_subfield_list.html.erb
@@ -29,7 +29,7 @@
<%= link_to "#{field.name}", organization_path(organization, :org_subfield_id => field.id), :class => "homepageMenuText" %>
<%=link_to "", new_organization_org_document_comment_path(organization, :field_id => field.id), :method => "get", :class => "homepageMenuSetting fr", :title => "发布帖子"%>
<% else %>
- <%#= link_to "#{field.name}", org_subfield_files_path(field), :class => "homepageMenuText" %>
+ <%= link_to "#{field.name}", org_subfield_files_path(field, :organization_id => organization.id), :class => "homepageMenuText" %>
<% end %>