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 if ($('#job_0').find("[name='jobs[0][name]']").val() == '') {
49 registerEnterpriseAutocomplete(0);
56 var educationDegreeAll
;
57 var educationDegreeName
;
63 function toggleNamesAdvanced()
65 $('.names_advanced').toggle();
68 function addSearchName(isFemale
)
71 while ($('#search_name_' + i
).length
!= 0) {
74 $('#search_name_' + i
)
75 .updateHtml('profile/ajax/searchname/' + i + '/' + isFemale
,
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 $.xget('profile/ajax/buildnames/' + searchnames + '/' + isFemale
,
118 var name
= data
.split(';');
119 $('#public_name').html(name
[0]);
120 $('#private_name').html(name
[0] + name
[1]);
124 function toggleParticle(id
)
126 if ($('#search_name_' + id
).find("[name*='[particle]']").val() == '') {
127 $('#search_name_' + id
).find("[name*='[particle]']").val(1);
129 $('#search_name_' + id
).find("[name*='[particle]']").val('');
135 function togglePromotionEdition()
137 $(".promotion_edition").toggle();
140 // Nationalities {{{1
142 function delNationality(i
)
144 $('#nationality' + i
).hide().find('select').val('');
147 function addNationality()
150 if ($('#nationality2').find('select').val() == "") {
152 } else if ($('#nationality3').find('select').val() == "") {
155 if ((i
== 2) || (i
== 3)) {
156 $('#nationality' + i
).show();
162 function prepareType(id
)
164 var edu
= $('.edu_' + id
).find("[name='edus[" + id
+ "][eduid]']").val() - 1;
165 var sel
= $('.edu_' + id
).find('[name=edu_' + id
+ '_tmp]').val();
167 if (educationDegree
[edu
]) {
168 var length
= educationDegree
[edu
].length
;
172 for (i
= 0; i
< length
; ++i
) {
173 html
+= '<option value="' + educationDegree
[edu
][i
] + '"';
174 if (sel
== educationDegree
[edu
][i
]) {
175 html
+= ' selected="selected"';
177 html
+= '>' + educationDegreeName
[educationDegree
[edu
][i
] - 1] + '</option>';
179 // XXX: to be removed once SQL table profile_merge_issues is.
180 if (sel
!= '' && html
== '') {
181 html
+= '<option value="' + sel
+ '" selected="selected">' + educationDegreeName
[sel
- 1] + '</option>';
183 $('.edu_' + id
).find("[name='edus[" + id
+ "][degreeid]']").html(html
);
193 while (!$('#edu_add').hasClass(prefix
+ i
)) {
194 if ($('.' + prefix
+ i
).length
!= 0) {
200 class_parity
= 'pair';
202 class_parity
= 'impair';
204 $('#edu_add').removeClass(prefix
+ i
);
206 $('#edu_add').addClass(prefix
+ i
);
208 $.get(platal_baseurl
+ 'profile/ajax/edu/' + i + '/' + class_parity
,
210 $('#edu_add').before(data
);
215 function removeEdu(i
)
218 $('.' + prefix
+ i
).remove();
219 while (!$('#edu_add').hasClass(prefix
+ i
)) {
220 $('.' + prefix
+ i
).toggleClass('pair');
221 $('.' + prefix
+ i
).toggleClass('impair');
228 function addNetworking()
231 while ($('#networking_' + i
).length
!= 0) {
235 var html
= '<tr id="networking_' + i
+ '">'
236 + ' <td colspan="2">'
237 + ' <div style="float: left; width: 200px;">'
238 + ' <span class="flags">'
239 + ' <input type="checkbox" name="networking[' + i
+ '][pub]"/>'
240 + ' <img src="images/icons/flag_green.gif" alt="site public" title="site public">'
242 + ' <select name="networking[' + i
+ '][type]" onchange="javascript:updateNetworking(' + i
+ ');">';
243 for (nw
in nw_list
) {
244 if (namefirst
== '') {
247 html
+= ' <option value="' + nw_list
[nw
] + '">' + nw
+ '</option>';
250 + ' <input type="hidden" name="networking[' + i
+ '][name]" value="' + namefirst
+ '"/>'
252 + ' <div style="float: left">'
253 + ' <input type="text" name="networking[' + i
+ '][address]" value="" size="30"/>'
254 + ' <a href="javascript:removeNetworking(' + i
+ ')">'
255 + ' <img src="images/icons/cross.gif" alt="cross" title="Supprimer cet élément"/>'
261 $('#networking').before(html
);
264 function removeNetworking(id
)
266 $('#networking_' + id
).remove();
269 function updateNetworking(i
)
271 $('#networking_' + i
).find("[name='networking[" + i
+ "][name]']").val($('#networking_' + i
).find('select option:selected').text());
276 function toggleAddress(id
, val
)
278 $('#addresses_' + id
+ '_grayed').toggle();
279 $('#addresses_' + id
).toggle();
280 $('#addresses_' + id
+ '_cont').find('[name*=removed]').val(val
);
281 checkCurrentAddress();
284 function checkCurrentAddress(id
)
286 var hasCurrentAddress
= id
? true : false;
288 while ($('#addresses_' + i
+ '_cont').length
!= 0) {
289 if ($('#addresses_' + i
+ '_cont').find('[name*=removed]').val() == 1) {
290 $('#addresses_' + i
+ '_cont').find('[name*=current]').attr('checked', false);
292 if (!hasCurrentAddress
&& $('#addresses_' + i
+ '_cont').find('[name*=current]:checked').length
!= 0) {
293 hasCurrentAddress
= true;
295 $('#addresses_' + i
+ '_cont').find('[name*=current]').attr('checked', false);
299 if (!hasCurrentAddress
) {
301 while ($('#addresses_' + i
+ '_cont').length
!= 0) {
302 if ($('#addresses_' + i
+ '_cont').find('[name*=removed]').val() == 0) {
303 $('#addresses_' + i
+ '_cont').find('[name*=current]').attr('checked', 'checked');
310 $('#addresses_' + id
+ '_cont').find('[name*=current]').attr('checked', 'checked');
314 function addAddress()
317 while ($('#addresses_' + i
+ '_cont').length
!= 0) {
320 $('#add_address').before('<div id="addresses_' + i
+ '_cont"></div>');
321 $('#addresses_' + i
+ '_cont').updateHtml('profile/ajax/address/' + i
,
322 checkCurrentAddress());
325 function addressChanged(prefid
)
327 $('#' + prefid
+ '_cont').find('[name*=changed]').val("1");
330 function validGeoloc(prefid
, id
, geoloc
)
333 $('#' + prefid
+ '_cont').find('[name*=text]').val($('#' + prefid
+ '_cont').find('[name*=geocodedText]').val());
334 $('#' + prefid
+ '_cont').find('[name*=postalText]').val($('#' + prefid
+ '_cont').find('[name*=geocodedPostalText]').val());
337 $('#' + prefid
+ '_cont').find("[name*='[geocodedText]']").remove();
338 $('#' + prefid
+ '_cont').find("[name*='[geocodedPostalText]']").remove();
340 $('#' + prefid
+ '_cont').find('[name*=text]').removeClass('error');
341 $('#' + prefid
+ '_cont').find('[name*=geocodeChosen]').val(geoloc
);
342 $('.' + prefid
+ '_geoloc').remove();
347 function addTel(prefid
, prefname
)
350 var prefix
= prefid
+ '_';
351 while ($('#' + prefix
+ i
).length
!= 0) {
354 $('#' + prefix
+ 'add').before('<div id="' + prefix
+ i
+ '" style="clear: both; padding-top: 4px; padding-bottom: 4px"></div>');
355 $('#' + prefix
+ i
).updateHtml('profile/ajax/tel/' + prefid + '/' + prefname
+ '/' + i
);
358 function removeTel(prefname
, prefid
, id
)
361 while ($('#' + prefid
+ '_' + total
).length
!= 0) {
364 $('#' + prefid
+ '_' + id
).remove();
365 for (var i
= parseInt(id
) + 1; i
< total
; ++i
) {
366 renumberPhone(prefname
, prefid
, i
);
370 function addPhoneComment(id
)
372 $('#' + id
+ '_comment').show();
373 $('#' + id
+ '_addComment').hide();
376 function removePhoneComment(id
, pref
)
378 $('#' + id
+ '_comment').hide();
379 $('#' + id
+ '_comment').find("[name='" + pref
+ "[comment]']").val('');
380 $('#' + id
+ '_addComment').show();
383 function renumberPhone(prefname
, prefid
, i
)
386 var telprefOld
= prefname
+ '[' + i
+ ']';
387 var telpref
= prefname
+ '[' + telid
+ ']';
388 var idOld
= prefid
+ '_' + i
;
389 var id
= prefid
+ '_' + telid
;
391 $('#' + idOld
).attr('id', id
);
392 $('#' + id
).find('div.titre').html('N°' + i
);
393 $('#' + id
).find('a.removeTel').attr('href', 'javascript:removeTel(\'' + prefname
+ '\',\'' + prefid
+ '\',' + telid
+ ')');
394 $('#' + id
).find('select').attr('name', telpref
+ '[type]');
395 $('#' + id
).find("[name='" + telprefOld
+ "[display]']").attr('name', telpref
+ '[display]');
396 $('#' + id
).find("[name='" + telprefOld
+ "[comment]']").attr('name', telpref
+ '[comment]');
397 $('#' + id
).find('a.removePhoneComment').attr('href', 'javascript:removePhoneComment(' + id
+ ',' + telpref
+ ')');
398 $('#' + id
).find('#' + idOld
+ '_addComment').attr('id', id
+ '_addComment');
399 $('#' + id
).find('#' + id
+ '_addComment').attr('href', 'javascript:addPhoneComment(' + id
+ ')');
400 $('#' + id
).find('#' + idOld
+ '_comment').attr('id', id
+ '_comment');
401 $('#' + id
).find("[name='" + telprefOld
+ "[pub]']").attr('name', telpref
+ '[pub]');
408 var id
= $('#binets_table').find('[name=binets_sel]').val();
409 var text
= $('#binets_table').find('select option:selected').text();
410 var html
= '<tr id="binets_' + id
+ '">'
412 + ' <input type="hidden" name="binets[' + id
+ ']" value="' + text
+ '" />'
415 + ' <div style="float: left; width: 70%">'
418 + ' <a href="javascript:removeElement(\'binets\',' + id
+ ')">'
419 + ' <img src="images/icons/cross.gif" alt="cross" title="Supprimer ce groupe" />'
423 $('#binets_table').after(html
);
424 updateElement('binets');
427 function updateGroupSubLink()
429 var href
= $('[name*=groupesx_sub]').val() ? $('[name*=groupesx_sub]').val() : 'http://www.polytechnique.net';
430 $('#groupesx_sub').attr('href', href
);
435 function updateMedal()
437 var val
= $('#medals').find('[name*=medal_sel]').val();
438 if (val
&& ($('#medal_' + val
).length
== 0)) {
439 $('#medal_add').show();
441 $('#medal_add').hide();
445 function getMedalName(id
)
447 $('#medal_name_' + id
).html(names
[id
]);
450 function buildGrade(id
, current
)
453 var subg
= subgrades
[id
];
454 var obj
= $('#medal_grade_' + id
);
456 obj
.prepend('<input type="hidden" name="medals[' + id
+ '][grade]" value="0" />');
458 var html
= 'Agrafe : <select name="medals[' + id
+ '][grade]">';
459 html
+= '<option value="0">Non précisée</option>';
460 for (grade
= 0 ; grade
< subg
.length
; grade
++) {
461 html
+= '<option value="' + subg
[grade
][0] + '"';
462 if (subg
[grade
][0] == current
) {
463 html
+= ' selected="selected"';
465 html
+= '>' + subg
[grade
][1] + '</option>';
473 function makeAddProcess(id
)
475 return function(data
)
477 $('#medals').after(data
);
486 var id
= $('#medals').find('[name=medal_sel]').val();
487 $.get(platal_baseurl
+ 'profile/ajax/medal/' + id
, makeAddProcess(id
));
490 function removeMedal(id
)
492 $("#medal_" + id
).remove();
498 function removeJob(id
, pref
)
500 $('#' + id
+ '_cont').hide();
501 if ($('#' + id
).find("[name='" + pref
+ "[new]']").val() == '0') {
502 $('#' + id
+ '_grayed').show();
503 $('#' + id
+ '_grayed_name').html($('#' + id
).find("[name='" + pref
+ "[name]']").val());
505 $('#' + id
).find("[name='" + pref
+ "[removed]']").val('1');
508 function restoreJob(id
, pref
)
510 $('#' + id
+ '_cont').show();
511 $('#' + id
+ '_grayed').hide();
512 $('#' + id
).find("[name='" + pref
+ "[removed]']").val('0');
515 function makeAddJob(id
)
517 return function(data
)
519 $('#add_job').before(data
);
520 registerEnterpriseAutocomplete(id
);
527 while ($('#job_' + i
).length
!= 0) {
530 $.get(platal_baseurl
+ 'profile/ajax/job/' + i
, makeAddJob(i
));
533 function addEntreprise(id
)
535 $('.entreprise_' + id
).toggle();
539 * Adds a job term in job profile page
540 * @param jobid id of profile's job among his different jobs
541 * @param jtid id of job term to add
542 * @param full_name full text of job term
543 * @return false if the term already exist for this job, true otherwise
545 function addJobTerm(jobid
, jtid
, full_name
)
553 formvarname
= 'terms';
555 parentpath
= '#job_'+jobid
+' ';
556 formvarname
= 'jobs['+jobid
+'][terms]';
558 var lastJobTerm
= $(parentpath
+ '.job_term:last');
559 if (lastJobTerm
.length
!= 0) {
560 termid
= parseInt(lastJobTerm
.children('input').attr('name').replace(/^(jobs\[[0-9]+\]\[terms\]|terms)\[([0-9]+)\]\[jtid\]/, '$2')) + 1;
561 if ($('#job'+jobid
+'_term'+jtid
).length
> 0) {
565 var newdiv
= '<div class="job_term" id="job'+jobid
+'_term'+jtid
+'">'+
566 '<span>'+full_name
+'</span>'+
567 '<input type="hidden" name="'+formvarname
+'['+termid
+'][jtid]" value="'+jtid
+'" />'+
568 '<img title="Retirer ce mot-clef" alt="retirer" src="images/icons/cross.gif" />'+
570 if (lastJobTerm
.length
== 0) {
571 $(parentpath
+ '.job_terms').prepend(newdiv
);
573 lastJobTerm
.after(newdiv
);
575 $('#job'+jobid
+'_term'+jtid
+' img').css('cursor','pointer').click(removeJobTerm
);
580 * Remove a job term in job profile page.
581 * Must be called from a button in a div containing the term
583 function removeJobTerm()
585 $(this).parent().remove();
589 * Prepare display for autocomplete suggestions in job terms
590 * @param row an array of (title of term, id of term)
591 * @return text to display
592 * If id is negative, it is because there are too much terms to
595 function displayJobTerm(row
)
598 return '... <em>parcourir les résultats dans un arbre</em> ...';
604 * Function called when a job term has been selected from autocompletion
606 * @param li is the list item (<li>) that has been clicked
607 * The context is the jsquery autocomplete object.
609 function selectJobTerm(li
)
611 var jobid
= this.extraParams
.jobid
;
612 if (li
.extra
[0] >= 0) {
613 addJobTerm(jobid
,li
.extra
[0],$(li
).text());
617 search_input
= $('.term_search')[0];
619 search_input
= $('#job_'+jobid
+' .term_search')[0];
621 if (li
.extra
[0] >= 0) {
622 search_input
.value
= '';
623 search_input
.focus();
625 search_input
.value
= li
.selectValue
.replace(/%$/,'');
626 toggleJobTermsTree(jobid
, li
.selectValue
);
631 * Function to show or hide a terms tree in job edition
632 * @param jobid is the id of the job currently edited
634 function toggleJobTermsTree(jobid
, textfilter
)
640 treepath
= '#job_'+jobid
+' ';
642 treepath
+= '.term_tree';
643 if ($(treepath
+ ' ul').length
> 0) {
644 $(treepath
).empty().removeClass().addClass('term_tree');
649 createJobTermsTree(treepath
, 'profile/ajax/tree/jobterms/all', 'job' + jobid
, 'chooseJobTerm', textfilter
);
653 * Function called when a job term is chosen from terms tree
654 * @param treeid is the full id of the tree (must look like job3)
655 * @param jtid is the id of the job term chosen
656 * @param fullname is the complete name (understandable without context) of the term
658 function chooseJobTerm(treeid
, jtid
, fullname
)
660 addJobTerm(treeid
.replace(/^job(.*)$/, '$1'), jtid
, fullname
);
665 function addSkill(cat
)
667 var val
= $('#' + cat
+ '_table').find('[name=' + cat
+ '_sel]').val();
668 var text
= $('#' + cat
+ '_table').find('[name=' + cat
+ '_sel] :selected').text();
669 $.get(platal_baseurl
+ 'profile/ajax/skill/' + cat + '/' + val
,
671 $('#' + cat
).append(data
);
672 $('#' + cat
+ '_' + val
+ '_title').text(text
);
679 function addCountry()
681 var val
= $('#countries_table').find('[name=countries_sel] :selected').val();
682 var text
= $('#countries_table').find('[name=countries_sel] :selected').text();
683 var html
= '<div id="countries_' + val
+ '" style="clear: both; margin-bottom: 0.7em">'
684 + ' <a href="javascript:removeElement(\'countries\',\'' + val
+ '\')" style="display: block; float:right">'
685 + ' <img src="images/icons/cross.gif" alt="" title="Supprimer ce pays" />'
687 + ' <div style="float: left; width: 50%">' + text
+ '</div>'
688 + ' <input type="hidden" name="countries[' + val
+ ']" value="' + text
+ '" />'
690 $('#countries').append(html
);
691 updateElement('countries');
694 function registerEnterpriseAutocomplete(id
)
696 $(".enterpriseName").each(
698 if (id
== -1 || this.name
== "jobs[" + id
+ "][name]") {
699 $(this).autocomplete(platal_baseurl
+ "search/autocomplete/entreprise",
704 width
:$(this).width()
709 $(".sectorName").each(
711 if (id
== -1 || this.name
== "jobs[" + id
+ "][subSubSectorName]") {
712 $(this).autocomplete(platal_baseurl
+ "search/autocomplete/subSubSector",
717 width
:$(this).width()
723 // {{{1 Multiusage functions
725 function updateElement(cat
)
727 var val
= $('#' + cat
+ '_table').find('[name=' + cat
+ '_sel]').val();
728 if (val
== '' || $('#' + cat
+ '_' + val
).length
!= 0) {
729 $('#' + cat
+ '_add').hide();
731 $('#' + cat
+ '_add').show();
735 function removeElement(cat
, id
)
737 $('#' + cat
+ '_' + id
).remove();
741 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: