fbf4063584c5473246f5585a3cad5d143842704a
1 /***************************************************************************
2 * Copyright (C) 2003-2009 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());
57 var educationDegreeAll
;
58 var educationDegreeName
;
64 function toggleNamesAdvanced()
66 $('.names_advanced').toggle();
69 function addSearchName()
72 while ($('#search_name_' + i
).length
!= 0) {
75 Ajax
.update_html('search_name_' + i
, 'profile/ajax/searchname/' + i
, function(data
){
76 $('#searchname').before(data
);
81 function removeSearchName(i
)
83 $('#search_name_' + i
).remove();
87 function changeNameFlag(i
)
89 $('#flag_' + i
).remove();
90 var typeid
= $('#search_name_' + i
).find('select').val();
91 var type
= $('#search_name_' + i
).find('select :selected').text();
92 if ($('[name=sn_type_' + typeid
+ '_' + i
+ ']').val() > 0) {
93 $('#flag_cb_' + i
).after('<span id="flag_' + i
+ '"> ' +
94 '<img src="images/icons/flag_green.gif" alt="site public" title="site public" />' +
95 '<input type="hidden" name="search_names[' + i
+ '][pub]" value="1"/>' +
96 '<input type="hidden" name="search_names[' + i
+ '][typeid]" value="' + typeid
+ '"/>' +
97 '<input type="hidden" name="search_names[' + i
+ '][type]" value="' + type
+ '"/></span>');
99 $('#flag_cb_' + i
).after('<span id="flag_' + i
+ '"> ' +
100 '<img src="images/icons/flag_red.gif" alt="site privé" title="site privé" />' +
101 '<input type="hidden" name="search_names[' + i
+ '][typeid]" value="' + typeid
+ '"/>' +
102 '<input type="hidden" name="search_names[' + i
+ '][type]" value="' + type
+ '"/></span>');
106 function updateNameDisplay()
108 var searchnames
= '';
109 for (var i
= 0; i
< 10; i
++) {
110 if ($('#search_name_' + i
).find(':text').val()) {
111 searchnames
+= $('#search_name_' + i
).find('[name*=typeid]').val() + ';';
112 searchnames
+= $('#search_name_' + i
).find(':text').val() + ';;';
115 Ajax
.update_html(null, 'profile/ajax/buildnames/' + searchnames
, function(data
){
116 var name
= data
.split(';');
117 $('#public_name').html(name
[0]);
118 $('#private_name').html(name
[0] + name
[1]);
122 // Nationalities {{{1
124 function delNationality(i
)
126 $('#nationalite' + i
).hide().find('select').val('');
129 function addNationality()
132 if ($('#nationalite2').find('select').val() == "") {
134 } else if ($('#nationalite3').find('select').val() == "") {
137 if ((i
== 2) || (i
== 3)) {
138 $('#nationalite' + i
).show();
144 function prepareType(id
)
146 var edu
= $('.edu_' + id
).find("[name='edus[" + id
+ "][eduid]']").val() - 1;
147 var sel
= $('.edu_' + id
).find('[name=edu_' + id
+ '_tmp]').val();
149 var length
= educationDegree
[edu
].length
;
150 for (i
= 0; i
< length
; ++i
) {
151 html
+= '<option value="' + educationDegree
[edu
][i
] + '"';
152 if (sel
== educationDegree
[edu
][i
]) {
153 html
+= ' selected="selected"';
155 html
+= '>' + educationDegreeName
[educationDegree
[edu
][i
] - 1] + '</option>';
157 $('.edu_' + id
).find("[name='edus[" + id
+ "][degreeid]']").html(html
);
167 while (!$('#edu_add').hasClass(prefix
+ i
)) {
168 if ($('.' + prefix
+ i
).length
!= 0) {
174 class_parity
= 'pair';
176 class_parity
= 'impair';
178 $('#edu_add').removeClass(prefix
+ i
);
180 $('#edu_add').addClass(prefix
+ i
);
182 $.get(platal_baseurl
+ 'profile/ajax/edu/' + i + '/' + class_parity
,
184 $('#edu_add').before(data
);
189 function removeEdu(i
)
192 $('.' + prefix
+ i
).remove();
193 while (!$('#edu_add').hasClass(prefix
+ i
)) {
194 $('.' + prefix
+ i
).toggleClass('pair');
195 $('.' + prefix
+ i
).toggleClass('impair');
202 function addNetworking()
205 while ($('#networking_' + i
).length
!= 0) {
209 var html
= '<tr id="networking_' + i
+ '">'
210 + ' <td colspan="2">'
211 + ' <div style="float: left; width: 200px;">'
212 + ' <span class="flags">'
213 + ' <input type="checkbox" name="networking[' + i
+ '][pub]"/>'
214 + ' <img src="images/icons/flag_green.gif" alt="site public" title="site public">'
216 + ' <select name="networking[' + i
+ '][type]" onchange="javascript:updateNetworking(' + i
+ ');">';
217 for (nw
in nw_list
) {
218 if (namefirst
== '') {
221 html
+= ' <option value="' + nw_list
[nw
] + '">' + nw
+ '</option>';
224 + ' <input type="hidden" name="networking[' + i
+ '][name]" value="' + namefirst
+ '"/>'
226 + ' <div style="float: left">'
227 + ' <input type="text" name="networking[' + i
+ '][address]" value="" size="30"/>'
228 + ' <a href="javascript:removeNetworking(' + i
+ ')">'
229 + ' <img src="images/icons/cross.gif" alt="cross" title="Supprimer cet élément"/>'
235 $('#networking').before(html
);
238 function removeNetworking(id
)
240 $('#networking_' + id
).remove();
243 function updateNetworking(i
)
245 $('#networking_' + i
).find("[name='networking[" + i
+ "][name]']").val($('#networking_' + i
).find('select option:selected').text());
250 function toggleAddress(id
, val
)
252 $('#addresses_' + id
+ '_grayed').toggle();
253 $('#addresses_' + id
).toggle();
254 $('#addresses_' + id
+ '_cont').find('[name*=removed]').val(val
);
255 checkCurrentAddress();
258 function checkCurrentAddress(id
)
260 var hasCurrentAddress
= id
? true : false;
262 while ($('#addresses_' + i
+ '_cont').length
!= 0) {
263 if ($('#addresses_' + i
+ '_cont').find('[name*=removed]').val() == 1) {
264 $('#addresses_' + i
+ '_cont').find('[name*=current]').attr('checked', false);
266 if (!hasCurrentAddress
&& $('#addresses_' + i
+ '_cont').find('[name*=current]:checked').length
!= 0) {
267 hasCurrentAddress
= true;
269 $('#addresses_' + i
+ '_cont').find('[name*=current]').attr('checked', false);
273 if (!hasCurrentAddress
) {
275 while ($('#addresses_' + i
+ '_cont').length
!= 0) {
276 if ($('#addresses_' + i
+ '_cont').find('[name*=removed]').val() == 0) {
277 $('#addresses_' + i
+ '_cont').find('[name*=current]').attr('checked', 'checked');
284 $('#addresses_' + id
+ '_cont').find('[name*=current]').attr('checked', 'checked');
288 function addAddress()
291 while ($('#addresses_' + i
+ '_cont').length
!= 0) {
294 $('#add_address').before('<div id="addresses_' + i
+ '_cont"></div>');
295 Ajax
.update_html('addresses_' + i
+ '_cont', 'profile/ajax/address/' + i
, checkCurrentAddress());
298 function addressChanged(prefid
)
300 $('#' + prefid
+ '_cont').find('[name*=changed]').val("1");
303 function validGeoloc(prefid
, id
, geoloc
)
306 $('#' + prefid
+ '_cont').find('[name*=text]').val($('#' + prefid
+ '_cont').find('[name*=geoloc]').val());
307 $('#' + prefid
+ '_cont').find('[name*=postalText]').val($('#' + prefid
+ '_cont').find('[name*=geocodedPostalText]').val());
310 $('#' + prefid
+ '_cont').find("[name*='[geoloc]']").remove();
312 $('#' + prefid
+ '_cont').find('[name*=text]').removeClass('error');
313 $('#' + prefid
+ '_cont').find('[name*=geoloc_choice]').val(geoloc
);
314 $('.' + prefid
+ '_geoloc').remove();
319 function addTel(prefid
, prefname
)
322 var prefix
= prefid
+ '_';
323 while ($('#' + prefix
+ i
).length
!= 0) {
326 $('#' + prefix
+ 'add').before('<div id="' + prefix
+ i
+ '" style="clear: both; padding-top: 4px; padding-bottom: 4px"></div>');
327 Ajax
.update_html(prefix
+ i
, 'profile/ajax/tel/' + prefid + '/' + prefname
+ '/' + i
);
330 function removeTel(id
)
332 $('#' + id
).remove();
335 function addPhoneComment(id
)
337 $(id
+ '_comment').show();
338 $(id
+ '_addComment').hide();
341 function removePhoneComment(id
, pref
)
343 $(id
+ '_comment').hide();
344 $(id
+ '_comment').find("[name='" + pref
+ "[comment]']").val('');
345 $(id
+ '_addComment').show();
352 var id
= $('#binets_table').find('[name=binets_sel]').val();
353 var text
= $('#binets_table').find('select option:selected').text();
354 var html
= '<tr id="binets_' + id
+ '">'
356 + ' <input type="hidden" name="binets[' + id
+ ']" value="' + text
+ '" />'
359 + ' <div style="float: left; width: 70%">'
362 + ' <a href="javascript:removeElement(\'binets\', ' + id
+ ')">'
363 + ' <img src="images/icons/cross.gif" alt="cross" title="Supprimer ce groupe" />'
367 $('#binets_table').after(html
);
368 updateElement('binets');
371 function updateGroupSubLink()
373 var href
= $('[name*=groupesx_sub]').val() ? $('[name*=groupesx_sub]').val() : 'http://www.polytechnique.net';
374 $('#groupesx_sub').attr('href', href
);
379 function updateMedal()
381 var val
= $('#medals').find('[name*=medal_sel]').val();
382 if (val
&& ($('#medal_' + val
).length
== 0)) {
383 $('#medal_add').show();
385 $('#medal_add').hide();
389 function getMedalName(id
)
391 $('#medal_name_' + id
).html(names
[id
]);
394 function buildGrade(id
, current
)
397 var subg
= subgrades
[id
];
398 var obj
= $('#medal_grade_' + id
);
400 obj
.prepend('<input type="hidden" name="medals[' + id
+ '][grade]" value="0" />');
402 var html
= 'Agrafe : <select name="medals[' + id
+ '][grade]">';
403 html
+= '<option value="0">Non précisée</option>';
404 for (grade
= 0 ; grade
< subg
.length
; grade
++) {
405 html
+= '<option value="' + subg
[grade
][0] + '"';
406 if (subg
[grade
][0] == current
) {
407 html
+= ' selected="selected"';
409 html
+= '>' + subg
[grade
][1] + '</option>';
417 function makeAddProcess(id
)
419 return function(data
)
421 $('#medals').after(data
);
430 var id
= $('#medals').find('[name=medal_sel]').val();
431 $.get(platal_baseurl
+ 'profile/ajax/medal/' + id
, makeAddProcess(id
));
434 function removeMedal(id
)
436 $("#medal_" + id
).remove();
442 function removeJob(id
, pref
)
444 $('#' + id
+ '_cont').hide();
445 if ($('#' + id
).find("[name='" + id
+ "[new]']").val() == '0') {
446 $('#' + id
+ '_grayed').show();
447 $('#' + id
+ '_grayed_name').html($('#' + id
).find("[name='" + id
+ "[name]']").val());
449 $('#' + id
).find("[name='" + id
+ "[removed]']").val('1');
452 function restoreJob(id
, pref
)
454 $('#' + id
+ '_cont').show();
455 $('#' + id
+ '_grayed').hide();
456 $('#' + id
).find("[name='" + id
+ "[removed]']").val('0');
459 function updateJobSector(id
, sel
)
461 var sector
= $('#job_' + id
).find("[name='jobs[" + id
+ "][sector]']").val();
465 Ajax
.update_html('job_' + id
+ '_subSector', 'profile/ajax/sector/' + id + '/job_' + id
+ '/jobs[' + id + ']/' + sector
+ '/' + sel
);
468 function updateJobSubSector(id
, sel
)
470 var subSector
= $('#job_' + id
).find("[name='jobs[" + id
+ "][subSector]']").val();
471 if (subSector
== '') {
474 Ajax
.update_html('job_' + id
+ '_subSubSector', 'profile/ajax/sub_sector/' + id + '/' + subSector
+ '/' + sel
);
477 function displayAllSector(id
)
479 $('.sector_text_' + id
).remove();
480 $('.sector_' + id
).show();
483 function makeAddJob(id
)
485 return function(data
)
487 $('#add_job').before(data
);
488 registerEnterpriseAutocomplete(id
);
489 updateSector('job_' + id
, 'jobs[' + id
+ ']', '');
496 while ($('#job_' + i
).length
!= 0) {
499 $.get(platal_baseurl
+ 'profile/ajax/job/' + i
, makeAddJob(i
));
502 function addEntreprise(id
)
504 $('.entreprise_' + id
).toggle();
509 function addSkill(cat
)
511 var val
= $('#' + cat
+ '_table').find('[name=' + cat
+ '_sel]').val();
512 var text
= $('#' + cat
+ '_table').find('[name=' + cat
+ '_sel] :selected').text();
513 $.get(platal_baseurl
+ 'profile/ajax/skill/' + cat + '/' + val
,
515 $('#' + cat
).append(data
);
516 $('#' + cat
+ '_' + val
+ '_title').text(text
);
523 function addCountry()
525 var val
= $('#countries_table').find('[name=countries_sel] :selected').val();
526 var text
= $('#countries_table').find('[name=countries_sel] :selected').text();
527 var html
= '<div id="countries_' + val
+ '" style="clear: both; margin-bottom: 0.7em">'
528 + ' <a href="javascript:removeElement(\'countries\', \'' + val
+ '\')" style="display: block; float:right">'
529 + ' <img src="images/icons/cross.gif" alt="" title="Supprimer ce pays" />'
531 + ' <div style="float: left; width: 50%">' + text
+ '</div>'
532 + ' <input type="hidden" name="countries[' + val
+ ']" value="' + text
+ '" />'
534 $('#countries').append(html
);
535 updateElement('countries');
538 function updateSubSector()
540 var s
= $('#sectorSelection').find('[name=sectorSelection]').val();
541 var ss
= $('#selectedSubSector').find("[name='jobs[-1][subSector]']").val();
542 if ((s
== '' || ss
== '') || $('#sectors_' + s
+ '_' + ss
).length
!= 0) {
543 $('#addSector').hide();
545 $('#addSector').show();
549 function removeSector(s
, ss
)
551 $('#sectors_' + s
+ '_' + ss
).remove();
555 function updateSector()
557 var sector
= $('#sectorSelection').find('[name=sectorSelection]').val();
560 $('#selectedSubSector').html('');
563 $.get(platal_baseurl
+ 'profile/ajax/sector/-1/0/0/' + sector
,
565 data
= '<a href="javascript:addSector()" style="display: none; float: right" id="addSector">'
566 + ' <img src="images/icons/add.gif" alt="" title="Ajouter ce secteur" />'
568 $('#selectedSubSector').html(data
);
569 $('#selectedSubSector').find("[name='jobs[-1][subSector]']").change(updateSubSector
);
575 var s
= $('#sectorSelection').find('[name=sectorSelection]').val();
576 var ss
= $('#selectedSubSector').find("[name='jobs[-1][subSector]']").val();
577 var sst
= $('#selectedSubSector').find("[name='jobs[-1][subSector]'] :selected").text();
579 var html
= '<div id="sectors_' + s
+ '_' + ss
+ '" style="clear: both; margin-top: 0.5em" class="titre">'
580 + ' <a href="javascript:removeSector(\'' + s
+ '\', \'' + ss
+ '\')" style="display: block; float: right">'
581 + ' <img src="images/icons/cross.gif" alt="" title="Supprimer ce secteur" />'
583 + ' <input type="hidden" name="sectors[' + s
+ '][' + ss
+ ']" value="' + sst
+ '" />'
586 $('#sectors').append(html
);
590 function registerEnterpriseAutocomplete(id
)
592 $(".enterprise_name").each(
594 if (id
== -1 || this.name
== "jobs[" + id
+ "][name]") {
595 $(this).autocomplete(platal_baseurl
+ "search/autocomplete/entreprise",
600 width
:$(this).width()
605 $(".sector_name").each(
607 if (id
== -1 || this.name
== "jobs[" + id
+ "][subSubSector]") {
608 $(this).autocomplete(platal_baseurl
+ "search/autocomplete/subSubSector",
613 width
:$(this).width()
619 // {{{1 Multiusage functions
621 function updateElement(cat
)
623 var val
= $('#' + cat
+ '_table').find('[name=' + cat
+ '_sel]').val();
624 if (val
== '' || $('#' + cat
+ '_' + val
).length
!= 0) {
625 $('#' + cat
+ '_add').hide();
627 $('#' + cat
+ '_add').show();
631 function removeElement(cat
, id
)
633 $('#' + cat
+ '_' + id
).remove();
637 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: