home.js
3.71 KB
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
$(document).ready(function() {
/********** Tableau **********/
var tableNodes = $('#nodes-table').DataTable( {
select: {
style: 'multi'
}
} );
var nodeSet = new Set();
tableNodes.on('select', function (e, dt, type, indexes) {
var rowData = tableNodes.rows(indexes).data().toArray()[0];
nodeSet.add(rowData[0]);
} );
tableNodes.on('deselect', function (e, dt, type, indexes) {
var rowData = tableNodes.rows(indexes).data().toArray()[0];
nodeSet.delete(rowData[0]);
} );
/********** Drop Zone **********/
var formData = new FormData();
var dropZone = document.querySelector("#drop-zone");
dropZone.style.cursor = "pointer";
var file = document.getElementById("filesExplorer");
var fileProgress = document.getElementById("file-progress");
var readyToSend = false;
dropZone.addEventListener('click', function() {
delete formData;
formData = new FormData();
file.click();
})
file.addEventListener('change', function() {
dropZone.innerHTML = this.files[0].name;
formData.append("file", this.files[0]);
formData.append("filename", this.files[0].name);
readyToSend = true;
}, false)
dropZone.addEventListener('drop', function(e) {
e.preventDefault();
delete formData;
formData = new FormData();
dropZone.style.borderWidth = '2px';
var files = e.dataTransfer.files;
if(files.length > 1) {
$("#warningFilesNumber").modal()
return;
}
dropZone.innerHTML = files[0].name;
formData.append("file", files[0]);
formData.append("filename", files[0].name);
readyToSend = true;
}, false)
dropZone.addEventListener('dragenter', function(e) {
console.log("Enter");
dropZone.style.borderWidth = '5px';
}, false);
dropZone.addEventListener('dragleave', function(e) {
console.log("Leave");
dropZone.style.borderWidth = '2px';
}, false);
dropZone.addEventListener('dragover', function(e) {
e.preventDefault();
}, false);
document.getElementById("sendButton").addEventListener('click', function() {
var modalContent = document.getElementById("modal-content");
var modalTitle = document.getElementById("modal-title");
if(readyToSend && nodeSet.size > 0) {
formData.append("nodes", Array.from(nodeSet).join(';'));
var request = new XMLHttpRequest();
request.open("POST", "file.php");
request.upload.onloadstart = function(e) {
fileProgress.style.display = 'block';
fileProgress.style.width = 0 + "px"
fileProgress.innerHTML = "0%";
}
request.upload.onprogress = function(e) {
var p = 100 - ((e.total - e.loaded) / e.total * 100);
fileProgress.style.width = Math.ceil(p) + "%"
fileProgress.innerHTML = Math.ceil(p) + "%";
}
request.upload.onloadend = function(e) {
fileProgress.style.width = 100 + "%"
fileProgress.innerHTML = "100%";
var modalButton = document.getElementById("modal-button");
modalButton.addEventListener('click', function(e) {
location.reload();
})
modalContent.innerHTML = "Upload terminé !";
modalTitle.innerHTML = "Félicitations";
$("#warningFilesNumber").modal()
}
request.send(formData);
delete formData;
formData = new FormData();
}
else {
if(readyToSend) {
modalContent.innerHTML = "Veuillez choisir un ou plusieurs noeuds !";
}
else {
modalContent.innerHTML = "Veuillez choisir un fichier !";
}
modalTitle.innerHTML = "Attention";
$("#warningFilesNumber").modal()
}
})
} );