add name edition in profile
[platal.git] / htdocs / javascript / profile.js
CommitLineData
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
23function 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
54var applisType;
55var applisTypeAll;
56
57// General
58
59var subgrades;
60var names;
61function 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
83function 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
b04882ff
PC
91function addSearchName()
92{
93 var i = 0;
94 while (document.getElementById('search_name_' + i) != null) {
95 i++;
96 }
97 $('#add_search_name').before('<div id="search_name_' + i + '" style="padding:2px" class="center"></div>');
98 Ajax.update_html('search_name_' + i, 'profile/ajax/searchname/' + i,function(){
99 $('#search_name_'+i+' input')[1].focus();
100 });
101}
46ae38a9 102
b04882ff
PC
103function removeSearchName(i)
104{
105 if (document.getElementById('search_name_'+i+'_new') != null) {
106 $('#search_name_'+i).remove();
107 } else {
108 removeObject('search_name_'+i, 'search_name['+i+']');
109 }
110}
46ae38a9
FB
111
112// Addresses
113
114function removeObject(id, pref)
115{
116 document.getElementById(id).style.display = "none";
117 document.forms.prof_annu[pref + "[removed]"].value = "1";
118}
119
120function restoreObject(id, pref)
121{
122 document.getElementById(id).style.display = '';
123 document.forms.prof_annu[pref + "[removed]"].value = "0";
124}
125
126function getAddressElement(adrid, adelement)
127{
128 return document.forms.prof_annu["addresses[" + adrid + "][" + adelement + "]"];
129}
130
131function checkCurrentAddress(newCurrent)
132{
133 var hasCurrent = false;
134 var i = 0;
135 while (getAddressElement(i, 'pub') != null) {
136 var radio = getAddressElement(i, 'current');
137 var removed = getAddressElement(i, 'removed');
138 if (removed.value == "1" && radio.checked) {
139 radio.checked = false;
140 } else if (radio.checked && radio != newCurrent) {
141 radio.checked = false;
142 } else if (radio.checked) {
143 hasCurrent = true;
144 }
145 i++;
146 }
147 if (!hasCurrent) {
148 i = 0;
149 while (getAddressElement(i, 'pub') != null) {
150 var radio = getAddressElement(i, 'current');
151 var removed = getAddressElement(i, 'removed');
152 if (removed.value != "1") {
153 radio.checked= true;
154 return;
155 }
156 i++;
157 }
158 }
159}
160
161function removeAddress(id, pref)
162{
163 removeObject(id, pref);
164 checkCurrentAddress(null);
165 if (document.forms.prof_annu[pref + '[datemaj]'].value != '') {
166 document.getElementById(id + '_grayed').style.display = '';
167 }
168}
169
170function restoreAddress(id, pref)
171{
172 document.getElementById(id + '_grayed').style.display = 'none';
173 checkCurrentAddress(null);
174 restoreObject(id, pref);
175}
176
177function addAddress()
178{
179 var i = 0;
180 while (getAddressElement(i, 'pub') != null) {
181 i++;
182 }
183 $("#add_adr").before('<div id="addresses_' + i + '_cont"></div>');
184 Ajax.update_html('addresses_' + i + '_cont', 'profile/ajax/address/' + i, checkCurrentAddress);
185}
186
187function addTel(id)
188{
189 var i = 0;
190 var adid = 'addresses_' + id;
191 var tel = adid + '_tel_';
192 while (document.getElementById(tel + i) != null) {
193 i++;
194 }
195 $('#' + adid + '_add_tel').before('<div id="' + tel + i + '" style="clear: both"></div>');
196 Ajax.update_html(tel + i, 'profile/ajax/tel/' + id + '/' + i);
197}
198
199
200// Geoloc
201
202function validGeoloc(id, pref)
203{
204 document.getElementById(id + '_geoloc').style.display = 'none';
205 document.getElementById(id + '_geoloc_error').style.display = 'none';
206 document.getElementById(id + '_geoloc_valid').style.display = 'none';
207 document.forms.prof_annu[pref + "[parsevalid]"].value = "1";
208 document.forms.prof_annu[pref + "[text]"].value = document.forms.prof_annu[pref + "[geoloc]"].value;
af66b871 209 document.forms.prof_annu[pref + "[cityid]"].value = document.forms.prof_annu[pref + "[geoloc_cityid]"].value;
46ae38a9
FB
210 attachEvent(document.forms.prof_annu[pref + "[text]"], "click",
211 function() { document.forms.prof_annu[pref + "[text]"].blur(); });
212 document.forms.prof_annu[pref + "[text]"].className = '';
213}
214
215function validAddress(id, pref)
216{
217 document.getElementById(id + '_geoloc').style.display = 'none';
218 document.getElementById(id + '_geoloc_error').style.display = 'none';
219 document.getElementById(id + '_geoloc_valid').style.display = 'none';
af66b871 220 document.forms.prof_annu[pref + "[parsevalid]"].value = "1";
46ae38a9
FB
221 attachEvent(document.forms.prof_annu[pref + "[text]"], "click",
222 function() { document.forms.prof_annu[pref + "[text]"].blur(); });
223 document.forms.prof_annu[pref + "[text]"].className = '';
224}
225
226
227// Groups
228
229function updateGroup(type)
230{
231 var val = document.forms.prof_annu[type + '_sel'].value;
232 if (val == '0' || document.getElementById(type + '_' + val) != null) {
233 document.getElementById(type + '_add').style.display = 'none';
234 } else {
235 document.getElementById(type + '_add').style.display = '';
236 }
237}
238
239function removeGroup(cat, id)
240{
241 $('#' + cat + '_' + id).remove();
242 updateGroup(cat);
243}
244
245function addGroup(cat)
246{
247 var cb = document.forms.prof_annu[cat + '_sel'];
248 var id = cb.value;
249 var text = cb.options[cb.selectedIndex].text;
250 var html = '<tr id="' + cat + '_' + id + '">'
251 + ' <td>'
252 + ' <input type="hidden" name="' + cat + '[' + id + ']" value="' + text + '" />'
253 + ' </td>'
254 + ' <td>'
255 + ' <div style="float: left; width: 70%">'
256 + text
257 + ' </div>'
258 + ' <a href="javascript:removeGroup(\'' + cat + '\', ' + id + ')">'
259 + ' <img src="images/icons/cross.gif" alt="cross" title="Supprimer ce groupe" />'
260 + ' </a>'
261 + ' </td>'
262 + '</tr>';
263 $('#' + cat).after(html);
264 updateGroup(cat);
265}
266
267function updateGroupSubLink(cb)
268{
269 var href = cb.value ? cb.value : "http://www.polytechnique.net";
270 document.getElementById("groupesx_sub").href = href;
271}
272
273
274// Medals
275
276function updateMedal()
277{
278 var val = document.forms.prof_annu['medal_sel'].value;
279 if (val == '' || document.getElementById('medal_' + val) != null) {
280 document.getElementById('medal_add').style.display = 'none';
281 } else {
282 document.getElementById('medal_add').style.display = '';
283 }
284}
285
286function getMedalName(id)
287{
288 document.getElementById('medal_name_' + id).innerHTML = names[id];
289}
290
291function buildGrade(id, current)
292{
293 var grade;
294 var subg = subgrades[id];
295 var obj = $('#medal_grade_' + id);
296 if (!subg) {
297 obj.prepend('<input type="hidden" name="medals[' + id + '][grade]" value="0" />');
298 } else {
299 var html = 'Agrafe : <select name="medals[' + id + '][grade]">';
300 html += '<option value="0">Non précisée</option>';
301 for (grade = 0 ; grade < subg.length ; grade++) {
302 html += '<option value="' + subg[grade][0] + '"';
303 if (subg[grade][0] == current) {
304 html += ' selected="selected"';
305 }
306 html += '>' + subg[grade][1] + '</option>';
307 }
308
309 html += '</select>';
310 obj.prepend(html);
311 }
312}
313
314function makeAddProcess(id)
315{
316 return function(data)
317 {
318 $('#medals').after(data);
319 updateMedal();
320 getMedalName(id);
321 buildGrade(id, 0);
322 };
323}
324
325function addMedal()
326{
327 var id = document.forms.prof_annu['medal_sel'].value;
328 $.get(platal_baseurl + 'profile/ajax/medal/' + id, makeAddProcess(id));
329}
330
331function removeMedal(id)
332{
333 $("#medal_" + id).remove();
334 updateMedal();
335}
336
337
338// Jobs
339
340function removeJob(id, pref)
341{
342 document.getElementById(id + '_cont').style.display = 'none';
343 if (document.forms.prof_annu[pref + '[new]'].value == '0') {
344 document.getElementById(id + '_grayed').style.display = '';
345 document.getElementById(id + '_grayed_name').innerHTML =
346 document.forms.prof_annu[pref + "[name]"].value.replace('<', '&lt;');
347 }
348 document.forms.prof_annu[pref + "[removed]"].value = "1";
349}
350
351function restoreJob(id, pref)
352{
353 document.getElementById(id + '_cont').style.display = '';
354 document.getElementById(id + '_grayed').style.display = 'none';
355 document.forms.prof_annu[pref + "[removed]"].value = "0";
356}
357
358function updateJobSecteur(nb, id, pref, sel)
359{
360 var secteur = document.forms.prof_annu[pref + '[secteur]'].value;
361 if (secteur == '') {
362 secteur = '-1';
363 }
364 Ajax.update_html(id + '_ss_secteur', 'profile/ajax/secteur/' +nb + '/' + secteur + '/' + sel);
365}
366
367function makeAddJob(id)
368{
369 return function(data)
370 {
371 $('#add_job').before(data);
372 updateSecteur('job_' + id, 'jobs[' + id + ']', '');
373 };
374}
375
376function addJob()
377{
378 var i = 0;
379 while (document.getElementById('job_' + i) != null) {
380 ++i;
381 }
382 $.get(platal_baseurl + 'profile/ajax/job/' + i, makeAddJob(i));
383}
384
385
386// Skills
387
388function updateSkill(cat)
389{
390 var val = document.forms.prof_annu[cat + '_sel'].value;
391 var show = true;
392 if (val == '') {
393 show = false;
394 }
395 if (document.getElementById(cat + '_' + val) != null) {
396 show = false;
397 }
398 document.getElementById(cat + '_add').style.display = show ? '' : 'none';
399}
400
401function addSkill(cat)
402{
403 var sel = document.forms.prof_annu[cat + '_sel'];
404 var val = sel.value;
405 var text = sel.options[sel.selectedIndex].text;
406 $.get(platal_baseurl + 'profile/ajax/skill/' + cat + '/' + val,
407 function(data) {
408 $('#' + cat).append(data);
409 document.getElementById(cat + '_' + val + '_title').innerHTML = text;
410 updateSkill(cat);
411 });
412}
413
414function removeSkill(cat, id)
415{
416 $('#' + cat + '_' + id).remove();
417 updateSkill(cat);
418}
419
420
421// Mentor
422
423function updateCountry()
424{
425 var val = document.forms.prof_annu.countries_sel.value;
426 var show = true;
427 if (val == '') {
428 show = false;
429 }
430 if (document.getElementById('countries_' + val) != null) {
431 show = false;
432 }
433 document.getElementById('countries_add').style.display = show ? '' : 'none';
434}
435
436function addCountry()
437{
438 var cb = document.forms.prof_annu.countries_sel;
439 var val = cb.value;
440 var text = cb.options[cb.selectedIndex].text;
441 var html = '<div id="countries_' + val + '" style="clear: both; margin-bottom: 0.7em">'
442 + ' <div style="float: left; width: 50%">' + text + '</div>'
443 + ' <input type="hidden" name="countries[' + val + ']" value="' + text + '" />'
444 + ' <a href="javascript:removeCountry(\'' + val + '\')">'
445 + ' <img src="images/icons/cross.gif" alt="" title="Supprimer ce pays" />'
446 + ' </a>'
447 + '</div>';
448 $('#countries').append(html);
449 updateCountry();
450}
451
452function removeCountry(id)
453{
454 $('#countries_' + id).remove();
455 updateCountry();
456}
457function updateSSecteur()
458{
459 var s = document.forms.prof_annu.secteur_sel.value;
460 var ss = document.forms.prof_annu['jobs[-1][ss_secteur]'].value;
461 var show = true;
462 if (s == '' || ss == '') {
463 show = false;
464 }
465 if (document.getElementById('secteurs_' + s + '_' + ss) != null) {
466 show = false;
467 }
468 document.getElementById('secteurs_add').style.display = show ? 'block' : 'none';
469}
470
471function updateSecteur()
472{
473 var secteur = document.forms.prof_annu.secteur_sel.value;
474 if (secteur == '') {
475 secteur = '-1';
476 }
477 $.get(platal_baseurl + 'profile/ajax/secteur/-1/' + secteur,
478 function(data) {
479 data = '<a href="javascript:addSecteur()" style="display: none; float: right" id="secteurs_add">'
480 + ' <img src="images/icons/add.gif" alt="" title="Ajouter ce secteur" />'
481 + '</a>' + data;
482 document.getElementById('ss_secteur_sel').innerHTML = data;
483 attachEvent(document.forms.prof_annu['jobs[-1][ss_secteur]'], 'change', updateSSecteur);
484 });
485}
486
487function addSecteur()
488{
489 var scb = document.forms.prof_annu.secteur_sel;
490 var s = scb.value;
491 var st = scb.options[scb.selectedIndex].text;
492
493 var sscb = document.forms.prof_annu['jobs[-1][ss_secteur]'];
494 var ss = sscb.value;
495 var sst = sscb.options[sscb.selectedIndex].text;
496
497 var html = '<div id="secteurs_' + s + '_' + ss + '" style="clear: both; margin-top: 0.5em" class="titre">'
498 + ' <a href="javascript:removeSecteur(\'' + s + '\', \'' + ss + '\')" style="display: block; float: right">'
499 + ' <img src="images/icons/cross.gif" alt="" title="Supprimer ce secteur" />'
500 + ' </a>'
501 + ' <input type="hidden" name="secteurs[' + s + '][' + ss + ']" value="' + sst + '" />'
502 + ' ' + sst
503 + '</div>';
504 $('#secteurs').append(html);
505 updateSSecteur();
506}
507
508function removeSecteur(s, ss)
509{
510 $('#secteurs_' + s + '_' + ss).remove();
511 updateSSecteur();
512}
513
514// vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: