d5106b09979c5876fef07ebd46f1542f021cf558
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 ($('#jobs_0').find("[name='jobs[0][name]']").val() == '') {
49 registerEnterpriseAutocomplete(0);
56 var educationDegreeAll
;
57 var educationDegreeName
;
61 // Publicity follows the following ordering: private < ax < public.
63 publicity
['private'] = 0;
65 publicity
['public'] = 2;
69 function toggleNamesAdvanced()
71 $('.names_advanced').toggle();
74 function addSearchName(isFemale
)
77 while ($('#search_name_' + i
).length
!= 0) {
80 $('#search_name_' + i
)
81 .updateHtml('profile/ajax/searchname/' + i + '/' + isFemale
,
83 $('#searchname').before(data
);
88 function removeSearchName(i
, isFemale
)
90 $('#search_name_' + i
).remove();
91 updateNameDisplay(isFemale
);
94 function changeNameFlag(i
)
96 $('#flag_' + i
).remove();
97 var typeid
= $('#search_name_' + i
).find('select').val();
98 var type
= $('#search_name_' + i
).find('select :selected').text();
99 if ($('[name=sn_type_' + typeid
+ '_' + i
+ ']').val() > 0) {
100 $('#flag_cb_' + i
).after('<span id="flag_' + i
+ '"> ' +
101 '<img src="images/icons/flag_green.gif" alt="site public" title="site public" />' +
102 '<input type="hidden" name="search_names[' + i
+ '][pub]" value="1"/>' +
103 '<input type="hidden" name="search_names[' + i
+ '][typeid]" value="' + typeid
+ '"/>' +
104 '<input type="hidden" name="search_names[' + i
+ '][type]" value="' + type
+ '"/></span>');
106 $('#flag_cb_' + i
).after('<span id="flag_' + i
+ '"> ' +
107 '<img src="images/icons/flag_red.gif" alt="site privé" title="site privé" />' +
108 '<input type="hidden" name="search_names[' + i
+ '][typeid]" value="' + typeid
+ '"/>' +
109 '<input type="hidden" name="search_names[' + i
+ '][type]" value="' + type
+ '"/></span>');
113 function updateNameDisplay(isFemale
)
115 var searchnames
= '';
116 for (var i
= 0; i
< 10; i
++) {
117 if ($('#search_name_' + i
).find(':text').val()) {
118 searchnames
+= $('#search_name_' + i
).find('[name*=typeid]').val() + ';';
119 searchnames
+= $('#search_name_' + i
).find(':text').val() + ';;';
122 $.xget('profile/ajax/buildnames/' + searchnames + '/' + isFemale
, 'text',
124 var name
= data
.split(';');
125 $('#public_name').html(name
[0]);
126 $('#private_name').html(name
[0] + name
[1]);
130 function toggleParticle(id
)
132 if ($('#search_name_' + id
).find("[name*='[particle]']").val() == '') {
133 $('#search_name_' + id
).find("[name*='[particle]']").val(1);
135 $('#search_name_' + id
).find("[name*='[particle]']").val('');
141 function togglePromotionEdition()
143 $(".promotion_edition").toggle();
146 // Nationalities {{{1
148 function delNationality(i
)
150 $('#nationality' + i
).hide().find('select').val('');
153 function addNationality()
156 if ($('#nationality2').find('select').val() == "") {
158 } else if ($('#nationality3').find('select').val() == "") {
161 if ((i
== 2) || (i
== 3)) {
162 $('#nationality' + i
).show();
168 function prepareType(id
)
170 var edu
= $('.edu_' + id
).find("[name='edus[" + id
+ "][eduid]']").val() - 1;
171 var sel
= $('.edu_' + id
).find('[name=edu_' + id
+ '_tmp]').val();
173 if (educationDegree
[edu
]) {
174 var length
= educationDegree
[edu
].length
;
178 for (i
= 0; i
< length
; ++i
) {
179 html
+= '<option value="' + educationDegree
[edu
][i
] + '"';
180 if (sel
== educationDegree
[edu
][i
]) {
181 html
+= ' selected="selected"';
183 html
+= '>' + educationDegreeName
[educationDegree
[edu
][i
] - 1] + '</option>';
185 // XXX: to be removed once SQL table profile_merge_issues is.
186 if (sel
!= '' && html
== '') {
187 html
+= '<option value="' + sel
+ '" selected="selected">' + educationDegreeName
[sel
- 1] + '</option>';
189 $('.edu_' + id
).find("[name='edus[" + id
+ "][degreeid]']").html(html
);
199 while (!$('#edu_add').hasClass(prefix
+ i
)) {
200 if ($('.' + prefix
+ i
).length
!= 0) {
206 class_parity
= 'pair';
208 class_parity
= 'impair';
210 $('#edu_add').removeClass(prefix
+ i
);
212 $('#edu_add').addClass(prefix
+ i
);
214 $.get(platal_baseurl
+ 'profile/ajax/edu/' + i + '/' + class_parity
,
216 $('#edu_add').before(data
);
221 function removeEdu(i
)
224 $('.' + prefix
+ i
).remove();
225 while (!$('#edu_add').hasClass(prefix
+ i
)) {
226 $('.' + prefix
+ i
).toggleClass('pair');
227 $('.' + prefix
+ i
).toggleClass('impair');
234 function addNetworking()
237 while ($('#networking_' + i
).length
!= 0) {
241 var html
= '<tr id="networking_' + i
+ '">'
242 + ' <td colspan="2">'
243 + ' <div style="float: left; width: 200px;">'
244 + ' <span class="flags">'
245 + ' <input type="checkbox" name="networking[' + i
+ '][pub]"/>'
246 + ' <img src="images/icons/flag_green.gif" alt="site public" title="site public">'
248 + ' <select name="networking[' + i
+ '][type]" onchange="javascript:updateNetworking(' + i
+ ');">';
249 for (nw
in nw_list
) {
250 if (namefirst
== '') {
253 html
+= ' <option value="' + nw_list
[nw
] + '">' + nw
+ '</option>';
256 + ' <input type="hidden" name="networking[' + i
+ '][name]" value="' + namefirst
+ '"/>'
258 + ' <div style="float: left">'
259 + ' <input type="text" name="networking[' + i
+ '][address]" value="" size="30"/>'
260 + ' <a href="javascript:removeNetworking(' + i
+ ')">'
261 + ' <img src="images/icons/cross.gif" alt="cross" title="Supprimer cet élément"/>'
267 $('#networking').before(html
);
270 function removeNetworking(id
)
272 $('#networking_' + id
).remove();
275 function updateNetworking(i
)
277 $('#networking_' + i
).find("[name='networking[" + i
+ "][name]']").val($('#networking_' + i
).find('select option:selected').text());
282 function toggleAddress(id
, val
)
284 $('#addresses_' + id
+ '_grayed').toggle();
285 $('#addresses_' + id
).toggle();
286 $('#addresses_' + id
+ '_cont').find('[name*=removed]').val(val
);
287 checkCurrentAddress();
290 function checkCurrentAddress(id
)
292 var hasCurrentAddress
= id
? true : false;
294 while ($('#addresses_' + i
+ '_cont').length
!= 0) {
295 if ($('#addresses_' + i
+ '_cont').find('[name*=removed]').val() == 1) {
296 $('#addresses_' + i
+ '_cont').find('[name*=current]').attr('checked', false);
298 if (!hasCurrentAddress
&& $('#addresses_' + i
+ '_cont').find('[name*=current]:checked').length
!= 0) {
299 hasCurrentAddress
= true;
301 $('#addresses_' + i
+ '_cont').find('[name*=current]').attr('checked', false);
305 if (!hasCurrentAddress
) {
307 while ($('#addresses_' + i
+ '_cont').length
!= 0) {
308 if ($('#addresses_' + i
+ '_cont').find('[name*=removed]').val() == 0) {
309 $('#addresses_' + i
+ '_cont').find('[name*=current]').attr('checked', 'checked');
316 $('#addresses_' + id
+ '_cont').find('[name*=current]').attr('checked', 'checked');
320 function addAddress()
323 while ($('#addresses_' + i
+ '_cont').length
!= 0) {
326 $('#add_address').before('<div id="addresses_' + i
+ '_cont"></div>');
327 $('#addresses_' + i
+ '_cont').updateHtml('profile/ajax/address/' + i
,
328 checkCurrentAddress());
331 function addressChanged(prefid
)
333 $('#' + prefid
+ '_cont').find('[name*=changed]').val("1");
336 function validGeoloc(prefid
, id
, geoloc
)
339 $('#' + prefid
+ '_cont').find('[name*=text]').val($('#' + prefid
+ '_cont').find('[name*=geocodedText]').val());
340 $('#' + prefid
+ '_cont').find('[name*=postalText]').val('');
343 $('#' + prefid
+ '_cont').find("[name*='[geocodedText]']").remove();
345 $('#' + prefid
+ '_cont').find('[name*=text]').removeClass('error');
346 $('#' + prefid
+ '_cont').find('[name*=geocodeChosen]').val(geoloc
);
347 $('.' + prefid
+ '_geoloc').remove();
352 function addTel(prefid
, prefname
, subField
, mainField
, mainId
)
355 var prefix
= prefid
+ '_';
356 while ($('#' + prefix
+ i
).length
!= 0) {
359 $('#' + prefix
+ 'add').before('<div id="' + prefix
+ i
+ '" style="clear: both; padding-top: 4px; padding-bottom: 4px"></div>');
360 $('#' + prefix
+ i
).updateHtml('profile/ajax/tel/' + prefid + '/' + prefname
+ '/' + i + '/' + subField
+ '/' + mainField + '/' + mainId
);
363 function removeTel(prefname
, prefid
, id
)
366 while ($('#' + prefid
+ '_' + total
).length
!= 0) {
369 $('#' + prefid
+ '_' + id
).remove();
370 for (var i
= parseInt(id
) + 1; i
< total
; ++i
) {
371 renumberPhone(prefname
, prefid
, i
);
375 function addPhoneComment(id
)
377 $('#' + id
+ '_comment').show();
378 $('#' + id
+ '_addComment').hide();
381 function removePhoneComment(id
, pref
)
383 $('#' + id
+ '_comment').hide();
384 $('#' + id
+ '_comment').find("[name='" + pref
+ "[comment]']").val('');
385 $('#' + id
+ '_addComment').show();
388 function renumberPhone(prefname
, prefid
, i
)
391 var telprefOld
= prefname
+ '[' + i
+ ']';
392 var telpref
= prefname
+ '[' + telid
+ ']';
393 var idOld
= prefid
+ '_' + i
;
394 var id
= prefid
+ '_' + telid
;
396 $('#' + idOld
).attr('id', id
);
397 $('#' + id
).find('div.titre').html('N°' + i
);
398 $('#' + id
).find('a.removeTel').attr('href', 'javascript:removeTel(\'' + prefname
+ '\',\'' + prefid
+ '\',' + telid
+ ')');
399 $('#' + id
).find('select').attr('name', telpref
+ '[type]');
400 $('#' + id
).find("[name='" + telprefOld
+ "[display]']").attr('name', telpref
+ '[display]');
401 $('#' + id
).find("[name='" + telprefOld
+ "[comment]']").attr('name', telpref
+ '[comment]');
402 $('#' + id
).find('a.removePhoneComment').attr('href', 'javascript:removePhoneComment(' + id
+ ',' + telpref
+ ')');
403 $('#' + id
).find('#' + idOld
+ '_addComment').attr('id', id
+ '_addComment');
404 $('#' + id
).find('#' + id
+ '_addComment').attr('href', 'javascript:addPhoneComment(' + id
+ ')');
405 $('#' + id
).find('#' + idOld
+ '_comment').attr('id', id
+ '_comment');
406 $('#' + id
).find("[name='" + telprefOld
+ "[pub]']").attr('name', telpref
+ '[pub]');
413 var id
= $('#binets_table').find('[name=binets_sel]').val();
414 var text
= $('#binets_table').find('select option:selected').text();
415 var html
= '<tr id="binets_' + id
+ '">'
417 + ' <input type="hidden" name="binets[' + id
+ ']" value="' + text
+ '" />'
420 + ' <div style="float: left; width: 70%">'
423 + ' <a href="javascript:removeElement(\'binets\',' + id
+ ')">'
424 + ' <img src="images/icons/cross.gif" alt="cross" title="Supprimer ce groupe" />'
428 $('#binets_table').after(html
);
429 updateElement('binets');
432 function updateGroupSubLink()
434 var href
= $('[name*=groupesx_sub]').val() ? $('[name*=groupesx_sub]').val() : 'http://www.polytechnique.net';
435 $('#groupesx_sub').attr('href', href
);
440 function updateMedal()
442 var val
= $('#medals').find('[name*=medal_sel]').val();
443 if (val
&& ($('#medal_' + val
).length
== 0)) {
444 $('#medal_add').show();
446 $('#medal_add').hide();
450 function getMedalName(id
)
452 $('#medal_name_' + id
).html(names
[id
]);
455 function buildGrade(id
, current
)
458 var subg
= subgrades
[id
];
459 var obj
= $('#medal_grade_' + id
);
461 obj
.prepend('<input type="hidden" name="medals[' + id
+ '][grade]" value="0" />');
463 var html
= 'Agrafe : <select name="medals[' + id
+ '][grade]">';
464 html
+= '<option value="0">Non précisée</option>';
465 for (grade
= 0 ; grade
< subg
.length
; grade
++) {
466 html
+= '<option value="' + subg
[grade
][0] + '"';
467 if (subg
[grade
][0] == current
) {
468 html
+= ' selected="selected"';
470 html
+= '>' + subg
[grade
][1] + '</option>';
478 function makeAddProcess(id
)
480 return function(data
)
482 $('#medals').after(data
);
491 var id
= $('#medals').find('[name=medal_sel]').val();
492 $.get(platal_baseurl
+ 'profile/ajax/medal/' + id
, makeAddProcess(id
));
495 function removeMedal(id
)
497 $("#medal_" + id
).remove();
503 function removeJob(id
, pref
)
505 $('#' + id
+ '_cont').hide();
506 if ($('#' + id
).find("[name='" + pref
+ "[new]']").val() == '0') {
507 $('#' + id
+ '_grayed').show();
508 $('#' + id
+ '_grayed_name').html($('#' + id
).find("[name='" + pref
+ "[name]']").val());
510 $('#' + id
).find("[name='" + pref
+ "[removed]']").val('1');
513 function restoreJob(id
, pref
)
515 $('#' + id
+ '_cont').show();
516 $('#' + id
+ '_grayed').hide();
517 $('#' + id
).find("[name='" + pref
+ "[removed]']").val('0');
520 function makeAddJob(id
)
522 return function(data
)
524 $('#add_job').before(data
);
525 registerEnterpriseAutocomplete(id
);
532 while ($('#jobs_' + i
).length
!= 0) {
535 $.get(platal_baseurl
+ 'profile/ajax/job/' + i
, makeAddJob(i
));
538 function addEntreprise(id
)
540 $('.entreprise_' + id
).toggle();
544 * Adds a job term in job profile page
545 * @param jobid id of profile's job among his different jobs
546 * @param jtid id of job term to add
547 * @param full_name full text of job term
548 * @return false if the term already exist for this job, true otherwise
550 function addJobTerm(jobid
, jtid
, full_name
)
558 formvarname
= 'terms';
560 parentpath
= '#jobs_'+jobid
+' ';
561 formvarname
= 'jobs['+jobid
+'][terms]';
563 var lastJobTerm
= $(parentpath
+ '.jobs_term:last');
564 if (lastJobTerm
.length
!= 0) {
565 termid
= parseInt(lastJobTerm
.children('input').attr('name').replace(/^(jobs\[[0-9]+\]\[terms\]|terms)\[([0-9]+)\]\[jtid\]/, '$2')) + 1;
566 if ($('#job'+jobid
+'_term'+jtid
).length
> 0) {
570 var newdiv
= '<div class="jobs_term" id="job'+jobid
+'_term'+jtid
+'">'+
571 '<span>'+full_name
+'</span>'+
572 '<input type="hidden" name="'+formvarname
+'['+termid
+'][jtid]" value="'+jtid
+'" />'+
573 '<img title="Retirer ce mot-clef" alt="retirer" src="images/icons/cross.gif" />'+
575 if (lastJobTerm
.length
== 0) {
576 $(parentpath
+ '.jobs_terms').prepend(newdiv
);
578 lastJobTerm
.after(newdiv
);
580 $('#job'+jobid
+'_term'+jtid
+' img').css('cursor','pointer').click(removeJobTerm
);
585 * Remove a job term in job profile page.
586 * Must be called from a button in a div containing the term
588 function removeJobTerm()
590 $(this).parent().remove();
594 * Prepare display for autocomplete suggestions in job terms
595 * @param row an array of (title of term, id of term)
596 * @return text to display
597 * If id is negative, it is because there are too much terms to
600 function displayJobTerm(row
)
603 return '... <em>parcourir les résultats dans un arbre</em> ...';
609 * Function called when a job term has been selected from autocompletion
611 * @param li is the list item (<li>) that has been clicked
612 * The context is the jsquery autocomplete object.
614 function selectJobTerm(li
)
616 var jobid
= this.extraParams
.jobid
;
617 if (li
.extra
[0] >= 0) {
618 addJobTerm(jobid
,li
.extra
[0],$(li
).text());
622 search_input
= $('.term_search')[0];
624 search_input
= $('#jobs_'+jobid
+' .term_search')[0];
626 if (li
.extra
[0] >= 0) {
627 search_input
.value
= '';
628 search_input
.focus();
630 search_input
.value
= li
.selectValue
.replace(/%$/,'');
631 toggleJobTermsTree(jobid
, li
.selectValue
);
636 * Function to show or hide a terms tree in job edition
637 * @param jobid is the id of the job currently edited
639 function toggleJobTermsTree(jobid
, textfilter
)
645 treepath
= '#jobs_'+jobid
+' ';
647 treepath
+= '.term_tree';
648 if ($(treepath
+ ' ul').length
> 0) {
649 $(treepath
).empty().removeClass().addClass('term_tree');
654 createJobTermsTree(treepath
, 'profile/ajax/tree/jobterms/all', 'job' + jobid
, 'chooseJobTerm', textfilter
);
658 * Function called when a job term is chosen from terms tree
659 * @param treeid is the full id of the tree (must look like job3)
660 * @param jtid is the id of the job term chosen
661 * @param fullname is the complete name (understandable without context) of the term
663 function chooseJobTerm(treeid
, jtid
, fullname
)
665 addJobTerm(treeid
.replace(/^job(.*)$/, '$1'), jtid
, fullname
);
670 function addSkill(cat
)
672 var val
= $('#' + cat
+ '_table').find('[name=' + cat
+ '_sel]').val();
673 var text
= $('#' + cat
+ '_table').find('[name=' + cat
+ '_sel] :selected').text();
674 $.get(platal_baseurl
+ 'profile/ajax/skill/' + cat + '/' + val
,
676 $('#' + cat
).append(data
);
677 $('#' + cat
+ '_' + val
+ '_title').text(text
);
684 function addCountry()
686 var val
= $('#countries_table').find('[name=countries_sel] :selected').val();
687 var text
= $('#countries_table').find('[name=countries_sel] :selected').text();
688 var html
= '<div id="countries_' + val
+ '" style="clear: both; margin-bottom: 0.7em">'
689 + ' <a href="javascript:removeElement(\'countries\',\'' + val
+ '\')" style="display: block; float:right">'
690 + ' <img src="images/icons/cross.gif" alt="" title="Supprimer ce pays" />'
692 + ' <div style="float: left; width: 50%">' + text
+ '</div>'
693 + ' <input type="hidden" name="countries[' + val
+ ']" value="' + text
+ '" />'
695 $('#countries').append(html
);
696 updateElement('countries');
699 function registerEnterpriseAutocomplete(id
)
701 $(".enterpriseName").each(
703 if (id
== -1 || this.name
== "jobs[" + id
+ "][name]") {
704 $(this).autocomplete(platal_baseurl
+ "search/autocomplete/entreprise",
709 width
:$(this).width()
714 $(".sectorName").each(
716 if (id
== -1 || this.name
== "jobs[" + id
+ "][subSubSectorName]") {
717 $(this).autocomplete(platal_baseurl
+ "search/autocomplete/subSubSector",
722 width
:$(this).width()
728 // {{{1 Multiusage functions
730 function updateElement(cat
)
732 var val
= $('#' + cat
+ '_table').find('[name=' + cat
+ '_sel]').val();
733 if (val
== '' || $('#' + cat
+ '_' + val
).length
!= 0) {
734 $('#' + cat
+ '_add').hide();
736 $('#' + cat
+ '_add').show();
740 function removeElement(cat
, id
)
742 $('#' + cat
+ '_' + id
).remove();
746 function updateSubPublicity(subFieldId
, name
, mainPub
)
748 var subPub
= $(subFieldId
).find("[name='" + name
+ "']:checked").val();
749 if (publicity
[subPub
] > publicity
[mainPub
]) {
750 $(subFieldId
).find("[name='" + name
+ "']:checked").removeAttr('checked');
751 $(subFieldId
).find('[value=' + mainPub
+ ']').attr('checked', 'checked');
755 function updatePublicity(mainField
, mainId
, subField
, subId
)
757 var mainFieldId
= '#' + mainField
+ '_' + mainId
;
758 var mainPub
= $(mainFieldId
).find("[name='" + mainField
+ "[" + mainId
+ "][pub]']:checked").val();
760 var subFields
= subField
.split(',');
761 for (var i
=0; i
< subFields
.length
; ++i
) {
762 var subFieldBaseId
= mainFieldId
+ '_' + subFields
[i
];
763 var name
= mainField
+ '[' + mainId
+ '][' + subFields
[i
] + ']';
764 if ($(subFieldBaseId
).length
!= 0) {
765 updateSubPublicity(subFieldBaseId
, name
+ '[pub]', mainPub
);
766 updateSubPublicity(subFieldBaseId
, mainField
+ '[' + mainId
+ '][' + subFields
[i
] + '_pub]', mainPub
);
769 while ($(subFieldBaseId
+ '_' + subId
).length
!= 0) {
770 updateSubPublicity(subFieldBaseId
+ '_' + subId
, name
+ '[' + subId
+ '][pub]', mainPub
);
776 updateSubPublicity(mainFieldId
+ '_' + subField
, mainField
+ '[' + mainId
+ '][' + subField
+ '_pub]', mainPub
);
777 updateSubPublicity(mainFieldId
+ '_' + subField
, mainField
+ '[' + mainId
+ '][' + subField
+ '][pub]', mainPub
);
779 updateSubPublicity(mainFieldId
+ '_' + subField
+ '_' + subId
, mainField
+ '[' + mainId
+ '][' + subField
+ '][' + subId
+ '][pub]', mainPub
);
784 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: