File size: 2,453 Bytes
6747401
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
function submitForm() {
    var fileInput = document.getElementById('csvFile');
    var processingMsg = document.getElementById('processingMsg');

    if (fileInput.files.length === 0) {
        alert('Please select a CSV file.');
        return;
    }

    var formData = new FormData();
    formData.append('csvFile', fileInput.files[0]);

    // Show processing message
    document.getElementById('uploadForm').classList.add('hidden');
    processingMsg.classList.remove('hidden');

    // Simulate backend processing (replace with actual AJAX call)
    setTimeout(function() {
        // After processing (simulated with setTimeout), show success message
        processingMsg.innerHTML = '<p>File processed successfully. <a href="#" onclick="downloadProcessedFile()">Download processed file</a></p>';
    }, 2000);
}

function downloadProcessedFile() {
    // Here you can add code to download the processed file
    alert('Downloading processed file...');
    // Replace this alert with your actual download logic
}

document.getElementById('submitBtn').addEventListener('click', function() {
    var fileInput = document.getElementById('csvFile');
    var file = fileInput.files[0];
    if (file) {
         var formData = new FormData();
         formData.append('file', file);

         // Capture checkbox values
         var checkboxes = document.querySelectorAll('input[name="option"]:checked');
         checkboxes.forEach(function(checkbox) {
               formData.append('option', checkbox.value);
         });

         var xhr = new XMLHttpRequest();
         xhr.open('POST', '/');
         xhr.upload.onprogress = function(event) {
         if (event.lengthComputable) {
               var percentComplete = (event.loaded / event.total) * 100;
               document.getElementById('progressBar').style.width = percentComplete + '%';
         }
    };
    xhr.onloadstart = function() {
           document.getElementById('processingMsg').classList.remove('hidden');
    };
    xhr.onloadend = function() {
           document.getElementById('processingMsg').classList.add('hidden');
           document.getElementById('downloadBtn').classList.remove('hidden');
           var response = JSON.parse(xhr.responseText);
           document.getElementById('downloadBtn').addEventListener('click', function() {
                  window.location.href = '/downloads/output.xlsx';
           });
    };
    xhr.send(formData);
    }
});