This repository has been archived by the owner on Aug 16, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathscript.js
278 lines (243 loc) · 9.36 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
$(document).ready(function () {
initButtonsAction();
if (location.pathname.split("/").slice(-1)[0] == "form.php") {
initJobChange();
initButtonsAction();
initAddChildButtons();
initAddRadioButtonEvent();
initDateChecker();
initDatepicker();
clearFiles();
checkRequired();
}
});
function checkDate() {
var birthdate = moment(document.getElementById("birthApp").value, "DD/MM/YYYY")._d;
var cur = new Date();
var diff = cur - birthdate; // This is the difference in milliseconds
var age = Math.floor(diff / 31536000000); // Divide by 1000*60*60*24*365
if (age <= 12 || birthdate.getFullYear() < 1910 || age > 60) {
document.getElementById('errorMsg').innerHTML = '<p class ="errorMsgs">Date invalide';
}
else {
document.getElementById('errorMsg').innerHTML = '';
}
}
function initDateChecker() {
$("#birthApp").change(function () {
checkDate();
});
$("#dejaCandAnnee").change(function () {
checkYearDate("#dejaCandAnnee", "#dejaCandError", 0);
});
$("#anneeFin").change(function () {
checkYearDate("#anneeFin", "#anneeFinError", 1);
});
}
function addChildren(parentId, maxItems, childTemplate, addButtonId) {
var i = $(parentId + ' > tbody').children().size() + 1;
if (i < maxItems) {
var fullTemplate = childTemplate.replace(/\{(.*?)\}/g, i);
$(parentId).append(fullTemplate);
if (i == maxItems - 1) {
$(addButtonId).hide(750);
}
}
}
function changeTitleFile(objFile) {
objFile.parentNode.setAttribute('title', objFile.value.replace(/^.*[\\/]/, ''));
checkFileFormat(objFile);
}
function checkFileFormat(obj) {
var errorSection = obj.parentElement.nextElementSibling.nextElementSibling.nextElementSibling;
var fileExtension = ['pdf', 'jpeg', 'png', 'jpg'];
if (fileExtension.indexOf(obj.value.split('.').pop().toLowerCase()) == -1) {
//extension invalide
errorSection.innerHTML = '<p class ="errorMsgs">Format invalide</p>';
clearFileInput(obj);
} else {
//extension valide
errorSection.innerHTML = '';
}
}
function checkYearDate(toCheckValue, errorZone, coefficiantYear) {
var inputYear = $(toCheckValue).val();
var currentYear = (new Date).getFullYear() + coefficiantYear;
if ((inputYear != parseInt(inputYear, 10)) || (currentYear < inputYear)) {
$(errorZone).html('<p class ="errorMsgs">Date invalide');
} else {
$(errorZone).html("");
}
}
function initButtonsAction() {
$('#createAc').click(function () {
window.open("https://guests.epfl.ch/selfaddform", '_blank');
});
$('#connectB').click(function () {
document.location.href = "form.php";
});
$('#infoFilieres').click(function () {
window.open("https://www.ict-berufsbildung.ch/fr/formation-professionnelle/formation-initiale-ict/", '_blank');
});
$('#retourHome').click(function () {
document.location.href = "http://apprentis.epfl.ch/";
// logout
});
$('#retourFormulaire').click(function () {
history.go(-1);
});
}
function initAddChildButtons() {
$('#addSch').click(function () {
var template = '<tr><td><input type="text" name="ecole{i}" placeholder="Ecole" autocomplete="off"/></td><td><input type="text" name="lieuEcole{i}" placeholder="Lieu" autocomplete="off"/></td> <td><input type="text" name="niveauEcole{i}" placeholder="Niveau" autocomplete="off"/></td><td><input type="text" name="anneesEcole{i}" placeholder="de-à(années)" autocomplete="off"/></td></tr>';
addChildren('#scolaire', 6, template, '#addSch');
});
$('#addPro').click(function () {
var template = '<tr><td><input type="text" name="employeurPro{i}" placeholder="Employeur" autocomplete="off"/></td><td><input type="text" name="lieuPro{i}" placeholder="Lieu" autocomplete="off"/></td><td><input type="text" name="activitePro{i}" placeholder="Activité" autocomplete="off"/></td><td><input type="text" name="anneesPro{i}" placeholder="de-à(années)" autocomplete="off"/></td></tr>';
addChildren('#activites', 4, template, '#addPro');
});
$('#addStage').click(function () {
var template = '<tr><td><input type="text" name="activiteStage{i}" placeholder="Métier" autocomplete="off"></td><td><input type="text" name="entrepriseStage{i}" placeholder="Entreprise" autocomplete="off"></td></tr>';
addChildren('#stages', 5, template, '#addStage');
});
$('#addInputFile').click(function () {
var nextIndex = $('#newCertifZone > tbody').children().size() + 1;
var zoneId = nextIndex + 7;
if (nextIndex < 10) {
$('#newCertifZone').append('<tr><td><div class="tooltip"><label class="file" title="" id="certifLabel' + nextIndex
+ '"><input type="file" name="certifs' + nextIndex
+ '" id="certifs' + nextIndex
+ '" onchange="changeTitleFile(this)" /></label><span class="tooltiptext tooltip-right">Formats autorisés: pdf-jpg-jpeg-png</span><p></p><section id="formatErrorZone' + zoneId
+ '"></section></div></td></tr>');
if (nextIndex == 9) {
$('#addInputFile').hide(750);
}
}
});
}
function setMajState() {
$('#maj1')[0].checked ? $("#representants").show(1000) : $("#representants").hide(1000);
}
function setDejaCandState() {
if ($('#dejaCand1')[0].checked) {
$("#dejaCandAnnee").hide(750);
$("#dejaCandAnnee").val("");
$("#dejaCandError").html("");
} else {
$("#dejaCandAnnee").show(750);
}
}
function setLieuState() {
if ($('#lieuLausanne')[0].checked) {
$("#jbLausanne").show(0);
$("#jbSion").hide(0);
}
else if ($('#lieuSion')[0].checked) {
$("#jbSion").show(0);
$("#jbLausanne").hide(0);
}
}
function initAddRadioButtonEvent() {
$('#maj1').change(setMajState);
$('#maj2').change(setMajState);
setMajState();
$("#dejaCand1").change(setDejaCandState);
$("#dejaCand2").change(setDejaCandState);
setDejaCandState();
$('#lieuLausanne').change(setLieuState);
$('#lieuSion').change(setLieuState);
}
function clearRepresentants() {
for (i = 1; i <= 2; i++) {
$("#genreRep" + i + " :nth-child(1)").prop('selected', true);
$("#nameRep" + i).val("");
$("#surnameRep" + i).val("");
$("#adrRep" + i).val("");
$("#NPARep" + i).val("");
$("#telRep" + i).val("");
}
}
function initDatepicker() {
$.datepicker.setDefaults($.datepicker.regional["fr"]);
$("#birthApp").datepicker({ minDate: '-60y', maxDate: '-13y', dateFormat: "dd/mm/yy" });
}
function getFormation() {
if ($('#lieuLausanne').is(":checked")) {
return $("#jbLausanne option:selected")[0].value;
}
else {
return $("#jbSion option:selected")[0].value;
}
}
function initJobChange() {
$(".jobSelectors").change(function () {
var selectedFormation = getFormation();
showPolyAndInfoDivs(selectedFormation);
// var laborantPeople = ["laborantinChimie", "laborantinPhysique", "laborantinBiologie"];
// if (laborantPeople.indexOf(selectedFormation) == -1) {
// showPolyAndInfoDivs(selectedFormation);
// } else {
// $("#all").hide(1000);
// if (confirm("Pour les métiers de laborantins, l'inscription se fait auprès de l'AVML, cliquer sur ok pour être redirigé-e.")) {
// window.location.replace("https://wp.unil.ch/avml/");
// }
// }
});
$("#lieux").change(function () {
var selectedFormation = getFormation();
showPolyAndInfoDivs(selectedFormation);
});
}
function showOnFormReturn(lieu) {
if (lieu == 'Lausanne') {
var selectedFormation = $("#jbLausanne option:selected")[0].value;
}
else if (lieu == 'Sion') {
var selectedFormation = $("#jbSion option:selected")[0].value;
}
showListJob(lieu)
showPolyAndInfoDivs(selectedFormation);
}
function showListJob(lieu) {
if (lieu == 'Lausanne') {
$("#jbSion").hide();
$("#jbLausanne").show();
}
else if (lieu == 'Sion') {
$("#jbSion").show();
$("#jbLausanne").hide();
}
}
function showPolyAndInfoDivs(selectedFormation) {
$("#all").show(1000);
selectedFormation == "informaticien" ? $("#infoOnly").show(1000) : $("#infoOnly").hide(500);
selectedFormation == "informaticien" ? $("#griTest").show(1000) : $("#griTest").hide(500);
selectedFormation == "polyMecanicien" ? $("#polyOnly").show(1000) : $("#polyOnly").hide(500);
}
function clearFileInput(fileInput) {
$(fileInput).wrap('<form>').closest('form').get(0).reset();
$(fileInput).unwrap();
}
function clearFileLabel(fileInputLabel) {
$(fileInputLabel)[0].title = "Aucun fichier choisi";
}
function clearFiles() {
$("#files input").each(function (input) {
clearFileInput(this);
});
$("#files label").each(function (input) {
clearFileLabel(this);
});
}
function checkRequired() {
$("form").submit(function (e) {
$($(this).find("[data-required]")).each(function () {
if ($(this).val() == '') {
alert("Certains champs requis n'ont pas été remplis.");
e.preventDefault();
return false;
}
});
return true;
});
}