fineUpload.js 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /* eslint-disable
  2. no-undef,
  3. */
  4. // TODO: This file was created by bulk-decaffeinate.
  5. // Fix any style issues and re-enable lint.
  6. /*
  7. * decaffeinate suggestions:
  8. * DS102: Remove unnecessary code created because of implicit returns
  9. * DS207: Consider shorter variations of null checks
  10. * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
  11. */
  12. define(['base', 'fineuploader'], (App, qq) =>
  13. 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. })))