diff --git a/app/controllers/statistics_controller.rb b/app/controllers/statistics_controller.rb index 1d22bd5eb..563bbf257 100644 --- a/app/controllers/statistics_controller.rb +++ b/app/controllers/statistics_controller.rb @@ -14,7 +14,7 @@ class StatisticsController < ApplicationController # GET /statistics/1.json def show @statistic = Statistic.find(params[:id]) - + @attachments = @statistic.attachments respond_to do |format| format.html # show.html.erb format.json { render json: @statistic } @@ -41,7 +41,7 @@ class StatisticsController < ApplicationController # POST /statistics.json def create @statistic = Statistic.new(params[:statistic]) - + @statistic.save_attachments_containers(params[:attachments], User.current, true) respond_to do |format| if @statistic.save format.html { redirect_to @statistic, notice: 'Statistic was successfully created.' } diff --git a/app/helpers/statistics_helper.rb b/app/helpers/statistics_helper.rb index 2d25d41c5..142100fbe 100644 --- a/app/helpers/statistics_helper.rb +++ b/app/helpers/statistics_helper.rb @@ -1,2 +1,3 @@ module StatisticsHelper + include AttachmentsHelper end diff --git a/app/models/attachment.rb b/app/models/attachment.rb index ff87f533c..cf1c60493 100644 --- a/app/models/attachment.rb +++ b/app/models/attachment.rb @@ -26,6 +26,7 @@ class Attachment < ActiveRecord::Base belongs_to :organization, foreign_key: 'container_id', conditions: "attachements.container_type = 'Organization'" belongs_to :syllabus, foreign_key: 'container_id', conditions: "attachements.container_type = 'Syllabus'" belongs_to :softapplication, foreign_key: 'container_id', conditions: "attachments.container_type = 'Softapplication'" + belongs_to :statistic, foreign_key: 'container_id', conditions: "attachments.container_type = 'Statistic'" belongs_to :author, :class_name => "User", :foreign_key => "author_id" belongs_to :attachmentstype, :foreign_key => "attachtype",:primary_key => "id" # 被ForgeActivity虚拟关联 diff --git a/app/models/statistic.rb b/app/models/statistic.rb index b3f6d00e7..e375f3230 100644 --- a/app/models/statistic.rb +++ b/app/models/statistic.rb @@ -1,3 +1,4 @@ class Statistic < ActiveRecord::Base attr_accessible :description, :name, :status, :user_id + acts_as_attachable end diff --git a/app/views/attachments/_form_statistic.html.erb b/app/views/attachments/_form_statistic.html.erb new file mode 100644 index 000000000..58449abc9 --- /dev/null +++ b/app/views/attachments/_form_statistic.html.erb @@ -0,0 +1,76 @@ + +<% if defined?(container) && container && container.saved_attachments %> + <% if isReply %> + <% container.saved_attachments.each_with_index do |attachment, i| %> +

+ + <%= text_field_tag("attachments[p#{i}][filename]", attachment.filename, :class => 'upload_filename readonly', :readonly=>'readonly')%> + <%#= text_field_tag("attachments[p#{i}][description]", attachment.description, :maxlength => 255, :placeholder => l(:label_optional_description), :class => 'description', :style=>"display: inline-block;") %> + + <%#= check_box_tag("attachments[p#{i}][is_public_checkbox]", attachment.is_public,attachment.is_public == 1 ? true : false, :class => 'is_public_checkbox')%> + + <%= link_to(' '.html_safe, attachment_path(attachment, :attachment_id => "#{i+1}", :format => 'js'), :method => 'delete', :remote => true, :class => 'remove-upload', :containerid => "2") %> + <%= hidden_field_tag "attachments[p#{i}][token]", "#{attachment.token}" %> +

+ <% end %> + <% else %> + <% container.attachments.each_with_index do |attachment, i| %> +

+ + <%= text_field_tag("attachments[p#{i}][filename]", attachment.filename, :class => 'upload_filename readonly', :readonly=>'readonly')%> + <%#= text_field_tag("attachments[p#{i}][description]", attachment.description, :maxlength => 255, :placeholder => l(:label_optional_description), :class => 'description', :style=>"display: inline-block;") %> + + <%#= check_box_tag("attachments[p#{i}][is_public_checkbox]", attachment.is_public,attachment.is_public == 1 ? true : false, :class => 'is_public_checkbox')%> + + <%= link_to(' '.html_safe, attachment_path(attachment, :attachment_id => "#{i+1}", :format => 'js'), :method => 'delete', :remote => true, :class => 'remove-upload', :containerid => "2") %> + <%#= render :partial => 'tags/tag', :locals => {:obj => attachment, :object_flag => "6"} %> + + <%= hidden_field_tag "attachments[p#{i}][token]", "#{attachment.token}" %> +

+ <% end %> + <% end %> +<% end %> +
+ + +<%#= button_tag "浏览", :type=>"button", :onclick=>"CompatibleSend();" %> + +<%#= button_tag "#{l(:button_browse)}", :type=>"button", :onclick=>"file#{container.id}.click()",:class =>"sub_btn",:style => ie8? ? 'display:none' : '' %> + <% id ="file#{container.id}"%> + 上传附件 + <%= file_field_tag 'attachments[dummy][file]', + :id => "file#{container.id}", + :class => 'file_selector', + :multiple => true, + :onchange => "addInputFiles_board(this, '#{container.id}');", + :style => '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), + :delete_all_files => l(:text_are_you_sure_all), + :lebel_file_uploding => l(:lebel_file_uploding) + } %> + <% if container.nil? %> + <%= l(:label_no_file_uploaded)%> + <% end %> + + + +<% content_for :header_tags do %> + <%= javascript_include_tag 'attachments' %> +<% end %> + + diff --git a/app/views/statistics/_attachments.html.erb b/app/views/statistics/_attachments.html.erb new file mode 100644 index 000000000..817ebe400 --- /dev/null +++ b/app/views/statistics/_attachments.html.erb @@ -0,0 +1,18 @@ +<% attachments.each do |attachment| %> +
+ + + <%= link_to_short_attachment attachment,:length=> 58, :class => 'hidden link_file_a fl newsBlue mw380', :download => true %> + + + ( + <%= number_to_human_size attachment.filesize %>) + + <% user_name = attachment.author.show_name.empty? ? attachment.author : attachment.author.show_name %> + + <%= link_to h(truncate(user_name, length: 15, omission: '...')),user_path(attachment.author),:class => "linkBlue2" %>, + <%= format_time(attachment.created_on) %> + +
+
+<% end %> diff --git a/app/views/statistics/_form.html.erb b/app/views/statistics/_form.html.erb index 096ad265c..2ab07892d 100644 --- a/app/views/statistics/_form.html.erb +++ b/app/views/statistics/_form.html.erb @@ -27,6 +27,11 @@ <%= f.label :status %>
<%= f.number_field :status %> + +
+ <%= f.label :label_attachment_plural %>
+ <%= render :partial => 'attachments/form_statistic', :locals => {:container => @statistic, :isReply => @isReply} %> +
<%= f.submit %>
diff --git a/app/views/statistics/show.html.erb b/app/views/statistics/show.html.erb index 17aeade49..fff68af8c 100644 --- a/app/views/statistics/show.html.erb +++ b/app/views/statistics/show.html.erb @@ -20,6 +20,10 @@ <%= @statistic.status %>

+<%# 附件局部刷新 %> +<% if @attachments.present? %> + <%= render :partial => 'attachments',:locals => {:attachments => @attachments} %> +<% end %> <%= link_to 'Edit', edit_statistic_path(@statistic) %> | <%= link_to 'Back', statistics_path %>