2025-08-18 15:33:39 +07:00
|
|
|
|
import { Uppy, Dashboard, XHRUpload } from "https://releases.transloadit.com/uppy/v3.15.0/uppy.min.mjs";
|
|
|
|
|
|
|
2026-04-14 14:24:17 +07:00
|
|
|
|
const uploadEndpoint = window.crmActivitiesUploadEndpoint ?? "/activities/upload";
|
|
|
|
|
|
|
2025-08-18 15:33:39 +07:00
|
|
|
|
// var uppy = new Uppy({
|
|
|
|
|
|
// onBeforeFileAdded: (currentFile, files) => {
|
|
|
|
|
|
|
|
|
|
|
|
// //const name = Date.now() + '_' + currentFile.name
|
|
|
|
|
|
// const month = (new Date().getMonth() + 1).toString().padStart(2, '0');
|
|
|
|
|
|
// const day = (new Date().getDate()).toString().padStart(2, '0');
|
|
|
|
|
|
// const name = `${new Date().getFullYear()}_${month}_${day}_${currentFile.name}`;
|
|
|
|
|
|
// console.log(name);
|
|
|
|
|
|
// const modifiedFile = {
|
|
|
|
|
|
// ...currentFile,
|
|
|
|
|
|
// meta: {
|
|
|
|
|
|
// ...currentFile.meta,
|
|
|
|
|
|
// name
|
|
|
|
|
|
// },
|
|
|
|
|
|
// name
|
|
|
|
|
|
// };
|
|
|
|
|
|
// return modifiedFile
|
|
|
|
|
|
// }})
|
|
|
|
|
|
|
|
|
|
|
|
var uppy = new Uppy({
|
|
|
|
|
|
onBeforeFileAdded: (currentFile, files) => {
|
|
|
|
|
|
|
2026-04-14 14:24:17 +07:00
|
|
|
|
const now = new Date();
|
|
|
|
|
|
const hours = now.getHours().toString().padStart(2, '0');
|
|
|
|
|
|
const minutes = now.getMinutes().toString().padStart(2, '0');
|
|
|
|
|
|
const seconds = now.getSeconds().toString().padStart(2, '0');
|
|
|
|
|
|
const milliseconds = now.getMilliseconds().toString().padStart(3, '0');
|
2025-08-18 15:33:39 +07:00
|
|
|
|
|
|
|
|
|
|
// Menghilangkan koma (,) dalam nama file
|
|
|
|
|
|
const sanitizedFileName = currentFile.name.replace(/,/g, '');
|
|
|
|
|
|
|
2026-04-14 14:24:17 +07:00
|
|
|
|
// Format: HHMMSSmmm_FILENAME
|
|
|
|
|
|
const name = `${hours}${minutes}${seconds}${milliseconds}_${sanitizedFileName}`;
|
2025-08-18 15:33:39 +07:00
|
|
|
|
|
|
|
|
|
|
// Membuat objek file yang dimodifikasi
|
|
|
|
|
|
const modifiedFile = {
|
|
|
|
|
|
...currentFile,
|
|
|
|
|
|
meta: {
|
|
|
|
|
|
...currentFile.meta,
|
|
|
|
|
|
name
|
|
|
|
|
|
},
|
|
|
|
|
|
name
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
return modifiedFile;
|
|
|
|
|
|
}
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
.use(Dashboard, {
|
|
|
|
|
|
inline: true,
|
|
|
|
|
|
target: "#drag-drop-area",
|
|
|
|
|
|
width: '100%',
|
|
|
|
|
|
height: 300,
|
|
|
|
|
|
})
|
|
|
|
|
|
|
2026-04-14 14:24:17 +07:00
|
|
|
|
.use(XHRUpload, { endpoint: uploadEndpoint, method: 'post' });
|
2025-08-18 15:33:39 +07:00
|
|
|
|
|
|
|
|
|
|
uppy.on("complete", (result) => {
|
|
|
|
|
|
let array = result.successful;
|
|
|
|
|
|
let arrtext = [];
|
|
|
|
|
|
|
|
|
|
|
|
for (let i = 0; i < array.length; i++) {
|
|
|
|
|
|
let text = result.successful[i].name;
|
2026-04-17 09:44:27 +07:00
|
|
|
|
if (result.successful[i].response && result.successful[i].response.body && result.successful[i].response.body.relativePath) {
|
|
|
|
|
|
text = result.successful[i].response.body.relativePath;
|
|
|
|
|
|
}
|
2025-08-18 15:33:39 +07:00
|
|
|
|
arrtext.push(text);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
let text = arrtext.join();
|
|
|
|
|
|
|
|
|
|
|
|
$('#attachment').val(function(){
|
|
|
|
|
|
if (this.value == '') {
|
|
|
|
|
|
return this.value + text;
|
|
|
|
|
|
} else if (this.value != ''){
|
|
|
|
|
|
return this.value + ',' + text;
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
console.log( "Upload complete! We’ve uploaded these files:", result.successful);
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
const attachmentList = document.querySelector('#attachment').value;
|
|
|
|
|
|
const arrayx = attachmentList ? attachmentList.split(',') : [];
|
|
|
|
|
|
arrayx.forEach((fileName) => {
|
|
|
|
|
|
fetch(`<?=base_url();?>/upload/${fileName}`)
|
|
|
|
|
|
.then((response) => response.blob())
|
|
|
|
|
|
.then((blob) => {
|
|
|
|
|
|
uppy.addFile({
|
|
|
|
|
|
name: fileName.substring(11),
|
|
|
|
|
|
type: blob.type,
|
|
|
|
|
|
data: blob,
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
if (fileName === arrayx[arrayx.length - 1]) {
|
|
|
|
|
|
uppy.getFiles().forEach((file) => {
|
|
|
|
|
|
uppy.setFileState(file.id, {
|
|
|
|
|
|
progress: { uploadComplete: true, uploadStarted: true },
|
|
|
|
|
|
});
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
});
|
|
|
|
|
|
*/
|