diff --git a/public/javascripts/attachments.js b/public/javascripts/attachments.js index 8fbaa5981..bbaf18bb4 100644 --- a/public/javascripts/attachments.js +++ b/public/javascripts/attachments.js @@ -12,6 +12,17 @@ function postUpMsg(attachmentId) }) } + +function reload(fileSpan) { + fileSpan.remove(); + $('#upload_file_count').html("未上传文件"); + $old_file = $("#_file"); + $new_file = $old_file.clone(true); + $old_file.replaceWith($new_file); + $new_file.show(); + +} + function addFile(inputEl, file, eagerUpload) { if ($('#attachments_fields').children().length < 10) { @@ -25,7 +36,17 @@ function addFile(inputEl, file, eagerUpload) { $('', { 'type': 'text', 'class': 'description', 'name': 'attachments[' + attachmentId + '][description]', 'maxlength': 254, 'placeholder': $(inputEl).data('description-placeholder') } ).toggle(!eagerUpload), $('公开:').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', 'data-confirm' : "您确定要删除吗?" }).click(removeFile).toggle(!eagerUpload), + $(' ').attr({ 'href': "#", 'class': 'remove-upload' }).click(function(){ + if(confirm('您确定要删除吗?')){ + removeFile(); + if(!eagerUpload){ + (function(e){ + reload(e); + })(fileSpan); + } + } + + }).toggle(!eagerUpload), $('
', { 'class': 'div_attachments', 'name': 'div_'+'attachments_' + attachmentId} ) ).appendTo('#attachments_fields'); @@ -168,14 +189,15 @@ function addInputFiles(inputEl) { 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; var aFilename = inputEl.value.split(/\/|\\/); attachmentId = addFile(inputEl, { name: aFilename[ aFilename.length - 1 ] }, false); if (attachmentId) { - $(inputEl).attr({ name: 'attachments[' + attachmentId + '][file]', style: 'display:none;' }).appendTo('#attachments_' + attachmentId); + $(inputEl).attr({ name: 'attachments[' + attachmentId + '][file]'}).hide(); + $('#upload_file_count').html("已上传"+""+1+""+"个文件"); } }