217658bc30593364df59e695d3c3038bd73e1f0e
1 /***************************************************************************
2 * Copyright (C) 2003-2010 Polytechnique.org *
3 * http://opensource.polytechnique.org/ *
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. *
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. *
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 *
18 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
19 ***************************************************************************/
21 // Page initialization {{{1
23 function wizPage_onLoad(id
)
28 while ($('.edu_' + i
).length
!= 0) {
34 checkCurrentAddress();
40 for (var i
in names
) {
41 if ($('#medal_' + i
).length
!= 0) {
43 buildGrade(i
, $('#medal_' + i
).find('[name*=medal_' + i
+ '_grade]').val());
48 for (var i
= 0 ; $('#job_' + i
).length
!= 0; ++i
) {
49 updateJobSector(i
, $('#job_' + i
).find("[name='jobs[" + i
+ "][subSector]']").val());
50 updateJobSubSector(i
, $('#job_' + i
).find("[name='jobs[" + i
+ "][subSubSector]']").val());
51 updateJobAlternates(i
);
58 var educationDegreeAll
;
59 var educationDegreeName
;
65 function toggleNamesAdvanced()
67 $('.names_advanced').toggle();
70 function addSearchName(isFemale
)
73 while ($('#search_name_' + i
).length
!= 0) {
76 Ajax
.update_html('search_name_' + i
, 'profile/ajax/searchname/' + i + '/' + isFemale
, function(data
){
77 $('#searchname').before(data
);
82 function removeSearchName(i
, isFemale
)
84 $('#search_name_' + i
).remove();
85 updateNameDisplay(isFemale
);
88 function changeNameFlag(i
)
90 $('#flag_' + i
).remove();
91 var typeid
= $('#search_name_' + i
).find('select').val();
92 var type
= $('#search_name_' + i
).find('select :selected').text();
93 if ($('[name=sn_type_' + typeid
+ '_' + i
+ ']').val() > 0) {
94 $('#flag_cb_' + i
).after('<span id="flag_' + i
+ '"> ' +
95 '<img src="images/icons/flag_green.gif" alt="site public" title="site public" />' +
96 '<input type="hidden" name="search_names[' + i
+ '][pub]" value="1"/>' +
97 '<input type="hidden" name="search_names[' + i
+ '][typeid]" value="' + typeid
+ '"/>' +
98 '<input type="hidden" name="search_names[' + i
+ '][type]" value="' + type
+ '"/></span>');
100 $('#flag_cb_' + i
).after('<span id="flag_' + i
+ '"> ' +
101 '<img src="images/icons/flag_red.gif" alt="site privé" title="site privé" />' +
102 '<input type="hidden" name="search_names[' + i
+ '][typeid]" value="' + typeid
+ '"/>' +
103 '<input type="hidden" name="search_names[' + i
+ '][type]" value="' + type
+ '"/></span>');
107 function updateNameDisplay(isFemale
)
109 var searchnames
= '';
110 for (var i
= 0; i
< 10; i
++) {
111 if ($('#search_name_' + i
).find(':text').val()) {
112 searchnames
+= $('#search_name_' + i
).find('[name*=typeid]').val() + ';';
113 searchnames
+= $('#search_name_' + i
).find(':text').val() + ';;';
116 Ajax
.update_html(null, 'profile/ajax/buildnames/' + searchnames + '/' + isFemale
, function(data
){
117 var name
= data
.split(';');
118 $('#public_name').html(name
[0]);
119 $('#private_name').html(name
[0] + name
[1]);
123 function toggleParticle(id
)
125 if ($('#search_name_' + id
).find("[name*='[particle]']").val() == '') {
126 $('#search_name_' + id
).find("[name*='[particle]']").val(1);
128 $('#search_name_' + id
).find("[name*='[particle]']").val('');
134 function togglePromotionEdition()
136 $(".promotion_edition").toggle();
139 // Nationalities {{{1
141 function delNationality(i
)
143 $('#nationality' + i
).hide().find('select').val('');
146 function addNationality()
149 if ($('#nationality2').find('select').val() == "") {
151 } else if ($('#nationality3').find('select').val() == "") {
154 if ((i
== 2) || (i
== 3)) {
155 $('#nationality' + i
).show();
161 function prepareType(id
)
163 var edu
= $('.edu_' + id
).find("[name='edus[" + id
+ "][eduid]']").val() - 1;
164 var sel
= $('.edu_' + id
).find('[name=edu_' + id
+ '_tmp]').val();
166 var length
= educationDegree
[edu
].length
;
167 for (i
= 0; i
< length
; ++i
) {
168 html
+= '<option value="' + educationDegree
[edu
][i
] + '"';
169 if (sel
== educationDegree
[edu
][i
]) {
170 html
+= ' selected="selected"';
172 html
+= '>' + educationDegreeName
[educationDegree
[edu
][i
] - 1] + '</option>';
174 $('.edu_' + id
).find("[name='edus[" + id
+ "][degreeid]']").html(html
);
184 while (!$('#edu_add').hasClass(prefix
+ i
)) {
185 if ($('.' + prefix
+ i
).length
!= 0) {
191 class_parity
= 'pair';
193 class_parity
= 'impair';
195 $('#edu_add').removeClass(prefix
+ i
);
197 $('#edu_add').addClass(prefix
+ i
);
199 $.get(platal_baseurl
+ 'profile/ajax/edu/' + i + '/' + class_parity
,
201 $('#edu_add').before(data
);
206 function removeEdu(i
)
209 $('.' + prefix
+ i
).remove();
210 while (!$('#edu_add').hasClass(prefix
+ i
)) {
211 $('.' + prefix
+ i
).toggleClass('pair');
212 $('.' + prefix
+ i
).toggleClass('impair');
219 function addNetworking()
222 while ($('#networking_' + i
).length
!= 0) {
226 var html
= '<tr id="networking_' + i
+ '">'
227 + ' <td colspan="2">'
228 + ' <div style="float: left; width: 200px;">'
229 + ' <span class="flags">'
230 + ' <input type="checkbox" name="networking[' + i
+ '][pub]"/>'
231 + ' <img src="images/icons/flag_green.gif" alt="site public" title="site public">'
233 + ' <select name="networking[' + i
+ '][type]" onchange="javascript:updateNetworking(' + i
+ ');">';
234 for (nw
in nw_list
) {
235 if (namefirst
== '') {
238 html
+= ' <option value="' + nw_list
[nw
] + '">' + nw
+ '</option>';
241 + ' <input type="hidden" name="networking[' + i
+ '][name]" value="' + namefirst
+ '"/>'
243 + ' <div style="float: left">'
244 + ' <input type="text" name="networking[' + i
+ '][address]" value="" size="30"/>'
245 + ' <a href="javascript:removeNetworking(' + i
+ ')">'
246 + ' <img src="images/icons/cross.gif" alt="cross" title="Supprimer cet élément"/>'
252 $('#networking').before(html
);
255 function removeNetworking(id
)
257 $('#networking_' + id
).remove();
260 function updateNetworking(i
)
262 $('#networking_' + i
).find("[name='networking[" + i
+ "][name]']").val($('#networking_' + i
).find('select option:selected').text());
267 function toggleAddress(id
, val
)
269 $('#addresses_' + id
+ '_grayed').toggle();
270 $('#addresses_' + id
).toggle();
271 $('#addresses_' + id
+ '_cont').find('[name*=removed]').val(val
);
272 checkCurrentAddress();
275 function checkCurrentAddress(id
)
277 var hasCurrentAddress
= id
? true : false;
279 while ($('#addresses_' + i
+ '_cont').length
!= 0) {
280 if ($('#addresses_' + i
+ '_cont').find('[name*=removed]').val() == 1) {
281 $('#addresses_' + i
+ '_cont').find('[name*=current]').attr('checked', false);
283 if (!hasCurrentAddress
&& $('#addresses_' + i
+ '_cont').find('[name*=current]:checked').length
!= 0) {
284 hasCurrentAddress
= true;
286 $('#addresses_' + i
+ '_cont').find('[name*=current]').attr('checked', false);
290 if (!hasCurrentAddress
) {
292 while ($('#addresses_' + i
+ '_cont').length
!= 0) {
293 if ($('#addresses_' + i
+ '_cont').find('[name*=removed]').val() == 0) {
294 $('#addresses_' + i
+ '_cont').find('[name*=current]').attr('checked', 'checked');
301 $('#addresses_' + id
+ '_cont').find('[name*=current]').attr('checked', 'checked');
305 function addAddress()
308 while ($('#addresses_' + i
+ '_cont').length
!= 0) {
311 $('#add_address').before('<div id="addresses_' + i
+ '_cont"></div>');
312 Ajax
.update_html('addresses_' + i
+ '_cont', 'profile/ajax/address/' + i
, checkCurrentAddress());
315 function addressChanged(prefid
)
317 $('#' + prefid
+ '_cont').find('[name*=changed]').val("1");
320 function validGeoloc(prefid
, id
, geoloc
)
323 $('#' + prefid
+ '_cont').find('[name*=text]').val($('#' + prefid
+ '_cont').find('[name*=geoloc]').val());
324 $('#' + prefid
+ '_cont').find('[name*=postalText]').val($('#' + prefid
+ '_cont').find('[name*=geocodedPostalText]').val());
327 $('#' + prefid
+ '_cont').find("[name*='[geoloc]']").remove();
329 $('#' + prefid
+ '_cont').find('[name*=text]').removeClass('error');
330 $('#' + prefid
+ '_cont').find('[name*=geoloc_choice]').val(geoloc
);
331 $('.' + prefid
+ '_geoloc').remove();
336 function addTel(prefid
, prefname
)
339 var prefix
= prefid
+ '_';
340 while ($('#' + prefix
+ i
).length
!= 0) {
343 $('#' + prefix
+ 'add').before('<div id="' + prefix
+ i
+ '" style="clear: both; padding-top: 4px; padding-bottom: 4px"></div>');
344 Ajax
.update_html(prefix
+ i
, 'profile/ajax/tel/' + prefid + '/' + prefname
+ '/' + i
);
347 function removeTel(prefname
, prefid
, id
)
350 while ($('#' + prefid
+ '_' + total
).length
!= 0) {
353 $('#' + prefid
+ '_' + id
).remove();
354 for (var i
= parseInt(id
) + 1; i
< total
; ++i
) {
355 renumberPhone(prefname
, prefid
, i
);
359 function addPhoneComment(id
)
361 $('#' + id
+ '_comment').show();
362 $('#' + id
+ '_addComment').hide();
365 function removePhoneComment(id
, pref
)
367 $('#' + id
+ '_comment').hide();
368 $('#' + id
+ '_comment').find("[name='" + pref
+ "[comment]']").val('');
369 $('#' + id
+ '_addComment').show();
372 function renumberPhone(prefname
, prefid
, i
)
375 var telprefOld
= prefname
+ '[' + i
+ ']';
376 var telpref
= prefname
+ '[' + telid
+ ']';
377 var idOld
= prefid
+ '_' + i
;
378 var id
= prefid
+ '_' + telid
;
380 $('#' + idOld
).attr('id', id
);
381 $('#' + id
).find('div.titre').html('N°' + i
);
382 $('#' + id
).find('a.removeTel').attr('href', 'javascript:removeTel(\'' + prefname
+ '\',\'' + prefid
+ '\',' + telid
+ ')');
383 $('#' + id
).find('select').attr('name', telpref
+ '[type]');
384 $('#' + id
).find("[name='" + telprefOld
+ "[tel]']").attr('name', telpref
+ '[tel]');
385 $('#' + id
).find("[name='" + telprefOld
+ "[comment]']").attr('name', telpref
+ '[comment]');
386 $('#' + id
).find('a.removePhoneComment').attr('href', 'javascript:removePhoneComment(' + id
+ ',' + telpref
+ ')');
387 $('#' + id
).find('#' + idOld
+ '_addComment').attr('id', id
+ '_addComment');
388 $('#' + id
).find('#' + id
+ '_addComment').attr('href', 'javascript:addPhoneComment(' + id
+ ')');
389 $('#' + id
).find('#' + idOld
+ '_comment').attr('id', id
+ '_comment');
390 $('#' + id
).find("[name='" + telprefOld
+ "[pub]']").attr('name', telpref
+ '[pub]');
397 var id
= $('#binets_table').find('[name=binets_sel]').val();
398 var text
= $('#binets_table').find('select option:selected').text();
399 var html
= '<tr id="binets_' + id
+ '">'
401 + ' <input type="hidden" name="binets[' + id
+ ']" value="' + text
+ '" />'
404 + ' <div style="float: left; width: 70%">'
407 + ' <a href="javascript:removeElement(\'binets\',' + id
+ ')">'
408 + ' <img src="images/icons/cross.gif" alt="cross" title="Supprimer ce groupe" />'
412 $('#binets_table').after(html
);
413 updateElement('binets');
416 function updateGroupSubLink()
418 var href
= $('[name*=groupesx_sub]').val() ? $('[name*=groupesx_sub]').val() : 'http://www.polytechnique.net';
419 $('#groupesx_sub').attr('href', href
);
424 function updateMedal()
426 var val
= $('#medals').find('[name*=medal_sel]').val();
427 if (val
&& ($('#medal_' + val
).length
== 0)) {
428 $('#medal_add').show();
430 $('#medal_add').hide();
434 function getMedalName(id
)
436 $('#medal_name_' + id
).html(names
[id
]);
439 function buildGrade(id
, current
)
442 var subg
= subgrades
[id
];
443 var obj
= $('#medal_grade_' + id
);
445 obj
.prepend('<input type="hidden" name="medals[' + id
+ '][grade]" value="0" />');
447 var html
= 'Agrafe : <select name="medals[' + id
+ '][grade]">';
448 html
+= '<option value="0">Non précisée</option>';
449 for (grade
= 0 ; grade
< subg
.length
; grade
++) {
450 html
+= '<option value="' + subg
[grade
][0] + '"';
451 if (subg
[grade
][0] == current
) {
452 html
+= ' selected="selected"';
454 html
+= '>' + subg
[grade
][1] + '</option>';
462 function makeAddProcess(id
)
464 return function(data
)
466 $('#medals').after(data
);
475 var id
= $('#medals').find('[name=medal_sel]').val();
476 $.get(platal_baseurl
+ 'profile/ajax/medal/' + id
, makeAddProcess(id
));
479 function removeMedal(id
)
481 $("#medal_" + id
).remove();
487 function removeJob(id
, pref
)
489 $('#' + id
+ '_cont').hide();
490 if ($('#' + id
).find("[name='" + pref
+ "[new]']").val() == '0') {
491 $('#' + id
+ '_grayed').show();
492 $('#' + id
+ '_grayed_name').html($('#' + id
).find("[name='" + pref
+ "[name]']").val());
494 $('#' + id
).find("[name='" + pref
+ "[removed]']").val('1');
497 function restoreJob(id
, pref
)
499 $('#' + id
+ '_cont').show();
500 $('#' + id
+ '_grayed').hide();
501 $('#' + id
).find("[name='" + pref
+ "[removed]']").val('0');
504 function updateJobSector(id
, sel
)
506 var sector
= $('#job_' + id
).find("[name='jobs[" + id
+ "][sector]']").val();
510 Ajax
.update_html('job_' + id
+ '_subSector', 'profile/ajax/sector/' + id + '/job_' + id
+ '/jobs[' + id + ']/' + sector
+ '/' + sel
);
513 function updateJobSubSector(id
, sel
)
515 var subSector
= $('#job_' + id
).find("[name='jobs[" + id
+ "][subSector]']").val();
516 if (subSector
== '') {
519 Ajax
.update_html('job_' + id
+ '_subSubSector', 'profile/ajax/sub_sector/' + id + '/' + subSector
+ '/' + sel
);
522 function updateJobAlternates(id
)
524 var subSubSector
= $('#job_' + id
).find("[name='jobs[" + id
+ "][subSubSector]']").val();
525 if (subSubSector
!= '') {
526 Ajax
.update_html('job_' + id
+ '_alternates', 'profile/ajax/alternates/' + id + '/' + subSubSector
);
530 function emptyJobSubSector(id
)
532 Ajax
.update_html('job_' + id
+ '_subSubSector', 'profile/ajax/sub_sector/' + id + '/-1/-1');
535 function emptyJobAlternates(id
)
537 Ajax
.update_html('job_' + id
+ '_alternates', 'profile/ajax/alternates/' + id + '/-1');
540 function displayAllSector(id
)
542 $('.sector_text_' + id
).remove();
543 $('.sector_' + id
).show();
546 function makeAddJob(id
)
548 return function(data
)
550 $('#add_job').before(data
);
551 registerEnterpriseAutocomplete(id
);
558 while ($('#job_' + i
).length
!= 0) {
561 $.get(platal_baseurl
+ 'profile/ajax/job/' + i
, makeAddJob(i
));
564 function addEntreprise(id
)
566 $('.entreprise_' + id
).toggle();
571 function addSkill(cat
)
573 var val
= $('#' + cat
+ '_table').find('[name=' + cat
+ '_sel]').val();
574 var text
= $('#' + cat
+ '_table').find('[name=' + cat
+ '_sel] :selected').text();
575 $.get(platal_baseurl
+ 'profile/ajax/skill/' + cat + '/' + val
,
577 $('#' + cat
).append(data
);
578 $('#' + cat
+ '_' + val
+ '_title').text(text
);
585 function addCountry()
587 var val
= $('#countries_table').find('[name=countries_sel] :selected').val();
588 var text
= $('#countries_table').find('[name=countries_sel] :selected').text();
589 var html
= '<div id="countries_' + val
+ '" style="clear: both; margin-bottom: 0.7em">'
590 + ' <a href="javascript:removeElement(\'countries\',\'' + val
+ '\')" style="display: block; float:right">'
591 + ' <img src="images/icons/cross.gif" alt="" title="Supprimer ce pays" />'
593 + ' <div style="float: left; width: 50%">' + text
+ '</div>'
594 + ' <input type="hidden" name="countries[' + val
+ ']" value="' + text
+ '" />'
596 $('#countries').append(html
);
597 updateElement('countries');
600 function updateSubSector()
602 var s
= $('#sectorSelection').find('[name=sectorSelection]').val();
603 var ss
= $('#subSectorSelection').find("[name='jobs[-1][subSector]']").val();
604 if ((s
== '' || ss
== '') || $('#sectors_' + s
+ '_' + ss
).length
!= 0) {
605 $('#addSector').hide();
607 $('#addSector').show();
611 function removeSector(s
, ss
)
613 $('#sectors_' + s
+ '_' + ss
).remove();
617 function updateSector()
619 var sector
= $('#sectorSelection').find('[name=sectorSelection]').val();
622 $('#subSectorSelection').html('');
625 $.get(platal_baseurl
+ 'profile/ajax/sector/-1/0/0/' + sector
,
627 data
= '<a href="javascript:addSector()" style="display: none; float: right" id="addSector">'
628 + ' <img src="images/icons/add.gif" alt="Ajouter ce secteur" title="Ajouter ce secteur" />'
630 $('#subSectorSelection').html(data
);
631 $('#subSectorSelection').find("[name='jobs[-1][subSector]']").change(updateSubSector
);
637 var s
= $('#sectorSelection').find('[name=sectorSelection]').val();
638 var ss
= $('#subSectorSelection').find("[name='jobs[-1][subSector]']").val();
639 var sst
= $('#subSectorSelection').find("[name='jobs[-1][subSector]'] :selected").text();
641 var html
= '<div id="sectors_' + s
+ '_' + ss
+ '" style="clear: both; margin-top: 0.5em" class="titre">'
642 + ' <a href="javascript:removeSector(\'' + s
+ '\',\'' + ss
+ '\')" style="display: block; float: right">'
643 + ' <img src="images/icons/cross.gif" alt="" title="Supprimer ce secteur" />'
645 + ' <input type="hidden" name="sectors[' + s
+ '][' + ss
+ ']" value="' + sst
+ '" />'
648 $('#sectors').append(html
);
652 function registerEnterpriseAutocomplete(id
)
654 $(".enterpriseName").each(
656 if (id
== -1 || this.name
== "jobs[" + id
+ "][name]") {
657 $(this).autocomplete(platal_baseurl
+ "search/autocomplete/entreprise",
662 width
:$(this).width()
667 $(".sectorName").each(
669 if (id
== -1 || this.name
== "jobs[" + id
+ "][subSubSectorName]") {
670 $(this).autocomplete(platal_baseurl
+ "search/autocomplete/subSubSector",
675 width
:$(this).width()
681 // {{{1 Multiusage functions
683 function updateElement(cat
)
685 var val
= $('#' + cat
+ '_table').find('[name=' + cat
+ '_sel]').val();
686 if (val
== '' || $('#' + cat
+ '_' + val
).length
!= 0) {
687 $('#' + cat
+ '_add').hide();
689 $('#' + cat
+ '_add').show();
693 function removeElement(cat
, id
)
695 $('#' + cat
+ '_' + id
).remove();
699 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: