Bonjour à tous.
J'essaye de simplifier une de mes fonctions mais j'ai un problème de portée de variables qui sont écrasées par la dernière instance.
La fonction suivante fonctionne très bien.
Code javascript : Sélectionner tout - Visualiser dans une fenêtre à part
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 function ChargementTableRelance() { var day = new Date(); day.setDate(day.getDate() - 1); // On sélectionne le jour précédent var mm = ((day.getMonth() + 1) < 10) ? '0' + (day.getMonth() + 1) : (day.getMonth() + 1); var dd = (day.getDate() < 10) ? '0' + day.getDate() : day.getDate(); var dayInit_Rel = day.getFullYear().toString() + mm + dd; var dayInitAlt_Rel = dd + "/" + mm + "/" + day.getFullYear(); // Utiliser pour le nouveau DatePicket let TabRelanceByID = document.getElementById("table_relance"); let InsertLig = ""; let InsertCell = ""; let NomLig = ""; let NomCell = ""; let BtnCell = ""; let NomDate = ""; let NomDate2 = ""; let Rel_NomDate = ""; let TitreExec = ""; let CmdAExecuter_01 = ""; let MinutesExec_01 = ""; let CmdAExecuter_02 = ""; let MinutesExec_02 = ""; let CmdAExecuter_03 = ""; let MinutesExec_03 = ""; let DateExec = ""; let JJExec = ""; let MMExec = ""; let AAExec = ""; let Rel_NumLig = 0; // Relance et envoie les emails pour tous les traitements VISTA pour une date données. // => reconstitue le répertoire $visu/aaaa/mm/oljjmmaaaa // cd $ss // sh scripts_batch_auto_guichet.csh JJ MM AAAA Rel_NumLig = Rel_NumLig + 1; TitreExec = "Relance et envoie les emails pour tous les traitements VISTA pour une date données => reconstitue le répertoire $visu/aaaa/mm/oljjmmaaaa"; TitreExec = TitreExec + "<br />" + "(cd $ss;sh scripts_batch_auto_guichet.csh JJ MM AAAA)"; NomLig = "L" + twoDigit(Rel_NumLig); NomCell = "C01"; InsertLig = TabRelanceByID.insertRow(-1); InsertLig.id = NomLig; InsertCell = InsertLig.insertCell(-1); InsertCell.id = NomLig + NomCell; InsertCell.innerHTML = TitreExec; InsertCell.className = "CentrageVerticalForce"; InsertCell.classList.add("Table_Largeur_Col3"); NomCell = "C02"; InsertCell = InsertLig.insertCell(-1); InsertCell.id = NomLig + NomCell; NomDate = "Rel_date_deb_" + twoDigit(Rel_NumLig) Rel_NomDate = "<INPUT class='' name='" + NomDate +"' id='" + NomDate+ "' type='text';></INPUT>"; InsertCell.innerHTML = Rel_NomDate; InsertCell.className = "CentrageVerticalForce"; InsertCell.classList.add("Table_Largeur_Col4"); datePickerInit(dayInitAlt_Rel, NomDate, "dd/mm/yy"); // InsertCell.className = "CentrageVerticalForce"; InsertCell.classList.add("Table_Largeur_Col4"); NomCell = "C03"; InsertCell = InsertLig.insertCell(-1); InsertCell.id = NomLig + NomCell; BtnCell = document.createElement("button"); BtnCell.id = "Rel_BTN" + twoDigit(Rel_NumLig); BtnCell.title = "Exécution : " + TitreExec; DateExec = $('input[name=' + NomDate + ']').val(); JJExec = DateExec.substr(0, 2); MMExec = DateExec.substr(3, 2); AAExec = DateExec.substr(6, 4); CmdAExecuter_01 = "cd $ss;"; CmdAExecuter_01 = CmdAExecuter_01 + "sh scripts_batch_auto_guichet.csh "; CmdAExecuter_01 = CmdAExecuter_01 + JJExec + " " + MMExec + " " + AAExec; CmdAExecuter_01 = CmdAExecuter_01 + " &"; MinutesExec_01 = "1234567"; BtnCell.onclick = function() { ExecSSH(CmdAExecuter_01, MinutesExec_01); }; InsertCell.appendChild(BtnCell); BtnCell.className = "btn btn-warning fas fa-rocket fa-2x center"; InsertCell.classList.add("text-center"); InsertCell.classList.add("CentrageVerticalForce"); InsertCell.classList.add("Table_Largeur_Col6"); // Relance fichiers mensuels ou annuels incomplets => IL FAUT EXECUTER LES 3 SCRIPTS // cd $ss // sh go.fab.stats.vista.mois_candidate.csh mm aaaa traitement_tot_dep_arr_aerobahn_v7 // sh go.fab.stats.vista.mois_candidate.csh mm aaaa traitement_tot_dep_arr_aerobahn_taxi_time_v7 // sh go.fab.stats.vista.annee.candidate.csh aaaa Rel_NumLig = Rel_NumLig + 1; TitreExec = "Relance fichiers mensuels ou annuels incomplets => IL FAUT EXECUTER LES 3 SCRIPTS"; TitreExec = TitreExec + "<br />" + "(cd $ss;sh go.fab.stats.vista.mois_candidate.csh mm aaaa traitement_tot_dep_arr_aerobahn_v7;<br />sh go.fab.stats.vista.mois_candidate.csh mm aaaa traitement_tot_dep_arr_aerobahn_taxi_time_v7;<br />sh go.fab.stats.vista.annee.candidate.csh aaaa)"; NomLig = "L" + twoDigit(Rel_NumLig); NomCell = "C01"; InsertLig = TabRelanceByID.insertRow(-1); InsertLig.id = NomLig; InsertCell = InsertLig.insertCell(-1); InsertCell.id = NomLig + NomCell; InsertCell.innerHTML = TitreExec; InsertCell.className = "CentrageVerticalForce"; InsertCell.classList.add("Table_Largeur_Col3"); NomCell = "C02"; InsertCell = InsertLig.insertCell(-1); InsertCell.id = NomLig + NomCell; NomDate = "Rel_date_deb_" + twoDigit(Rel_NumLig) Rel_NomDate = "<INPUT class='' name='" + NomDate +"' id='" + NomDate+ "' type='text';></INPUT>"; InsertCell.innerHTML = Rel_NomDate; InsertCell.className = "CentrageVerticalForce"; InsertCell.classList.add("Table_Largeur_Col4"); datePickerInit(dayInitAlt_Rel, NomDate, "dd/mm/yy"); // InsertCell.className = "CentrageVerticalForce"; InsertCell.classList.add("Table_Largeur_Col4"); NomCell = "C03"; InsertCell = InsertLig.insertCell(-1); InsertCell.id = NomLig + NomCell; BtnCell = document.createElement("button"); BtnCell.id = "Rel_BTN" + twoDigit(Rel_NumLig); BtnCell.title = "Exécution : " + TitreExec; DateExec = $('input[name=' + NomDate + ']').val(); JJExec = DateExec.substr(0, 2); MMExec = DateExec.substr(3, 2); AAExec = DateExec.substr(6, 4); CmdAExecuter_02 = "cd $ss;"; CmdAExecuter_02 = CmdAExecuter_02 + "sh go.fab.stats.vista.mois_candidate.csh mm aaaa traitement_tot_dep_arr_aerobahn_v7 "; CmdAExecuter_02 = CmdAExecuter_02 + JJExec + " " + MMExec + " " + AAExec + ";"; CmdAExecuter_02 = CmdAExecuter_02 + "sh go.fab.stats.vista.mois_candidate.csh mm aaaa traitement_tot_dep_arr_aerobahn_taxi_time_v7 "; CmdAExecuter_02 = CmdAExecuter_02 + JJExec + " " + MMExec + " " + AAExec + ";"; CmdAExecuter_02 = CmdAExecuter_02 + "sh go.fab.stats.vista.annee.candidate.csh aaaa "; CmdAExecuter_02 = CmdAExecuter_02 + AAExec; CmdAExecuter_02 = CmdAExecuter_02 + " &"; MinutesExec_02 = "1234567"; BtnCell.onclick = function() { ExecSSH(CmdAExecuter_02, MinutesExec_02); }; InsertCell.appendChild(BtnCell); BtnCell.className = "btn btn-warning fas fa-rocket fa-2x center"; InsertCell.classList.add("text-center"); InsertCell.classList.add("CentrageVerticalForce"); InsertCell.classList.add("Table_Largeur_Col6"); ... ... ...
Mais lorsque j'essaye de limiter le nombre de variables en passant par un tableau, le contenu du tableau est toujours écrasé par la dernière affectation.
Ainsi je me retrouve avec CmdAExecuter[1] qui contient la même chose que CmdAExecuter[2].
J'espère que je suis assez clair dans mes explication et que vous pourrez m'aider.
Merci d'avance.
Code javascript : Sélectionner tout - Visualiser dans une fenêtre à part
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 function ChargementTableRelance() { var day = new Date(); day.setDate(day.getDate() - 1); // On sélectionne le jour précédent var mm = ((day.getMonth() + 1) < 10) ? '0' + (day.getMonth() + 1) : (day.getMonth() + 1); var dd = (day.getDate() < 10) ? '0' + day.getDate() : day.getDate(); var dayInit_Rel = day.getFullYear().toString() + mm + dd; var dayInitAlt_Rel = dd + "/" + mm + "/" + day.getFullYear(); // Utiliser pour le nouveau DatePicket let TabRelanceByID = document.getElementById("table_relance"); let InsertLig = ""; let InsertCell = ""; let NomLig = ""; let NomCell = ""; let BtnCell = ""; let NomDate = ""; let NomDate2 = ""; let Rel_NomDate = ""; let TitreExec = ""; let CmdAExecuter_01 = ""; let MinutesExec_01 = ""; let CmdAExecuter_02 = ""; let MinutesExec_02 = ""; let CmdAExecuter_03 = ""; let MinutesExec_03 = ""; let DateExec = ""; let JJExec = ""; let MMExec = ""; let AAExec = ""; let Rel_NumLig = 0; let NumAction = 0; let CmdAExecuter = []; let Minutes = []; let cmd = ""; let min = ""; // Relance et envoie les emails pour tous les traitements VISTA pour une date données. // => reconstitue le répertoire $visu/aaaa/mm/oljjmmaaaa // cd $ss // sh scripts_batch_auto_guichet.csh JJ MM AAAA Rel_NumLig = Rel_NumLig + 1; NumAction = 1; TitreExec = "Relance et envoie les emails pour tous les traitements VISTA pour une date données => reconstitue le répertoire $visu/aaaa/mm/oljjmmaaaa"; TitreExec = TitreExec + "<br />" + "(cd $ss;sh scripts_batch_auto_guichet.csh JJ MM AAAA)"; NomLig = "L" + twoDigit(Rel_NumLig); NomCell = "C01"; InsertLig = TabRelanceByID.insertRow(-1); InsertLig.id = NomLig; InsertCell = InsertLig.insertCell(-1); InsertCell.id = NomLig + NomCell; InsertCell.innerHTML = TitreExec; InsertCell.className = "CentrageVerticalForce"; InsertCell.classList.add("Table_Largeur_Col3"); NomCell = "C02"; InsertCell = InsertLig.insertCell(-1); InsertCell.id = NomLig + NomCell; NomDate = "Rel_date_deb_" + twoDigit(Rel_NumLig) Rel_NomDate = "<INPUT class='' name='" + NomDate +"' id='" + NomDate+ "' type='text';></INPUT>"; InsertCell.innerHTML = Rel_NomDate; InsertCell.className = "CentrageVerticalForce"; InsertCell.classList.add("Table_Largeur_Col4"); datePickerInit(dayInitAlt_Rel, NomDate, "dd/mm/yy"); // InsertCell.className = "CentrageVerticalForce"; InsertCell.classList.add("Table_Largeur_Col4"); NomCell = "C03"; InsertCell = InsertLig.insertCell(-1); InsertCell.id = NomLig + NomCell; BtnCell = document.createElement("button"); BtnCell.id = "Rel_BTN" + twoDigit(Rel_NumLig); BtnCell.title = "Exécution : " + TitreExec; DateExec = $('input[name=' + NomDate + ']').val(); JJExec = DateExec.substr(0, 2); MMExec = DateExec.substr(3, 2); AAExec = DateExec.substr(6, 4); CmdAExecuter[NumAction] = "cd $ss;"; CmdAExecuter[NumAction] = CmdAExecuter[NumAction] + "sh scripts_batch_auto_guichet.csh "; CmdAExecuter[NumAction] = CmdAExecuter[NumAction] + JJExec + " " + MMExec + " " + AAExec; CmdAExecuter[NumAction] = CmdAExecuter[NumAction] + " &"; Minutes[NumAction] = "1234567"; BtnCell.onclick = function() { ExecSSH(CmdAExecuter[NumAction], Minutes[NumAction]); }; InsertCell.appendChild(BtnCell); BtnCell.className = "btn btn-warning fas fa-rocket fa-2x center"; InsertCell.classList.add("text-center"); InsertCell.classList.add("CentrageVerticalForce"); InsertCell.classList.add("Table_Largeur_Col6"); // Relance fichiers mensuels ou annuels incomplets => IL FAUT EXECUTER LES 3 SCRIPTS // cd $ss // sh go.fab.stats.vista.mois_candidate.csh mm aaaa traitement_tot_dep_arr_aerobahn_v7 // sh go.fab.stats.vista.mois_candidate.csh mm aaaa traitement_tot_dep_arr_aerobahn_taxi_time_v7 // sh go.fab.stats.vista.annee.candidate.csh aaaa Rel_NumLig = Rel_NumLig + 1; NumAction = 2; TitreExec = "Relance fichiers mensuels ou annuels incomplets => IL FAUT EXECUTER LES 3 SCRIPTS"; TitreExec = TitreExec + "<br />" + "(cd $ss;sh go.fab.stats.vista.mois_candidate.csh mm aaaa traitement_tot_dep_arr_aerobahn_v7;<br />sh go.fab.stats.vista.mois_candidate.csh mm aaaa traitement_tot_dep_arr_aerobahn_taxi_time_v7;<br />sh go.fab.stats.vista.annee.candidate.csh aaaa)"; NomLig = "L" + twoDigit(Rel_NumLig); NomCell = "C01"; InsertLig = TabRelanceByID.insertRow(-1); InsertLig.id = NomLig; InsertCell = InsertLig.insertCell(-1); InsertCell.id = NomLig + NomCell; InsertCell.innerHTML = TitreExec; InsertCell.className = "CentrageVerticalForce"; InsertCell.classList.add("Table_Largeur_Col3"); NomCell = "C02"; InsertCell = InsertLig.insertCell(-1); InsertCell.id = NomLig + NomCell; NomDate = "Rel_date_deb_" + twoDigit(Rel_NumLig) Rel_NomDate = "<INPUT class='' name='" + NomDate +"' id='" + NomDate+ "' type='text';></INPUT>"; InsertCell.innerHTML = Rel_NomDate; InsertCell.className = "CentrageVerticalForce"; InsertCell.classList.add("Table_Largeur_Col4"); datePickerInit(dayInitAlt_Rel, NomDate, "dd/mm/yy"); // InsertCell.className = "CentrageVerticalForce"; InsertCell.classList.add("Table_Largeur_Col4"); NomCell = "C03"; InsertCell = InsertLig.insertCell(-1); InsertCell.id = NomLig + NomCell; BtnCell = document.createElement("button"); BtnCell.id = "Rel_BTN" + twoDigit(Rel_NumLig); BtnCell.title = "Exécution : " + TitreExec; DateExec = $('input[name=' + NomDate + ']').val(); JJExec = DateExec.substr(0, 2); MMExec = DateExec.substr(3, 2); AAExec = DateExec.substr(6, 4); CmdAExecuter[NumAction] = "cd $ss;"; CmdAExecuter[NumAction] = CmdAExecuter[NumAction] + "sh go.fab.stats.vista.mois_candidate.csh mm aaaa traitement_tot_dep_arr_aerobahn_v7 "; CmdAExecuter[NumAction] = CmdAExecuter[NumAction] + JJExec + " " + MMExec + " " + AAExec + ";"; CmdAExecuter[NumAction] = CmdAExecuter[NumAction] + "sh go.fab.stats.vista.mois_candidate.csh mm aaaa traitement_tot_dep_arr_aerobahn_taxi_time_v7 "; CmdAExecuter[NumAction] = CmdAExecuter[NumAction] + JJExec + " " + MMExec + " " + AAExec + ";"; CmdAExecuter[NumAction] = CmdAExecuter[NumAction] + "sh go.fab.stats.vista.annee.candidate.csh aaaa "; CmdAExecuter[NumAction] = CmdAExecuter[NumAction] + AAExec; CmdAExecuter[NumAction] = CmdAExecuter[NumAction] + " &"; MinutesExec_02 = "1234567"; BtnCell.onclick = function() { ExecSSH(CmdAExecuter[NumAction], MinutesExec[NumAction]); }; InsertCell.appendChild(BtnCell); BtnCell.className = "btn btn-warning fas fa-rocket fa-2x center"; InsertCell.classList.add("text-center"); InsertCell.classList.add("CentrageVerticalForce"); InsertCell.classList.add("Table_Largeur_Col6");
C'est sûrement un truc tout bête, mais impossible de mettre le doigt dessus.
Partager