2014-06-22 12:32:15 -04:00
|
|
|
define [
|
|
|
|
"base"
|
2017-12-01 06:22:41 -05:00
|
|
|
"fineuploader"
|
2017-11-20 09:43:13 -05:00
|
|
|
], (App, qq) ->
|
2014-06-22 12:32:15 -04:00
|
|
|
App.directive 'fineUpload', ($timeout) ->
|
|
|
|
return {
|
|
|
|
scope: {
|
|
|
|
multiple: "="
|
|
|
|
endpoint: "@"
|
2017-11-27 07:06:18 -05:00
|
|
|
templateId: "@"
|
2014-06-22 12:32:15 -04:00
|
|
|
allowedExtensions: "="
|
|
|
|
onCompleteCallback: "="
|
|
|
|
onUploadCallback: "="
|
2015-12-01 07:55:35 -05:00
|
|
|
onValidateBatch: "="
|
2015-12-01 08:08:49 -05:00
|
|
|
onErrorCallback: "="
|
2016-02-24 11:35:05 -05:00
|
|
|
onSubmitCallback: "="
|
|
|
|
onCancelCallback: "="
|
|
|
|
autoUpload: "="
|
2014-06-22 12:32:15 -04:00
|
|
|
params: "="
|
2016-02-24 11:35:05 -05:00
|
|
|
control: "="
|
2014-06-22 12:32:15 -04:00
|
|
|
}
|
|
|
|
link: (scope, element, attrs) ->
|
|
|
|
multiple = scope.multiple or false
|
|
|
|
endpoint = scope.endpoint
|
2017-11-27 07:06:18 -05:00
|
|
|
templateId = scope.templateId
|
2014-06-22 12:32:15 -04:00
|
|
|
if scope.allowedExtensions?
|
2017-11-27 07:06:18 -05:00
|
|
|
validation =
|
2014-06-22 12:32:15 -04:00
|
|
|
allowedExtensions: scope.allowedExtensions
|
|
|
|
else
|
|
|
|
validation = {}
|
2015-12-07 11:50:09 -05:00
|
|
|
maxConnections = scope.maxConnections or 1
|
2014-06-22 12:32:15 -04:00
|
|
|
onComplete = scope.onCompleteCallback or () ->
|
|
|
|
onUpload = scope.onUploadCallback or () ->
|
2015-12-01 08:08:49 -05:00
|
|
|
onError = scope.onErrorCallback or () ->
|
2015-12-01 07:55:35 -05:00
|
|
|
onValidateBatch = scope.onValidateBatch or () ->
|
2016-02-24 11:35:05 -05:00
|
|
|
onSubmit = scope.onSubmitCallback or () ->
|
|
|
|
onCancel = scope.onCancelCallback or () ->
|
|
|
|
if !scope.autoUpload?
|
|
|
|
autoUpload = true
|
|
|
|
else
|
|
|
|
autoUpload = scope.autoUpload
|
2014-06-22 12:32:15 -04:00
|
|
|
params = scope.params or {}
|
|
|
|
params._csrf = window.csrfToken
|
|
|
|
|
2015-12-01 07:55:35 -05:00
|
|
|
q = new qq.FineUploader
|
2014-06-22 12:32:15 -04:00
|
|
|
element: element[0]
|
|
|
|
multiple: multiple
|
2016-02-24 11:35:05 -05:00
|
|
|
autoUpload: autoUpload
|
2014-06-22 12:32:15 -04:00
|
|
|
disabledCancelForFormUploads: true
|
|
|
|
validation: validation
|
2015-12-07 11:50:09 -05:00
|
|
|
maxConnections: maxConnections
|
2014-06-22 12:32:15 -04:00
|
|
|
request:
|
|
|
|
endpoint: endpoint
|
|
|
|
forceMultipart: true
|
|
|
|
params: params
|
|
|
|
paramsInBody: false
|
|
|
|
callbacks:
|
|
|
|
onComplete: onComplete
|
|
|
|
onUpload: onUpload
|
2015-12-01 07:55:35 -05:00
|
|
|
onValidateBatch: onValidateBatch
|
2015-12-01 08:08:49 -05:00
|
|
|
onError: onError
|
2016-02-24 11:35:05 -05:00
|
|
|
onSubmit: onSubmit
|
|
|
|
onCancel: onCancel
|
2017-11-27 07:06:18 -05:00
|
|
|
template: templateId
|
2016-02-24 11:35:05 -05:00
|
|
|
window.q = q
|
|
|
|
scope.control?.q = q
|
2015-12-01 07:55:35 -05:00
|
|
|
return q
|
2017-11-20 09:43:13 -05:00
|
|
|
}
|