2018-11-05 05:06:39 -05:00
|
|
|
// TODO: This file was created by bulk-decaffeinate.
|
|
|
|
// Fix any style issues and re-enable lint.
|
|
|
|
/*
|
|
|
|
* decaffeinate suggestions:
|
|
|
|
* DS102: Remove unnecessary code created because of implicit returns
|
|
|
|
* DS207: Consider shorter variations of null checks
|
|
|
|
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
|
|
|
|
*/
|
2020-05-19 05:02:56 -04:00
|
|
|
import App from '../base'
|
|
|
|
import qq from 'fineuploader'
|
|
|
|
|
|
|
|
export default App.directive('fineUpload', $timeout => ({
|
|
|
|
scope: {
|
|
|
|
multiple: '=',
|
|
|
|
endpoint: '@',
|
|
|
|
templateId: '@',
|
|
|
|
sizeLimit: '@',
|
|
|
|
allowedExtensions: '=',
|
|
|
|
onCompleteCallback: '=',
|
|
|
|
onUploadCallback: '=',
|
|
|
|
onValidateBatch: '=',
|
|
|
|
onErrorCallback: '=',
|
|
|
|
onSubmitCallback: '=',
|
|
|
|
onCancelCallback: '=',
|
|
|
|
autoUpload: '=',
|
|
|
|
params: '=',
|
2021-04-27 03:52:58 -04:00
|
|
|
control: '=',
|
2020-05-19 05:02:56 -04:00
|
|
|
},
|
|
|
|
link(scope, element, attrs) {
|
|
|
|
let autoUpload, validation
|
|
|
|
const multiple = scope.multiple || false
|
|
|
|
const { endpoint } = scope
|
|
|
|
const { templateId } = scope
|
|
|
|
if (scope.allowedExtensions != null) {
|
|
|
|
validation = { allowedExtensions: scope.allowedExtensions }
|
|
|
|
} else {
|
|
|
|
validation = {}
|
|
|
|
}
|
|
|
|
if (scope.sizeLimit) {
|
|
|
|
validation.sizeLimit = scope.sizeLimit
|
|
|
|
}
|
|
|
|
const maxConnections = scope.maxConnections || 1
|
2021-04-14 09:17:21 -04:00
|
|
|
const onComplete = scope.onCompleteCallback || function () {}
|
|
|
|
const onUpload = scope.onUploadCallback || function () {}
|
|
|
|
const onError = scope.onErrorCallback || function () {}
|
|
|
|
const onValidateBatch = scope.onValidateBatch || function () {}
|
|
|
|
const onSubmit = scope.onSubmitCallback || function () {}
|
|
|
|
const onCancel = scope.onCancelCallback || function () {}
|
2020-05-19 05:02:56 -04:00
|
|
|
if (scope.autoUpload == null) {
|
|
|
|
autoUpload = true
|
|
|
|
} else {
|
|
|
|
;({ autoUpload } = scope)
|
|
|
|
}
|
|
|
|
const params = scope.params || {}
|
|
|
|
params._csrf = window.csrfToken
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2020-05-19 05:02:56 -04:00
|
|
|
const q = new qq.FineUploader({
|
|
|
|
element: element[0],
|
|
|
|
multiple,
|
|
|
|
autoUpload,
|
|
|
|
disabledCancelForFormUploads: true,
|
|
|
|
validation,
|
|
|
|
maxConnections,
|
|
|
|
request: {
|
|
|
|
endpoint,
|
|
|
|
forceMultipart: true,
|
|
|
|
params,
|
2021-04-27 03:52:58 -04:00
|
|
|
paramsInBody: false,
|
2020-05-19 05:02:56 -04:00
|
|
|
},
|
|
|
|
callbacks: {
|
|
|
|
onComplete,
|
|
|
|
onUpload,
|
|
|
|
onValidateBatch,
|
|
|
|
onError,
|
|
|
|
onSubmit,
|
2021-04-27 03:52:58 -04:00
|
|
|
onCancel,
|
2020-05-19 05:02:56 -04:00
|
|
|
},
|
|
|
|
template: templateId,
|
|
|
|
failedUploadTextDisplay: {
|
|
|
|
mode: 'custom',
|
2021-04-27 03:52:58 -04:00
|
|
|
responseProperty: 'error',
|
|
|
|
},
|
2020-05-19 05:02:56 -04:00
|
|
|
})
|
|
|
|
window.q = q
|
|
|
|
if (scope.control != null) {
|
|
|
|
scope.control.q = q
|
2018-11-05 05:06:39 -05:00
|
|
|
}
|
2020-05-19 05:02:56 -04:00
|
|
|
return q
|
2021-04-27 03:52:58 -04:00
|
|
|
},
|
2020-05-19 05:02:56 -04:00
|
|
|
}))
|