修复:当1个页面存在多个上传控件时的各种bug

redis_cache
yutao 10 years ago
parent 66f8bed978
commit 68cf5fa55e

@ -24,7 +24,7 @@
<span class="ispublic-label"><%= l(:field_is_public)%>:</span>
<%= check_box_tag("attachments[p#{i}][is_public_checkbox]", attachment.is_public,attachment.is_public == 1 ? true : false, :class => 'is_public_checkbox')%>
<%= link_to('&nbsp;'.html_safe, attachment_path(attachment, :attachment_id => "p#{i}", :format => 'js'), :method => 'delete', :remote => true, :class => 'remove-upload') %>
<%= link_to('&nbsp;'.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();
// }
</script>
<span class="add_attachment">
<span class="add_attachment" data-containerid="<%= container.id %>">
<%#= button_tag "浏览", :type=>"button", :onclick=>"CompatibleSend();" %>
<!--%= link_to image_tag(),"javascript:void(0)", :onclick => "_file.click()"%-->
<%= 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}"
} %>
<span id="upload_file_count<%=container.id %>" :class="c_grey"><%= l(:label_no_file_uploaded)%></span>
(<%= l(:label_max_size) %>: <%= number_to_human_size(Setting.attachment_max_size.to_i.kilobytes) %>)

@ -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("<span id=\"count\">"+count+"</span>"+"个文件"+"已上传");
}
}else{
$("#upload_file_count").html("已上传"+"<span id=\"count\">"+count+"</span>"+"个文件");
}
$('#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("<span id=\"count\">"+count+"</span>"+"个文件"+"已上传");
}
}
//modify by yutao 2015-5-14 当1个页面存在多个上传控件时此块代码存在bug 故改之 end

@ -37,7 +37,7 @@ function addFile_board(inputEl, file, eagerUpload, id) {
$('<input>', { 'type': 'text', 'class': 'description', 'name': 'attachments[' + attachmentId + '][description]', 'maxlength': 254, 'placeholder': $(inputEl).data('descriptionPlaceholder') } ).toggle(!eagerUpload),
$('<span >'+$(inputEl).data('fieldIsPublic')+':</span>').attr({ 'class': 'ispublic-label' }) ,
$('<input>', { 'type': 'checkbox', 'class': 'is_public_checkbox','value':1, 'name': 'attachments[' + attachmentId + '][is_public_checkbox]', checked:'checked' } ).toggle(!eagerUpload),
$('<a>&nbsp</a>').attr({ 'href': "#", 'class': 'remove-upload' }).click(function(){
$('<a>&nbsp</a>').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("<span id=\"count\">"+count+"</span>"+$(inputEl).data('fileCount'));
if(count>=1){
var add_attachs=$('.add_attachment');
var delete_all=$('.remove_all');
if(delete_all.length<1){
add_attachs.append($("<a>&nbsp</a>").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("<span id=\"count\">"+count+"</span>"+$(inputEl).data('fileCount'));
if(count>=1){
var add_attachs=$('.add_attachment');
var delete_all=$('.remove_all');
if(delete_all.length<1){
add_attachs.append($("<a>&nbsp</a>").attr({"href":"javascript:void(0)", 'class': 'remove_all',"onclick": "removeAll()"}));
}
}
}else{
var count=$('#attachments_fields'+containerid+'>span').length;
$('#upload_file_count'+containerid).html("<span id=\"count\">"+count+"</span>"+$(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($("<a>&nbsp</a>").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("<span id=\"count\">" + count + "</span>" + $(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($("<a>&nbsp</a>").attr({
"href": "javascript:void(0)",
'class': 'remove_all',
'data-containerid': containerid,
"onclick": "removeAll('" + containerid + "')"
}));
}
}
});
});
Loading…
Cancel
Save