|
|
|
@ -186,7 +186,7 @@ function searchDocuments(activity_id) {
|
|
|
|
|
columns: [ |
|
|
|
|
{ data: null, title: "Action", |
|
|
|
|
"mRender": function(data, type, row){ |
|
|
|
|
var optContent = '<button title="Download File" type="button" class="btn btn-xs btn-default" onclick="downloadDocument('+row.id+');"><span class="fa fa-download"></span></button>'; |
|
|
|
|
var optContent = '<button title="Download File" type="button" class="btn btn-xs btn-default" onclick="downloadDocument(' + row.id + ',`' + row.file + '`);"><span class="fa fa-download"></span></button>'; |
|
|
|
|
optContent += '<button title="Delete File" type="button" class="btn btn-xs btn-default" onclick="deleteDocument('+row.id+', '+activity_id+');"><span class="fa fa-trash"></span></button>'; |
|
|
|
|
return optContent; |
|
|
|
|
} |
|
|
|
@ -207,17 +207,35 @@ function searchDocuments(activity_id) {
|
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
async function downloadDocument(id) { |
|
|
|
|
console.log('download document', id); |
|
|
|
|
var urlDownload = DOCUMENT_DOWNLOAD_URL(id); |
|
|
|
|
const result = await axiosInstance |
|
|
|
|
.get(DOCUMENT_DOWNLOAD_URL(id)) |
|
|
|
|
.then(res => res) |
|
|
|
|
.catch((error) => error.response); |
|
|
|
|
console.log('downloadDocument', result); |
|
|
|
|
if (result && result.data.code === 200) { |
|
|
|
|
async function downloadDocument(id, name) { |
|
|
|
|
let result; |
|
|
|
|
await fetch(DOCUMENT_DOWNLOAD_URL(id), { |
|
|
|
|
headers: new Headers({ |
|
|
|
|
'Content-Type': 'application/json', |
|
|
|
|
'Authorization': `Bearer ${token}` |
|
|
|
|
}) |
|
|
|
|
}) |
|
|
|
|
.then(response => { |
|
|
|
|
if (!response.ok) { |
|
|
|
|
throw new Error(`HTTP error! status: ${response.status}`); |
|
|
|
|
} |
|
|
|
|
result = response; |
|
|
|
|
return response.blob(); |
|
|
|
|
}) |
|
|
|
|
.then(blob => { |
|
|
|
|
let url = window.URL.createObjectURL(blob); |
|
|
|
|
let a = document.createElement('a'); |
|
|
|
|
a.href = url; |
|
|
|
|
a.download = name; |
|
|
|
|
a.click(); |
|
|
|
|
}) |
|
|
|
|
.catch(error => { |
|
|
|
|
console.error(`Error: ${error.message}`); |
|
|
|
|
alert('File not found'); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
if (result && result.status == 200) { |
|
|
|
|
$("body").removeClass("loading");
|
|
|
|
|
window.open(urlDownload); |
|
|
|
|
} |
|
|
|
|
else { |
|
|
|
|
$("body").removeClass("loading");
|
|
|
|
|