From 10371e8bddb4f4ec12f16d7256c8eea25fa175b5 Mon Sep 17 00:00:00 2001 From: huang Date: Fri, 1 Apr 2016 00:27:34 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E9=99=84=E4=BB=B6=E5=9B=BE?= =?UTF-8?q?=E7=89=87=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/files_controller.rb | 46 +++++++ app/models/attachment.rb | 1 + app/models/organization.rb | 2 + .../files/_upload_org_new_files.html.erb | 26 ++++ app/views/files/create.js.erb | 125 ++++++++++-------- app/views/layouts/base_org_newstyle.html.erb | 18 ++- config/routes.rb | 8 ++ 7 files changed, 167 insertions(+), 59 deletions(-) create mode 100644 app/views/files/_upload_org_new_files.html.erb diff --git a/app/controllers/files_controller.rb b/app/controllers/files_controller.rb index 69b356b5a..8db287b0e 100644 --- a/app/controllers/files_controller.rb +++ b/app/controllers/files_controller.rb @@ -623,6 +623,52 @@ class FilesController < ApplicationController @attachtype = 0 @contenttype = 0 + respond_to do |format| + format.js + # format.html { + # redirect_to org_subfield_files_url(@org_subfield) + # } + end + elsif @organization + @addTag=false + attachments = Attachment.attach_filesex(@organization, params[:attachments], params[:org_attachment_type]) + + if params[:org_attachment_type] && params[:org_attachment_type].is_a?(Array) + params[:org_attachment_type].each do |type| + tag_name = get_tag_name_by_type_number type + if !attachments.empty? && attachments[:files] && tag_name != "" + attachments[:files].each do |attachment| + attachment.tag_list.add(tag_name) + attachment.save + end + end + end + else + if params[:org_attachment_type] && params[:org_attachment_type] != "5" + tag_name = get_tag_name_by_type_number params[:org_attachment_type] + if !attachments.empty? && attachments[:files] && tag_name != "" + attachments[:files].each do |attachment| + attachment.tag_list.add(tag_name) + attachment.save + end + end + end + 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 = [Organization.includes(:attachments).reorder("#{Attachment.table_name}.created_on DESC").find(@organization.id)] + + show_attachments @containers + @tag_list = attachment_tag_list @all_attachments + @attachtype = 0 + @contenttype = 0 + respond_to do |format| format.js # format.html { diff --git a/app/models/attachment.rb b/app/models/attachment.rb index 881621c3a..754bd4dee 100644 --- a/app/models/attachment.rb +++ b/app/models/attachment.rb @@ -23,6 +23,7 @@ class Attachment < ActiveRecord::Base 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 :organization, foreign_key: 'container_id', conditions: "attachements.container_type = 'Organization'" 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/organization.rb b/app/models/organization.rb index 248783a26..427cd4c10 100644 --- a/app/models/organization.rb +++ b/app/models/organization.rb @@ -8,6 +8,8 @@ class Organization < ActiveRecord::Base has_many :org_courses, :dependent => :destroy has_many :org_subfields, :dependent => :destroy has_many :users, :through => :org_members + has_many :files + acts_as_attachable validates_uniqueness_of :name after_create :save_as_org_activity, :add_default_subfields diff --git a/app/views/files/_upload_org_new_files.html.erb b/app/views/files/_upload_org_new_files.html.erb new file mode 100644 index 000000000..43b189b65 --- /dev/null +++ b/app/views/files/_upload_org_new_files.html.erb @@ -0,0 +1,26 @@ + +
+
+

<%= l(:label_upload_files)%>

