Commit | Line | Data |
---|---|---|
46ae38a9 FB |
1 | /*************************************************************************** |
2 | * Copyright (C) 2003-2007 Polytechnique.org * | |
3 | * http://opensource.polytechnique.org/ * | |
4 | * * | |
5 | * This program is free software; you can redistribute it and/or modify * | |
6 | * it under the terms of the GNU General Public License as published by * | |
7 | * the Free Software Foundation; either version 2 of the License, or * | |
8 | * (at your option) any later version. * | |
9 | * * | |
10 | * This program is distributed in the hope that it will be useful, * | |
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * | |
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * | |
13 | * GNU General Public License for more details. * | |
14 | * * | |
15 | * You should have received a copy of the GNU General Public License * | |
16 | * along with this program; if not, write to the Free Software * | |
17 | * Foundation, Inc., * | |
18 | * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * | |
19 | ***************************************************************************/ | |
20 | ||
21 | // Page initialization | |
22 | ||
23 | function wizPage_onLoad(id) | |
24 | { | |
25 | switch (id) { | |
26 | case 'general': | |
27 | fillType(document.forms.prof_annu['appli1[type]'], document.forms.prof_annu['appli1[id]'].selectedIndex-1); | |
28 | selectType(document.forms.prof_annu['appli1[type]'], document.forms.prof_annu['appli1_tmp'].value); | |
29 | fillType(document.forms.prof_annu['appli2[type]'], document.forms.prof_annu['appli2[id]'].selectedIndex-1); | |
30 | selectType(document.forms.prof_annu['appli2[type]'], document.forms.prof_annu['appli2_tmp'].value); | |
31 | break; | |
32 | case 'poly': | |
33 | updateGroupSubLink(document.forms.prof_annu.groupesx_sub); | |
34 | break; | |
35 | case 'deco': | |
36 | for (var i in names) { | |
37 | if (typeof names[i] != 'function') { | |
38 | if (document.getElementById("medal_" + i) != null) { | |
39 | getMedalName(i); | |
40 | buildGrade(i, document.forms.prof_annu["medal_" + i + "_grade"].value); | |
41 | } | |
42 | } | |
43 | } | |
44 | break; | |
45 | case 'emploi': | |
46 | for (var i = 0 ; document.getElementById('job_' + i) != null ; ++i) { | |
47 | updateJobSecteur(i, 'job_' + i, 'jobs[' + i + ']', | |
48 | document.forms.prof_annu["jobs[" + i + "][ss_secteur]"].value); | |
49 | } | |
50 | break; | |
51 | } | |
52 | } | |
53 | ||
54 | var applisType; | |
55 | var applisTypeAll; | |
56 | ||
57 | // General | |
58 | ||
59 | var subgrades; | |
60 | var names; | |
61 | function fillType(selectCtrl, appli, fill) | |
62 | { | |
63 | var i; | |
64 | var i0=0; | |
65 | ||
66 | for (i = selectCtrl.options.length; i >=0; i--) { | |
67 | selectCtrl.options[i] = null; | |
68 | } | |
69 | ||
70 | if (fill || appli <0) { | |
71 | selectCtrl.options[0] = new Option(' '); | |
72 | i0=1; | |
73 | } | |
74 | if (appli>=0) | |
75 | for (i=0; i < applisType[appli].length; i++) | |
76 | selectCtrl.options[i0+i] = new Option(applisType[appli][i]); | |
77 | else if (fill) | |
78 | for (i=0; i < applisTypeAll.length; i++) | |
79 | selectCtrl.options[i0+i] = new Option(applisTypeAll[i]); | |
80 | } | |
81 | ||
82 | ||
83 | function selectType(selectCtrl, type) | |
84 | { | |
85 | for (i = 0; i < selectCtrl.options.length; i++) { | |
86 | if (selectCtrl.options[i].text == type) | |
87 | selectCtrl.selectedIndex=i; | |
88 | } | |
89 | } | |
90 | ||
91 | ||
92 | ||
93 | // Addresses | |
94 | ||
95 | function removeObject(id, pref) | |
96 | { | |
97 | document.getElementById(id).style.display = "none"; | |
98 | document.forms.prof_annu[pref + "[removed]"].value = "1"; | |
99 | } | |
100 | ||
101 | function restoreObject(id, pref) | |
102 | { | |
103 | document.getElementById(id).style.display = ''; | |
104 | document.forms.prof_annu[pref + "[removed]"].value = "0"; | |
105 | } | |
106 | ||
107 | function getAddressElement(adrid, adelement) | |
108 | { | |
109 | return document.forms.prof_annu["addresses[" + adrid + "][" + adelement + "]"]; | |
110 | } | |
111 | ||
112 | function checkCurrentAddress(newCurrent) | |
113 | { | |
114 | var hasCurrent = false; | |
115 | var i = 0; | |
116 | while (getAddressElement(i, 'pub') != null) { | |
117 | var radio = getAddressElement(i, 'current'); | |
118 | var removed = getAddressElement(i, 'removed'); | |
119 | if (removed.value == "1" && radio.checked) { | |
120 | radio.checked = false; | |
121 | } else if (radio.checked && radio != newCurrent) { | |
122 | radio.checked = false; | |
123 | } else if (radio.checked) { | |
124 | hasCurrent = true; | |
125 | } | |
126 | i++; | |
127 | } | |
128 | if (!hasCurrent) { | |
129 | i = 0; | |
130 | while (getAddressElement(i, 'pub') != null) { | |
131 | var radio = getAddressElement(i, 'current'); | |
132 | var removed = getAddressElement(i, 'removed'); | |
133 | if (removed.value != "1") { | |
134 | radio.checked= true; | |
135 | return; | |
136 | } | |
137 | i++; | |
138 | } | |
139 | } | |
140 | } | |
141 | ||
142 | function removeAddress(id, pref) | |
143 | { | |
144 | removeObject(id, pref); | |
145 | checkCurrentAddress(null); | |
146 | if (document.forms.prof_annu[pref + '[datemaj]'].value != '') { | |
147 | document.getElementById(id + '_grayed').style.display = ''; | |
148 | } | |
149 | } | |
150 | ||
151 | function restoreAddress(id, pref) | |
152 | { | |
153 | document.getElementById(id + '_grayed').style.display = 'none'; | |
154 | checkCurrentAddress(null); | |
155 | restoreObject(id, pref); | |
156 | } | |
157 | ||
158 | function addAddress() | |
159 | { | |
160 | var i = 0; | |
161 | while (getAddressElement(i, 'pub') != null) { | |
162 | i++; | |
163 | } | |
164 | $("#add_adr").before('<div id="addresses_' + i + '_cont"></div>'); | |
165 | Ajax.update_html('addresses_' + i + '_cont', 'profile/ajax/address/' + i, checkCurrentAddress); | |
166 | } | |
167 | ||
168 | function addTel(id) | |
169 | { | |
170 | var i = 0; | |
171 | var adid = 'addresses_' + id; | |
172 | var tel = adid + '_tel_'; | |
173 | while (document.getElementById(tel + i) != null) { | |
174 | i++; | |
175 | } | |
176 | $('#' + adid + '_add_tel').before('<div id="' + tel + i + '" style="clear: both"></div>'); | |
177 | Ajax.update_html(tel + i, 'profile/ajax/tel/' + id + '/' + i); | |
178 | } | |
179 | ||
180 | ||
181 | // Geoloc | |
182 | ||
183 | function validGeoloc(id, pref) | |
184 | { | |
185 | document.getElementById(id + '_geoloc').style.display = 'none'; | |
186 | document.getElementById(id + '_geoloc_error').style.display = 'none'; | |
187 | document.getElementById(id + '_geoloc_valid').style.display = 'none'; | |
188 | document.forms.prof_annu[pref + "[parsevalid]"].value = "1"; | |
189 | document.forms.prof_annu[pref + "[text]"].value = document.forms.prof_annu[pref + "[geoloc]"].value; | |
190 | attachEvent(document.forms.prof_annu[pref + "[text]"], "click", | |
191 | function() { document.forms.prof_annu[pref + "[text]"].blur(); }); | |
192 | document.forms.prof_annu[pref + "[text]"].className = ''; | |
193 | } | |
194 | ||
195 | function validAddress(id, pref) | |
196 | { | |
197 | document.getElementById(id + '_geoloc').style.display = 'none'; | |
198 | document.getElementById(id + '_geoloc_error').style.display = 'none'; | |
199 | document.getElementById(id + '_geoloc_valid').style.display = 'none'; | |
200 | document.forms.prof_annu[pref + "[parsevalid]"].value = "0"; | |
201 | attachEvent(document.forms.prof_annu[pref + "[text]"], "click", | |
202 | function() { document.forms.prof_annu[pref + "[text]"].blur(); }); | |
203 | document.forms.prof_annu[pref + "[text]"].className = ''; | |
204 | } | |
205 | ||
206 | ||
207 | // Groups | |
208 | ||
209 | function updateGroup(type) | |
210 | { | |
211 | var val = document.forms.prof_annu[type + '_sel'].value; | |
212 | if (val == '0' || document.getElementById(type + '_' + val) != null) { | |
213 | document.getElementById(type + '_add').style.display = 'none'; | |
214 | } else { | |
215 | document.getElementById(type + '_add').style.display = ''; | |
216 | } | |
217 | } | |
218 | ||
219 | function removeGroup(cat, id) | |
220 | { | |
221 | $('#' + cat + '_' + id).remove(); | |
222 | updateGroup(cat); | |
223 | } | |
224 | ||
225 | function addGroup(cat) | |
226 | { | |
227 | var cb = document.forms.prof_annu[cat + '_sel']; | |
228 | var id = cb.value; | |
229 | var text = cb.options[cb.selectedIndex].text; | |
230 | var html = '<tr id="' + cat + '_' + id + '">' | |
231 | + ' <td>' | |
232 | + ' <input type="hidden" name="' + cat + '[' + id + ']" value="' + text + '" />' | |
233 | + ' </td>' | |
234 | + ' <td>' | |
235 | + ' <div style="float: left; width: 70%">' | |
236 | + text | |
237 | + ' </div>' | |
238 | + ' <a href="javascript:removeGroup(\'' + cat + '\', ' + id + ')">' | |
239 | + ' <img src="images/icons/cross.gif" alt="cross" title="Supprimer ce groupe" />' | |
240 | + ' </a>' | |
241 | + ' </td>' | |
242 | + '</tr>'; | |
243 | $('#' + cat).after(html); | |
244 | updateGroup(cat); | |
245 | } | |
246 | ||
247 | function updateGroupSubLink(cb) | |
248 | { | |
249 | var href = cb.value ? cb.value : "http://www.polytechnique.net"; | |
250 | document.getElementById("groupesx_sub").href = href; | |
251 | } | |
252 | ||
253 | ||
254 | // Medals | |
255 | ||
256 | function updateMedal() | |
257 | { | |
258 | var val = document.forms.prof_annu['medal_sel'].value; | |
259 | if (val == '' || document.getElementById('medal_' + val) != null) { | |
260 | document.getElementById('medal_add').style.display = 'none'; | |
261 | } else { | |
262 | document.getElementById('medal_add').style.display = ''; | |
263 | } | |
264 | } | |
265 | ||
266 | function getMedalName(id) | |
267 | { | |
268 | document.getElementById('medal_name_' + id).innerHTML = names[id]; | |
269 | } | |
270 | ||
271 | function buildGrade(id, current) | |
272 | { | |
273 | var grade; | |
274 | var subg = subgrades[id]; | |
275 | var obj = $('#medal_grade_' + id); | |
276 | if (!subg) { | |
277 | obj.prepend('<input type="hidden" name="medals[' + id + '][grade]" value="0" />'); | |
278 | } else { | |
279 | var html = 'Agrafe : <select name="medals[' + id + '][grade]">'; | |
280 | html += '<option value="0">Non précisée</option>'; | |
281 | for (grade = 0 ; grade < subg.length ; grade++) { | |
282 | html += '<option value="' + subg[grade][0] + '"'; | |
283 | if (subg[grade][0] == current) { | |
284 | html += ' selected="selected"'; | |
285 | } | |
286 | html += '>' + subg[grade][1] + '</option>'; | |
287 | } | |
288 | ||
289 | html += '</select>'; | |
290 | obj.prepend(html); | |
291 | } | |
292 | } | |
293 | ||
294 | function makeAddProcess(id) | |
295 | { | |
296 | return function(data) | |
297 | { | |
298 | $('#medals').after(data); | |
299 | updateMedal(); | |
300 | getMedalName(id); | |
301 | buildGrade(id, 0); | |
302 | }; | |
303 | } | |
304 | ||
305 | function addMedal() | |
306 | { | |
307 | var id = document.forms.prof_annu['medal_sel'].value; | |
308 | $.get(platal_baseurl + 'profile/ajax/medal/' + id, makeAddProcess(id)); | |
309 | } | |
310 | ||
311 | function removeMedal(id) | |
312 | { | |
313 | $("#medal_" + id).remove(); | |
314 | updateMedal(); | |
315 | } | |
316 | ||
317 | ||
318 | // Jobs | |
319 | ||
320 | function removeJob(id, pref) | |
321 | { | |
322 | document.getElementById(id + '_cont').style.display = 'none'; | |
323 | if (document.forms.prof_annu[pref + '[new]'].value == '0') { | |
324 | document.getElementById(id + '_grayed').style.display = ''; | |
325 | document.getElementById(id + '_grayed_name').innerHTML = | |
326 | document.forms.prof_annu[pref + "[name]"].value.replace('<', '<'); | |
327 | } | |
328 | document.forms.prof_annu[pref + "[removed]"].value = "1"; | |
329 | } | |
330 | ||
331 | function restoreJob(id, pref) | |
332 | { | |
333 | document.getElementById(id + '_cont').style.display = ''; | |
334 | document.getElementById(id + '_grayed').style.display = 'none'; | |
335 | document.forms.prof_annu[pref + "[removed]"].value = "0"; | |
336 | } | |
337 | ||
338 | function updateJobSecteur(nb, id, pref, sel) | |
339 | { | |
340 | var secteur = document.forms.prof_annu[pref + '[secteur]'].value; | |
341 | if (secteur == '') { | |
342 | secteur = '-1'; | |
343 | } | |
344 | Ajax.update_html(id + '_ss_secteur', 'profile/ajax/secteur/' +nb + '/' + secteur + '/' + sel); | |
345 | } | |
346 | ||
347 | function makeAddJob(id) | |
348 | { | |
349 | return function(data) | |
350 | { | |
351 | $('#add_job').before(data); | |
352 | updateSecteur('job_' + id, 'jobs[' + id + ']', ''); | |
353 | }; | |
354 | } | |
355 | ||
356 | function addJob() | |
357 | { | |
358 | var i = 0; | |
359 | while (document.getElementById('job_' + i) != null) { | |
360 | ++i; | |
361 | } | |
362 | $.get(platal_baseurl + 'profile/ajax/job/' + i, makeAddJob(i)); | |
363 | } | |
364 | ||
365 | ||
366 | // Skills | |
367 | ||
368 | function updateSkill(cat) | |
369 | { | |
370 | var val = document.forms.prof_annu[cat + '_sel'].value; | |
371 | var show = true; | |
372 | if (val == '') { | |
373 | show = false; | |
374 | } | |
375 | if (document.getElementById(cat + '_' + val) != null) { | |
376 | show = false; | |
377 | } | |
378 | document.getElementById(cat + '_add').style.display = show ? '' : 'none'; | |
379 | } | |
380 | ||
381 | function addSkill(cat) | |
382 | { | |
383 | var sel = document.forms.prof_annu[cat + '_sel']; | |
384 | var val = sel.value; | |
385 | var text = sel.options[sel.selectedIndex].text; | |
386 | $.get(platal_baseurl + 'profile/ajax/skill/' + cat + '/' + val, | |
387 | function(data) { | |
388 | $('#' + cat).append(data); | |
389 | document.getElementById(cat + '_' + val + '_title').innerHTML = text; | |
390 | updateSkill(cat); | |
391 | }); | |
392 | } | |
393 | ||
394 | function removeSkill(cat, id) | |
395 | { | |
396 | $('#' + cat + '_' + id).remove(); | |
397 | updateSkill(cat); | |
398 | } | |
399 | ||
400 | ||
401 | // Mentor | |
402 | ||
403 | function updateCountry() | |
404 | { | |
405 | var val = document.forms.prof_annu.countries_sel.value; | |
406 | var show = true; | |
407 | if (val == '') { | |
408 | show = false; | |
409 | } | |
410 | if (document.getElementById('countries_' + val) != null) { | |
411 | show = false; | |
412 | } | |
413 | document.getElementById('countries_add').style.display = show ? '' : 'none'; | |
414 | } | |
415 | ||
416 | function addCountry() | |
417 | { | |
418 | var cb = document.forms.prof_annu.countries_sel; | |
419 | var val = cb.value; | |
420 | var text = cb.options[cb.selectedIndex].text; | |
421 | var html = '<div id="countries_' + val + '" style="clear: both; margin-bottom: 0.7em">' | |
422 | + ' <div style="float: left; width: 50%">' + text + '</div>' | |
423 | + ' <input type="hidden" name="countries[' + val + ']" value="' + text + '" />' | |
424 | + ' <a href="javascript:removeCountry(\'' + val + '\')">' | |
425 | + ' <img src="images/icons/cross.gif" alt="" title="Supprimer ce pays" />' | |
426 | + ' </a>' | |
427 | + '</div>'; | |
428 | $('#countries').append(html); | |
429 | updateCountry(); | |
430 | } | |
431 | ||
432 | function removeCountry(id) | |
433 | { | |
434 | $('#countries_' + id).remove(); | |
435 | updateCountry(); | |
436 | } | |
437 | function updateSSecteur() | |
438 | { | |
439 | var s = document.forms.prof_annu.secteur_sel.value; | |
440 | var ss = document.forms.prof_annu['jobs[-1][ss_secteur]'].value; | |
441 | var show = true; | |
442 | if (s == '' || ss == '') { | |
443 | show = false; | |
444 | } | |
445 | if (document.getElementById('secteurs_' + s + '_' + ss) != null) { | |
446 | show = false; | |
447 | } | |
448 | document.getElementById('secteurs_add').style.display = show ? 'block' : 'none'; | |
449 | } | |
450 | ||
451 | function updateSecteur() | |
452 | { | |
453 | var secteur = document.forms.prof_annu.secteur_sel.value; | |
454 | if (secteur == '') { | |
455 | secteur = '-1'; | |
456 | } | |
457 | $.get(platal_baseurl + 'profile/ajax/secteur/-1/' + secteur, | |
458 | function(data) { | |
459 | data = '<a href="javascript:addSecteur()" style="display: none; float: right" id="secteurs_add">' | |
460 | + ' <img src="images/icons/add.gif" alt="" title="Ajouter ce secteur" />' | |
461 | + '</a>' + data; | |
462 | document.getElementById('ss_secteur_sel').innerHTML = data; | |
463 | attachEvent(document.forms.prof_annu['jobs[-1][ss_secteur]'], 'change', updateSSecteur); | |
464 | }); | |
465 | } | |
466 | ||
467 | function addSecteur() | |
468 | { | |
469 | var scb = document.forms.prof_annu.secteur_sel; | |
470 | var s = scb.value; | |
471 | var st = scb.options[scb.selectedIndex].text; | |
472 | ||
473 | var sscb = document.forms.prof_annu['jobs[-1][ss_secteur]']; | |
474 | var ss = sscb.value; | |
475 | var sst = sscb.options[sscb.selectedIndex].text; | |
476 | ||
477 | var html = '<div id="secteurs_' + s + '_' + ss + '" style="clear: both; margin-top: 0.5em" class="titre">' | |
478 | + ' <a href="javascript:removeSecteur(\'' + s + '\', \'' + ss + '\')" style="display: block; float: right">' | |
479 | + ' <img src="images/icons/cross.gif" alt="" title="Supprimer ce secteur" />' | |
480 | + ' </a>' | |
481 | + ' <input type="hidden" name="secteurs[' + s + '][' + ss + ']" value="' + sst + '" />' | |
482 | + ' ' + sst | |
483 | + '</div>'; | |
484 | $('#secteurs').append(html); | |
485 | updateSSecteur(); | |
486 | } | |
487 | ||
488 | function removeSecteur(s, ss) | |
489 | { | |
490 | $('#secteurs_' + s + '_' + ss).remove(); | |
491 | updateSSecteur(); | |
492 | } | |
493 | ||
494 | // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: |