{"version":3,"sources":["webpack:///./app/javascript/src/uppy_document.js"],"names":["document","querySelectorAll","length","forEach","element","trigger","querySelector","direct_upload_url","closest","getAttribute","field_name","dataset","uppyDoc","addEventListener","event","preventDefault","uppy","Uppy","autoProceed","allowMultipleUploads","logger","debugLogger","note","allowedFileTypes","use","ActiveStorageUpload","directUploadUrl","Dashboard","inline","closeAfterFinish","on","result","parentNode","removeChild","successful","file","hiddenField","createElement","setAttribute","response","signed_id","appendChild","appendUploadedFile","preview","iconClass","type","innerHTML","concat","name","style","display","message","className","textContent","setPreview","reset","setupUppy"],"mappings":"2FAAA,2FAWoBA,SAASC,iBAAiB,oBAAsB,IAClDC,OAAS,GACzBF,SACGC,iBAAiB,mBACjBE,SAAQ,SAACC,GAAO,OAGrB,SAAmBA,GACjB,IAAIC,EAAUD,EAAQE,cAAc,sCAEhCC,GADOH,EAAQI,QAAQ,QACHR,SACrBM,cAAc,kCACdG,aAAa,YACZC,EAAaN,EAAQO,QAAQC,QACjCP,EAAQQ,iBAAiB,SAAS,SAACC,GAAK,OAAKA,EAAMC,gBAAgB,IAEnE,IAAIC,EAAO,IAAIC,IAAK,CAClBC,aAAa,EACbC,sBAAsB,EACtBC,OAAQH,IAAKI,YACbC,KAAM,6CACNC,iBAAkB,CAChB,kBACA,qBACA,0EACA,aACA,qBAIJP,EAAKQ,IAAIC,IAAqB,CAC5BC,gBAAiBnB,IAGnBS,EAAKQ,IAAIG,IAAW,CAClBtB,QAASA,EACTuB,QAAQ,EACRC,kBAAkB,IAGpBb,EAAKc,GAAG,YAAY,SAACC,GACnB3B,EACGH,iBAAiB,yBACjBE,SAAQ,SAACC,GAAO,OAAKA,EAAQ4B,WAAWC,YAAY7B,EAAQ,IAE/D2B,EAAOG,WAAW/B,SAAQ,SAACgC,IAS/B,SAA4B/B,EAAS+B,EAAMzB,GACzC,IAAM0B,EAAcpC,SAASqC,cAAc,SAE3CD,EAAYE,aAAa,OAAQ,UACjCF,EAAYE,aAAa,OAAQ5B,GACjC0B,EAAYE,aAAa,uBAAuB,GAChDF,EAAYE,aAAa,QAASH,EAAKI,SAASC,WAEhDpC,EAAQqC,YAAYL,EACtB,CAjBMM,CAAmBtC,EAAS+B,EAAMzB,GAmBxC,SAAoBN,EAAS+B,GAC3B,IAAIQ,EAAUvC,EAAQE,cAAc,sCACpC,GAAIqC,EAAS,CACX,IAAIC,EACJ,OAAQT,EAAKU,MACX,IAAK,kBACHD,EAAY,cACZ,MACF,IAAK,qBACL,IAAK,0EACHA,EAAY,eACZ,MACF,IAAK,aAGL,IAAK,kBACHA,EAAY,cACZ,MACF,QACEA,EAAY,UAGhBD,EAAQG,UAAS,iBAAAC,OAAoBH,EAAS,uBAAAG,OAAsBZ,EAAKa,KAAI,yDAC7EL,EAAQM,MAAMC,QAAU,eAGxB,IAAIC,EAAU/C,EAAQE,cAAc,sCAChC6C,IACFA,EAAQC,UAAY,WACpBD,EAAQE,YAAc,uCAE1B,CACF,CAlDMC,CAAWlD,EAAS+B,EACtB,IAEAnB,EAAKuC,OACP,GACF,CAhD0BC,CAAUpD,EAAQ,G","file":"js/14-11f7b33780dea59719c8.chunk.js","sourcesContent":["import { Modal } from \"bootstrap\";\nimport \"data-confirm-modal\";\n\nimport Uppy from \"@uppy/core\";\nimport Dashboard from \"@uppy/dashboard\";\nimport ActiveStorageUpload from \"@excid3/uppy-activestorage-upload\";\nimport Url from \"@uppy/url\";\n\nimport \"@uppy/core/dist/style.css\";\nimport \"@uppy/dashboard/dist/style.css\";\n\nlet uppyInstances = document.querySelectorAll(\"[data-uppy-doc]\") || [];\nif (uppyInstances.length > 0) {\n document\n .querySelectorAll(\"[data-uppy-doc]\")\n .forEach((element) => setupUppy(element));\n}\n\nfunction setupUppy(element) {\n let trigger = element.querySelector('[data-behavior=\"uppy-doc-trigger\"]');\n let form = element.closest(\"form\");\n let direct_upload_url = document\n .querySelector(\"meta[name='direct-upload-url']\")\n .getAttribute(\"content\");\n let field_name = element.dataset.uppyDoc;\n trigger.addEventListener(\"click\", (event) => event.preventDefault());\n\n let uppy = new Uppy({\n autoProceed: true,\n allowMultipleUploads: false,\n logger: Uppy.debugLogger,\n note: \"Word and PDF documents only, 500kb or less\",\n allowedFileTypes: [\n \"application/pdf\",\n \"application/msword\",\n \"application/vnd.openxmlformats-officedocument.wordprocessingml.document\",\n \"text/plain\",\n \"application/rtf\"\n ],\n });\n\n uppy.use(ActiveStorageUpload, {\n directUploadUrl: direct_upload_url,\n });\n\n uppy.use(Dashboard, {\n trigger: trigger,\n inline: false,\n closeAfterFinish: true,\n });\n\n uppy.on(\"complete\", (result) => {\n element\n .querySelectorAll(\"[data-pending-upload]\")\n .forEach((element) => element.parentNode.removeChild(element));\n\n result.successful.forEach((file) => {\n appendUploadedFile(element, file, field_name);\n setPreview(element, file);\n });\n\n uppy.reset();\n });\n}\n\nfunction appendUploadedFile(element, file, field_name) {\n const hiddenField = document.createElement(\"input\");\n\n hiddenField.setAttribute(\"type\", \"hidden\");\n hiddenField.setAttribute(\"name\", field_name);\n hiddenField.setAttribute(\"data-pending-upload\", true);\n hiddenField.setAttribute(\"value\", file.response.signed_id);\n\n element.appendChild(hiddenField);\n}\n\nfunction setPreview(element, file) {\n let preview = element.querySelector('[data-behavior=\"uppy-doc-preview\"]');\n if (preview) {\n let iconClass;\n switch (file.type) {\n case 'application/pdf':\n iconClass = 'fa-file-pdf';\n break;\n case 'application/msword':\n case 'application/vnd.openxmlformats-officedocument.wordprocessingml.document':\n iconClass = 'fa-file-word';\n break;\n case 'text/plain':\n iconClass = 'fa-file-alt';\n break;\n case 'application/rtf':\n iconClass = 'fa-file-alt';\n break;\n default:\n iconClass = 'fa-file';\n }\n\n preview.innerHTML = ` ${file.name} New Document`;\n preview.style.display = 'inline-block';\n\n // Update the message to indicate the document is attached\n let message = element.querySelector('[data-behavior=\"uppy-doc-message\"]');\n if (message) {\n message.className = \"info-box\"\n message.textContent = \"Document Attached - Save to Continue\";\n }\n }\n}\n"],"sourceRoot":""}