Typos.
[platal.git] / htdocs / javascript / profile.js
CommitLineData
46ae38a9 1/***************************************************************************
179afa7f 2 * Copyright (C) 2003-2008 Polytechnique.org *
46ae38a9
FB
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 }
933d9a4c 50 setTimeout('registerEnterpriseAutocomplete(-1)', 100);
46ae38a9
FB
51 break;
52 }
53}
54
55var applisType;
56var applisTypeAll;
57
58// General
59
60var subgrades;
61var names;
62function fillType(selectCtrl, appli, fill)
63{
64 var i;
65 var i0=0;
66
67 for (i = selectCtrl.options.length; i >=0; i--) {
68 selectCtrl.options[i] = null;
69 }
70
71 if (fill || appli <0) {
72 selectCtrl.options[0] = new Option(' ');
73 i0=1;
74 }
75 if (appli>=0)
76 for (i=0; i < applisType[appli].length; i++)
77 selectCtrl.options[i0+i] = new Option(applisType[appli][i]);
78 else if (fill)
79 for (i=0; i < applisTypeAll.length; i++)
80 selectCtrl.options[i0+i] = new Option(applisTypeAll[i]);
81}
82
83
84function selectType(selectCtrl, type)
85{
86 for (i = 0; i < selectCtrl.options.length; i++) {
87 if (selectCtrl.options[i].text == type)
88 selectCtrl.selectedIndex=i;
89 }
90}
91
92
93
94// Addresses
95
96function removeObject(id, pref)
97{
98 document.getElementById(id).style.display = "none";
99 document.forms.prof_annu[pref + "[removed]"].value = "1";
100}
101
102function restoreObject(id, pref)
103{
104 document.getElementById(id).style.display = '';
105 document.forms.prof_annu[pref + "[removed]"].value = "0";
106}
107
108function getAddressElement(adrid, adelement)
109{
110 return document.forms.prof_annu["addresses[" + adrid + "][" + adelement + "]"];
111}
112
113function checkCurrentAddress(newCurrent)
114{
115 var hasCurrent = false;
116 var i = 0;
117 while (getAddressElement(i, 'pub') != null) {
118 var radio = getAddressElement(i, 'current');
119 var removed = getAddressElement(i, 'removed');
120 if (removed.value == "1" && radio.checked) {
121 radio.checked = false;
122 } else if (radio.checked && radio != newCurrent) {
123 radio.checked = false;
124 } else if (radio.checked) {
125 hasCurrent = true;
126 }
127 i++;
128 }
129 if (!hasCurrent) {
130 i = 0;
131 while (getAddressElement(i, 'pub') != null) {
132 var radio = getAddressElement(i, 'current');
133 var removed = getAddressElement(i, 'removed');
134 if (removed.value != "1") {
135 radio.checked= true;
136 return;
137 }
138 i++;
139 }
140 }
141}
142
143function removeAddress(id, pref)
144{
145 removeObject(id, pref);
146 checkCurrentAddress(null);
147 if (document.forms.prof_annu[pref + '[datemaj]'].value != '') {
148 document.getElementById(id + '_grayed').style.display = '';
149 }
150}
151
152function restoreAddress(id, pref)
153{
154 document.getElementById(id + '_grayed').style.display = 'none';
155 checkCurrentAddress(null);
156 restoreObject(id, pref);
157}
158
159function addAddress()
160{
161 var i = 0;
162 while (getAddressElement(i, 'pub') != null) {
163 i++;
164 }
165 $("#add_adr").before('<div id="addresses_' + i + '_cont"></div>');
166 Ajax.update_html('addresses_' + i + '_cont', 'profile/ajax/address/' + i, checkCurrentAddress);
167}
168
169function addTel(id)
170{
171 var i = 0;
172 var adid = 'addresses_' + id;
173 var tel = adid + '_tel_';
174 while (document.getElementById(tel + i) != null) {
175 i++;
176 }
177 $('#' + adid + '_add_tel').before('<div id="' + tel + i + '" style="clear: both"></div>');
178 Ajax.update_html(tel + i, 'profile/ajax/tel/' + id + '/' + i);
179}
180
181
182// Geoloc
183
184function validGeoloc(id, pref)
185{
186 document.getElementById(id + '_geoloc').style.display = 'none';
187 document.getElementById(id + '_geoloc_error').style.display = 'none';
188 document.getElementById(id + '_geoloc_valid').style.display = 'none';
189 document.forms.prof_annu[pref + "[parsevalid]"].value = "1";
190 document.forms.prof_annu[pref + "[text]"].value = document.forms.prof_annu[pref + "[geoloc]"].value;
af66b871 191 document.forms.prof_annu[pref + "[cityid]"].value = document.forms.prof_annu[pref + "[geoloc_cityid]"].value;
8bcadd32 192 $(document.forms.prof_annu[pref + "[text]"]).click(function() { document.forms.prof_annu[pref + "[text]"].blur(); });
46ae38a9
FB
193 document.forms.prof_annu[pref + "[text]"].className = '';
194}
195
196function validAddress(id, pref)
197{
198 document.getElementById(id + '_geoloc').style.display = 'none';
199 document.getElementById(id + '_geoloc_error').style.display = 'none';
200 document.getElementById(id + '_geoloc_valid').style.display = 'none';
af66b871 201 document.forms.prof_annu[pref + "[parsevalid]"].value = "1";
8bcadd32 202 $(document.forms.prof_annu[pref + "[text]"]).click(function() { document.forms.prof_annu[pref + "[text]"].blur(); });
46ae38a9
FB
203 document.forms.prof_annu[pref + "[text]"].className = '';
204}
205
206
207// Groups
208
209function 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
219function removeGroup(cat, id)
220{
221 $('#' + cat + '_' + id).remove();
222 updateGroup(cat);
223}
224
225function 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
247function 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
256function 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
266function getMedalName(id)
267{
268 document.getElementById('medal_name_' + id).innerHTML = names[id];
269}
270
271function 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
294function makeAddProcess(id)
295{
296 return function(data)
297 {
298 $('#medals').after(data);
299 updateMedal();
300 getMedalName(id);
301 buildGrade(id, 0);
302 };
303}
304
305function addMedal()
306{
307 var id = document.forms.prof_annu['medal_sel'].value;
308 $.get(platal_baseurl + 'profile/ajax/medal/' + id, makeAddProcess(id));
309}
310
311function removeMedal(id)
312{
313 $("#medal_" + id).remove();
314 updateMedal();
315}
316
317
318// Jobs
319
320function 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('<', '&lt;');
327 }
328 document.forms.prof_annu[pref + "[removed]"].value = "1";
329}
330
331function 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
338function 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
347function makeAddJob(id)
348{
349 return function(data)
350 {
351 $('#add_job').before(data);
16594a1a 352 registerEnterpriseAutocomplete(id);
46ae38a9
FB
353 updateSecteur('job_' + id, 'jobs[' + id + ']', '');
354 };
355}
356
357function addJob()
358{
359 var i = 0;
360 while (document.getElementById('job_' + i) != null) {
361 ++i;
362 }
363 $.get(platal_baseurl + 'profile/ajax/job/' + i, makeAddJob(i));
364}
365
366
367// Skills
368
369function updateSkill(cat)
370{
371 var val = document.forms.prof_annu[cat + '_sel'].value;
372 var show = true;
373 if (val == '') {
374 show = false;
375 }
376 if (document.getElementById(cat + '_' + val) != null) {
377 show = false;
378 }
379 document.getElementById(cat + '_add').style.display = show ? '' : 'none';
380}
381
382function addSkill(cat)
383{
384 var sel = document.forms.prof_annu[cat + '_sel'];
385 var val = sel.value;
386 var text = sel.options[sel.selectedIndex].text;
387 $.get(platal_baseurl + 'profile/ajax/skill/' + cat + '/' + val,
388 function(data) {
389 $('#' + cat).append(data);
390 document.getElementById(cat + '_' + val + '_title').innerHTML = text;
391 updateSkill(cat);
392 });
393}
394
395function removeSkill(cat, id)
396{
397 $('#' + cat + '_' + id).remove();
398 updateSkill(cat);
399}
400
401
402// Mentor
403
404function updateCountry()
405{
406 var val = document.forms.prof_annu.countries_sel.value;
407 var show = true;
1d414e12 408 if (val == '' || val == '00') {
46ae38a9
FB
409 show = false;
410 }
411 if (document.getElementById('countries_' + val) != null) {
412 show = false;
413 }
414 document.getElementById('countries_add').style.display = show ? '' : 'none';
415}
416
417function addCountry()
418{
419 var cb = document.forms.prof_annu.countries_sel;
420 var val = cb.value;
421 var text = cb.options[cb.selectedIndex].text;
422 var html = '<div id="countries_' + val + '" style="clear: both; margin-bottom: 0.7em">'
1d414e12 423 + ' <a href="javascript:removeCountry(\'' + val + '\')" style="display: block; float:right">'
46ae38a9
FB
424 + ' <img src="images/icons/cross.gif" alt="" title="Supprimer ce pays" />'
425 + ' </a>'
1d414e12
PC
426 + ' <div style="float: left; width: 50%">' + text + '</div>'
427 + ' <input type="hidden" name="countries[' + val + ']" value="' + text + '" />'
46ae38a9
FB
428 + '</div>';
429 $('#countries').append(html);
430 updateCountry();
431}
432
433function removeCountry(id)
434{
435 $('#countries_' + id).remove();
436 updateCountry();
437}
438function updateSSecteur()
439{
440 var s = document.forms.prof_annu.secteur_sel.value;
441 var ss = document.forms.prof_annu['jobs[-1][ss_secteur]'].value;
442 var show = true;
443 if (s == '' || ss == '') {
444 show = false;
445 }
446 if (document.getElementById('secteurs_' + s + '_' + ss) != null) {
447 show = false;
448 }
449 document.getElementById('secteurs_add').style.display = show ? 'block' : 'none';
450}
451
452function updateSecteur()
453{
454 var secteur = document.forms.prof_annu.secteur_sel.value;
455 if (secteur == '') {
456 secteur = '-1';
76a2858c
PC
457 document.getElementById('ss_secteur_sel').innerHTML = '';
458 return;
46ae38a9
FB
459 }
460 $.get(platal_baseurl + 'profile/ajax/secteur/-1/' + secteur,
461 function(data) {
462 data = '<a href="javascript:addSecteur()" style="display: none; float: right" id="secteurs_add">'
463 + ' <img src="images/icons/add.gif" alt="" title="Ajouter ce secteur" />'
464 + '</a>' + data;
465 document.getElementById('ss_secteur_sel').innerHTML = data;
e9d26809 466 $(document.forms.prof_annu['jobs[-1][ss_secteur]']).change(updateSSecteur);
46ae38a9
FB
467 });
468}
469
470function addSecteur()
471{
472 var scb = document.forms.prof_annu.secteur_sel;
473 var s = scb.value;
474 var st = scb.options[scb.selectedIndex].text;
475
476 var sscb = document.forms.prof_annu['jobs[-1][ss_secteur]'];
477 var ss = sscb.value;
478 var sst = sscb.options[sscb.selectedIndex].text;
479
480 var html = '<div id="secteurs_' + s + '_' + ss + '" style="clear: both; margin-top: 0.5em" class="titre">'
481 + ' <a href="javascript:removeSecteur(\'' + s + '\', \'' + ss + '\')" style="display: block; float: right">'
482 + ' <img src="images/icons/cross.gif" alt="" title="Supprimer ce secteur" />'
483 + ' </a>'
484 + ' <input type="hidden" name="secteurs[' + s + '][' + ss + ']" value="' + sst + '" />'
485 + ' ' + sst
486 + '</div>';
487 $('#secteurs').append(html);
488 updateSSecteur();
489}
490
491function removeSecteur(s, ss)
492{
493 $('#secteurs_' + s + '_' + ss).remove();
494 updateSSecteur();
495}
496
16594a1a
FB
497function registerEnterpriseAutocomplete(id)
498{
16594a1a
FB
499 $(".enterprise_name").each(
500 function() {
16594a1a
FB
501 if (id == -1 || this.name == "jobs[" + id + "][name]") {
502 $(this).autocomplete(platal_baseurl + "search/autocomplete/entreprise",
503 {
504 selectOnly:1,
505 field:this.name,
506 matchSubset:0,
507 width:$(this).width()
508 });
509 }
510 }
511 );
512}
513
46ae38a9 514// vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: