From 68cf5fa55e6cae945927564a3d97ea8c9c58cb6b Mon Sep 17 00:00:00 2001 From: yutao <283765470@qq.com> Date: Fri, 15 May 2015 11:45:15 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D:=E5=BD=931=E4=B8=AA=E9=A1=B5?= =?UTF-8?q?=E9=9D=A2=E5=AD=98=E5=9C=A8=E5=A4=9A=E4=B8=AA=E4=B8=8A=E4=BC=A0?= =?UTF-8?q?=E6=8E=A7=E4=BB=B6=E6=97=B6=E7=9A=84=E5=90=84=E7=A7=8Dbug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/attachments/_form_project.html.erb | 7 +- app/views/attachments/destroy.js.erb | 32 ++++++-- public/javascripts/attachments.js | 82 +++++++++++++++++--- 3 files changed, 100 insertions(+), 21 deletions(-) diff --git a/app/views/attachments/_form_project.html.erb b/app/views/attachments/_form_project.html.erb index 0478ba613..998766b27 100644 --- a/app/views/attachments/_form_project.html.erb +++ b/app/views/attachments/_form_project.html.erb @@ -24,7 +24,7 @@ <%= 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_checkbox')%> - <%= link_to(' '.html_safe, attachment_path(attachment, :attachment_id => "p#{i}", :format => 'js'), :method => 'delete', :remote => true, :class => 'remove-upload') %> + <%= link_to(' '.html_safe, attachment_path(attachment, :attachment_id => "p#{i}", :format => 'js'), 'data-containerid'=>"#{container.id}",:method => 'delete', :remote => true, :class => 'remove-upload') %> <%#= render :partial => 'tags/tag', :locals => {:obj => attachment, :object_flag => "6"} %> <%= hidden_field_tag "attachments[p#{i}][token]", "#{attachment.token}" %> @@ -41,7 +41,7 @@ // file.click(); // } - + <%#= button_tag "浏览", :type=>"button", :onclick=>"CompatibleSend();" %> <%= button_tag "文件浏览", :type=>"button", :onclick=>"_file#{container.id}.click()", :class =>"sub_btn",:style => ie8? ? 'display:none' : '' %> @@ -60,7 +60,8 @@ :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) + :delete_all_files => l(:text_are_you_sure_all), + :containerid => "#{container.id}" } %> <%= l(:label_no_file_uploaded)%> (<%= l(:label_max_size) %>: <%= number_to_human_size(Setting.attachment_max_size.to_i.kilobytes) %>) diff --git a/app/views/attachments/destroy.js.erb b/app/views/attachments/destroy.js.erb index d2a3a11a1..0b6cee0df 100644 --- a/app/views/attachments/destroy.js.erb +++ b/app/views/attachments/destroy.js.erb @@ -1,8 +1,26 @@ -$('#attachments_<%= j params[:attachment_id] %>').remove(); -var count=$('#attachments_fields>span').length; -if(count<=0){ - $("#upload_file_count").text(<%= l(:label_no_file_uploaded)%>); - $(".remove_all").remove(); +var attachment_html_obj = $('#attachments_<%= j params[:attachment_id] %>'); +//modify by yutao 2015-5-14 当1个页面存在多个上传控件时此块代码存在bug 故改之 start +var containerid=$('.remove-upload',attachment_html_obj).data('containerid'); +if(containerid==undefined){ + $('#attachments_<%= j params[:attachment_id] %>').remove(); + var count=$('#attachments_fields>span').length; + if(count<=0){ + $("#upload_file_count").text('<%= l(:label_no_file_uploaded)%>'); + $(".remove_all").remove(); + }else{ + $("#upload_file_count").html(""+count+""+"个文件"+"已上传"); + } }else{ - $("#upload_file_count").html("已上传"+""+count+""+"个文件"); -} \ No newline at end of file + $('#attachments_<%= j params[:attachment_id] %>').remove(); + var count=$('#attachments_fields'+containerid+'>span').length; + if(count<=0){ + $('#upload_file_count'+containerid).text('<%= l(:label_no_file_uploaded)%>'); + var remove_all_html_obj = $(".remove_all").filter(function(index){ + return $(this).data('containerid')==containerid; + }); + remove_all_html_obj.remove(); + }else{ + $('#upload_file_count'+containerid).html(""+count+""+"个文件"+"已上传"); + } +} +//modify by yutao 2015-5-14 当1个页面存在多个上传控件时此块代码存在bug 故改之 end \ No newline at end of file diff --git a/public/javascripts/attachments.js b/public/javascripts/attachments.js index 01e587e97..3df755a7f 100644 --- a/public/javascripts/attachments.js +++ b/public/javascripts/attachments.js @@ -37,7 +37,7 @@ function addFile_board(inputEl, file, eagerUpload, id) { $('', { 'type': 'text', 'class': 'description', 'name': 'attachments[' + attachmentId + '][description]', 'maxlength': 254, 'placeholder': $(inputEl).data('descriptionPlaceholder') } ).toggle(!eagerUpload), $(''+$(inputEl).data('fieldIsPublic')+':').attr({ 'class': 'ispublic-label' }) , $('', { 'type': 'checkbox', 'class': 'is_public_checkbox','value':1, 'name': 'attachments[' + attachmentId + '][is_public_checkbox]', checked:'checked' } ).toggle(!eagerUpload), - $(' ').attr({ 'href': "#", 'class': 'remove-upload' }).click(function(){ + $(' ').attr({ 'href': "#", 'class': 'remove-upload', 'data-containerid':id }).click(function(){ if(confirm($(inputEl).data('areYouSure'))){ removeFile(); if(!eagerUpload){ @@ -142,14 +142,38 @@ function ajaxUpload(file, attachmentId, fileSpan, inputEl) { //gcm files count and add delete_all link - var count=$('#attachments_fields>span').length; - $('#upload_file_count').html(""+count+""+$(inputEl).data('fileCount')); - if(count>=1){ - var add_attachs=$('.add_attachment'); - var delete_all=$('.remove_all'); - if(delete_all.length<1){ - add_attachs.append($(" ").attr({"href":"javascript:void(0)", 'class': 'remove_all',"onclick": "removeAll()"})); + //modify by yutao 2015-5-14 1ҳڶϴؼʱ˿bug ʸ֮ start + var containerid=$(inputEl).data('containerid'); + if(containerid==undefined){ + var count=$('#attachments_fields>span').length; + $('#upload_file_count').html(""+count+""+$(inputEl).data('fileCount')); + if(count>=1){ + var add_attachs=$('.add_attachment'); + var delete_all=$('.remove_all'); + if(delete_all.length<1){ + add_attachs.append($(" ").attr({"href":"javascript:void(0)", 'class': 'remove_all',"onclick": "removeAll()"})); + } } + }else{ + var count=$('#attachments_fields'+containerid+'>span').length; + $('#upload_file_count'+containerid).html(""+count+""+$(inputEl).data('fileCount')); + if(count>=1){ + var add_attachs=$('.add_attachment').filter(function(index){ + return $(this).data('containerid')==containerid; + }); + var delete_all=$('.remove_all').filter(function(index){ + return $(this).data('containerid')==containerid; + }); + if(delete_all.length<1){ + add_attachs.append($(" ").attr({ + "href":"javascript:void(0)", + 'class': 'remove_all', + 'data-containerid': containerid, + "onclick": "removeAll('"+containerid+"')" + })); + } + } + //modify by yutao 2015-5-14 1ҳڶϴؼʱ˿bug ʸ֮ end } //gcm @@ -176,13 +200,23 @@ function removeFile() { } //gcm delete all file -function removeAll(){ +//modify by yutao 2015-5-14 1ҳڶϴؼʱ˿bug ʸ֮ start +function removeAll(containerid){ if(confirm(deleteallfiles)){ - $(".remove-upload").removeAttr("data-confirm"); - $(".remove-upload").click(); + if(containerid==undefined){ + $(".remove-upload").removeAttr("data-confirm"); + $(".remove-upload").click(); + }else{ + var arr = $(".remove-upload").filter(function(){ + return $(this).data('containerid')==containerid; + }); + arr.removeAttr("data-confirm"); + arr.click(); + } } // return false; } +//modify by yutao 2015-5-14 1ҳڶϴؼʱ˿bug ʸ֮ end //gcm function uploadBlob(blob, uploadUrl, attachmentId, options) { @@ -324,3 +358,29 @@ function setupFileDrop() { } $(document).ready(setupFileDrop); +$(function(){ + $(".file_selector").each(function() { + deleteallfiles = $(this).data('deleteAllFiles'); + var containerid = $(this).data('containerid'); + if (containerid == undefined)containerid = ''; + var count = $('#attachments_fields' + containerid + '>span').length; + if (count >= 1) { + $('#upload_file_count' + containerid).html("" + count + "" + $(this).data('fileCount')); + var add_attachs = $('.add_attachment').filter(function (index) { + return $(this).data('containerid') == containerid; + }); + var delete_all = $('.remove_all').filter(function (index) { + return $(this).data('containerid') == containerid; + }); + if (delete_all.length < 1) { + add_attachs.append($(" ").attr({ + "href": "javascript:void(0)", + 'class': 'remove_all', + 'data-containerid': containerid, + "onclick": "removeAll('" + containerid + "')" + })); + } + + } + }); +}); \ No newline at end of file