X-Git-Url: http://git.polytechnique.org/?a=blobdiff_plain;f=htdocs%2Fjavascript%2Fprofile.js;h=6858861451ddbcf827a6478f986e777a11c6b51c;hb=8fcfc71f92d6f96e97c46413af0382d8a2e5cc1e;hp=01d00695dac2f8843bb45475f9e4401f9a3d222d;hpb=2992a284ddad592d4e985004a35a66e45aedfff7;p=platal.git diff --git a/htdocs/javascript/profile.js b/htdocs/javascript/profile.js index 01d0069..6858861 100644 --- a/htdocs/javascript/profile.js +++ b/htdocs/javascript/profile.js @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2003-2009 Polytechnique.org * + * Copyright (C) 2003-2011 Polytechnique.org * * http://opensource.polytechnique.org/ * * * * This program is free software; you can redistribute it and/or modify * @@ -37,17 +37,15 @@ function wizPage_onLoad(id) updateGroupSubLink(); break; case 'deco': - for (var i in names) { - if ($('#medal_' + i).length != 0) { - getMedalName(i); - buildGrade(i, $('#medal_' + i).find('[name*=medal_' + i + '_grade]').val()); - } + var i = 0; + while ($('#medal_' + i).length != 0) { + prepareMedal(i); + ++i; } break; case 'emploi': - for (var i = 0 ; $('#job_' + i).length != 0; ++i) { - updateJobSector(i, $('#job_' + i).find("[name='jobs[" + i + "][subSector]']").val()); - updateJobSubSector(i, $('#job_' + i).find("[name='jobs[" + i + "][subSubSector]']").val()); + if ($('#jobs_0').find("[name='jobs[0][name]']").val() == '') { + registerEnterpriseAutocomplete(0); } break; } @@ -58,6 +56,13 @@ var educationDegreeAll; var educationDegreeName; var subgrades; var names; +var multiples; + +// Publicity follows the following ordering: private < ax < public. +var publicity = []; +publicity['private'] = 0; +publicity['ax'] = 1; +publicity['public'] = 2; // Names {{{1 @@ -66,76 +71,79 @@ function toggleNamesAdvanced() $('.names_advanced').toggle(); } -function addSearchName() +function addSearchName(isFemale) { var i = 0; while ($('#search_name_' + i).length != 0) { i++; } - Ajax.update_html('search_name_' + i, 'profile/ajax/searchname/' + i, function(data){ - $('#searchname').before(data); - changeNameFlag(i); + $('#search_name_' + i).updateHtml('profile/ajax/searchname/' + i + '/' + isFemale, + function(data) { + $('#searchname').before(data); }); } -function removeSearchName(i) +function removeSearchName(i, isFemale) { $('#search_name_' + i).remove(); - updateNameDisplay(); + updateNameDisplay(isFemale); } -function changeNameFlag(i) +function updateNameDisplay(isFemale) { - $('#flag_' + i).remove(); - var typeid = $('#search_name_' + i).find('select').val(); - var type = $('#search_name_' + i).find('select :selected').text(); - if ($('[name=sn_type_' + typeid + '_' + i + ']').val() > 0) { - $('#flag_cb_' + i).after(' ' + - 'site public' + - '' + - '' + - ''); - } else { - $('#flag_cb_' + i).after(' ' + - 'site privé' + - '' + - ''); + var lastnames = new Array('lastname_main', 'lastname_ordinary', 'lastname_marital', 'pseudonym'); + var firstnames = new Array('firstname_main', 'firstname_ordinary'); + var searchnames = ''; + + for (var i = 0; i < 4; ++i) { + searchnames += $('.names_advanced').find('[name*=' + lastnames[i] + ']').val() + ';'; } -} + searchnames += '-;' + for (var i = 0; i < 2; ++i) { + searchnames += $('.names_advanced').find('[name*=' + firstnames[i] + ']').val() + ';'; + } + searchnames += '-'; -function updateNameDisplay() -{ - var searchnames = ''; - for (var i = 0; i < 10; i++) { + var has_private = false; + for (var i = 0; i < 10; ++i) { if ($('#search_name_' + i).find(':text').val()) { - searchnames += $('#search_name_' + i).find('[name*=typeid]').val() + ';'; - searchnames += $('#search_name_' + i).find(':text').val() + ';;'; + searchnames += ';' + $('#search_name_' + i).find('[name*=type]').val() + ';' + $('#search_name_' + i).find(':text').val(); + has_private = true; } } - Ajax.update_html(null, 'profile/ajax/buildnames/' + searchnames, function(data){ - var name = data.split(';'); - $('#public_name').html(name[0]); - $('#private_name').html(name[0] + name[1]); - }); + searchnames += (has_private ? '' : ';'); + $.xget('profile/ajax/buildnames/' + searchnames + '/' + isFemale, + function(data){ + var name = data.split(';'); + $('#public_name').html(name[0]); + $('#private_name').html(name[0] + name[1]); + }); +} + +// Promotions {{{1 + +function togglePromotionEdition() +{ + $(".promotion_edition").toggle(); } // Nationalities {{{1 function delNationality(i) { - $('#nationalite' + i).hide().find('select').val(''); + $('#nationality' + i).hide().find('select').val(''); } function addNationality() { var i = 0; - if ($('#nationalite2').find('select').val() == "") { + if ($('#nationality2').find('select').val() == "") { i = 2; - } else if ($('#nationalite3').find('select').val() == "") { + } else if ($('#nationality3').find('select').val() == "") { i = 3; } if ((i == 2) || (i == 3)) { - $('#nationalite' + i).show(); + $('#nationality' + i).show(); } } @@ -146,7 +154,11 @@ function prepareType(id) var edu = $('.edu_' + id).find("[name='edus[" + id + "][eduid]']").val() - 1; var sel = $('.edu_' + id).find('[name=edu_' + id + '_tmp]').val(); var html = ''; - var length = educationDegree[edu].length; + if (educationDegree[edu]) { + var length = educationDegree[edu].length; + } else { + var length = 0; + } for (i = 0; i < length; ++i) { html += ''; + } $('.edu_' + id).find("[name='edus[" + id + "][degreeid]']").html(html); } @@ -179,7 +195,7 @@ function addEdu() i++; $('#edu_add').addClass(prefix + i); i--; - $.get(platal_baseurl + 'profile/ajax/edu/' + i + '/' + class_parity, + $.xget('profile/ajax/edu/' + i + '/' + class_parity, function(data) { $('#edu_add').before(data); prepareType(i); @@ -245,6 +261,44 @@ function updateNetworking(i) $('#networking_' + i).find("[name='networking[" + i + "][name]']").val($('#networking_' + i).find('select option:selected').text()); } +// Hobby {{{1 + +function addHobby() +{ + var i = 0; + while ($('#hobby_' + i).length != 0) { + ++i; + } + var html = '' + + ' ' + + '
' + + ' ' + + ' ' + + ' site public' + + '  ' + + ' ' + + '
' + + '
' + + ' ' + + ' ' + + ' cross' + + ' ' + + '
' + + ' ' + + ''; + + $('#hobby').before(html); +} + +function removeHobby(id) +{ + $('#hobby_' + id).remove(); +} + // Addresses {{{1 function toggleAddress(id, val) @@ -285,38 +339,51 @@ function checkCurrentAddress(id) } } -function addAddress() +function addAddress(pid) { var i = 0; while ($('#addresses_' + i + '_cont').length != 0) { i++; } $('#add_address').before('
'); - Ajax.update_html('addresses_' + i + '_cont', 'profile/ajax/address/' + i, checkCurrentAddress()); + $('#addresses_' + i + '_cont').updateHtml('profile/ajax/address/' + i + '/' + pid, + checkCurrentAddress()); } -function addressChanged(prefid) +function addressChanged(prefid, color) { + var text = $('#' + prefid + '_cont').find("[name*='[text]']").val(); $('#' + prefid + '_cont').find('[name*=changed]').val("1"); + $.xpost('map_url/', { text:text, color:color }, function(data) { + if (data) { + $('#' + prefid + '_static_map_url').show(); + $('#' + prefid + '_static_map_url').find('img').attr('src', data); + } else { + $('#' + prefid + '_static_map_url').hide(); + $('#' + prefid + '_geocoding_removal').find('[name*=request]:checkbox').removeAttr('checked'); + } + }); } -function validGeoloc(prefid, id, geoloc) +function deleteGeocoding(prefid) { - if (geoloc == 1) { - $('#' + prefid + '_cont').find('[name*=text]').val($('#' + prefid + '_cont').find('[name*=geoloc]').val()); - $('#' + prefid + '_cont').find('[name*=postalText]').val($('#' + prefid + '_cont').find('[name*=geocodedPostalText]').val()); - } - if (geoloc > 0) { - $('#' + prefid + '_cont').find("[name*='[geoloc]']").remove(); + if($('#' + prefid + '_geocoding_removal').find('[name*=request]:checkbox:checked').length == 0) { + return true; } - $('#' + prefid + '_cont').find('[name*=text]').removeClass('error'); - $('#' + prefid + '_cont').find('[name*=geoloc_choice]').val(geoloc); - $('.' + prefid + '_geoloc').remove(); + + return confirm( + "La localisation de l'adresse sert à deux choses : te placer dans " + + "le planisphère et te faire apparaître dans la recherche avancée par " + + "pays, région, département, ville... La supprimer t'en fera disparaître. " + + "\nIl ne faut le faire que si cette localisation " + + "est réellement erronée. Avant de supprimer cette localisation, l'équipe de " + + "Polytechnique.org tentera de la réparer.\n\nConfirmes-tu ta " + + "demande de suppression de cette localisation ?"); } // {{{1 Phones -function addTel(prefid, prefname) +function addTel(prefid, prefname, subField, mainField, mainId) { var i = 0; var prefix = prefid + '_'; @@ -324,25 +391,53 @@ function addTel(prefid, prefname) i++; } $('#' + prefix + 'add').before('
'); - Ajax.update_html(prefix + i, 'profile/ajax/tel/' + prefid + '/' + prefname + '/' + i); + $('#' + prefix + i).updateHtml('profile/ajax/tel/' + prefid + '/' + prefname + '/' + i + '/' + subField + '/' + mainField + '/' + mainId); } -function removeTel(id) +function removeTel(prefname, prefid, id) { - $('#' + id).remove(); + var total = 0; + while ($('#' + prefid + '_' + total).length != 0) { + ++total; + } + $('#' + prefid + '_' + id).remove(); + for (var i = parseInt(id) + 1; i < total; ++i) { + renumberPhone(prefname, prefid, i); + } } function addPhoneComment(id) { - $(id + '_comment').show(); - $(id + '_addComment').hide(); + $('#' + id + '_comment').show(); + $('#' + id + '_addComment').hide(); } function removePhoneComment(id, pref) { - $(id + '_comment').hide(); - $(id + '_comment').find("[name='" + pref + "[comment]']").val(''); - $(id + '_addComment').show(); + $('#' + id + '_comment').hide(); + $('#' + id + '_comment').find("[name='" + pref + "[comment]']").val(''); + $('#' + id + '_addComment').show(); +} + +function renumberPhone(prefname, prefid, i) +{ + var telid = i - 1; + var telprefOld = prefname + '[' + i + ']'; + var telpref = prefname + '[' + telid + ']'; + var idOld = prefid + '_' + i; + var id = prefid + '_' + telid; + + $('#' + idOld).attr('id', id); + $('#' + id).find('div.titre').html('N°' + i); + $('#' + id).find('a.removeTel').attr('href', 'javascript:removeTel(\'' + prefname + '\',\'' + prefid + '\',' + telid + ')'); + $('#' + id).find('select').attr('name', telpref + '[type]'); + $('#' + id).find("[name='" + telprefOld + "[display]']").attr('name', telpref + '[display]'); + $('#' + id).find("[name='" + telprefOld + "[comment]']").attr('name', telpref + '[comment]'); + $('#' + id).find('a.removePhoneComment').attr('href', 'javascript:removePhoneComment(' + id + ',' + telpref + ')'); + $('#' + id).find('#' + idOld + '_addComment').attr('id', id + '_addComment'); + $('#' + id).find('#' + id + '_addComment').attr('href', 'javascript:addPhoneComment(' + id + ')'); + $('#' + id).find('#' + idOld + '_comment').attr('id', id + '_comment'); + $('#' + id).find("[name='" + telprefOld + "[pub]']").attr('name', telpref + '[pub]'); } // {{{1 Groups @@ -359,7 +454,7 @@ function addBinet() + '
' + text + '
' - + ' ' + + ' ' + ' cross' + ' ' + ' ' @@ -376,10 +471,17 @@ function updateGroupSubLink() // {{{1 Medals +function prepareMedal(i) +{ + getMedalName($('#medal_' + i).find('[name="medals[' + i + '][id]"]').val()); + buildGrade(i); +} + function updateMedal() { var val = $('#medals').find('[name*=medal_sel]').val(); - if (val && ($('#medal_' + val).length == 0)) { + + if ((multiple[val] && subgrades[val]) || $('.medal_name_' + val).length == 0) { $('#medal_add').show(); } else { $('#medal_add').hide(); @@ -388,55 +490,80 @@ function updateMedal() function getMedalName(id) { - $('#medal_name_' + id).html(names[id]); + $('.medal_name_' + id).html(names[id]); } -function buildGrade(id, current) +function buildGrade(i) { - var grade; - var subg = subgrades[id]; - var obj = $('#medal_grade_' + id); + var id = $('#medal_' + i).find('[name="medals[' + i + '][id]"]').val(); + var current = $('#medal_' + i).find('[name="medals_' + i + '_grade"]').val(); + var subg = subgrades[id]; + var obj = $('#medal_grade_' + i); if (!subg) { - obj.prepend(''); + obj.prepend(''); } else { - var html = 'Agrafe : '; html += ''; - for (grade = 0 ; grade < subg.length ; grade++) { + for (var grade = 0; grade < subg.length; ++grade) { html += '