From cc5738c12f70e81031baf18255ae54fea0532f8e Mon Sep 17 00:00:00 2001 From: alan <547533434@qq.com> Date: Fri, 15 May 2015 10:07:52 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AF=BE=E7=A8=8B=E8=AE=A8=E8=AE=BA=E5=8C=BA?= =?UTF-8?q?=E5=9B=9E=E5=A4=8D=E6=A0=B7=E5=BC=8F=E9=94=99=E8=AF=AF=20Signed?= =?UTF-8?q?-off-by:=20alan=20<547533434@qq.com>?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/attachments/_form_course.html.erb | 32 +- app/views/attachments/_form_project.html.erb | 4 +- app/views/boards/_course_show.html.erb | 3 +- public/javascripts/attachments.js | 304 +++++++++---------- 4 files changed, 176 insertions(+), 167 deletions(-) diff --git a/app/views/attachments/_form_course.html.erb b/app/views/attachments/_form_course.html.erb index 4a297fb7b..b0ab39b5a 100644 --- a/app/views/attachments/_form_course.html.erb +++ b/app/views/attachments/_form_course.html.erb @@ -2,26 +2,30 @@ <% 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 => '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;") + - link_to(' '.html_safe, attachment_path(attachment, :attachment_id => "p#{i}", :format => 'js'), :method => 'delete', :remote => true, :class => 'remove-upload') %> - <%#= render :partial => 'tags/tag', :locals => {:obj => attachment, :object_flag => "6"} %> + <%= text_field_tag("attachments[p#{i}][description]", attachment.description, :maxlength => 255, :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')%> + <%= 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') %> <%= 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 => '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;") + - link_to(' '.html_safe, attachment_path(attachment, :attachment_id => "p#{i}", :format => 'js'), :method => 'delete', :remote => true, :class => 'remove-upload') %> - <%#= render :partial => 'tags/tag', :locals => {:obj => attachment, :object_flag => "6"} %> - <%= 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')%> - <%= hidden_field_tag "attachments[p#{i}][token]", "#{attachment.token}" %> + <%= text_field_tag("attachments[p#{i}][description]", attachment.description, :maxlength => 255, :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_checkbox')%> + + <%= link_to(' '.html_safe, attachment_path(attachment, :attachment_id => "p#{i}", :format => 'js'), :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}" %> <% end %> <% end %> @@ -56,7 +60,9 @@ :file_count => l(:label_file_count), :delete_all_files => l(:text_are_you_sure_all) } %> -<%= l(:label_no_file_uploaded)%> + <% if container.nil? %> + <%= l(:label_no_file_uploaded)%> + <% end %> (<%= l(:label_max_size) %>: <%= number_to_human_size(Setting.attachment_max_size.to_i.kilobytes) %>) diff --git a/app/views/attachments/_form_project.html.erb b/app/views/attachments/_form_project.html.erb index 515e307f6..0478ba613 100644 --- a/app/views/attachments/_form_project.html.erb +++ b/app/views/attachments/_form_project.html.erb @@ -124,7 +124,9 @@ :file_count => l(:label_file_count), :delete_all_files => l(:text_are_you_sure_all) } %> - <%= l(:label_no_file_uploaded)%> + <% if container.nil? %> + <%= l(:label_no_file_uploaded)%> + <% end %> (<%= l(:label_max_size) %>: <%= number_to_human_size(Setting.attachment_max_size.to_i.kilobytes) %>) diff --git a/app/views/boards/_course_show.html.erb b/app/views/boards/_course_show.html.erb index 2d0bda162..2a078553c 100644 --- a/app/views/boards/_course_show.html.erb +++ b/app/views/boards/_course_show.html.erb @@ -68,6 +68,7 @@ +
<%= link_to_user_header message.author,false,:class => 'fl c_orange ' %>
-

<%= textAreailizable message,:content,:attachments => message.attachments %>

+

<%= textAreailizable message,:content,:attachments => message.attachments %>


