fineUpload.js 2.4 KB

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