-
Notifications
You must be signed in to change notification settings - Fork 1
/
script.js
720 lines (666 loc) · 20.2 KB
/
script.js
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
/*
This file is part of egg-force-one.
egg-force-one is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Foobar is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with egg-force-one. If not, see <http://www.gnu.org/licenses/>. 2
############################################################################
Created on Mon Sep 25 16:24:39 2017
@author: CASAL Guillaume
*/
var lenTerm = 1000 // nombre de ligne garder sur le terminal
var temp = "no temp data" // garde les derniere temperature recu
var print = "0" // statut de l'impression
var oldPosLayer = 0 // ancienne position du layer
var PosLayer = 0 // position actiel du layer
var statutPrintData = 0 // donne le statu de l'impression
var timeUpdate = 1000 // temps avant la mise a jour
var pathFolder = "" //emplacement dans le dossier
var elementRightClic = false //element ayant recu un clic droit
var allParam = {} // tout les paramettre de l'application
var usbModify = 0 // element qui a recu le clic droit
var dragTimer //timeout on drag
var listDirOld = [] //liste les dossier
////////////////////////////////////////////////////////////////////////////////
//// DEV ////
function test_post() {
$.ajax({
type: 'POST',
url: document.getElementById("test_post_url").value,
data: document.getElementById("test_post_data").value,
success: function (data) {
alert("test_post : " + data);
},
error: function (data) {
alert("test_post : return error");
}
});
}
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
//// fonction a chargé en priorité ////
//
function getAllParam() {
$.ajax({
type : 'POST',
url : '/paramGetAll',
data : '',
success : function(data) {
setTimeout(update,timeUpdate);
//
allParam = {};
tableParam = data.split("&");
for (var i = 0; i < tableParam.length; i++) {
var pos = tableParam[i].indexOf(":");
if (tableParam[i][pos+1] == "["){
//console.log("tableau : " + tableParam[i].slice(0,pos));
var tmp = [];
var data = tableParam[i].slice(pos+2).split(",");
//console.log(tableParam[i].slice(0,pos)+" : "+data);
for (var j = 0; j < data.length; j++) {
tmp.push(data[j]);
}
//alert(data[data.length -1].substring(0, data[data.length-1].length-2));
var tmp2 = data[data.length -1].substring(0, data[data.length-1].length-1);
tmp.pop();
tmp.push(tmp2);
allParam[tableParam[i].slice(0,pos)] = tmp;
}
else{
allParam[tableParam[i].slice(0,pos)] = tableParam[i].slice(pos+1);
}
}
if (allParam.logDev == "True") {
console.log(allParam);
}
updateAllInfo();
},
error : function() {
setTimeout(update,timeUpdate);
console.error("update param bug");
}
});
}
function update() {
getAllParam();
listDirUpdate(pathFolder);
}
function updateAllInfo(){
updateUsb();
updatePrint();
}
function updateUsb(){
if (allParam.usbRun == "True"){
$('#inprimanteRunUsb').text("utiliser");
}
else {
$('#inprimanteRunUsb').text("non utiliser");
}
if (allParam.usbConnect == "True"){
$('#inprimanteConnecterUsb').text("Connecté");
}
else {
$('#inprimanteConnecterUsb').text("Non connecté");
}
if (document.getElementById("modifyUsb").className == ""){
$('#inprimantePortUsb').text(allParam.usbPort);
$('#inprimanteBauderateUsb').text(allParam.usbBauderate);
}
}
function updatePrint(){
//statut impression
switch (allParam.printStatut) {
case "5":
// initialisation de l'impression
$('#statutImpression').text("analyse en cour");
break;
case "0":
// aucune impression
$('#statutImpression').text("Aucune impression");
break;
case "1":
// impression en cour
$('#statutImpression').text("Impression en cour");
break;
case "2":
// impression terminer
$('#statutImpression').text("Impression terminer");
break;
case "3":
// impression en pause
$('#statutImpression').text("Impression en pause");
break;
case "4":
// impression areter
$('#statutImpression').text("Impression arrêtée");
break;
default:
$('#statutImpression').text("Bug");
}
//max total
document.getElementById("progressPrint").max = allParam.printNbLine;
//pos total
document.getElementById("progressPrint").value = allParam.printPosLine;
//max layer
var tmp = allParam.printPosLayer[allParam.printLayer] - allParam.printOldLayer;
document.getElementById("progressLayer").max = tmp;
//pos layer
document.getElementById("progressLayer").value = allParam.printPosLine - allParam.printOldLayer;
//print src
$('#emplacementFichier').text(allParam.printSrc);
//print nb lines
$('#nbLinesPrint').text(allParam.printNbLine);
//print line
$('#LinesPrint').text(allParam.printPosLine);
//print nb layer
$('#nbLayerPrint').text(allParam.printNbLayer);
//print layer
$('#layerPrint').text(allParam.printLayer);
}
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
//// fonction a lancer au démarrage ////
update();
window.onload=function(){
addAtribute();
}
////////////////////////////////////////////////////////////////////////////////
function modifyUsb(send = 0) {
if (usbModify == 0){
usbModify = 1
}
else{
usbModify = 0
}
var modifyUsb = document.getElementById("modifyUsb");
var modifyCancelUsb = document.getElementById("modifyCancelUsb");
var modifySendUsb = document.getElementById("modifySendUsb");
if (modifyUsb.className == "none") {
if(send == 1) {
console.log("send");
modifyUsb.className = "";
modifyCancelUsb.className = "none";
modifySendUsb.className = "none";
console.log(document.getElementById("optionBauderate").value);
$.ajax({
type : 'POST',
url : '/changeUsb',
data : 'port=' + document.getElementById("optionPort").value +
'&bauderate=' + document.getElementById("optionBauderate").value,
success : function(data) {
updateUsb();
},
error : function() {
updateUsb();
}
});
}
else {
modifyUsb.className = "";
modifyCancelUsb.className = "none";
modifySendUsb.className = "none";
updateUsb();
}
}
else {
modifyUsb.className = "none";
modifyCancelUsb.className = "";
modifySendUsb.className = "";
// modifier activé
//bauderate
var test = document.createElement('select');
test.id = "optionBauderate";
//add auto
var tmp = document.createElement('option');
tmp.value = "auto";
tmp.innerHTML = "auto";
test.appendChild(tmp);
var tempAllBaud = allParam.allBauderate;
for (var i = tempAllBaud.length - 1; i >= 0; i--) {
var tmp = document.createElement('option');
tmp.value = tempAllBaud[i];
tmp.innerHTML = tempAllBaud[i];
if (parseInt(tempAllBaud[i]) == parseInt(allParam.usbBauderate)){
console.log("pass selected : " + tempAllBaud[i]);
tmp.setAttribute('selected', true);
}
test.appendChild(tmp);
}
document.getElementById("inprimanteBauderateUsb").innerHTML = "";
document.getElementById("inprimanteBauderateUsb").appendChild(test);
//port
var test = document.createElement('select');
test.id = "optionPort";
//add auto
var tmp = document.createElement('option');
tmp.value = "auto";
tmp.innerHTML = "auto";
test.appendChild(tmp);
var tempAllPort = allParam.usbAllPort;
for (var i = tempAllPort.length - 1; i >= 0; i--) {
var tmp = document.createElement('option');
tmp.value = tempAllPort[i];
tmp.innerHTML = tempAllPort[i];
if (tempAllPort[i] == allParam.usbPort){
console.log("pass selected : " + tempAllPort[i]);
tmp.setAttribute('selected', true);
}
test.appendChild(tmp);
}
document.getElementById("inprimantePortUsb").innerHTML = "";
document.getElementById("inprimantePortUsb").appendChild(test);
}
}
//
function openClose(test) {
if (test.parentNode.parentNode.childNodes[3].className == "none") {
test.parentNode.parentNode.childNodes[3].className = "infoBody";
}
else {
test.parentNode.parentNode.childNodes[3].className = "none";
}
}
function openCloseMenu(test) {
if (test.parentNode.childNodes[1].className == "none") {
test.parentNode.childNodes[1].className = "menuHome";
}
else {
test.parentNode.childNodes[1].className = "none";
}
}
//
function openCloseMenu2(test) {
if (test.parentNode.childNodes[1].className == "none") {
test.parentNode.childNodes[1].className = "menu2Home";
}
else {
test.parentNode.childNodes[1].className = "none";
}
}
//
function printStatut(data) {
console.log("modify printStatut : " + data);
$.ajax({
type: 'POST',
url: '/paramChange',
data: 'printStatut=' + data,
success: function(data) {
console.log("printStatut update");
},
error: function() {
console.error("error statutPrint");
}
});
}
function printFolder() {
path = document.getElementById("dirPath").lastChild.lastChild.lastChild.innerHTML + this.lastChild.innerHTML;
//alert(path);
$.ajax({
type: 'POST',
url: '/printSrc',
data : 'path=' + path,
success: function(data) {
console.log("start Print : " + path);
// body...
},
error: function() {
alert('error');
}
});
}
function listDirPos(pos="/") {
if (pathFolder != pos) {
pathFolder = pos;
document.getElementById('dirPath').innerHTML = "";
var newLine = document.createElement('tr');
newLine.className = "trPath";
var firstElement = document.createElement('td');
firstElement.innerHTML = "Position";
firstElement.className = "td1";
var secondElement = document.createElement('td');
secondElement.className = "td2";
var divSecondElement = document.createElement('div');
divSecondElement.innerHTML = pos;
divSecondElement.className = "tdDivDirPath";
secondElement.appendChild(divSecondElement);
newLine.appendChild(firstElement);
newLine.appendChild(secondElement);
document.getElementById('dirPath').appendChild(newLine);
}
}
function posDirUpdate() {
//alert(this.innerHTML);
tmp = document.getElementById('dirPath').lastChild.lastChild.lastChild.innerHTML + this.lastChild.innerHTML + '/';
listDirUpdate(tmp);
}
function posDirUpdate2(){
tmp = document.getElementById('dirPath').lastChild.lastChild.lastChild.innerHTML + elementRightClic.lastChild.innerHTML + '/';
listDirUpdate(tmp);
}
function dirReturn() {
listDirUpdate(returnPath);
}
function getRightClic() {
document.getElementById('rightClicNone').className = "none";
document.getElementById('rightClicDir').className = "none";
document.getElementById('rightClicFolder').className = "none";
}
function rightClickext(tmp = "", event) {
getRightClic();
console.log("right click ext");
event.stopPropagation();
event.preventDefault();
var menu = document.getElementById('rightClicNone');
menu.className = "rightClic";
menu.style.left = event.pageX + "px";
menu.style.top = event.pageY + "px";
/*alert("ext right click");
console.log(event.pageX);
console.log(event.pageY);*/
}
function rightClickDir(event) {
elementRightClic = this;
getRightClic();
console.log("right click Dir : " + this.lastChild.innerHTML);
event.stopPropagation();
event.preventDefault();
var menu = document.getElementById('rightClicDir');
menu.className = "rightClic";
menu.style.left = event.pageX + "px";
menu.style.top = event.pageY + "px";
/*if (tmp != "") {
alert("dossier : " + tmp.lastChild.innerHTML);
}*/
}
function rightClickFolder(event) {
elementRightClic = this;
getRightClic();
console.log("right click Folder : " + this.lastChild.innerHTML);
event.stopPropagation();
event.preventDefault();
var menu = document.getElementById('rightClicFolder');
menu.className = "rightClic";
menu.style.left = event.pageX + "px";
menu.style.top = event.pageY + "px";
/*if (tmp != "") {
alert("fichier : " +tmp.lastChild.innerHTML);
}*/
}
function listDirUpdate(addPath="/") {
if (addPath == ""){
addPath = "/";
}
$.ajax({
type: 'POST',
url: '/dirPrint',
data : 'path=' + addPath,
success: function(data) {
if (addPath != pathFolder){
//si on change de dossier
console.log("change dir");
document.getElementById('listDirStartTable').innerHTML = "";
listDirPos(addPath);
listDirUpdateTestReturn(temp, addPath);
var temp = data.split(";");
var newList = [];
for (var pos = 0; pos < temp.length && temp[pos] != ""; pos++) {
//ajoute tout les dossier et fichier
var temp2 = temp[pos].split('|');
newList.push(temp2);
listDirUpdateCreateLine(temp2);
}
listDirOld = newList;
}
else{
//on est toujour dans le meme dossier
var temp = data.split(";");
var newList = [];
for (var pos = 0; pos < temp.length && temp[pos] != ""; pos++) {
//ajoute tout les dossier et fichier
var temp2 = temp[pos].split('|');
newList.push(temp2);
}
if (newList.length != listDirOld.length){
// si on a pas le meme nombre d'elements
console.log("change detected on dir");
document.getElementById('listDirStartTable').innerHTML = "";
listDirUpdateTestReturn(temp, addPath);
for (var pos = 0; pos < newList.length && newList[pos] != ""; pos++) {
//ajoute tout les dossier et fichier
listDirUpdateCreateLine(newList[pos]);
}
listDirOld = newList;
}
else{
//si on a le mem nombre d'elements
for (var pos = 0; pos < newList.length && newList[pos] != ""; pos++) {
//ajoute tout les dossier et fichier
if (newList[pos][0] != listDirOld[pos][0] || newList[pos][1] != listDirOld[pos][1]){
console.log("change detected on dir");
listDirUpdateLine(newList[pos], pos);
}
}
listDirOld = newList
}
}
},
error: function() {
console.log('error update dir');
}
});
}
function listDirUpdateLine(temp2, pos){
ret = 0;
if(document.getElementById('listDirStartTable').firstChild.firstChild.innerHTML == "Retour"){
ret = 1;
}
var tmp = document.getElementById('listDirStartTable').children[ret + pos];
if(tmp.firstChild.innerHTML == "Dossier"){
//Dossier
tmp.removeEventListener("dblclick", posDirUpdate, false);
tmp.removeEventListener("contextmenu", rightClickDir, false);
}
else{
//Fichier
tmp.removeEventListener("dblclick", printFolder, false);
tmp.removeEventListener("contextmenu", rightClickFolder, false);
}
if (temp2[1] == "True") {
// True
tmp.firstChild.innerHTML = "Dossier";
// double clic
tmp.addEventListener("dblclick", posDirUpdate, false);
//clic Droit
tmp.addEventListener('contextmenu',rightClickDir, false);
}
else {
// False
tmp.firstChild.innerHTML = "Fichier";
// double clic
tmp.addEventListener("dblclick", printFolder, false);
//clic Droit
tmp.addEventListener('contextmenu',rightClickFolder, false);
}
tmp.lastChild.innerHTML = temp2[0];
}
function listDirUpdateTestReturn(temp, addPath) {
if (addPath != "/"){
var newLine = document.createElement('tr');
var firstElement = document.createElement('td');
firstElement.innerHTML = "Retour";
firstElement.className = "td1";
var secondElement = document.createElement('td');
var temp = addPath.split("/");
returnPath = "";
for (var pos = 0; pos < temp.length - 2; pos++) {
returnPath += temp[pos] + "/";
}
//alert("test : " + returnPath);
secondElement.innerHTML = returnPath;
secondElement.className = "td2";
//newLine.onclick = listDirUpdate(returnPath);
newLine.addEventListener("dblclick", dirReturn, false);
newLine.appendChild(firstElement);
newLine.appendChild(secondElement);
document.getElementById('listDirStartTable').appendChild(newLine);
}
}
function listDirUpdateCreateLine(temp2){
var newLine = document.createElement('tr');
var firstElement = document.createElement('td');
if (temp2[1] == "True") {
// True
firstElement.innerHTML = "Dossier";
// double clic
newLine.addEventListener("dblclick", posDirUpdate, false);
//clic Droit
newLine.addEventListener('contextmenu',rightClickDir, false);
}
else {
// False
firstElement.innerHTML = "Fichier";
// double clic
newLine.addEventListener("dblclick", printFolder, false);
//clic Droit
newLine.addEventListener('contextmenu',rightClickFolder, false);
}
firstElement.className = "td1";
var secondElement = document.createElement('td');
secondElement.innerHTML = temp2[0];
secondElement.className = "td2";
newLine.tabIndex = "1";
newLine.appendChild(firstElement);
newLine.appendChild(secondElement);
document.getElementById('listDirStartTable').appendChild(newLine);
}
function updateSoftware() {
//met a jour le logiciel
console.log("update run");
$.ajax({
type: 'POST',
url: '/update',
data: '',
success: function(data) {
console.log("updateSoftware : " + data);
},
error: function() {
console.error('error updateSoftware');
}
});
}
function sendAlive(code) {
//modifie le alive du programme
console.log("modify alive : " + code);
$.ajax({
type: 'POST',
url: '/paramChange',
data: 'alive=' + code,
success: function(data) {
console.log("alive update");
setTimeout(function() {
document.location.reload(true);
}, 2000);
},
error: function() {
console.error("error sendAlive");
}
});
}
function createDir(){
console.log("create dir");
$.ajax({
type : 'POST',
url : '/createDir',
data : 'path=' + pathFolder
+ '&name=' + "nouveau dossier",
success: function(data){
console.log("createDir ok");
},
error: function() {
console.error("error createDir");
}
});
}
function deleteThisDir() {
pathDel = pathFolder + elementRightClic.lastChild.innerHTML;
console.log("delete Dir : " + pathDel);
$.ajax({
type : 'POST',
url : '/deletePathDir',
data : 'path=' + pathDel,
success: function(data){
console.log("createDir ok");
},
error: function() {
console.error("error createDir");
}
});
}
function deleteThisFolder() {
pathDel = pathFolder + elementRightClic.lastChild.innerHTML;
console.log("delete folder : " + pathDel);
$.ajax({
type : 'POST',
url : '/deletePathFolder',
data : 'path=' + pathDel,
success: function(data){
console.log("createDir ok");
},
error: function() {
console.error("error createDir");
}
});
}
function renameThis() {
console.log("rename : " + elementRightClic.lastChild.innerHTML + " by: " + "........");
$.ajax({
type : 'POST',
url : '/deletePathFolder',
data : 'path=' + pathFolder
+ '&pathRename=' + pathRename,
success: function(data){
console.log("createDir ok");
},
error: function() {
console.error("error createDir");
}
});
}
function addAtribute(){
document.getElementById('listDir').addEventListener('contextmenu',function(event){
rightClickext(this, event);
}, false);
//
document.getElementById('info').onscroll = function(event){
document.getElementById('rightClicNone').className = "none";
document.getElementById('rightClicDir').className = "none";
document.getElementById('rightClicFolder').className = "none";
}
document.getElementById('listDirStart').onscroll = function(event){
document.getElementById('rightClicNone').className = "none";
document.getElementById('rightClicDir').className = "none";
document.getElementById('rightClicFolder').className = "none";
}
document.addEventListener("click", function (event) {
document.getElementById('rightClicNone').className = "none";
document.getElementById('rightClicDir').className = "none";
document.getElementById('rightClicFolder').className = "none";
}, false);
document.addEventListener("dragover", function(event) {
document.getElementById('listDirStartTable').className = "none";
document.getElementById('dragFileUpload').className = "dragFileUpload";
window.clearTimeout(dragTimer);
}, false);
document.addEventListener("dragleave", function(event) {
dragTimer = window.setTimeout(function() {
document.getElementById('listDirStartTable').className = "";
document.getElementById('dragFileUpload').className = "none";
}, 120);
}, false);
}