<%= format_time(message.created_on) %> diff --git a/public/javascripts/attachments.js b/public/javascripts/attachments.js index 6eb73182d..01e587e97 100644 --- a/public/javascripts/attachments.js +++ b/public/javascripts/attachments.js @@ -1,10 +1,10 @@ /* Redmine - project management software - Copyright (C) 2006-2013 Jean-Philippe Lang */ + Copyright (C) 2006-2013 Jean-Philippe Lang */ function postUpMsg(attachmentId) { $.ajax({ - url: '/attachments/renderTag', + url: '/attachments/renderTag', type: "GET", data: { attachmentId: attachmentId @@ -25,39 +25,39 @@ function reload(fileSpan) { function addFile_board(inputEl, file, eagerUpload, id) { - var attachments_frame = '#attachments_fields' + id; - if ($(attachments_frame).children().length < 30) { - deleteallfiles = $(inputEl).data('deleteAllFiles'); - var attachmentId = addFile.nextAttachmentId++; + var attachments_frame = '#attachments_fields' + id; + if ($(attachments_frame).children().length < 30) { + deleteallfiles = $(inputEl).data('deleteAllFiles'); + var attachmentId = addFile.nextAttachmentId++; - var fileSpan = $('', { 'id': 'attachments_' + attachmentId, 'class':'attachment' }); + var fileSpan = $('', { 'id': 'attachments_' + attachmentId, 'class':'attachment' }); - fileSpan.append( - $('', { 'type': 'text', 'class': 'filename readonly', 'name': 'attachments[' + attachmentId + '][filename]', 'readonly': 'readonly'} ).val(file.name), - $('', { '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(){ - if(confirm($(inputEl).data('areYouSure'))){ - removeFile(); - if(!eagerUpload){ - (function(e){ - reload(e); - })(fileSpan); + fileSpan.append( + $('', { 'type': 'text', 'class': 'filename readonly', 'name': 'attachments[' + attachmentId + '][filename]', 'readonly': 'readonly'} ).val(file.name), + $('', { '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(){ + if(confirm($(inputEl).data('areYouSure'))){ + removeFile(); + if(!eagerUpload){ + (function(e){ + reload(e); + })(fileSpan); + } } - } - }).toggle(!eagerUpload), - $('
', { 'class': 'div_attachments', 'name': 'div_'+'attachments_' + attachmentId} ) - ).appendTo(attachments_frame); + }).toggle(!eagerUpload), + $('
', { 'class': 'div_attachments', 'name': 'div_'+'attachments_' + attachmentId} ) + ).appendTo(attachments_frame); - if(eagerUpload) { - ajaxUpload(file, attachmentId, fileSpan, inputEl); + if(eagerUpload) { + ajaxUpload(file, attachmentId, fileSpan, inputEl); + } + return attachmentId; } - return attachmentId; - } - return null; + return null; } function addFile(inputEl, file, eagerUpload) { @@ -99,132 +99,132 @@ addFile.nextAttachmentId = 1; function ajaxUpload(file, attachmentId, fileSpan, inputEl) { - function onLoadstart(e) { - fileSpan.removeClass('ajax-waiting'); - fileSpan.addClass('ajax-loading'); - $('input:submit', $(this).parents('form')).attr('disabled', 'disabled'); - } - - function onProgress(e) { - if(e.lengthComputable) { - this.progressbar( 'value', e.loaded * 100 / e.total ); + function onLoadstart(e) { + fileSpan.removeClass('ajax-waiting'); + fileSpan.addClass('ajax-loading'); + $('input:submit', $(this).parents('form')).attr('disabled', 'disabled'); } - } - function actualUpload(file, attachmentId, fileSpan, inputEl) { - - ajaxUpload.uploading++; - - uploadBlob(file, $(inputEl).data('upload-path'), attachmentId, { - loadstartEventHandler: onLoadstart.bind(progressSpan), - progressEventHandler: onProgress.bind(progressSpan) - }) - .done(function(result) { - progressSpan.progressbar( 'value', 100 ).remove(); - fileSpan.find('input.description, a').css('display', 'inline-block'); - fileSpan.find('input.is_public_checkbox, a').css('display', 'inline-block'); - }) - .fail(function(result) { - progressSpan.text(result.statusText); - if($("#network_issue")) - { - $("#network_issue").show(); + function onProgress(e) { + if(e.lengthComputable) { + this.progressbar( 'value', e.loaded * 100 / e.total ); } - }).always(function() { - ajaxUpload.uploading--; - fileSpan.removeClass('ajax-loading'); - var form = fileSpan.parents('form'); - if (form.queue('upload').length == 0 && ajaxUpload.uploading == 0) { - $('input:submit', form).removeAttr('disabled'); + } + + function actualUpload(file, attachmentId, fileSpan, inputEl) { + + ajaxUpload.uploading++; + + uploadBlob(file, $(inputEl).data('upload-path'), attachmentId, { + loadstartEventHandler: onLoadstart.bind(progressSpan), + progressEventHandler: onProgress.bind(progressSpan) + }) + .done(function(result) { + progressSpan.progressbar( 'value', 100 ).remove(); + fileSpan.find('input.description, a').css('display', 'inline-block'); + fileSpan.find('input.is_public_checkbox, a').css('display', 'inline-block'); + }) + .fail(function(result) { + progressSpan.text(result.statusText); + if($("#network_issue")) + { + $("#network_issue").show(); + } + }).always(function() { + ajaxUpload.uploading--; + fileSpan.removeClass('ajax-loading'); + var form = fileSpan.parents('form'); + if (form.queue('upload').length == 0 && ajaxUpload.uploading == 0) { + $('input:submit', form).removeAttr('disabled'); + } + form.dequeue('upload'); + }); + + //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()"})); + } } - form.dequeue('upload'); - }); - - //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()"})); - } - } + //gcm - //gcm - - } + } - var progressSpan = $('
').insertAfter(fileSpan.find('input.filename')); - progressSpan.progressbar(); - fileSpan.addClass('ajax-waiting'); + var progressSpan = $('
').insertAfter(fileSpan.find('input.filename')); + progressSpan.progressbar(); + fileSpan.addClass('ajax-waiting'); - var maxSyncUpload = $(inputEl).data('max-concurrent-uploads'); + var maxSyncUpload = $(inputEl).data('max-concurrent-uploads'); - if(maxSyncUpload == null || maxSyncUpload <= 0 || ajaxUpload.uploading < maxSyncUpload) - actualUpload(file, attachmentId, fileSpan, inputEl); - else - $(inputEl).parents('form').queue('upload', actualUpload.bind(this, file, attachmentId, fileSpan, inputEl)); + if(maxSyncUpload == null || maxSyncUpload <= 0 || ajaxUpload.uploading < maxSyncUpload) + actualUpload(file, attachmentId, fileSpan, inputEl); + else + $(inputEl).parents('form').queue('upload', actualUpload.bind(this, file, attachmentId, fileSpan, inputEl)); } ajaxUpload.uploading = 0; function removeFile() { - $(this).parent('span').remove(); - return false; + $(this).parent('span').remove(); + return false; } //gcm delete all file function removeAll(){ - if(confirm(deleteallfiles)){ - $(".remove-upload").removeAttr("data-confirm"); - $(".remove-upload").click(); - } + if(confirm(deleteallfiles)){ + $(".remove-upload").removeAttr("data-confirm"); + $(".remove-upload").click(); + } // return false; } //gcm function uploadBlob(blob, uploadUrl, attachmentId, options) { - var actualOptions = $.extend({ - loadstartEventHandler: $.noop, - progressEventHandler: $.noop - }, options); - if(uploadUrl.indexOf('?') > 0){ - uploadUrl = uploadUrl + '&attachment_id=' + attachmentId; - }else{ - uploadUrl = uploadUrl + '?attachment_id=' + attachmentId; - } - if (blob instanceof window.File) { - uploadUrl += '&filename=' + encodeURIComponent(blob.name); - } + var actualOptions = $.extend({ + loadstartEventHandler: $.noop, + progressEventHandler: $.noop + }, options); + if(uploadUrl.indexOf('?') > 0){ + uploadUrl = uploadUrl + '&attachment_id=' + attachmentId; + }else{ + uploadUrl = uploadUrl + '?attachment_id=' + attachmentId; + } + if (blob instanceof window.File) { + uploadUrl += '&filename=' + encodeURIComponent(blob.name); + } - return $.ajax(uploadUrl, { - type: 'POST', - contentType: 'application/octet-stream', - beforeSend: function(jqXhr) { - jqXhr.setRequestHeader('Accept', 'application/js'); - }, - xhr: function() { - var xhr = $.ajaxSettings.xhr(); - xhr.upload.onloadstart = actualOptions.loadstartEventHandler; - xhr.upload.onprogress = actualOptions.progressEventHandler; - return xhr; - }, - data: blob, - cache: false, - processData: false - }); + return $.ajax(uploadUrl, { + type: 'POST', + contentType: 'application/octet-stream', + beforeSend: function(jqXhr) { + jqXhr.setRequestHeader('Accept', 'application/js'); + }, + xhr: function() { + var xhr = $.ajaxSettings.xhr(); + xhr.upload.onloadstart = actualOptions.loadstartEventHandler; + xhr.upload.onprogress = actualOptions.progressEventHandler; + return xhr; + }, + data: blob, + cache: false, + processData: false + }); } function addInputFiles(inputEl) { - // var clearedFileInput = $(inputEl).clone().val(''); + // var clearedFileInput = $(inputEl).clone().val(''); if (inputEl.files) { // upload files using ajax uploadAndAttachFiles(inputEl.files, inputEl); - // $(inputEl).remove(); + // $(inputEl).remove(); } else { // browser not supporting the file API, upload on form submission var attachmentId; @@ -260,18 +260,18 @@ function addInputFiles_board(inputEl, id) { } function uploadAndAttachFiles(files, inputEl) { - var maxFileSize = $(inputEl).data('max-file-size'); - var maxFileSizeExceeded = $(inputEl).data('max-file-size-message'); + var maxFileSize = $(inputEl).data('max-file-size'); + var maxFileSizeExceeded = $(inputEl).data('max-file-size-message'); - var sizeExceeded = false; - $.each(files, function() { - if (this.size && maxFileSize != null && this.size > parseInt(maxFileSize)) {sizeExceeded=true;} - }); - if (sizeExceeded) { - window.alert(maxFileSizeExceeded); - } else { - $.each(files, function() {addFile(inputEl, this, true);}); - } + var sizeExceeded = false; + $.each(files, function() { + if (this.size && maxFileSize != null && this.size > parseInt(maxFileSize)) {sizeExceeded=true;} + }); + if (sizeExceeded) { + window.alert(maxFileSizeExceeded); + } else { + $.each(files, function() {addFile(inputEl, this, true);}); + } } function uploadAndAttachFiles_board(files, inputEl, id) { @@ -290,37 +290,37 @@ function uploadAndAttachFiles_board(files, inputEl, id) { } function handleFileDropEvent(e) { - $(this).removeClass('fileover'); - blockEventPropagation(e); + $(this).removeClass('fileover'); + blockEventPropagation(e); - if ($.inArray('Files', e.dataTransfer.types) > -1) { - uploadAndAttachFiles(e.dataTransfer.files, $('input:file.file_selector')); - } + if ($.inArray('Files', e.dataTransfer.types) > -1) { + uploadAndAttachFiles(e.dataTransfer.files, $('input:file.file_selector')); + } } function dragOverHandler(e) { - $(this).addClass('fileover'); - blockEventPropagation(e); + $(this).addClass('fileover'); + blockEventPropagation(e); } function dragOutHandler(e) { - $(this).removeClass('fileover'); - blockEventPropagation(e); + $(this).removeClass('fileover'); + blockEventPropagation(e); } function setupFileDrop() { - if (window.File && window.FileList && window.ProgressEvent && window.FormData) { + if (window.File && window.FileList && window.ProgressEvent && window.FormData) { - $.event.fixHooks.drop = { props: [ 'dataTransfer' ] }; + $.event.fixHooks.drop = { props: [ 'dataTransfer' ] }; - $('form div.box').has('input:file').each(function() { - $(this).on({ - dragover: dragOverHandler, - dragleave: dragOutHandler, - drop: handleFileDropEvent - }); - }); - } + $('form div.box').has('input:file').each(function() { + $(this).on({ + dragover: dragOverHandler, + dragleave: dragOutHandler, + drop: handleFileDropEvent + }); + }); + } } $(document).ready(setupFileDrop);