From 9dc2cb8541c5c2e0ec4fce897c98c7f97afbf967 Mon Sep 17 00:00:00 2001 From: ouyangxuhua Date: Wed, 23 Dec 2015 10:40:50 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E7=BB=84=E7=BB=87=E6=96=87?= =?UTF-8?q?=E7=AB=A0=E9=99=84=E4=BB=B6=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/attachments_controller.rb | 2 + .../org_document_comments_controller.rb | 5 +- app/models/org_document_comment.rb | 6 ++ .../_attachment.html.erb | 79 +++++++++++++++++++ app/views/org_document_comments/edit.html.erb | 7 +- app/views/org_document_comments/new.html.erb | 8 +- app/views/org_document_comments/show.html.erb | 3 + 7 files changed, 106 insertions(+), 4 deletions(-) create mode 100644 app/views/org_document_comments/_attachment.html.erb diff --git a/app/controllers/attachments_controller.rb b/app/controllers/attachments_controller.rb index 664dc4cf5..9ce76dca8 100644 --- a/app/controllers/attachments_controller.rb +++ b/app/controllers/attachments_controller.rb @@ -242,6 +242,8 @@ class AttachmentsController < ApplicationController 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)} + elsif !@attachment.container.nil? && @attachment.container.is_a?(OrgDocumentComment) + format.html {redirect_to_referer_or org_document_comment_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/org_document_comments_controller.rb b/app/controllers/org_document_comments_controller.rb index b8584fea3..67d3b247a 100644 --- a/app/controllers/org_document_comments_controller.rb +++ b/app/controllers/org_document_comments_controller.rb @@ -1,16 +1,18 @@ class OrgDocumentCommentsController < ApplicationController before_filter :find_organization, :only => [:new, :create, :show, :index] - + helper :attachments layout 'base_org' def new @org_document_comment = OrgDocumentComment.new end + def create @org_document_comment = OrgDocumentComment.new(:organization_id => @organization.id, :creator_id => User.current.id) @org_document_comment.title = params[:org_document_comment][:title] @org_document_comment.content = params[:org_document_comment][:content] + @org_document_comment.save_attachments(params[:attachments]) if params[:field_id] @org_document_comment.org_subfield_id = params[:field_id].to_i end @@ -40,6 +42,7 @@ class OrgDocumentCommentsController < ApplicationController def update @org_document = OrgDocumentComment.find(params[:id]) @org_document.update_attributes(:title => params[:org_document_comment][:title], :content => params[:org_document_comment][:content]) + @org_document.save_attachments(params[:attachments]) if @org_document.parent.nil? act = OrgActivity.where("org_act_type='OrgDocumentComment' and org_act_id =?", @org_document.id).first act.update_attributes(:updated_at => @org_document.updated_at) diff --git a/app/models/org_document_comment.rb b/app/models/org_document_comment.rb index e2ce350ce..8febbf981 100644 --- a/app/models/org_document_comment.rb +++ b/app/models/org_document_comment.rb @@ -5,6 +5,7 @@ class OrgDocumentComment < ActiveRecord::Base belongs_to :creator, :class_name => 'User', :foreign_key => 'creator_id' has_many :editor_of_documents, :dependent => :destroy acts_as_tree :order => "#{OrgDocumentComment.table_name}.sticky asc, #{OrgDocumentComment.table_name}.created_at desc" + acts_as_attachable has_many :org_acts, :class_name => 'OrgActivity',:as =>:org_act ,:dependent => :destroy after_create :document_save_as_org_activity @@ -17,4 +18,9 @@ class OrgDocumentComment < ActiveRecord::Base end end + + def project + + end + end diff --git a/app/views/org_document_comments/_attachment.html.erb b/app/views/org_document_comments/_attachment.html.erb new file mode 100644 index 000000000..86298a330 --- /dev/null +++ b/app/views/org_document_comments/_attachment.html.erb @@ -0,0 +1,79 @@ + +
+ +<% if defined?(container) && container && container.saved_attachments %> + <% container.attachments.each_with_index do |attachment, i| %> + + <%= text_field_tag("attachments[p#{i}][filename]", attachment.filename, :class => 'filename readonly', :readonly => 'readonly') %><%= text_field_tag("attachments[p#{i}][description]", attachment.description, :maxlength => 254, :placeholder => l(:label_optional_description), :class => 'description', :style => "display: inline-block;") %><%= l(:field_is_public) %>: + <%= check_box_tag("attachments[p#{i}][is_public_checkbox]", attachment.is_public, attachment.is_public == 1 ? true : false, :class => 'is_public') %> + <%= if attachment.id.nil? + #待补充代码 + else + link_to(' '.html_safe, attachment_path(attachment, :attachment_id => "p#{i}", :format => 'js'), :method => 'delete', :remote => true, :class => 'remove-upload') + end + %> + <%#= render :partial => 'tags/tag', :locals => {:obj => attachment, :object_flag => "6"} %> + + <%= hidden_field_tag "attachments[p#{i}][token]", "#{attachment.token}" %> + +
+ <% end %> + <% container.saved_attachments.each_with_index do |attachment, i| %> + + <%= text_field_tag("attachments[p#{i}][filename]", attachment.filename, :class => 'filename readonly', :readonly => 'readonly') %> + <%= text_field_tag("attachments[p#{i}][description]", attachment.description, :maxlength => 254, :placeholder => l(:label_optional_description), :class => 'description', :style => "display: inline-block;") %> + <%= l(:field_is_public) %>: + <%= check_box_tag("attachments[p#{i}][is_public_checkbox]", attachment.is_public, attachment.is_public == 1 ? true : false, :class => 'is_public') %> + <%= if attachment.id.nil? + #待补充代码 + else + link_to(' '.html_safe, attachment_path(attachment, :attachment_id => "p#{i}", :format => 'js'), :method => 'delete', :remote => true, :class => 'remove-upload') + end + %> + <%#= render :partial => 'tags/tag', :locals => {:obj => attachment, :object_flag => "6"} %> + + <%= hidden_field_tag "attachments[p#{i}][token]", "#{attachment.token}" %> + +
+ <% end %> +<% end %> +
+
+ + <%#= button_tag "浏览", :type=>"button", :onclick=>"CompatibleSend();" %> + + <%#= button_tag "文件浏览", :type=>"button", :onclick=>"$('#_file').click();",:onmouseover => 'this.focus()',:class => 'sub_btn' %> + 上传附件 + <%= file_field_tag 'attachments[dummy][file]', + :id => '_file', + :class => '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) + } %> + + <%= l(:label_no_file_uploaded) %> + + (<%= l(:label_max_size) %>: + <%= number_to_human_size(Setting.attachment_max_size.to_i.kilobytes) %>) + + + <% content_for :header_tags do %> + <%= javascript_include_tag 'attachments' %> + <% end %> +
+ diff --git a/app/views/org_document_comments/edit.html.erb b/app/views/org_document_comments/edit.html.erb index 33244ef14..6ee42bb08 100644 --- a/app/views/org_document_comments/edit.html.erb +++ b/app/views/org_document_comments/edit.html.erb @@ -33,10 +33,15 @@
-

+
+
+ <%= render :partial => 'org_document_comments/attachment', :locals => {:container => @org_document} %> +
+
+
确定 diff --git a/app/views/org_document_comments/new.html.erb b/app/views/org_document_comments/new.html.erb index 24160f6eb..6b0a275c3 100644 --- a/app/views/org_document_comments/new.html.erb +++ b/app/views/org_document_comments/new.html.erb @@ -39,10 +39,14 @@ <%= kindeditor_tag 'org_document_comment[content]','', :editor_id => 'org_document_description_editor', :height => "150px" %>
- -

+
+
+ <%= render :partial => 'org_document_comments/attachment', :locals => {:container => nil} %> +
+
+
确定 diff --git a/app/views/org_document_comments/show.html.erb b/app/views/org_document_comments/show.html.erb index 0848bc4e5..5815483e5 100644 --- a/app/views/org_document_comments/show.html.erb +++ b/app/views/org_document_comments/show.html.erb @@ -29,6 +29,9 @@ <%= @document.content.html_safe %>
<% end %> +
+ <%= link_to_attachments_course @document, :author => false %> +