diff options
author | Stan Hu <stanhu@gmail.com> | 2015-09-15 16:58:49 +0300 |
---|---|---|
committer | Stan Hu <stanhu@gmail.com> | 2015-09-15 23:07:32 +0300 |
commit | d9af6f79ed439308d13f44a0cfade6a355607f14 (patch) | |
tree | 99ea6028fee1cf0b506fc9aacd810daa1ad1b326 /app/assets/javascripts/blob | |
parent | 0a8ef29b3d2504ba66cd0a98992c1f5f70b11daa (diff) |
Change the replace placeholder to use the filename
Dynamically adjust placedholder for uploads and fix Dropzone event handlers
Override error handler to prevent error messages from being inserted underneath image preview
Fix tests
Use regexp instead of startsWith for better browser compatibility
Remove duplicate code in _replace.html.haml and use one template
Remove files upon error and retain alert messages until user adds a new file
Diffstat (limited to 'app/assets/javascripts/blob')
-rw-r--r-- | app/assets/javascripts/blob/blob_file_dropzone.js.coffee | 47 |
1 files changed, 31 insertions, 16 deletions
diff --git a/app/assets/javascripts/blob/blob_file_dropzone.js.coffee b/app/assets/javascripts/blob/blob_file_dropzone.js.coffee index 090af9bb376..3ab3ba66754 100644 --- a/app/assets/javascripts/blob/blob_file_dropzone.js.coffee +++ b/app/assets/javascripts/blob/blob_file_dropzone.js.coffee @@ -20,26 +20,41 @@ class @BlobFileDropzone headers: "X-CSRF-Token": $("meta[name=\"csrf-token\"]").attr("content") - success: (header, response) -> - window.location.href = response.filePath - return + init: -> + this.on 'addedfile', (file) -> + $('.dropzone-alerts').html('').hide() + commit_message = form.find('#commit_message')[0] - error: (temp, errorMessage) -> - stripped = $("<div/>").html(errorMessage).text(); - $('.dropzone-alerts').html('Error uploading file: \"' + stripped + '\"').show() - return + if /^Upload/.test(commit_message.placeholder) + commit_message.placeholder = 'Upload ' + file.name - maxfilesexceeded: (file) -> - @removeFile file - return + return + + this.on 'removedfile', (file) -> + commit_message = form.find('#commit_message')[0] - removedfile: (file) -> - $('.dropzone-previews')[0].removeChild(file.previewTemplate) - $('.dropzone-alerts').html('').hide() - return true + if /^Upload/.test(commit_message.placeholder) + commit_message.placeholder = 'Upload new file' - sending: (file, xhr, formData) -> - formData.append('commit_message', form.find('#commit_message').val()) + return + + this.on 'success', (header, response) -> + window.location.href = response.filePath + return + + this.on 'maxfilesexceeded', (file) -> + @removeFile file + return + + this.on 'sending', (file, xhr, formData) -> + formData.append('commit_message', form.find('#commit_message').val()) + return + + # Override behavior of adding error underneath preview + error: (file, errorMessage) -> + stripped = $("<div/>").html(errorMessage).text(); + $('.dropzone-alerts').html('Error uploading file: \"' + stripped + '\"').show() + @removeFile file return ) |