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 Ajax
.update_html('search_name_' + i
, 'profile/ajax/searchname/' + i + '/' + isFemale
, function(data
){
81 $('#searchname').before(data
);
86 function removeSearchName(i
, isFemale
)
88 $('#search_name_' + i
).remove();
89 updateNameDisplay(isFemale
);
92 function changeNameFlag(i
)
94 $('#flag_' + i
).remove();
95 var typeid
= $('#search_name_' + i
).find('select').val();
96 var type
= $('#search_name_' + i
).find('select :selected').text();
97 if ($('[name=sn_type_' + typeid
+ '_' + i
+ ']').val() > 0) {
98 $('#flag_cb_' + i
).after('<span id="flag_' + i
+ '"> ' +
99 '<img src="images/icons/flag_green.gif" alt="site public" title="site public" />' +
100 '<input type="hidden" name="search_names[' + i
+ '][pub]" value="1"/>' +
101 '<input type="hidden" name="search_names[' + i
+ '][typeid]" value="' + typeid
+ '"/>' +
102 '<input type="hidden" name="search_names[' + i
+ '][type]" value="' + type
+ '"/></span>');
104 $('#flag_cb_' + i
).after('<span id="flag_' + i
+ '"> ' +
105 '<img src="images/icons/flag_red.gif" alt="site privé" title="site privé" />' +
106 '<input type="hidden" name="search_names[' + i
+ '][typeid]" value="' + typeid
+ '"/>' +
107 '<input type="hidden" name="search_names[' + i
+ '][type]" value="' + type
+ '"/></span>');
111 function updateNameDisplay(isFemale
)
113 var searchnames
= '';
114 for (var i
= 0; i
< 10; i
++) {
115 if ($('#search_name_' + i
).find(':text').val()) {
116 searchnames
+= $('#search_name_' + i
).find('[name*=typeid]').val() + ';';
117 searchnames
+= $('#search_name_' + i
).find(':text').val() + ';;';
120 Ajax
.update_html(null, 'profile/ajax/buildnames/' + searchnames + '/' + isFemale
, function(data
){
121 var name
= data
.split(';');
122 $('#public_name').html(name
[0]);
123 $('#private_name').html(name
[0] + name
[1]);
127 function toggleParticle(id
)
129 if ($('#search_name_' + id
).find("[name*='[particle]']").val() == '') {
130 $('#search_name_' + id
).find("[name*='[particle]']").val(1);
132 $('#search_name_' + id
).find("[name*='[particle]']").val('');
138 function togglePromotionEdition()
140 $(".promotion_edition").toggle();
143 // Nationalities {{{1
145 function delNationality(i
)
147 $('#nationality' + i
).hide().find('select').val('');
150 function addNationality()
153 if ($('#nationality2').find('select').val() == "") {
155 } else if ($('#nationality3').find('select').val() == "") {
158 if ((i
== 2) || (i
== 3)) {
159 $('#nationality' + i
).show();
165 function prepareType(id
)
167 var edu
= $('.edu_' + id
).find("[name='edus[" + id
+ "][eduid]']").val() - 1;
168 var sel
= $('.edu_' + id
).find('[name=edu_' + id
+ '_tmp]').val();
170 if (educationDegree
[edu
]) {
171 var length
= educationDegree
[edu
].length
;
175 for (i
= 0; i
< length
; ++i
) {
176 html
+= '<option value="' + educationDegree
[edu
][i
] + '"';
177 if (sel
== educationDegree
[edu
][i
]) {
178 html
+= ' selected="selected"';
180 html
+= '>' + educationDegreeName
[educationDegree
[edu
][i
] - 1] + '</option>';
182 // XXX: to be removed once SQL table profile_merge_issues is.
183 if (sel
!= '' && html
== '') {
184 html
+= '<option value="' + sel
+ '" selected="selected">' + educationDegreeName
[sel
- 1] + '</option>';
186 $('.edu_' + id
).find("[name='edus[" + id
+ "][degreeid]']").html(html
);
196 while (!$('#edu_add').hasClass(prefix
+ i
)) {
197 if ($('.' + prefix
+ i
).length
!= 0) {
203 class_parity
= 'pair';
205 class_parity
= 'impair';
207 $('#edu_add').removeClass(prefix
+ i
);
209 $('#edu_add').addClass(prefix
+ i
);
211 $.get(platal_baseurl
+ 'profile/ajax/edu/' + i + '/' + class_parity
,
213 $('#edu_add').before(data
);
218 function removeEdu(i
)
221 $('.' + prefix
+ i
).remove();
222 while (!$('#edu_add').hasClass(prefix
+ i
)) {
223 $('.' + prefix
+ i
).toggleClass('pair');
224 $('.' + prefix
+ i
).toggleClass('impair');
231 function addNetworking()
234 while ($('#networking_' + i
).length
!= 0) {
238 var html
= '<tr id="networking_' + i
+ '">'
239 + ' <td colspan="2">'
240 + ' <div style="float: left; width: 200px;">'
241 + ' <span class="flags">'
242 + ' <input type="checkbox" name="networking[' + i
+ '][pub]"/>'
243 + ' <img src="images/icons/flag_green.gif" alt="site public" title="site public">'
245 + ' <select name="networking[' + i
+ '][type]" onchange="javascript:updateNetworking(' + i
+ ');">';
246 for (nw
in nw_list
) {
247 if (namefirst
== '') {
250 html
+= ' <option value="' + nw_list
[nw
] + '">' + nw
+ '</option>';
253 + ' <input type="hidden" name="networking[' + i
+ '][name]" value="' + namefirst
+ '"/>'
255 + ' <div style="float: left">'
256 + ' <input type="text" name="networking[' + i
+ '][address]" value="" size="30"/>'
257 + ' <a href="javascript:removeNetworking(' + i
+ ')">'
258 + ' <img src="images/icons/cross.gif" alt="cross" title="Supprimer cet élément"/>'
264 $('#networking').before(html
);
267 function removeNetworking(id
)
269 $('#networking_' + id
).remove();
272 function updateNetworking(i
)
274 $('#networking_' + i
).find("[name='networking[" + i
+ "][name]']").val($('#networking_' + i
).find('select option:selected').text());
279 function toggleAddress(id
, val
)
281 $('#addresses_' + id
+ '_grayed').toggle();
282 $('#addresses_' + id
).toggle();
283 $('#addresses_' + id
+ '_cont').find('[name*=removed]').val(val
);
284 checkCurrentAddress();
287 function checkCurrentAddress(id
)
289 var hasCurrentAddress
= id
? true : false;
291 while ($('#addresses_' + i
+ '_cont').length
!= 0) {
292 if ($('#addresses_' + i
+ '_cont').find('[name*=removed]').val() == 1) {
293 $('#addresses_' + i
+ '_cont').find('[name*=current]').attr('checked', false);
295 if (!hasCurrentAddress
&& $('#addresses_' + i
+ '_cont').find('[name*=current]:checked').length
!= 0) {
296 hasCurrentAddress
= true;
298 $('#addresses_' + i
+ '_cont').find('[name*=current]').attr('checked', false);
302 if (!hasCurrentAddress
) {
304 while ($('#addresses_' + i
+ '_cont').length
!= 0) {
305 if ($('#addresses_' + i
+ '_cont').find('[name*=removed]').val() == 0) {
306 $('#addresses_' + i
+ '_cont').find('[name*=current]').attr('checked', 'checked');
313 $('#addresses_' + id
+ '_cont').find('[name*=current]').attr('checked', 'checked');
317 function addAddress()
320 while ($('#addresses_' + i
+ '_cont').length
!= 0) {
323 $('#add_address').before('<div id="addresses_' + i
+ '_cont"></div>');
324 Ajax
.update_html('addresses_' + i
+ '_cont', 'profile/ajax/address/' + i
, checkCurrentAddress());
327 function addressChanged(prefid
)
329 $('#' + prefid
+ '_cont').find('[name*=changed]').val("1");
332 function validGeoloc(prefid
, id
, geoloc
)
335 $('#' + prefid
+ '_cont').find('[name*=text]').val($('#' + prefid
+ '_cont').find('[name*=geocodedText]').val());
336 $('#' + prefid
+ '_cont').find('[name*=postalText]').val('');
339 $('#' + prefid
+ '_cont').find("[name*='[geocodedText]']").remove();
341 $('#' + prefid
+ '_cont').find('[name*=text]').removeClass('error');
342 $('#' + prefid
+ '_cont').find('[name*=geocodeChosen]').val(geoloc
);
343 $('.' + prefid
+ '_geoloc').remove();
348 function addTel(prefid
, prefname
, subField
, mainField
, mainId
)
351 var prefix
= prefid
+ '_';
352 while ($('#' + prefix
+ i
).length
!= 0) {
355 $('#' + prefix
+ 'add').before('<div id="' + prefix
+ i
+ '" style="clear: both; padding-top: 4px; padding-bottom: 4px"></div>');
356 Ajax
.update_html(prefix
+ i
, 'profile/ajax/tel/' + prefid + '/' + prefname
+ '/' + i + '/' + subField
+ '/' + mainField + '/' + mainId
);
359 function removeTel(prefname
, prefid
, id
)
362 while ($('#' + prefid
+ '_' + total
).length
!= 0) {
365 $('#' + prefid
+ '_' + id
).remove();
366 for (var i
= parseInt(id
) + 1; i
< total
; ++i
) {
367 renumberPhone(prefname
, prefid
, i
);
371 function addPhoneComment(id
)
373 $('#' + id
+ '_comment').show();
374 $('#' + id
+ '_addComment').hide();
377 function removePhoneComment(id
, pref
)
379 $('#' + id
+ '_comment').hide();
380 $('#' + id
+ '_comment').find("[name='" + pref
+ "[comment]']").val('');
381 $('#' + id
+ '_addComment').show();
384 function renumberPhone(prefname
, prefid
, i
)
387 var telprefOld
= prefname
+ '[' + i
+ ']';
388 var telpref
= prefname
+ '[' + telid
+ ']';
389 var idOld
= prefid
+ '_' + i
;
390 var id
= prefid
+ '_' + telid
;
392 $('#' + idOld
).attr('id', id
);
393 $('#' + id
).find('div.titre').html('N°' + i
);
394 $('#' + id
).find('a.removeTel').attr('href', 'javascript:removeTel(\'' + prefname
+ '\',\'' + prefid
+ '\',' + telid
+ ')');
395 $('#' + id
).find('select').attr('name', telpref
+ '[type]');
396 $('#' + id
).find("[name='" + telprefOld
+ "[display]']").attr('name', telpref
+ '[display]');
397 $('#' + id
).find("[name='" + telprefOld
+ "[comment]']").attr('name', telpref
+ '[comment]');
398 $('#' + id
).find('a.removePhoneComment').attr('href', 'javascript:removePhoneComment(' + id
+ ',' + telpref
+ ')');
399 $('#' + id
).find('#' + idOld
+ '_addComment').attr('id', id
+ '_addComment');
400 $('#' + id
).find('#' + id
+ '_addComment').attr('href', 'javascript:addPhoneComment(' + id
+ ')');
401 $('#' + id
).find('#' + idOld
+ '_comment').attr('id', id
+ '_comment');
402 $('#' + id
).find("[name='" + telprefOld
+ "[pub]']").attr('name', telpref
+ '[pub]');
409 var id
= $('#binets_table').find('[name=binets_sel]').val();
410 var text
= $('#binets_table').find('select option:selected').text();
411 var html
= '<tr id="binets_' + id
+ '">'
413 + ' <input type="hidden" name="binets[' + id
+ ']" value="' + text
+ '" />'
416 + ' <div style="float: left; width: 70%">'
419 + ' <a href="javascript:removeElement(\'binets\',' + id
+ ')">'
420 + ' <img src="images/icons/cross.gif" alt="cross" title="Supprimer ce groupe" />'
424 $('#binets_table').after(html
);
425 updateElement('binets');
428 function updateGroupSubLink()
430 var href
= $('[name*=groupesx_sub]').val() ? $('[name*=groupesx_sub]').val() : 'http://www.polytechnique.net';
431 $('#groupesx_sub').attr('href', href
);
436 function updateMedal()
438 var val
= $('#medals').find('[name*=medal_sel]').val();
439 if (val
&& ($('#medal_' + val
).length
== 0)) {
440 $('#medal_add').show();
442 $('#medal_add').hide();
446 function getMedalName(id
)
448 $('#medal_name_' + id
).html(names
[id
]);
451 function buildGrade(id
, current
)
454 var subg
= subgrades
[id
];
455 var obj
= $('#medal_grade_' + id
);
457 obj
.prepend('<input type="hidden" name="medals[' + id
+ '][grade]" value="0" />');
459 var html
= 'Agrafe : <select name="medals[' + id
+ '][grade]">';
460 html
+= '<option value="0">Non précisée</option>';
461 for (grade
= 0 ; grade
< subg
.length
; grade
++) {
462 html
+= '<option value="' + subg
[grade
][0] + '"';
463 if (subg
[grade
][0] == current
) {
464 html
+= ' selected="selected"';
466 html
+= '>' + subg
[grade
][1] + '</option>';
474 function makeAddProcess(id
)
476 return function(data
)
478 $('#medals').after(data
);
487 var id
= $('#medals').find('[name=medal_sel]').val();
488 $.get(platal_baseurl
+ 'profile/ajax/medal/' + id
, makeAddProcess(id
));
491 function removeMedal(id
)
493 $("#medal_" + id
).remove();
499 function removeJob(id
, pref
)
501 $('#' + id
+ '_cont').hide();
502 if ($('#' + id
).find("[name='" + pref
+ "[new]']").val() == '0') {
503 $('#' + id
+ '_grayed').show();
504 $('#' + id
+ '_grayed_name').html($('#' + id
).find("[name='" + pref
+ "[name]']").val());
506 $('#' + id
).find("[name='" + pref
+ "[removed]']").val('1');
509 function restoreJob(id
, pref
)
511 $('#' + id
+ '_cont').show();
512 $('#' + id
+ '_grayed').hide();
513 $('#' + id
).find("[name='" + pref
+ "[removed]']").val('0');
516 function makeAddJob(id
)
518 return function(data
)
520 $('#add_job').before(data
);
521 registerEnterpriseAutocomplete(id
);
528 while ($('#jobs_' + i
).length
!= 0) {
531 $.get(platal_baseurl
+ 'profile/ajax/job/' + i
, makeAddJob(i
));
534 function addEntreprise(id
)
536 $('.entreprise_' + id
).toggle();
540 * Adds a job term in job profile page
541 * @param jobid id of profile's job among his different jobs
542 * @param jtid id of job term to add
543 * @param full_name full text of job term
544 * @return false if the term already exist for this job, true otherwise
546 function addJobTerm(jobid
, jtid
, full_name
)
554 formvarname
= 'terms';
556 parentpath
= '#jobs_'+jobid
+' ';
557 formvarname
= 'jobs['+jobid
+'][terms]';
559 var lastJobTerm
= $(parentpath
+ '.jobs_term:last');
560 if (lastJobTerm
.length
!= 0) {
561 termid
= parseInt(lastJobTerm
.children('input').attr('name').replace(/^(jobs\[[0-9]+\]\[terms\]|terms)\[([0-9]+)\]\[jtid\]/, '$2')) + 1;
562 if ($('#job'+jobid
+'_term'+jtid
).length
> 0) {
566 var newdiv
= '<div class="jobs_term" id="job'+jobid
+'_term'+jtid
+'">'+
567 '<span>'+full_name
+'</span>'+
568 '<input type="hidden" name="'+formvarname
+'['+termid
+'][jtid]" value="'+jtid
+'" />'+
569 '<img title="Retirer ce mot-clef" alt="retirer" src="images/icons/cross.gif" />'+
571 if (lastJobTerm
.length
== 0) {
572 $(parentpath
+ '.jobs_terms').prepend(newdiv
);
574 lastJobTerm
.after(newdiv
);
576 $('#job'+jobid
+'_term'+jtid
+' img').css('cursor','pointer').click(removeJobTerm
);
581 * Remove a job term in job profile page.
582 * Must be called from a button in a div containing the term
584 function removeJobTerm()
586 $(this).parent().remove();
590 * Prepare display for autocomplete suggestions in job terms
591 * @param row an array of (title of term, id of term)
592 * @return text to display
593 * If id is negative, it is because there are too much terms to
596 function displayJobTerm(row
)
599 return '... <em>parcourir les résultats dans un arbre</em> ...';
605 * Function called when a job term has been selected from autocompletion
607 * @param li is the list item (<li>) that has been clicked
608 * The context is the jsquery autocomplete object.
610 function selectJobTerm(li
)
612 var jobid
= this.extraParams
.jobid
;
613 if (li
.extra
[0] >= 0) {
614 addJobTerm(jobid
,li
.extra
[0],$(li
).text());
618 search_input
= $('.term_search')[0];
620 search_input
= $('#jobs_'+jobid
+' .term_search')[0];
622 if (li
.extra
[0] >= 0) {
623 search_input
.value
= '';
624 search_input
.focus();
626 search_input
.value
= li
.selectValue
.replace(/%$/,'');
627 toggleJobTermsTree(jobid
, li
.selectValue
);
632 * Function to show or hide a terms tree in job edition
633 * @param jobid is the id of the job currently edited
635 function toggleJobTermsTree(jobid
, textfilter
)
641 treepath
= '#jobs_'+jobid
+' ';
643 treepath
+= '.term_tree';
644 if ($(treepath
+ ' ul').length
> 0) {
645 $(treepath
).empty().removeClass().addClass('term_tree');
650 createJobTermsTree(treepath
, 'profile/ajax/tree/jobterms/all', 'job' + jobid
, 'chooseJobTerm', textfilter
);
654 * Function called when a job term is chosen from terms tree
655 * @param treeid is the full id of the tree (must look like job3)
656 * @param jtid is the id of the job term chosen
657 * @param fullname is the complete name (understandable without context) of the term
659 function chooseJobTerm(treeid
, jtid
, fullname
)
661 addJobTerm(treeid
.replace(/^job(.*)$/, '$1'), jtid
, fullname
);
666 function addSkill(cat
)
668 var val
= $('#' + cat
+ '_table').find('[name=' + cat
+ '_sel]').val();
669 var text
= $('#' + cat
+ '_table').find('[name=' + cat
+ '_sel] :selected').text();
670 $.get(platal_baseurl
+ 'profile/ajax/skill/' + cat + '/' + val
,
672 $('#' + cat
).append(data
);
673 $('#' + cat
+ '_' + val
+ '_title').text(text
);
680 function addCountry()
682 var val
= $('#countries_table').find('[name=countries_sel] :selected').val();
683 var text
= $('#countries_table').find('[name=countries_sel] :selected').text();
684 var html
= '<div id="countries_' + val
+ '" style="clear: both; margin-bottom: 0.7em">'
685 + ' <a href="javascript:removeElement(\'countries\',\'' + val
+ '\')" style="display: block; float:right">'
686 + ' <img src="images/icons/cross.gif" alt="" title="Supprimer ce pays" />'
688 + ' <div style="float: left; width: 50%">' + text
+ '</div>'
689 + ' <input type="hidden" name="countries[' + val
+ ']" value="' + text
+ '" />'
691 $('#countries').append(html
);
692 updateElement('countries');
695 function registerEnterpriseAutocomplete(id
)
697 $(".enterpriseName").each(
699 if (id
== -1 || this.name
== "jobs[" + id
+ "][name]") {
700 $(this).autocomplete(platal_baseurl
+ "search/autocomplete/entreprise",
705 width
:$(this).width()
710 $(".sectorName").each(
712 if (id
== -1 || this.name
== "jobs[" + id
+ "][subSubSectorName]") {
713 $(this).autocomplete(platal_baseurl
+ "search/autocomplete/subSubSector",
718 width
:$(this).width()
724 // {{{1 Multiusage functions
726 function updateElement(cat
)
728 var val
= $('#' + cat
+ '_table').find('[name=' + cat
+ '_sel]').val();
729 if (val
== '' || $('#' + cat
+ '_' + val
).length
!= 0) {
730 $('#' + cat
+ '_add').hide();
732 $('#' + cat
+ '_add').show();
736 function removeElement(cat
, id
)
738 $('#' + cat
+ '_' + id
).remove();
742 function updateSubPublicity(subFieldId
, name
, mainPub
)
744 var subPub
= $(subFieldId
).find("[name='" + name
+ "']:checked").val();
745 if (publicity
[subPub
] > publicity
[mainPub
]) {
746 $(subFieldId
).find("[name='" + name
+ "']:checked").removeAttr('checked');
747 $(subFieldId
).find('[value=' + mainPub
+ ']').attr('checked', 'checked');
751 function updatePublicity(mainField
, mainId
, subField
, subId
)
753 var mainFieldId
= '#' + mainField
+ '_' + mainId
;
754 var mainPub
= $(mainFieldId
).find("[name='" + mainField
+ "[" + mainId
+ "][pub]']:checked").val();
756 var subFields
= subField
.split(',');
757 for (var i
=0; i
< subFields
.length
; ++i
) {
758 var subFieldBaseId
= mainFieldId
+ '_' + subFields
[i
];
759 var name
= mainField
+ '[' + mainId
+ '][' + subFields
[i
] + ']';
760 if ($(subFieldBaseId
).length
!= 0) {
761 updateSubPublicity(subFieldBaseId
, name
+ '[pub]', mainPub
);
762 updateSubPublicity(subFieldBaseId
, mainField
+ '[' + mainId
+ '][' + subFields
[i
] + '_pub]', mainPub
);
765 while ($(subFieldBaseId
+ '_' + subId
).length
!= 0) {
766 updateSubPublicity(subFieldBaseId
+ '_' + subId
, name
+ '[' + subId
+ '][pub]', mainPub
);
772 updateSubPublicity(mainFieldId
+ '_' + subField
, mainField
+ '[' + mainId
+ '][' + subField
+ '_pub]', mainPub
);
773 updateSubPublicity(mainFieldId
+ '_' + subField
, mainField
+ '[' + mainId
+ '][' + subField
+ '][pub]', mainPub
);
775 updateSubPublicity(mainFieldId
+ '_' + subField
+ '_' + subId
, mainField
+ '[' + mainId
+ '][' + subField
+ '][' + subId
+ '][pub]', mainPub
);
780 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: