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 Ajax
.update_html('search_name_' + i
, 'profile/ajax/searchname/' + i + '/' + isFemale
, function(data
){
75 $('#searchname').before(data
);
80 function removeSearchName(i
, isFemale
)
82 $('#search_name_' + i
).remove();
83 updateNameDisplay(isFemale
);
86 function changeNameFlag(i
)
88 $('#flag_' + i
).remove();
89 var typeid
= $('#search_name_' + i
).find('select').val();
90 var type
= $('#search_name_' + i
).find('select :selected').text();
91 if ($('[name=sn_type_' + typeid
+ '_' + i
+ ']').val() > 0) {
92 $('#flag_cb_' + i
).after('<span id="flag_' + i
+ '"> ' +
93 '<img src="images/icons/flag_green.gif" alt="site public" title="site public" />' +
94 '<input type="hidden" name="search_names[' + i
+ '][pub]" value="1"/>' +
95 '<input type="hidden" name="search_names[' + i
+ '][typeid]" value="' + typeid
+ '"/>' +
96 '<input type="hidden" name="search_names[' + i
+ '][type]" value="' + type
+ '"/></span>');
98 $('#flag_cb_' + i
).after('<span id="flag_' + i
+ '"> ' +
99 '<img src="images/icons/flag_red.gif" alt="site privé" title="site privé" />' +
100 '<input type="hidden" name="search_names[' + i
+ '][typeid]" value="' + typeid
+ '"/>' +
101 '<input type="hidden" name="search_names[' + i
+ '][type]" value="' + type
+ '"/></span>');
105 function updateNameDisplay(isFemale
)
107 var searchnames
= '';
108 for (var i
= 0; i
< 10; i
++) {
109 if ($('#search_name_' + i
).find(':text').val()) {
110 searchnames
+= $('#search_name_' + i
).find('[name*=typeid]').val() + ';';
111 searchnames
+= $('#search_name_' + i
).find(':text').val() + ';;';
114 Ajax
.update_html(null, 'profile/ajax/buildnames/' + searchnames + '/' + isFemale
, function(data
){
115 var name
= data
.split(';');
116 $('#public_name').html(name
[0]);
117 $('#private_name').html(name
[0] + name
[1]);
121 function toggleParticle(id
)
123 if ($('#search_name_' + id
).find("[name*='[particle]']").val() == '') {
124 $('#search_name_' + id
).find("[name*='[particle]']").val(1);
126 $('#search_name_' + id
).find("[name*='[particle]']").val('');
132 function togglePromotionEdition()
134 $(".promotion_edition").toggle();
137 // Nationalities {{{1
139 function delNationality(i
)
141 $('#nationality' + i
).hide().find('select').val('');
144 function addNationality()
147 if ($('#nationality2').find('select').val() == "") {
149 } else if ($('#nationality3').find('select').val() == "") {
152 if ((i
== 2) || (i
== 3)) {
153 $('#nationality' + i
).show();
159 function prepareType(id
)
161 var edu
= $('.edu_' + id
).find("[name='edus[" + id
+ "][eduid]']").val() - 1;
162 var sel
= $('.edu_' + id
).find('[name=edu_' + id
+ '_tmp]').val();
164 if (educationDegree
[edu
]) {
165 var length
= educationDegree
[edu
].length
;
169 for (i
= 0; i
< length
; ++i
) {
170 html
+= '<option value="' + educationDegree
[edu
][i
] + '"';
171 if (sel
== educationDegree
[edu
][i
]) {
172 html
+= ' selected="selected"';
174 html
+= '>' + educationDegreeName
[educationDegree
[edu
][i
] - 1] + '</option>';
176 // XXX: to be removed once SQL table profile_merge_issues is.
177 if (sel
!= '' && html
== '') {
178 html
+= '<option value="' + sel
+ '" selected="selected">' + educationDegreeName
[sel
- 1] + '</option>';
180 $('.edu_' + id
).find("[name='edus[" + id
+ "][degreeid]']").html(html
);
190 while (!$('#edu_add').hasClass(prefix
+ i
)) {
191 if ($('.' + prefix
+ i
).length
!= 0) {
197 class_parity
= 'pair';
199 class_parity
= 'impair';
201 $('#edu_add').removeClass(prefix
+ i
);
203 $('#edu_add').addClass(prefix
+ i
);
205 $.get(platal_baseurl
+ 'profile/ajax/edu/' + i + '/' + class_parity
,
207 $('#edu_add').before(data
);
212 function removeEdu(i
)
215 $('.' + prefix
+ i
).remove();
216 while (!$('#edu_add').hasClass(prefix
+ i
)) {
217 $('.' + prefix
+ i
).toggleClass('pair');
218 $('.' + prefix
+ i
).toggleClass('impair');
225 function addNetworking()
228 while ($('#networking_' + i
).length
!= 0) {
232 var html
= '<tr id="networking_' + i
+ '">'
233 + ' <td colspan="2">'
234 + ' <div style="float: left; width: 200px;">'
235 + ' <span class="flags">'
236 + ' <input type="checkbox" name="networking[' + i
+ '][pub]"/>'
237 + ' <img src="images/icons/flag_green.gif" alt="site public" title="site public">'
239 + ' <select name="networking[' + i
+ '][type]" onchange="javascript:updateNetworking(' + i
+ ');">';
240 for (nw
in nw_list
) {
241 if (namefirst
== '') {
244 html
+= ' <option value="' + nw_list
[nw
] + '">' + nw
+ '</option>';
247 + ' <input type="hidden" name="networking[' + i
+ '][name]" value="' + namefirst
+ '"/>'
249 + ' <div style="float: left">'
250 + ' <input type="text" name="networking[' + i
+ '][address]" value="" size="30"/>'
251 + ' <a href="javascript:removeNetworking(' + i
+ ')">'
252 + ' <img src="images/icons/cross.gif" alt="cross" title="Supprimer cet élément"/>'
258 $('#networking').before(html
);
261 function removeNetworking(id
)
263 $('#networking_' + id
).remove();
266 function updateNetworking(i
)
268 $('#networking_' + i
).find("[name='networking[" + i
+ "][name]']").val($('#networking_' + i
).find('select option:selected').text());
273 function toggleAddress(id
, val
)
275 $('#addresses_' + id
+ '_grayed').toggle();
276 $('#addresses_' + id
).toggle();
277 $('#addresses_' + id
+ '_cont').find('[name*=removed]').val(val
);
278 checkCurrentAddress();
281 function checkCurrentAddress(id
)
283 var hasCurrentAddress
= id
? true : false;
285 while ($('#addresses_' + i
+ '_cont').length
!= 0) {
286 if ($('#addresses_' + i
+ '_cont').find('[name*=removed]').val() == 1) {
287 $('#addresses_' + i
+ '_cont').find('[name*=current]').attr('checked', false);
289 if (!hasCurrentAddress
&& $('#addresses_' + i
+ '_cont').find('[name*=current]:checked').length
!= 0) {
290 hasCurrentAddress
= true;
292 $('#addresses_' + i
+ '_cont').find('[name*=current]').attr('checked', false);
296 if (!hasCurrentAddress
) {
298 while ($('#addresses_' + i
+ '_cont').length
!= 0) {
299 if ($('#addresses_' + i
+ '_cont').find('[name*=removed]').val() == 0) {
300 $('#addresses_' + i
+ '_cont').find('[name*=current]').attr('checked', 'checked');
307 $('#addresses_' + id
+ '_cont').find('[name*=current]').attr('checked', 'checked');
311 function addAddress()
314 while ($('#addresses_' + i
+ '_cont').length
!= 0) {
317 $('#add_address').before('<div id="addresses_' + i
+ '_cont"></div>');
318 Ajax
.update_html('addresses_' + i
+ '_cont', 'profile/ajax/address/' + i
, checkCurrentAddress());
321 function addressChanged(prefid
)
323 $('#' + prefid
+ '_cont').find('[name*=changed]').val("1");
326 function validGeoloc(prefid
, id
, geoloc
)
329 $('#' + prefid
+ '_cont').find('[name*=text]').val($('#' + prefid
+ '_cont').find('[name*=geocodedText]').val());
330 $('#' + prefid
+ '_cont').find('[name*=postalText]').val($('#' + prefid
+ '_cont').find('[name*=geocodedPostalText]').val());
333 $('#' + prefid
+ '_cont').find("[name*='[geocodedText]']").remove();
334 $('#' + prefid
+ '_cont').find("[name*='[geocodedPostalText]']").remove();
336 $('#' + prefid
+ '_cont').find('[name*=text]').removeClass('error');
337 $('#' + prefid
+ '_cont').find('[name*=geocodeChosen]').val(geoloc
);
338 $('.' + prefid
+ '_geoloc').remove();
343 function addTel(prefid
, prefname
)
346 var prefix
= prefid
+ '_';
347 while ($('#' + prefix
+ i
).length
!= 0) {
350 $('#' + prefix
+ 'add').before('<div id="' + prefix
+ i
+ '" style="clear: both; padding-top: 4px; padding-bottom: 4px"></div>');
351 Ajax
.update_html(prefix
+ i
, 'profile/ajax/tel/' + prefid + '/' + prefname
+ '/' + i
);
354 function removeTel(prefname
, prefid
, id
)
357 while ($('#' + prefid
+ '_' + total
).length
!= 0) {
360 $('#' + prefid
+ '_' + id
).remove();
361 for (var i
= parseInt(id
) + 1; i
< total
; ++i
) {
362 renumberPhone(prefname
, prefid
, i
);
366 function addPhoneComment(id
)
368 $('#' + id
+ '_comment').show();
369 $('#' + id
+ '_addComment').hide();
372 function removePhoneComment(id
, pref
)
374 $('#' + id
+ '_comment').hide();
375 $('#' + id
+ '_comment').find("[name='" + pref
+ "[comment]']").val('');
376 $('#' + id
+ '_addComment').show();
379 function renumberPhone(prefname
, prefid
, i
)
382 var telprefOld
= prefname
+ '[' + i
+ ']';
383 var telpref
= prefname
+ '[' + telid
+ ']';
384 var idOld
= prefid
+ '_' + i
;
385 var id
= prefid
+ '_' + telid
;
387 $('#' + idOld
).attr('id', id
);
388 $('#' + id
).find('div.titre').html('N°' + i
);
389 $('#' + id
).find('a.removeTel').attr('href', 'javascript:removeTel(\'' + prefname
+ '\',\'' + prefid
+ '\',' + telid
+ ')');
390 $('#' + id
).find('select').attr('name', telpref
+ '[type]');
391 $('#' + id
).find("[name='" + telprefOld
+ "[display]']").attr('name', telpref
+ '[display]');
392 $('#' + id
).find("[name='" + telprefOld
+ "[comment]']").attr('name', telpref
+ '[comment]');
393 $('#' + id
).find('a.removePhoneComment').attr('href', 'javascript:removePhoneComment(' + id
+ ',' + telpref
+ ')');
394 $('#' + id
).find('#' + idOld
+ '_addComment').attr('id', id
+ '_addComment');
395 $('#' + id
).find('#' + id
+ '_addComment').attr('href', 'javascript:addPhoneComment(' + id
+ ')');
396 $('#' + id
).find('#' + idOld
+ '_comment').attr('id', id
+ '_comment');
397 $('#' + id
).find("[name='" + telprefOld
+ "[pub]']").attr('name', telpref
+ '[pub]');
404 var id
= $('#binets_table').find('[name=binets_sel]').val();
405 var text
= $('#binets_table').find('select option:selected').text();
406 var html
= '<tr id="binets_' + id
+ '">'
408 + ' <input type="hidden" name="binets[' + id
+ ']" value="' + text
+ '" />'
411 + ' <div style="float: left; width: 70%">'
414 + ' <a href="javascript:removeElement(\'binets\',' + id
+ ')">'
415 + ' <img src="images/icons/cross.gif" alt="cross" title="Supprimer ce groupe" />'
419 $('#binets_table').after(html
);
420 updateElement('binets');
423 function updateGroupSubLink()
425 var href
= $('[name*=groupesx_sub]').val() ? $('[name*=groupesx_sub]').val() : 'http://www.polytechnique.net';
426 $('#groupesx_sub').attr('href', href
);
431 function updateMedal()
433 var val
= $('#medals').find('[name*=medal_sel]').val();
434 if (val
&& ($('#medal_' + val
).length
== 0)) {
435 $('#medal_add').show();
437 $('#medal_add').hide();
441 function getMedalName(id
)
443 $('#medal_name_' + id
).html(names
[id
]);
446 function buildGrade(id
, current
)
449 var subg
= subgrades
[id
];
450 var obj
= $('#medal_grade_' + id
);
452 obj
.prepend('<input type="hidden" name="medals[' + id
+ '][grade]" value="0" />');
454 var html
= 'Agrafe : <select name="medals[' + id
+ '][grade]">';
455 html
+= '<option value="0">Non précisée</option>';
456 for (grade
= 0 ; grade
< subg
.length
; grade
++) {
457 html
+= '<option value="' + subg
[grade
][0] + '"';
458 if (subg
[grade
][0] == current
) {
459 html
+= ' selected="selected"';
461 html
+= '>' + subg
[grade
][1] + '</option>';
469 function makeAddProcess(id
)
471 return function(data
)
473 $('#medals').after(data
);
482 var id
= $('#medals').find('[name=medal_sel]').val();
483 $.get(platal_baseurl
+ 'profile/ajax/medal/' + id
, makeAddProcess(id
));
486 function removeMedal(id
)
488 $("#medal_" + id
).remove();
494 function removeJob(id
, pref
)
496 $('#' + id
+ '_cont').hide();
497 if ($('#' + id
).find("[name='" + pref
+ "[new]']").val() == '0') {
498 $('#' + id
+ '_grayed').show();
499 $('#' + id
+ '_grayed_name').html($('#' + id
).find("[name='" + pref
+ "[name]']").val());
501 $('#' + id
).find("[name='" + pref
+ "[removed]']").val('1');
504 function restoreJob(id
, pref
)
506 $('#' + id
+ '_cont').show();
507 $('#' + id
+ '_grayed').hide();
508 $('#' + id
).find("[name='" + pref
+ "[removed]']").val('0');
511 function makeAddJob(id
)
513 return function(data
)
515 $('#add_job').before(data
);
516 registerEnterpriseAutocomplete(id
);
523 while ($('#job_' + i
).length
!= 0) {
526 $.get(platal_baseurl
+ 'profile/ajax/job/' + i
, makeAddJob(i
));
529 function addEntreprise(id
)
531 $('.entreprise_' + id
).toggle();
535 * Adds a job term in job profile page
536 * @param jobid id of profile's job among his different jobs
537 * @param jtid id of job term to add
538 * @param full_name full text of job term
539 * @return false if the term already exist for this job, true otherwise
541 function addJobTerm(jobid
, jtid
, full_name
)
549 formvarname
= 'terms';
551 parentpath
= '#job_'+jobid
+' ';
552 formvarname
= 'jobs['+jobid
+'][terms]';
554 var lastJobTerm
= $(parentpath
+ '.job_term:last');
555 if (lastJobTerm
.length
!= 0) {
556 termid
= parseInt(lastJobTerm
.children('input').attr('name').replace(/^(jobs\[[0-9]+\]\[terms\]|terms)\[([0-9]+)\]\[jtid\]/, '$2')) + 1;
557 if ($('#job'+jobid
+'_term'+jtid
).length
> 0) {
561 var newdiv
= '<div class="job_term" id="job'+jobid
+'_term'+jtid
+'">'+
562 '<span>'+full_name
+'</span>'+
563 '<input type="hidden" name="'+formvarname
+'['+termid
+'][jtid]" value="'+jtid
+'" />'+
564 '<img title="Retirer ce mot-clef" alt="retirer" src="images/icons/cross.gif" />'+
566 if (lastJobTerm
.length
== 0) {
567 $(parentpath
+ '.job_terms').prepend(newdiv
);
569 lastJobTerm
.after(newdiv
);
571 $('#job'+jobid
+'_term'+jtid
+' img').css('cursor','pointer').click(removeJobTerm
);
576 * Remove a job term in job profile page.
577 * Must be called from a button in a div containing the term
579 function removeJobTerm()
581 $(this).parent().remove();
585 * Prepare display for autocomplete suggestions in job terms
586 * @param row an array of (title of term, id of term)
587 * @return text to display
588 * If id is negative, it is because there are too much terms to
591 function displayJobTerm(row
)
594 return '... <em>parcourir les résultats dans un arbre</em> ...';
600 * Function called when a job term has been selected from autocompletion
602 * @param li is the list item (<li>) that has been clicked
603 * The context is the jsquery autocomplete object.
605 function selectJobTerm(li
)
607 var jobid
= this.extraParams
.jobid
;
608 if (li
.extra
[0] >= 0) {
609 addJobTerm(jobid
,li
.extra
[0],$(li
).text());
613 search_input
= $('.term_search')[0];
615 search_input
= $('#job_'+jobid
+' .term_search')[0];
617 if (li
.extra
[0] >= 0) {
618 search_input
.value
= '';
619 search_input
.focus();
621 search_input
.value
= li
.selectValue
.replace(/%$/,'');
622 toggleJobTermsTree(jobid
, li
.selectValue
);
627 * Function to show or hide a terms tree in job edition
628 * @param jobid is the id of the job currently edited
630 function toggleJobTermsTree(jobid
, textfilter
)
636 treepath
= '#job_'+jobid
+' ';
638 treepath
+= '.term_tree';
639 if ($(treepath
+ ' ul').length
> 0) {
640 $(treepath
).empty().removeClass().addClass('term_tree');
645 createJobTermsTree(treepath
, 'profile/ajax/tree/jobterms/all', 'job' + jobid
, 'chooseJobTerm', textfilter
);
649 * Function called when a job term is chosen from terms tree
650 * @param treeid is the full id of the tree (must look like job3)
651 * @param jtid is the id of the job term chosen
652 * @param fullname is the complete name (understandable without context) of the term
654 function chooseJobTerm(treeid
, jtid
, fullname
)
656 addJobTerm(treeid
.replace(/^job(.*)$/, '$1'), jtid
, fullname
);
661 function addSkill(cat
)
663 var val
= $('#' + cat
+ '_table').find('[name=' + cat
+ '_sel]').val();
664 var text
= $('#' + cat
+ '_table').find('[name=' + cat
+ '_sel] :selected').text();
665 $.get(platal_baseurl
+ 'profile/ajax/skill/' + cat + '/' + val
,
667 $('#' + cat
).append(data
);
668 $('#' + cat
+ '_' + val
+ '_title').text(text
);
675 function addCountry()
677 var val
= $('#countries_table').find('[name=countries_sel] :selected').val();
678 var text
= $('#countries_table').find('[name=countries_sel] :selected').text();
679 var html
= '<div id="countries_' + val
+ '" style="clear: both; margin-bottom: 0.7em">'
680 + ' <a href="javascript:removeElement(\'countries\',\'' + val
+ '\')" style="display: block; float:right">'
681 + ' <img src="images/icons/cross.gif" alt="" title="Supprimer ce pays" />'
683 + ' <div style="float: left; width: 50%">' + text
+ '</div>'
684 + ' <input type="hidden" name="countries[' + val
+ ']" value="' + text
+ '" />'
686 $('#countries').append(html
);
687 updateElement('countries');
690 function registerEnterpriseAutocomplete(id
)
692 $(".enterpriseName").each(
694 if (id
== -1 || this.name
== "jobs[" + id
+ "][name]") {
695 $(this).autocomplete(platal_baseurl
+ "search/autocomplete/entreprise",
700 width
:$(this).width()
705 $(".sectorName").each(
707 if (id
== -1 || this.name
== "jobs[" + id
+ "][subSubSectorName]") {
708 $(this).autocomplete(platal_baseurl
+ "search/autocomplete/subSubSector",
713 width
:$(this).width()
719 // {{{1 Multiusage functions
721 function updateElement(cat
)
723 var val
= $('#' + cat
+ '_table').find('[name=' + cat
+ '_sel]').val();
724 if (val
== '' || $('#' + cat
+ '_' + val
).length
!= 0) {
725 $('#' + cat
+ '_add').hide();
727 $('#' + cat
+ '_add').show();
731 function removeElement(cat
, id
)
733 $('#' + cat
+ '_' + id
).remove();
737 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: