fineUpload.js 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. /* eslint-disable
  2. */
  3. // TODO: This file was created by bulk-decaffeinate.
  4. // Fix any style issues and re-enable lint.
  5. /*
  6. * decaffeinate suggestions:
  7. * DS102: Remove unnecessary code created because of implicit returns
  8. * DS207: Consider shorter variations of null checks
  9. * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
  10. */
  11. import App from '../base'
  12. import qq from 'fineuploader'
  13. export default App.directive('fineUpload', $timeout => ({
  14. scope: {
  15. multiple: '=',
  16. endpoint: '@',
  17. templateId: '@',
  18. sizeLimit: '@',
  19. allowedExtensions: '=',
  20. onCompleteCallback: '=',
  21. onUploadCallback: '=',
  22. onValidateBatch: '=',
  23. onErrorCallback: '=',
  24. onSubmitCallback: '=',
  25. onCancelCallback: '=',
  26. autoUpload: '=',
  27. params: '=',
  28. control: '='
  29. },
  30. link(scope, element, attrs) {
  31. let autoUpload, validation
  32. const multiple = scope.multiple || false
  33. const { endpoint } = scope
  34. const { templateId } = scope
  35. if (scope.allowedExtensions != null) {
  36. validation = { allowedExtensions: scope.allowedExtensions }
  37. } else {
  38. validation = {}
  39. }
  40. if (scope.sizeLimit) {
  41. validation.sizeLimit = scope.sizeLimit
  42. }
  43. const maxConnections = scope.maxConnections || 1
  44. const onComplete = scope.onCompleteCallback || function() {}
  45. const onUpload = scope.onUploadCallback || function() {}
  46. const onError = scope.onErrorCallback || function() {}
  47. const onValidateBatch = scope.onValidateBatch || function() {}
  48. const onSubmit = scope.onSubmitCallback || function() {}
  49. const onCancel = scope.onCancelCallback || function() {}
  50. if (scope.autoUpload == null) {
  51. autoUpload = true
  52. } else {
  53. ;({ autoUpload } = scope)
  54. }
  55. const params = scope.params || {}
  56. params._csrf = window.csrfToken
  57. const q = new qq.FineUploader({
  58. element: element[0],
  59. multiple,
  60. autoUpload,
  61. disabledCancelForFormUploads: true,
  62. validation,
  63. maxConnections,
  64. request: {
  65. endpoint,
  66. forceMultipart: true,
  67. params,
  68. paramsInBody: false
  69. },
  70. callbacks: {
  71. onComplete,
  72. onUpload,
  73. onValidateBatch,
  74. onError,
  75. onSubmit,
  76. onCancel
  77. },
  78. template: templateId,
  79. failedUploadTextDisplay: {
  80. mode: 'custom',
  81. responseProperty: 'error'
  82. }
  83. })
  84. window.q = q
  85. if (scope.control != null) {
  86. scope.control.q = q
  87. }
  88. return q
  89. }
  90. }))