1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 |
- const toggleVisible = ele => ele.style.display = ele.style.display === 'none' ? 'block' : 'none'
- const toggleClass = (ele, class1, class2) => ele.className = ele.className === class1 ? class2 : class1
- const downloadContent = path => {
- const csrfToken = document.querySelector('[name=csrfmiddlewaretoken]').value
- const downloadUrl = BASE === '' ? `/admin/download` : `/${BASE}/admin/download`
- return fetch(downloadUrl, {
- method: 'POST',
- body: `path=${path}`,
- headers: {
- 'Content-type': 'application/x-www-form-urlencoded',
- 'X-CSRFToken': csrfToken
- }
- }).then(async res => {
- console.log(res)
- if (res.status === 200) {
-
- const disposition = res.headers.get('Content-Disposition')
-
- const filename = `${expe_name}_${disposition.split('=')[1]}`
- const blob = await res.blob()
-
- saveAs(blob, filename)
- }
- })
- }
- window.addEventListener('DOMContentLoaded', () => {
-
-
- Array.from(document.getElementsByClassName('date-folder-list')).forEach(item => {
- item.addEventListener('click', event => {
- event.preventDefault()
- currentElem = event.currentTarget
-
- list = currentElem.parentElement.nextElementSibling
-
-
- toggleVisible(list)
-
- iconElem = currentElem.children[0]
- toggleClass(iconElem, 'fas fa-arrow-circle-right', 'fas fa-arrow-circle-down')
- })
- })
-
- Array.from(document.getElementsByClassName('download-list')).forEach(downloadElem => {
- downloadElem.addEventListener('click', event => {
- event.preventDefault()
- currentElem = event.currentTarget
- pathDownload = currentElem.getAttribute('data-download-path')
- downloadContent(pathDownload)
- })
- })
- })
|