+
+ <%= error_messages_for 'attachment' %> + + <%= form_tag(organization_files_path(org, :in_org => params[:in_org]), :multipart => true,:remote => !ie8?,:name=>"upload_form") do %> + + <%= render :partial => 'files/org_subfield_upload_attachment_list', :locals => {:container => org}%> +
+ <%= l(:button_cancel)%> + <%= l(:button_confirm)%> + <% end %> +
+ +
+ +
+ + \ No newline at end of file diff --git a/app/views/files/create.js.erb b/app/views/files/create.js.erb index 1d66c2955..5150a1dc3 100644 --- a/app/views/files/create.js.erb +++ b/app/views/files/create.js.erb @@ -1,71 +1,84 @@ <% if @addTag%> - <% if @obj_flag == '3'%> - $('#tags_show_issue').html('<%= escape_javascript(render :partial => 'tags/tag_name', +<% if @obj_flag == '3'%> +$('#tags_show_issue').html('<%= escape_javascript(render :partial => 'tags/tag_name', :locals => {:obj => @obj,:non_list_all => false,:object_flag => @obj_flag}) %>'); - //$('#put-tag-form-issue').hide(); - $('#name-issue').val(""); - <% elsif @obj_flag == '6'%> - $("#tags_show-<%=@obj.class%>-<%=@obj.id%>").empty(); - $("#tags_show-<%=@obj.class%>-<%=@obj.id%>").html('<%= escape_javascript(render :partial => 'tags/tag_name', +//$('#put-tag-form-issue').hide(); +$('#name-issue').val(""); +<% elsif @obj_flag == '6'%> +$("#tags_show-<%=@obj.class%>-<%=@obj.id%>").empty(); +$("#tags_show-<%=@obj.class%>-<%=@obj.id%>").html('<%= escape_javascript(render :partial => 'tags/tag_name', :locals => {:obj => @obj,:non_list_all => false,:object_flag => @obj_flag}) %>'); - $("#put-tag-form- <%=@obj.class%>- <%=@obj.id%>").hide(); - $("#put-tag-form-<%=@obj.class%>-<%=@obj.id%> #name").val(""); - <% else %> - $('#tags_show').html('<%= escape_javascript(render :partial => 'tags/tag_name', +$("#put-tag-form- <%=@obj.class%>- <%=@obj.id%>").hide(); +$("#put-tag-form-<%=@obj.class%>-<%=@obj.id%> #name").val(""); +<% else %> +$('#tags_show').html('<%= escape_javascript(render :partial => 'tags/tag_name', :locals => {:obj => @obj,:non_list_all => false,:object_flag => @obj_flag}) %>'); - $('#tags_show').html('<%=render_attachments_tag_save(@project, nil)%>'); - $('#put-tag-form #name').val(""); - //$('#put-tag-form').hide(); - <% end %> +$('#tags_show').html('<%=render_attachments_tag_save(@project, nil)%>'); +$('#put-tag-form #name').val(""); +//$('#put-tag-form').hide(); +<% end %> <% else %> $("#attachments_fields").children().remove(); $("#upload_file_count").text("未上传文件"); $('#upload_file_div').slideToggle('slow'); - <% if @project %> - hideModal(); - <% if @in_project_toolbar %> - window.location.href = '<%= project_files_path(@project) %>' - <% else %> +<% if @project %> +hideModal(); +<% if @in_project_toolbar %> +window.location.href = '<%= project_files_path(@project) %>' +<% else %> - $("#resource_list").html('<%= j(render partial:"project_file", locals: {project: @project}) %>'); - $("#project_files_count_info").html("<%= @all_attachments.count %>"); - $("#project_files_count_nav").html("(<%= @all_attachments.count %>)") - // 添加文件上传成功提示 - <% unless params[:attachments].nil? %> - var div = $('
文件上传成功!
'); - $("#course_list").prepend(div); - setTimeout( function(){div.remove();},3000) - <% end %> - <% end %> - <%elsif @course%> - hideModal(); - <%if @in_course_toolbar %> - window.location.href='<%= course_files_path(@course)%>' - <%else%> - $("#resource_list").html('<%= j(render partial: "course_file" ,locals: {course: @course}) %>'); - $("#courses_files_count_info").html("<%= @all_attachments.count%>"); - $("#courses_files_count_nav").html("(<%= @all_attachments.count%>)") - // 添加文件上传成功提示, - <% unless params[:attachments].nil? %> - var div = $('
文件上传成功!
'); - $("#course_list").prepend(div); - setTimeout( function(){div.remove();},3000) - <% end %> - <%end%> - <% elsif @org_subfield %> - <% if params[:in_org] %> - window.location.href = '<%= org_subfield_files_path @org_subfield %>'; - <%else %> - hideModal(); - $("#resource_list").html('<%= j(render partial: "subfield_files" ,locals: {org_subfield: @org_subfield}) %>'); - // 添加文件上传成功提示, - <% unless params[:attachments].nil? %> +$("#resource_list").html('<%= j(render partial:"project_file", locals: {project: @project}) %>'); +$("#project_files_count_info").html("<%= @all_attachments.count %>"); +$("#project_files_count_nav").html("(<%= @all_attachments.count %>)") +// 添加文件上传成功提示 +<% unless params[:attachments].nil? %> +var div = $('
文件上传成功!
'); +$("#course_list").prepend(div); +setTimeout( function(){div.remove();},3000) +<% end %> +<% end %> +<%elsif @course%> +hideModal(); +<%if @in_course_toolbar %> +window.location.href='<%= course_files_path(@course)%>' +<%else%> +$("#resource_list").html('<%= j(render partial: "course_file" ,locals: {course: @course}) %>'); +$("#courses_files_count_info").html("<%= @all_attachments.count%>"); +$("#courses_files_count_nav").html("(<%= @all_attachments.count%>)") +// 添加文件上传成功提示, +<% unless params[:attachments].nil? %> +var div = $('
文件上传成功!
'); +$("#course_list").prepend(div); +setTimeout( function(){div.remove();},3000) +<% end %> +<%end%> +<% elsif @org_subfield %> +<% if params[:in_org] %> +window.location.href = '<%= org_subfield_files_path @org_subfield %>'; +<%else %> +hideModal(); +$("#resource_list").html('<%= j(render partial: "subfield_files" ,locals: {org_subfield: @org_subfield}) %>'); +// 添加文件上传成功提示, +<% unless params[:attachments].nil? %> // var div = $('
文件上传成功!
'); // $("#org_subfield_list").prepend(div); // setTimeout( function(){div.remove();},3000); - <% end %> - <% end %> - <% end %> +<% end %> +<% end %> +<% elsif @organization %> //组织单独处理 +<% if params[:in_org] %> +window.location.href = '<%= organization_files_path @organization %>'; +<%else %> +hideModal(); +$("#resource_list").html('<%= j(render partial: "subfield_files" ,locals: {org_subfield: @org_subfield}) %>'); +// 添加文件上传成功提示, +<% unless params[:attachments].nil? %> +// var div = $('
文件上传成功!
'); +// $("#org_subfield_list").prepend(div); +// setTimeout( function(){div.remove();},3000); +<% end %> +<% end %> +<% end %> <% end %> $(document).ready(img_thumbnails); diff --git a/app/views/layouts/base_org_newstyle.html.erb b/app/views/layouts/base_org_newstyle.html.erb index b1656cf37..697113081 100644 --- a/app/views/layouts/base_org_newstyle.html.erb +++ b/app/views/layouts/base_org_newstyle.html.erb @@ -9,8 +9,8 @@ <%= favicon %> <%= javascript_heads %> <%= heads_for_theme %> - <%= stylesheet_link_tag 'org_new_style' %> - <%= javascript_include_tag 'org' %> + <%= stylesheet_link_tag 'org_new_style','jquery/jquery-ui-1.9.2' %> + <%= javascript_include_tag 'cookie','project', 'organization','header','prettify','select_list_move','org'%> <%= javascript_include_tag 'attachments' %> <%= call_hook :view_layouts_base_html_head %> @@ -59,13 +59,25 @@ + +
- + <%# 登录 %> <%= render :partial => 'organizations/org_logined_header' %>
diff --git a/config/routes.rb b/config/routes.rb index 56194bd20..c6b3d9da3 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -46,6 +46,14 @@ RedmineApp::Application.routes.draw do end end resources :organizations do + resource :files do + member do + + end + collection do + + end + end resources :org_document_comments do member do