X-Git-Url: http://git.polytechnique.org/?a=blobdiff_plain;f=htdocs%2Fjavascript%2Fprofile.js;h=527f8068af9a47b7fe1b46340c75176b0415fc5a;hb=f8a1899eceabb9648adb85071fab66d49d549337;hp=4bb7eb17752c593aa4c530f4d764aa280cc4f54f;hpb=9fce7016cd4cca4445f5c1037fe72f70b71ac3e5;p=platal.git diff --git a/htdocs/javascript/profile.js b/htdocs/javascript/profile.js index 4bb7eb1..527f806 100644 --- a/htdocs/javascript/profile.js +++ b/htdocs/javascript/profile.js @@ -45,10 +45,8 @@ function wizPage_onLoad(id) } 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()); - updateJobAlternates(i); + if ($('#jobs_0').find("[name='jobs[0][name]']").val() == '') { + registerEnterpriseAutocomplete(0); } break; } @@ -60,6 +58,12 @@ var educationDegreeName; var subgrades; var names; +// Publicity follows the following ordering: private < ax < public. +var publicity = []; +publicity['private'] = 0; +publicity['ax'] = 1; +publicity['public'] = 2; + // Names {{{1 function toggleNamesAdvanced() @@ -67,16 +71,18 @@ 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); + changeNameFlag(i); + }); } function removeSearchName(i, isFemale) @@ -113,11 +119,12 @@ function updateNameDisplay(isFemale) searchnames += $('#search_name_' + i).find(':text').val() + ';;'; } } - Ajax.update_html(null, 'profile/ajax/buildnames/' + searchnames + '/' + isFemale, function(data){ - var name = data.split(';'); - $('#public_name').html(name[0]); - $('#private_name').html(name[0] + name[1]); - }); + $.xget('profile/ajax/buildnames/' + searchnames + '/' + isFemale, + function(data){ + var name = data.split(';'); + $('#public_name').html(name[0]); + $('#private_name').html(name[0] + name[1]); + }); } function toggleParticle(id) @@ -140,19 +147,19 @@ function togglePromotionEdition() 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(); } } @@ -163,7 +170,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 += ''; } + // XXX: to be removed once SQL table profile_merge_issues is. + if (sel != '' && html == '') { + html += ''; + } $('.edu_' + id).find("[name='edus[" + id + "][degreeid]']").html(html); } @@ -309,7 +324,8 @@ function addAddress() i++; } $('#add_address').before('
'); - Ajax.update_html('addresses_' + i + '_cont', 'profile/ajax/address/' + i, checkCurrentAddress()); + $('#addresses_' + i + '_cont').updateHtml('profile/ajax/address/' + i, + checkCurrentAddress()); } function addressChanged(prefid) @@ -320,20 +336,20 @@ function addressChanged(prefid) function validGeoloc(prefid, id, geoloc) { 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()); + $('#' + prefid + '_cont').find('[name*=text]').val($('#' + prefid + '_cont').find('[name*=geocodedText]').val()); + $('#' + prefid + '_cont').find('[name*=postalText]').val(''); } if (geoloc > 0) { - $('#' + prefid + '_cont').find("[name*='[geoloc]']").remove(); + $('#' + prefid + '_cont').find("[name*='[geocodedText]']").remove(); } $('#' + prefid + '_cont').find('[name*=text]').removeClass('error'); - $('#' + prefid + '_cont').find('[name*=geoloc_choice]').val(geoloc); + $('#' + prefid + '_cont').find('[name*=geocodeChosen]').val(geoloc); $('.' + prefid + '_geoloc').remove(); } // {{{1 Phones -function addTel(prefid, prefname) +function addTel(prefid, prefname, subField, mainField, mainId) { var i = 0; var prefix = prefid + '_'; @@ -341,12 +357,19 @@ 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) @@ -362,6 +385,27 @@ function removePhoneComment(id, pref) $('#' + 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 function addBinet() @@ -473,59 +517,152 @@ function restoreJob(id, pref) $('#' + id).find("[name='" + pref + "[removed]']").val('0'); } -function updateJobSector(id, sel) +function makeAddJob(id) { - var sector = $('#job_' + id).find("[name='jobs[" + id + "][sector]']").val(); - if (sector == '') { - sector = '-1'; - } - Ajax.update_html('job_' + id + '_subSector', 'profile/ajax/sector/' + id + '/job_' + id + '/jobs[' + id + ']/' + sector + '/' + sel); + return function(data) + { + $('#add_job').before(data); + registerEnterpriseAutocomplete(id); + }; } -function updateJobSubSector(id, sel) +function addJob() { - var subSector = $('#job_' + id).find("[name='jobs[" + id + "][subSector]']").val(); - if (subSector == '') { - subSector = '-1'; + var i = 0; + while ($('#jobs_' + i).length != 0) { + ++i; } - Ajax.update_html('job_' + id + '_subSubSector', 'profile/ajax/sub_sector/' + id + '/' + subSector + '/' + sel); + $.get(platal_baseurl + 'profile/ajax/job/' + i, makeAddJob(i)); } -function updateJobAlternates(id) +function addEntreprise(id) { - var subSubSector = $('#job_' + id).find("[name='jobs[" + id + "][subSubSector]']").val(); - if (subSubSector != '') { - Ajax.update_html('job_' + id + '_alternates', 'profile/ajax/alternates/' + id + '/' + subSubSector); + $('.entreprise_' + id).toggle(); +} + +/** + * Adds a job term in job profile page + * @param jobid id of profile's job among his different jobs + * @param jtid id of job term to add + * @param full_name full text of job term + * @return false if the term already exist for this job, true otherwise + */ +function addJobTerm(jobid, jtid, full_name) +{ + var termid = 0; + var parentpath; + var formvarname; + if (jobid < 0) { + parentpath = ''; + jobid = ''; + formvarname = 'terms'; + } else { + parentpath = '#jobs_'+jobid+' '; + formvarname = 'jobs['+jobid+'][terms]'; + } + var lastJobTerm = $(parentpath + '.jobs_term:last'); + if (lastJobTerm.length != 0) { + termid = parseInt(lastJobTerm.children('input').attr('name').replace(/^(jobs\[[0-9]+\]\[terms\]|terms)\[([0-9]+)\]\[jtid\]/, '$2')) + 1; + if ($('#job'+jobid+'_term'+jtid).length > 0) { + return false; + } } + var newdiv = '