Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Async validation before_add #259

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions app/assets/javascripts/s3_direct_upload.js.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ $.fn.S3Uploader = (options) ->
path: ''
additional_data: null
before_add: null
before_add_async: null
remove_completed_progress_bar: true
remove_failed_progress_bar: false
progress_bar_target: null
Expand All @@ -41,12 +42,10 @@ $.fn.S3Uploader = (options) ->

setUploadForm = ->
$uploadForm.find("input[type='file']").fileupload

add: (e, data) ->
file = data.files[0]
file.unique_id = Math.random().toString(36).substr(2,16)

unless settings.before_add and not settings.before_add(file)
addFile = ->
current_files.push data
if $('#template-upload').length > 0
data.context = $($.trim(tmpl("template-upload", file)))
Expand All @@ -61,6 +60,12 @@ $.fn.S3Uploader = (options) ->
else
data.submit()

if settings.before_add_async
settings.before_add_async(file).then ->
addFile()
else if not (settings.before_add and not settings.before_add(file))
addFile()

start: (e) ->
$uploadForm.trigger("s3_uploads_start", [e])

Expand Down