overleaf/services/web/public/coffee/directives/fineUpload.coffee

69 lines
1.7 KiB
CoffeeScript
Raw Normal View History

2014-06-22 16:32:15 +00:00
define [
"base"
"fineuploader"
2017-11-20 14:43:13 +00:00
], (App, qq) ->
2014-06-22 16:32:15 +00:00
App.directive 'fineUpload', ($timeout) ->
return {
scope: {
multiple: "="
endpoint: "@"
templateId: "@"
2014-06-22 16:32:15 +00:00
allowedExtensions: "="
onCompleteCallback: "="
onUploadCallback: "="
onValidateBatch: "="
onErrorCallback: "="
onSubmitCallback: "="
onCancelCallback: "="
autoUpload: "="
2014-06-22 16:32:15 +00:00
params: "="
control: "="
2014-06-22 16:32:15 +00:00
}
link: (scope, element, attrs) ->
multiple = scope.multiple or false
endpoint = scope.endpoint
templateId = scope.templateId
2014-06-22 16:32:15 +00:00
if scope.allowedExtensions?
validation =
2014-06-22 16:32:15 +00:00
allowedExtensions: scope.allowedExtensions
else
validation = {}
maxConnections = scope.maxConnections or 1
2014-06-22 16:32:15 +00:00
onComplete = scope.onCompleteCallback or () ->
onUpload = scope.onUploadCallback or () ->
onError = scope.onErrorCallback or () ->
onValidateBatch = scope.onValidateBatch or () ->
onSubmit = scope.onSubmitCallback or () ->
onCancel = scope.onCancelCallback or () ->
if !scope.autoUpload?
autoUpload = true
else
autoUpload = scope.autoUpload
2014-06-22 16:32:15 +00:00
params = scope.params or {}
params._csrf = window.csrfToken
q = new qq.FineUploader
2014-06-22 16:32:15 +00:00
element: element[0]
multiple: multiple
autoUpload: autoUpload
2014-06-22 16:32:15 +00:00
disabledCancelForFormUploads: true
validation: validation
maxConnections: maxConnections
2014-06-22 16:32:15 +00:00
request:
endpoint: endpoint
forceMultipart: true
params: params
paramsInBody: false
callbacks:
onComplete: onComplete
onUpload: onUpload
onValidateBatch: onValidateBatch
onError: onError
onSubmit: onSubmit
onCancel: onCancel
template: templateId
window.q = q
scope.control?.q = q
return q
2017-11-20 14:43:13 +00:00
}