Files
docuseal/app/javascript/application.js
T

108 lines
3.9 KiB
JavaScript
Raw Normal View History

2023-07-02 17:56:14 +03:00
import '@hotwired/turbo'
import { encodeMethodIntoRequestBody } from '@hotwired/turbo-rails/app/javascript/turbo/fetch_requests'
2023-05-21 17:59:36 +03:00
2023-06-24 22:50:12 +03:00
import { createApp, reactive } from 'vue'
import TemplateBuilder from './template_builder/builder'
2023-05-21 17:59:36 +03:00
import ToggleVisible from './elements/toggle_visible'
import DisableHidden from './elements/disable_hidden'
import TurboModal from './elements/turbo_modal'
2023-05-28 23:20:48 +03:00
import FileDropzone from './elements/file_dropzone'
2023-05-30 00:55:14 +03:00
import MenuActive from './elements/menu_active'
2023-06-03 21:22:03 +03:00
import ClipboardCopy from './elements/clipboard_copy'
2023-06-17 20:22:21 +00:00
import DynamicList from './elements/dynamic_list'
2023-06-20 22:38:38 +03:00
import DownloadButton from './elements/download_button'
import SetOriginUrl from './elements/set_origin_url'
2023-06-30 01:26:13 +03:00
import SetTimezone from './elements/set_timezone'
2023-07-01 01:09:44 +03:00
import AutoresizeTextarea from './elements/autoresize_textarea'
2023-09-20 02:00:00 +03:00
import SubmittersAutocomplete from './elements/submitter_autocomplete'
2023-09-22 02:20:38 +03:00
import FolderAutocomplete from './elements/folder_autocomplete'
2023-09-22 21:50:39 +03:00
import SignatureForm from './elements/signature_form'
2023-10-28 23:07:18 +03:00
import SubmitForm from './elements/submit_form'
2024-01-14 23:22:41 +02:00
import PromptPassword from './elements/prompt_password'
2023-05-21 17:59:36 +03:00
2023-07-02 17:56:14 +03:00
import * as TurboInstantClick from './lib/turbo_instant_click'
2023-07-03 23:37:16 +03:00
import './images/preview.png'
2023-07-02 17:56:14 +03:00
TurboInstantClick.start()
2023-05-29 23:08:55 +03:00
document.addEventListener('turbo:before-cache', () => {
window.flash?.remove()
})
2023-06-04 01:08:45 +03:00
document.addEventListener('keyup', (e) => {
if (e.code === 'Escape') {
document.activeElement?.blur()
}
})
2023-05-21 17:59:36 +03:00
window.customElements.define('toggle-visible', ToggleVisible)
window.customElements.define('disable-hidden', DisableHidden)
window.customElements.define('turbo-modal', TurboModal)
2023-05-28 23:20:48 +03:00
window.customElements.define('file-dropzone', FileDropzone)
2023-05-30 00:55:14 +03:00
window.customElements.define('menu-active', MenuActive)
2023-06-03 21:22:03 +03:00
window.customElements.define('clipboard-copy', ClipboardCopy)
2023-06-17 20:22:21 +00:00
window.customElements.define('dynamic-list', DynamicList)
2023-06-20 22:38:38 +03:00
window.customElements.define('download-button', DownloadButton)
window.customElements.define('set-origin-url', SetOriginUrl)
2023-06-30 01:26:13 +03:00
window.customElements.define('set-timezone', SetTimezone)
2023-07-01 01:09:44 +03:00
window.customElements.define('autoresize-textarea', AutoresizeTextarea)
2023-09-20 02:00:00 +03:00
window.customElements.define('submitters-autocomplete', SubmittersAutocomplete)
2023-09-22 02:20:38 +03:00
window.customElements.define('folder-autocomplete', FolderAutocomplete)
2023-09-22 21:50:39 +03:00
window.customElements.define('signature-form', SignatureForm)
2023-10-28 23:07:18 +03:00
window.customElements.define('submit-form', SubmitForm)
2024-01-14 23:22:41 +02:00
window.customElements.define('prompt-password', PromptPassword)
2023-05-21 17:59:36 +03:00
2023-07-02 17:56:14 +03:00
document.addEventListener('turbo:before-fetch-request', encodeMethodIntoRequestBody)
2023-08-20 15:18:15 +03:00
document.addEventListener('turbo:submit-end', async (event) => {
const resp = event.detail?.formSubmission?.result?.fetchResponse?.response
if (!resp?.headers?.get('content-disposition')?.includes('attachment')) {
return
}
const url = URL.createObjectURL(await resp.blob())
const link = document.createElement('a')
link.href = url
link.setAttribute('download', decodeURIComponent(resp.headers.get('content-disposition').split('"')[1]))
document.body.appendChild(link)
link.click()
document.body.removeChild(link)
URL.revokeObjectURL(url)
})
2023-07-02 17:56:14 +03:00
2023-05-31 23:19:20 +03:00
window.customElements.define('template-builder', class extends HTMLElement {
2023-06-24 22:50:12 +03:00
connectedCallback () {
this.appElem = document.createElement('div')
2023-05-21 17:59:36 +03:00
2023-11-24 22:44:27 +02:00
this.appElem.classList.add('md:h-screen')
2023-05-31 23:19:20 +03:00
this.app = createApp(TemplateBuilder, {
template: reactive(JSON.parse(this.dataset.template)),
2023-08-28 23:43:33 +03:00
backgroundColor: '#faf7f5',
2023-09-05 01:00:21 +03:00
withPhone: this.dataset.withPhone === 'true',
2023-10-08 12:04:32 +03:00
withLogo: this.dataset.withLogo !== 'false',
editable: this.dataset.editable !== 'false',
2023-12-30 11:42:46 +02:00
withPayment: this.dataset.withPayment === 'true',
2024-01-26 10:43:32 +02:00
currencies: (this.dataset.currencies || '').split(',').filter(Boolean),
2023-09-05 20:33:40 +03:00
acceptFileTypes: this.dataset.acceptFileTypes,
isDirectUpload: this.dataset.isDirectUpload === 'true'
2023-05-21 17:59:36 +03:00
})
this.app.mount(this.appElem)
this.appendChild(this.appElem)
}
disconnectedCallback () {
this.app?.unmount()
2023-06-24 22:50:12 +03:00
this.appElem?.remove()
2023-05-21 17:59:36 +03:00
}
})